public void GivenWeeklyRepeatingSalesInvoice_WhenDeriving_ThenDayOfWeekMustMatchNextExecutionDate()
        {
            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 nextExecutionDate = this.Session.Now().AddDays(1);
            var weekDay           = nextExecutionDate.DayOfWeek.ToString();
            var daysOfWeek        = new DaysOfWeek(this.Session).Extent();

            daysOfWeek.Filter.AddEquals(M.Enumeration.Name, weekDay);
            var dayOfWeek = daysOfWeek.First;

            var repeatingInvoice = new RepeatingSalesInvoiceBuilder(this.Session)
                                   .WithSource(invoice)
                                   .WithFrequency(new TimeFrequencies(this.Session).Week)
                                   .WithDayOfWeek(dayOfWeek)
                                   .WithNextExecutionDate(nextExecutionDate)
                                   .Build();

            Assert.False(this.Session.Derive(false).HasErrors);

            repeatingInvoice.NextExecutionDate = repeatingInvoice.NextExecutionDate.AddDays(1);
            var validation = this.Session.Derive(false);

            Assert.True(validation.HasErrors);
            Assert.Single(validation.Errors);
            Assert.Contains(MetaRepeatingSalesInvoice.Instance.DayOfWeek, validation.Errors.First().RoleTypes);
        }
Example #2
0
        public void GivenRepeatingSalesInvoice_WhenDeriving_ThenFrequencyIsEitherMontlyOrWeekly()
        {
            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 repeatingInvoice = new RepeatingSalesInvoiceBuilder(this.Session)
                                   .WithSource(invoice)
                                   .WithFrequency(new TimeFrequencies(this.Session).Month)
                                   .WithNextExecutionDate(this.Session.Now().AddDays(1))
                                   .Build();

            Assert.False(this.Session.Derive(false).HasErrors);

            var weekDay    = repeatingInvoice.NextExecutionDate.DayOfWeek.ToString();
            var daysOfWeek = new DaysOfWeek(this.Session).Extent();

            daysOfWeek.Filter.AddEquals(M.Enumeration.Name, weekDay);
            var dayOfWeek = daysOfWeek.First;

            repeatingInvoice.Frequency = new TimeFrequencies(this.Session).Week;
            repeatingInvoice.DayOfWeek = dayOfWeek;

            Assert.False(this.Session.Derive(false).HasErrors);

            repeatingInvoice.Frequency = new TimeFrequencies(this.Session).Day;

            var validation = this.Session.Derive(false);

            Assert.True(validation.HasErrors);
            Assert.Single(validation.Errors);
            Assert.Contains(validation.Errors, v => v.Message.Contains("Selected frequency is not supported"));
        }