public void CreatePurchaseOrder_VendorExists_ReturnsPurchaseOrderCreatedEvent() { /// Arrange // Get a create purchase order command with the vendor. // (By the time the command gets to the domain it's already been structurally validated.) var command = new CreatePurchaseOrder( vendorId: Guid.NewGuid(), lines: new List <CreatePurchaseOrderLine> { new CreatePurchaseOrderLine(productId: Guid.NewGuid(), quantity: 354M, measure: "EA", pricePerUnit: 4.75M), new CreatePurchaseOrderLine(productId: Guid.NewGuid(), quantity: 10M, measure: "EA", pricePerUnit: 24.99M) } ); // Assume the vendor exists. Func <Guid, bool> getVendorExists = _ => true; // Get some id as the next id. var nextId = Guid.NewGuid(); // Get the event we expect the domain to return. var expected = new PurchaseOrderCreated( purchaseOrderId: nextId, status: PurchaseOrderStatus.Unpaid, vendorId: command.VendorId, lines: command.Lines.Select(l => new PurchaseOrderLine(l.ProductId, l.Quantity, l.Measure, l.PricePerUnit)) ); /// Act var actual = JC.CreatePurchaseOrder(getVendorExists, nextId, command); /// Assert CustomAssert.CoreValuesAreEqual(expected, actual); }
public void CreatePurchaseOrder_VendorDoesNotExist_ReturnsExpectedError() { /// Arrange // Get a create purchase order command with the vendor. // (By the time the command gets to the domain it's already been structurally validated.) var command = new CreatePurchaseOrder( vendorId: Guid.NewGuid(), lines: new List <CreatePurchaseOrderLine> { new CreatePurchaseOrderLine(productId: Guid.NewGuid(), quantity: 354M, measure: "EA", pricePerUnit: 4.75M), new CreatePurchaseOrderLine(productId: Guid.NewGuid(), quantity: 10M, measure: "EA", pricePerUnit: 24.99M) } ); // Assume the vendor does not exist. Func <Guid, bool> getVendorExists = _ => false; // Get some id as the next id. var nextId = Guid.NewGuid(); // Get the error we expect the domain to return. var expected = new VendorDoesNotExist(command.VendorId); /// Act var actual = JC.CreatePurchaseOrder(getVendorExists, nextId, command); /// Assert CustomAssert.CoreValuesAreEqual(expected, actual); }
public void loadtest() { // Get a MongoClient. var client = new MongoClient("mongodb://localhost:27017"); Func <Guid, bool> getVendorExists = _ => true; Func <Guid, PurchaseOrderForAddProductTask> getPurchaseOrderForAddProductTask = purchaseOrderId => MongoDBEventStore.GetPurchaseOrderForAddProductTask(client, purchaseOrderId); Func <Guid, PurchaseOrderForRemoveProductTask> getPurchaseOrderForRemoveProductTask = purchaseOrderId => MongoDBEventStore.GetPurchaseOrderForRemoveProductTask(client, purchaseOrderId); Func <Guid> nextId = Guid.NewGuid; var create = new CreatePurchaseOrder( vendorId: nextId(), lines: new List <CreatePurchaseOrderLine> { new CreatePurchaseOrderLine( productId: nextId(), quantity: 14.5M, measure: "FT", pricePerUnit: 2.8M), new CreatePurchaseOrderLine( productId: nextId(), quantity: 1.5M, measure: "YD", pricePerUnit: 235.82M) }); Guid purchaseOrderId = nextId(); var createResult = JC.CreatePurchaseOrder( getVendorExists: getVendorExists, nextId: purchaseOrderId, command: create); MongoDBEventStore.Save(client, nextId(), createResult); var expected = getPurchaseOrderForAddProductTask(purchaseOrderId); var productId = Guid.NewGuid(); // Put 10000 events in the store for this purchase order. for (int i = 0; i < 5000; i++) { var addResult = new ProductAddedToPurchaseOrder( purchaseOrderId: purchaseOrderId, productId: productId, measure: "EA", quantity: i); MongoDBEventStore.Save(client, nextId(), addResult); var removeResult = new ProductRemovedFromPurchaseOrder( purchaseOrderId: purchaseOrderId, productId: productId); MongoDBEventStore.Save(client, nextId(), removeResult); } // Now for the time trial var stopwatch = new Stopwatch(); stopwatch.Start(); var actual = getPurchaseOrderForAddProductTask(purchaseOrderId); stopwatch.Stop(); CustomAssert.CoreValuesAreEqual(expected, actual); Assert.Equal(0, stopwatch.ElapsedMilliseconds); }