Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Ashish avegaraju

I may be slow to respond.
View GitHub Profile
View MockingImposter.cs
public class ProductsImposter : IImposter
public Imposter Build()
return new ImposterDefinition("ProductsMock")
.DeclareResource("/api/Products", HttpMethod.Post)
.When(r => r.Content.Contains("Name:Test product"))
.Then(new ProductResponseCreator())
View MockMiddlewareInStartup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
//other configurations removed for brevity.
ImpostersAsMockConfiguration mockConfiguration =
new ImpostersAsMockConfiguration(new MockImpostersBuilder()
new MocksDataStore()
View StubMiddlewareInStartup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
//other configurations removed for brevity.
ImpostersAsStubConfiguration stubConfiguration =
new ImpostersAsStubConfiguration(new StubImpostersBuilder()
View MocksDataStore.cs
public class MocksDataStore
public AwsDynamoDbDataStore Create()
AmazonDynamoDBClient client = CreateAmazonDynamoDbClientWithLocalDbInstance();
AwsDynamoDbDataStore awsDynamoDbDataStore = new AwsDynamoDbDataStore(client);
return awsDynamoDbDataStore;
View OrdersResponseCreator.cs
public class OrdersResponseCreator : IResponseCreator
public Response CreateResponse()
var orderCreatedResponse = new OrderCreatedResponse
Message = "Order created.",
OrderId = (uint)new Random().Next(int.MaxValue)
avegaraju / OrdersImposter.cs
Created Feb 21, 2019
Imposter for orders endpoint which responds based on a condition.
View OrdersImposter.cs
public class OrdersImposter: IImposter
public Imposter Build()
return new ImposterDefinition("OrdersStub")
.DeclareResource("/api/Orders", HttpMethod.Post)
.When(r => r.Content.Contains("Product:1234"))
.Then(new OrdersResponseCreator())
View DBModule.fs
module DB
open System.Data.Common
open Dapper
open Rows
open Domain
let allProducts(connection: DbConnection) =
let getProductType productType =
View findfunctiontest.fs
let ``find_WhenProductDoesNotExists_ReturnsNone`` () =
let productId = Fixture().Create<int>();
let products = Fixture().CreateMany<Product>()
let result = UpdateProductDimensions.find (productId, products)
result.IsNone.Should().BeTrue("the product id does not exist")
View FunctionalProductDimensonsUpdate.fs
module UpdateProductDimensions
open Domain
open System
let find (productId:int, products: seq<Product>):Option<Product> =
|> Seq.tryPick<Product, Product>(fun x-> if x.ProductId = productId then Some(x) else None)
let update (productOption: Option<Product>, height, length, weight, width)=
View ImpureFunctionAtTheBoundary.fs
open System.Data.SqlClient
let main argv =
let getDbConnection() =
let connection = new SqlConnection("a_real_sql_connection_string")
let getAllProducts() =