public void GivenSalesInvoicePrintDocument_WhenPrinting_ThenMediaCreated() { // Arrange var demo = new Demo(this.Session, null); demo.Execute(); this.Session.Derive(true); var invoice = new SalesInvoices(this.Session).Extent().First; // Act invoice.Print(); this.Session.Derive(); this.Session.Commit(); // Assert Assert.True(invoice.PrintDocument.ExistMedia); var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var outputFile = System.IO.File.Create(System.IO.Path.Combine(desktopDir, "salesInvoice.odt")); var stream = new System.IO.MemoryStream(invoice.PrintDocument.Media.MediaContent.Data); stream.CopyTo(outputFile); stream.Close(); }
public void GivenWeeklyRepeatingSalesInvoice_WhenDayArrives_ThenNextInvoiceIsCreated() { var customer = new OrganisationBuilder(this.Session).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.Session) .WithAddress1("Haverwerf 15") .WithLocality("Mechelen") .WithCountry(new Countries(this.Session).FindBy(M.Country.IsoCode, "BE")) .Build(); var homeAddress = new PostalAddressBuilder(this.Session) .WithAddress1("Sint-Lambertuslaan 78") .WithLocality("Muizen") .WithCountry(new Countries(this.Session).FindBy(M.Country.IsoCode, "BE")) .Build(); var billingAddress = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(homeAddress) .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress) .WithUseAsDefault(true) .Build(); customer.AddPartyContactMechanism(billingAddress); new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build(); this.Session.Derive(); var invoice = new SalesInvoiceBuilder(this.Session) .WithInvoiceNumber("1") .WithBillToCustomer(customer) .WithAssignedBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .Build(); var mayFourteen2018 = new DateTime(2018, 5, 14, 12, 0, 0, DateTimeKind.Utc); var timeShift = mayFourteen2018 - this.Session.Now(); this.TimeShift = timeShift; var countBefore = new SalesInvoices(this.Session).Extent().Count; var repeatingInvoice = new RepeatingSalesInvoiceBuilder(this.Session) .WithSource(invoice) .WithFrequency(new TimeFrequencies(this.Session).Week) .WithDayOfWeek(new DaysOfWeek(this.Session).Monday) .WithNextExecutionDate(mayFourteen2018) .Build(); Assert.False(this.Session.Derive(false).HasErrors); RepeatingSalesInvoices.Daily(this.Session); Assert.Equal(countBefore + 1, new SalesInvoices(this.Session).Extent().Count); Assert.Equal(new DateTime(2018, 5, 21), repeatingInvoice.NextExecutionDate.Date); Assert.Single(repeatingInvoice.SalesInvoices); }
public void GivenSalesInvoice_WhenCreatingPrintModel_ThenPrintModelIsNotNull() { // Arrange var demo = new Demo(this.Session, null); demo.Execute(); this.Session.Derive(true); var invoice = new SalesInvoices(this.Session).Extent().First; // Act var printModel = new Print.SalesInvoiceModel.Model(invoice); // Assert Assert.NotNull(printModel); }
public void GivenSalesInvoice_WhenDeriving_ThenPrintDocumentWithoutMediaCreated() { // Arrange var demo = new Demo(this.Session, null); demo.Execute(); // Act this.Session.Derive(true); // Assert var invoice = new SalesInvoices(this.Session).Extent().First; Assert.True(invoice.ExistPrintDocument); Assert.False(invoice.PrintDocument.ExistMedia); }
public void GivenWeeklyRepeatingSalesInvoice_WhenRepeating_ThenRepeatStopReachingLastExecutionDate() { var customer = new OrganisationBuilder(this.Session).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.Session) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.Session) .WithLocality("Mechelen") .WithCountry(new Countries(this.Session).FindBy(M.Country.IsoCode, "BE")) .Build()) .Build(); var homeAddress = new PostalAddressBuilder(this.Session) .WithAddress1("Sint-Lambertuslaan 78") .WithPostalBoundary(new PostalBoundaryBuilder(this.Session) .WithLocality("Muizen") .WithCountry(new Countries(this.Session).FindBy(M.Country.IsoCode, "BE")) .Build()) .Build(); var billingAddress = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(homeAddress) .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress) .WithUseAsDefault(true) .Build(); customer.AddPartyContactMechanism(billingAddress); new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build(); this.Session.Derive(); var invoice = new SalesInvoiceBuilder(this.Session) .WithInvoiceNumber("1") .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .Build(); var mayFourteen2018 = new DateTime(2018, 5, 14, 12, 0, 0, DateTimeKind.Utc); var timeShift = mayFourteen2018 - DateTime.UtcNow; this.TimeShift = timeShift; var countBefore = new SalesInvoices(this.Session).Extent().Count; var repeatingInvoice = new RepeatingSalesInvoiceBuilder(this.Session) .WithSource(invoice) .WithFrequency(new TimeFrequencies(this.Session).Week) .WithDayOfWeek(new DaysOfWeek(this.Session).Monday) .WithNextExecutionDate(mayFourteen2018) .WithFinalExecutionDate(mayFourteen2018.AddDays(21)) .Build(); Assert.False(this.Session.Derive(false).HasErrors); RepeatingSalesInvoices.Daily(this.Session); Assert.Equal(countBefore + 1, new SalesInvoices(this.Session).Extent().Count); Assert.Equal(new DateTime(2018, 5, 21), repeatingInvoice.NextExecutionDate.Date); Assert.Equal(new DateTime(2018, 5, 14), repeatingInvoice.PreviousExecutionDate.Value.Date); Assert.Single(repeatingInvoice.SalesInvoices); var mayTwentyOne2018 = new DateTime(2018, 5, 21, 12, 0, 0, DateTimeKind.Utc); timeShift = mayTwentyOne2018 - DateTime.UtcNow; this.TimeShift = timeShift; Assert.False(this.Session.Derive(false).HasErrors); RepeatingSalesInvoices.Daily(this.Session); Assert.Equal(countBefore + 2, new SalesInvoices(this.Session).Extent().Count); Assert.Equal(new DateTime(2018, 5, 28), repeatingInvoice.NextExecutionDate.Date); Assert.Equal(2, repeatingInvoice.SalesInvoices.Count); var mayTwentyEight2018 = new DateTime(2018, 5, 28, 12, 0, 0, DateTimeKind.Utc); timeShift = mayTwentyEight2018 - DateTime.UtcNow; this.TimeShift = timeShift; Assert.False(this.Session.Derive(false).HasErrors); RepeatingSalesInvoices.Daily(this.Session); Assert.Equal(countBefore + 3, new SalesInvoices(this.Session).Extent().Count); Assert.Equal(new DateTime(2018, 6, 4), repeatingInvoice.NextExecutionDate.Date); Assert.Equal(new DateTime(2018, 5, 28), repeatingInvoice.PreviousExecutionDate.Value.Date); Assert.Equal(3, repeatingInvoice.SalesInvoices.Count); var juneFour2018 = new DateTime(2018, 6, 4, 12, 0, 0, DateTimeKind.Utc); timeShift = juneFour2018 - DateTime.UtcNow; this.TimeShift = timeShift; Assert.False(this.Session.Derive(false).HasErrors); RepeatingSalesInvoices.Daily(this.Session); Assert.Equal(countBefore + 4, new SalesInvoices(this.Session).Extent().Count); Assert.Equal(new DateTime(2018, 6, 4), repeatingInvoice.NextExecutionDate.Date); Assert.Equal(new DateTime(2018, 6, 4), repeatingInvoice.PreviousExecutionDate.Value.Date); Assert.Equal(4, repeatingInvoice.SalesInvoices.Count); var juneEleven2018 = new DateTime(2018, 6, 11, 12, 0, 0, DateTimeKind.Utc); timeShift = juneEleven2018 - DateTime.UtcNow; this.TimeShift = timeShift; Assert.False(this.Session.Derive(false).HasErrors); RepeatingSalesInvoices.Daily(this.Session); Assert.Equal(countBefore + 4, new SalesInvoices(this.Session).Extent().Count); Assert.Equal(new DateTime(2018, 6, 4), repeatingInvoice.NextExecutionDate.Date); Assert.Equal(new DateTime(2018, 6, 4), repeatingInvoice.PreviousExecutionDate.Value.Date); Assert.Equal(4, repeatingInvoice.SalesInvoices.Count); }