Skip to content

Instantly share code, notes, and snippets.

@senorincognito
senorincognito / index.js
Created August 28, 2018 10:59
jsonToPlain and jsonToQueryParams
export function jsonToPlain (obj) {
if (!obj) {
return ''
}
return Object.keys(obj).map(key => {
return key + '=' + encodeURIComponent(obj[key])
}).join('&')
}
export function jsonToQueryParams (obj) {
@senorincognito
senorincognito / FakeHttpMessageHandler.cs
Created August 3, 2018 08:41
MessageHandler for HttpClient to test HttpRequests
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Tests
{
public class FakeHttpMessageHandler : HttpMessageHandler
{
public int CallCount;
@senorincognito
senorincognito / MockFactory.cs
Created July 27, 2018 13:58
Create Mock of C# class with Moq and Reflection
public static class MockFactory
{
public static Mock<T> CreateMock<T>() where T : class
{
var ctorParams = typeof(T).GetConstructors().OrderByDescending(x => x.GetParameters().Length).First()
.GetParameters().Select<ParameterInfo, object>(x => null).ToArray();
return new Mock<T>(ctorParams);
}
}
@senorincognito
senorincognito / ByteArrayCombine.cs
Last active August 18, 2016 14:11
Concatenate two C# byte arrays
public static byte[] ArrayCombine(byte[] arr1, byte[] arr2)
{
var result = new byte[arr1.Length + arr2.Length];
Buffer.BlockCopy(arr1, 0, result, 0, arr1.Length);
Buffer.BlockCopy(arr2, 0, result, arr1.Length, arr2.Length);
return result;
}