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 CreatePO_IncorrectPO_ExceptionRaised() { var createPO = new CreatePurchaseOrder { Number = string.Empty, CustomerId = Guid.Empty, Lines = new List <PurchaseOrderLine>() { new PurchaseOrderLine { Description = string.Empty, Quantity = -50, IsPaired = true }, new PurchaseOrderLine { Description = "Robusta beans", Quantity = 700, IsPaired = false } } }; var client = CreateClient(); var ex = Assert.Throws <WebServiceException>(() => client.Post <PurchaseOrderResponse>(createPO)); Assert.IsTrue(ex.ResponseStatus.Errors.Count == 5); Assert.IsTrue(ex.ResponseStatus.Errors.Any(e => e.ErrorCode == "NotEmpty" && e.Message == "Specify Number for PurchaseOrder.")); Assert.IsTrue(ex.ResponseStatus.Errors.Any(e => e.ErrorCode == "NotEqual" && e.Message == "Specify nonempty CustomerId for PurchaseOrder.")); Assert.IsTrue(ex.ResponseStatus.Errors.Any(e => e.ErrorCode == "NotEmpty" && e.Message == "Each line in PurchaseOrder should have Description.")); Assert.IsTrue(ex.ResponseStatus.Errors.Any(e => e.ErrorCode == "GreaterThanOrEqual" && e.Message == "PurchaseOrderLine quantity should be positive or zero.")); Assert.IsTrue(ex.ResponseStatus.Errors.Any(e => e.ErrorCode == "Equal" && e.Message == "Initial IsPaired state should be false.")); }
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 CreatePO_CorrectPO_POCreated() { var createPO = new CreatePurchaseOrder { Number = "PO100025", CustomerId = starbucksBPResponse.Id, Lines = new List<PurchaseOrderLine>() { new PurchaseOrderLine { Description = "Excelsa beans", Quantity = 50, IsPaired = false }, new PurchaseOrderLine { Description = "Robusta beans", Quantity = 700, IsPaired = false } } }; var service = appHost.Container.Resolve<PurchaseOrderService>(); var response = service.Post(createPO); Assert.IsTrue(response.Id != Guid.Empty); }
public async Task <object> Any(CreatePurchaseOrder cmd) { await new PurchaseOrder() .AddLineItems(cmd.OrderLineItems) .SaveAsync(EventStore) .ConfigureAwait(false); return(Task.FromResult(true)); }
public void CreatePO_POWithOutLines_ExceptionRaised() { var createPO = new CreatePurchaseOrder { Number = string.Empty, CustomerId = Guid.Empty, Lines = new List <PurchaseOrderLine>() }; var client = CreateClient(); var ex = Assert.Throws <WebServiceException>(() => client.Post <PurchaseOrderResponse>(createPO)); Assert.IsTrue(ex.ResponseStatus.Errors.Any(e => e.ErrorCode == "NotEmpty" && e.Message == "Specify at least one Line for PurchaseOrder.")); }
public PurchaseOrderResponse Post(CreatePurchaseOrder request) { try { PurchaseOrderModel result = request.ConvertTo <PurchaseOrderModel>(); purchaseOrderRepository.Create(result); return(result.ConvertTo <PurchaseOrderResponse>()); } catch (Exception ex) { Log.Error(ex, "Something went wrong while posting PO."); throw; } }
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); }
public void PairInvoiceToPO_CanBePaired_PairedInvoiceReturned() { var createInvoice = new CreateInvoice { Number = "INV00900300", CreatedDate = DateTime.Now, DueDate = DateTime.Now.Date.AddDays(30), CustomerId = starbucksBPResponse.Id, VendorId = microsoftBPResponse.Id, TaxAmount = 368.99, NetAmount = 1844.95, TotalPrice = 2213.94, Lines = new List <InvoiceLine>() { new InvoiceLine { Description = "Xbox One S NBA 2K20 Bundle (1TB)", Quantity = 5, UnitPrice = 299, TaxRate = 20, TaxAmount = 299, TotalPrice = 1794, PoNumber = "PO000100", IsPaired = false }, new InvoiceLine { Description = "WRC 9 Deluxe Edition FIA World Rally Championship", Quantity = 5, UnitPrice = 69.99, TaxRate = 20, TaxAmount = 69.99, TotalPrice = 419.94, PoNumber = "PO000101", IsPaired = false } } }; var invoiceService = appHost.Container.Resolve <InvoiceService>(); var invoiceToPair = invoiceService.Post(createInvoice); var createPO100 = new CreatePurchaseOrder { Number = "PO000100", CustomerId = starbucksBPResponse.Id, Lines = new List <PurchaseOrderLine>() { new PurchaseOrderLine { Description = "Xbox One S NBA 2K20 Bundle (1TB)", Quantity = 5, IsPaired = false }, new PurchaseOrderLine { Description = "Xbox One S Star Wars Jedi: Fallen Order Bundle (1TB)", Quantity = 5, IsPaired = false } } }; var createPO101 = new CreatePurchaseOrder { Number = "PO000101", CustomerId = starbucksBPResponse.Id, Lines = new List <PurchaseOrderLine>() { new PurchaseOrderLine { Description = "WRC 9 Deluxe Edition FIA World Rally Championship", Quantity = 5, IsPaired = false }, new PurchaseOrderLine { Description = "Tony Hawk’s Pro Skater 1 + 2", Quantity = 5, IsPaired = false } } }; var poService = appHost.Container.Resolve <PurchaseOrderService>(); var poToPair100 = poService.Post(createPO100); var poToPair101 = poService.Post(createPO101); var patchInvoice = new PatchInvoice { Id = invoiceToPair.Id }; var pairedInvoice = invoiceService.Patch(patchInvoice); Assert.IsTrue(pairedInvoice.Lines.Where(l => l.IsPaired).Count() == 2); var getPO = new GetPurchaseOrder { Id = poToPair100.Id }; var partialyPairedPO100 = poService.Get(getPO); Assert.IsTrue(partialyPairedPO100.Lines.Where(l => l.IsPaired).Count() == 1); getPO.Id = poToPair101.Id; var partialyPairedPO101 = poService.Get(getPO); Assert.IsTrue(partialyPairedPO101.Lines.Where(l => l.IsPaired).Count() == 1); }