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())
avegaraju / UpdateProductDimensionsUseCase.fs
Last active Dec 25, 2018
Use case to update product dimensions with dependencies injected through the type constructor
View UpdateProductDimensionsUseCase.fs
type UpdateProductDimensions(dataStore: DataStore)=
//Other private methods removed for brevity
let updateDimensions(productId, height, length, weight, width)=
dataStore.getProduct productId
|> p-> p.updateDimensions(height, length, weight, width))
|> dataStore.updateProduct
member this.update (productId, (height,length,weight,width)) =
View DBModule.fs
module DB
open System.Data.Common
open Dapper
open Rows
open Domain
let allProducts(connection: DbConnection) =
let getProductType productType =
View ImpureFunctionAtTheBoundary.fs
open System.Data.SqlClient
let main argv =
let getDbConnection() =
let connection = new SqlConnection("a_real_sql_connection_string")
let getAllProducts() =
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")