Skip to content

Instantly share code, notes, and snippets.

[TestMethod]
public void ShouldNotAccessDataAccessLayerDirectly() {
Type webRepresentative = typeof(HomeController);
Type dataAccessRepresentative = typeof(BaseRepository);
var references = webRepresentative.Assembly.GetReferencedAssemblies();
AssemblyName webAssemblyName = webRepresentative.Assembly.GetName();
AssemblyName unwantedReferenceAssemblyName = dataAccessRepresentative.Assembly.GetName();
public class Option<T>: IEnumerable<T>
{
private T[] data;
private Option(T[] data)
{
this.data = data;
}
public static Option<T> Create(T element)
public static class IEnumerableExtensions
{
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (T obj in source)
action(obj);
}
public static IEnumerable<T> LazyDefaultIfEmpty<T>(this IEnumerable<T> source,
Func<T> defaultFactory)
public struct NullableBool
{
private readonly bool? value;
public NullableBool(bool? value)
{
this.value = value;
}
public static implicit operator bool(NullableBool input)
using System;
using System.IO;
using System.Net;
namespace Demo
{
class Failed
{
}
public static class OptionExtensions
{
public static async Task<Option<T>> AsOption<T>(this Task<T> item) => AsOption<T>(await item);
public static Option<T> AsOption<T>(this T item) => item == null ? Option.None<T>() : Option.Some<T>(item);
}
public abstract class Option<T> : IEquatable<Option<T>>, IEquatable<T>
{
public abstract void Do(Action<T> action);
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@farhad-taran
farhad-taran / elasticsearch.md
Created May 25, 2018 08:28 — forked from nicolashery/elasticsearch.md
Elasticsearch: updating the mappings and settings of an existing index

Elasticsearch: updating the mappings and settings of an existing index

Note: This was written using elasticsearch 0.9.

Elasticsearch will automatically create an index (with basic settings and mappings) for you if you post a first document:

$ curl -X POST 'http://localhost:9200/thegame/weapons/1' -d \
'{
  "_id": 1,
@farhad-taran
farhad-taran / MoqExtensions.cs
Created November 9, 2018 17:01 — forked from ngocvantran/MoqExtensions.cs
Extension methods to quickly ignore arguments without repeating It.IsAny<>()
using System;
using System.Linq.Expressions;
using Moq.Language.Flow;
namespace Moq
{
public static class MoqExtensions
{
public static ISetup<T, TResult> SetupIgnoreArgs<T, TResult>(this Mock<T> mock,
Expression<Func<T, TResult>> expression)
@farhad-taran
farhad-taran / README.md
Last active May 31, 2020 11:42
Setting up Autofixture and Automoq

When using Autofixture I usually combine it with Automoq to automatically moq my dependencies in the SUT that I am excercising.

public class AutoMoqDataAttribute : AutoDataAttribute
{
    public AutoMoqDataAttribute() : base(() => new Fixture().Customize(new AutoMoqCustomization()))
    {
    }
}

public class InlineAutoMoqDataAttribute : InlineAutoDataAttribute