public void GivenPaymentApplication_WhenDeriving_ThenRequiredRelationsMustExist() { var billToContactMechanism = new EmailAddressBuilder(this.Session).WithElectronicAddressString("*****@*****.**").Build(); var customer = new PersonBuilder(this.Session).WithLastName("customer").Build(); new CustomerRelationshipBuilder(this.Session) .WithCustomer(customer) .Build(); var good1 = new Goods(this.Session).FindBy(M.Good.Name, "good1"); new SalesInvoiceBuilder(this.Session) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session) .WithProduct(good1) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .WithQuantity(1) .WithAssignedUnitPrice(100M) .Build()) .Build(); var builder = new PaymentApplicationBuilder(this.Session); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void GivenPaymentApplication_WhenDeriving_ThenAmountAppliedCannotBeLargerThenAmountReceived() { var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(1000M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build()) .Build(); this.DatabaseSession.Derive(true); var receipt = new ReceiptBuilder(this.DatabaseSession) .WithAmount(100) .WithEffectiveDate(DateTime.UtcNow) .Build(); var paymentApplication = new PaymentApplicationBuilder(this.DatabaseSession) .WithAmountApplied(200) .WithInvoiceItem(invoice.InvoiceItems[0]) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); receipt.AddPaymentApplication(paymentApplication); var derivationLog = this.DatabaseSession.Derive(); Assert.IsTrue(derivationLog.HasErrors); Assert.Contains(PaymentApplications.Meta.AmountApplied, derivationLog.Errors[0].RoleTypes); }
public void GivenPaymentApplication_WhenDeriving_ThenAmountAppliedCannotBeLargerThenAmountReceived() { var contactMechanism = new ContactMechanisms(this.Session).Extent().First; var good = new Goods(this.Session).FindBy(M.Good.Name, "good1"); var customer = new PersonBuilder(this.Session).WithLastName("customer").Build(); new CustomerRelationshipBuilder(this.Session) .WithCustomer(customer) .Build(); var invoice = new SalesInvoiceBuilder(this.Session) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session).WithProduct(good).WithQuantity(1).WithAssignedUnitPrice(1000M).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem).Build()) .Build(); this.Session.Derive(); var receipt = new ReceiptBuilder(this.Session) .WithAmount(100) .WithEffectiveDate(this.Session.Now()) .Build(); var paymentApplication = new PaymentApplicationBuilder(this.Session) .WithAmountApplied(200) .WithInvoiceItem(invoice.InvoiceItems[0]) .Build(); this.Session.Derive(); this.Session.Commit(); receipt.AddPaymentApplication(paymentApplication); var derivationLog = this.Session.Derive(false); Assert.True(derivationLog.HasErrors); Assert.Contains(M.PaymentApplication.AmountApplied, derivationLog.Errors[0].RoleTypes); }
public void GivenPaymentApplication_WhenDeriving_ThenRequiredRelationsMustExist() { var billToContactMechanism = new EmailAddressBuilder(this.DatabaseSession).WithElectronicAddressString("*****@*****.**").Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); new SalesInvoiceBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession) .WithProduct(new GoodBuilder(this.DatabaseSession).WithName("good").Build()) .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem) .WithQuantity(1) .WithActualUnitPrice(100M) .Build()) .Build(); var builder = new PaymentApplicationBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithAmountApplied(0); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }