This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
.Build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
//other configurations removed for brevity. | |
ImpostersAsMockConfiguration mockConfiguration = | |
new ImpostersAsMockConfiguration(new MockImpostersBuilder() | |
.CreateMockImposters(), | |
new MocksDataStore() | |
.Create()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
//other configurations removed for brevity. | |
ImpostersAsStubConfiguration stubConfiguration = | |
new ImpostersAsStubConfiguration(new StubImpostersBuilder() | |
.CreateStubImposters()); | |
app.UseStubImposters(stubConfiguration); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MocksDataStore | |
{ | |
public AwsDynamoDbDataStore Create() | |
{ | |
AmazonDynamoDBClient client = CreateAmazonDynamoDbClientWithLocalDbInstance(); | |
AwsDynamoDbDataStore awsDynamoDbDataStore = new AwsDynamoDbDataStore(client); | |
return awsDynamoDbDataStore; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrdersResponseCreator : IResponseCreator | |
{ | |
public Response CreateResponse() | |
{ | |
var orderCreatedResponse = new OrderCreatedResponse | |
{ | |
Message = "Order created.", | |
OrderId = (uint)new Random().Next(int.MaxValue) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
.Build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type UpdateProductDimensions(dataStore: DataStore)= | |
//Other private methods removed for brevity | |
let updateDimensions(productId, height, length, weight, width)= | |
dataStore.getProduct productId | |
|> Result.map(fun p-> p.updateDimensions(height, length, weight, width)) | |
|> Result.map dataStore.updateProduct | |
member this.update (productId, (height,length,weight,width)) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DB | |
open System.Data.Common | |
open Dapper | |
open Rows | |
open Domain | |
let allProducts(connection: DbConnection) = | |
let getProductType productType = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Data.SqlClient | |
[<EntryPoint>] | |
let main argv = | |
let getDbConnection() = | |
let connection = new SqlConnection("a_real_sql_connection_string") | |
connection.Open() | |
connection | |
let getAllProducts() = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<Fact>] | |
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") |
NewerOlder