Skip to content

Instantly share code, notes, and snippets.

View bymyslf's full-sized avatar

Luís Barbosa bymyslf

View GitHub Profile
@bymyslf
bymyslf / EnumerableAssert.cs
Last active May 30, 2016 17:00
IEnumerable assert utilities
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public static class EnumerableAssert
{
/// <summary>
/// Assert that an array, list or other collection is empty
@bymyslf
bymyslf / DateTimeExtensions.cs
Last active May 27, 2016 16:29
DateTime extension methods
using System;
using System.Collections.Generic;
public static class DateTimeExtensions
{
public static bool IsBusinessDay(this DateTime date)
{
return date.DayOfWeek != DayOfWeek.Saturday
&& date.DayOfWeek != DayOfWeek.Sunday;
}
@bymyslf
bymyslf / MoqExtensions.cs
Created May 31, 2016 08:06
Moq extension methods
using System;
using System.Collections;
using System.Threading.Tasks;
using Moq.Language;
using Moq.Language.Flow;
public static class MoqExtensions
{
//see: http://haacked.com/archive/2010/11/24/moq-sequences-revisited.aspx/
public static void ReturnsInOrder<T, TResult>(this ISetup<T, TResult> setup, params object[] results)
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
internal class ObjectRenderer
{
private TextWriter writer;
private static readonly Func<PropertyInfo, object, object> propertyGetter;
using System;
using System.Threading;
using System.Threading.Tasks;
public static class TaskExtensions
{
public static T RunTaskSynchronously<T>(this Task<T> task)
{
using (NoSynchronizationContextScope.Enter())
{
using System;
public static class ConvertExtensions
{
public static T To<T>(this object obj)
{
try
{
Type type = typeof(T);
using System.Net.Http;
internal class EmptyContent : ByteArrayContent
{
public EmptyContent()
: base(new byte[0])
{
}
}
@bymyslf
bymyslf / ModelBinderTestsBase.cs
Created October 22, 2016 16:09
Model binder unit test base class
using System.Collections.Specialized;
using System.Web;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
//http://mdavies.net/2013/06/07/unit-testing-mvc3mvc4-model-binders/
public abstract class ModelBinderTestsBase<TBinder, TModel>
where TBinder : IModelBinder, new()
{
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
public class NotAcceptableResult : IHttpActionResult
{
private readonly HttpRequestMessage request;
@bymyslf
bymyslf / RegisterWatcherToCopy.psm1
Last active January 2, 2017 09:09
PowerShell module to register a FileSystemWatcher to copy files from source folder to destination folder
function Register-Watcher-ToCopy {
param (
[string]$sourceFolder,
[string]$destFolder,
[string]$id
)
$filter = "*.*"
$watcher = New-Object System.IO.FileSystemWatcher $sourceFolder, $filter -Property @{
IncludeSubdirectories = $true