public void GivenPostalBoundary_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var country        = new Countries(this.Session).CountryByIsoCode["BE"];
            var postalBoundary = new PostalBoundaryBuilder(this.Session).WithLocality("Mechelen").WithCountry(country).Build();

            this.Session.Derive();
            this.Session.Commit();

            new PostalAddressBuilder(this.Session).Build();

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

            this.Session.Rollback();

            new PostalAddressBuilder(this.Session).WithAddress1("address1").Build();

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

            this.Session.Rollback();

            new PostalAddressBuilder(this.Session).WithPostalBoundary(postalBoundary).Build();

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

            this.Session.Rollback();

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

            this.Session.Rollback();

            new PostalAddressBuilder(this.Session).WithAddress1("address1").WithPostalBoundary(postalBoundary).Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenPostalBoundary_WhenDeriving_ThenCountryAndCityAreDerived()
        {
            var country        = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE");
            var postalBoundary = new PostalBoundaryBuilder(this.Session).WithLocality("locality").WithCountry(country).Build();

            var address = new PostalAddressBuilder(this.Session)
                          .WithAddress1("Haverwerf 15")
                          .WithPostalBoundary(postalBoundary)
                          .Build();

            this.Session.Derive();

            Assert.Equal(country, address.Country);
        }
Exemple #3
0
        private static void SetupFull()
        {
            var configuration = new Adapters.Memory.IntegerId.Configuration { ObjectFactory = Config.ObjectFactory };
            Config.Default = new Adapters.Memory.IntegerId.Database(configuration);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");

            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                new Setup(session, null).Apply();
                new Security(session).Apply();

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        basicXml = stringWriter.ToString();
                    }
                }

                var singleton = Singleton.Instance(session);
                singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build();

                var administrator = new PersonBuilder(session).WithUserName("administrator").WithLastName("Administrator").Build();

                var belgium = new Countries(session).CountryByIsoCode["BE"];
                var euro = belgium.Currency;

                var bank = new BankBuilder(session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build();

                var ownBankAccount = new OwnBankAccountBuilder(session)
                    .WithBankAccount(new BankAccountBuilder(session).WithBank(bank)
                                        .WithCurrency(euro)
                                        .WithIban("BE68539007547034")
                                        .WithNameOnAccount("Koen")
                                        .Build())
                    .WithDescription("Main bank account")
                    .Build();

                var postalBoundary = new PostalBoundaryBuilder(session).WithLocality("Mechelen").WithCountry(belgium).Build();
                var postalAddress = new PostalAddressBuilder(session).WithAddress1("Kleine Nieuwedijkstraat 2").WithPostalBoundary(postalBoundary).Build();

                var billingAddress =
                    new PartyContactMechanismBuilder(session).WithContactMechanism(postalAddress).WithContactPurpose(
                        new ContactMechanismPurposes(session).BillingAddress).WithUseAsDefault(true).Build();

                var shippingAddress =
                    new PartyContactMechanismBuilder(session).WithContactMechanism(postalAddress).WithContactPurpose(
                        new ContactMechanismPurposes(session).ShippingAddress).WithUseAsDefault(true).Build();

                var internalOrganisation = new InternalOrganisationBuilder(session)
                    .WithLocale(new Locales(session).EnglishGreatBritain)
                    .WithName("internalOrganisation")
                    .WithPreferredCurrency(euro)
                    .WithIncomingShipmentNumberPrefix("incoming shipmentno: ")
                    .WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ")
                    .WithPurchaseOrderNumberPrefix("purchase orderno: ")
                    .WithPartyContactMechanism(billingAddress)
                    .WithPartyContactMechanism(shippingAddress)
                    .WithEmployeeRole(new Roles(session).Administrator)
                    .WithEmployeeRole(new Roles(session).Procurement)
                    .WithEmployeeRole(new Roles(session).Sales)
                    .WithEmployeeRole(new Roles(session).Operations)
                    .WithEmployeeRole(new Roles(session).Administrator)
                    .WithDefaultPaymentMethod(ownBankAccount)
                    .Build();

                Singleton.Instance(session).DefaultInternalOrganisation = internalOrganisation;

                var facility = new WarehouseBuilder(session).WithName("facility").WithOwner(internalOrganisation).Build();
                internalOrganisation.DefaultFacility = facility;

                new StoreBuilder(session)
                    .WithName("store")
                    .WithDefaultFacility(facility)
                    .WithOwner(internalOrganisation)
                    .WithOutgoingShipmentNumberPrefix("shipmentno: ")
                    .WithSalesInvoiceNumberPrefix("invoiceno: ")
                    .WithSalesOrderNumberPrefix("orderno: ")
                    .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
                    .WithDefaultCarrier(new Carriers(session).Fedex)
                    .WithCreditLimit(500)
                    .WithPaymentGracePeriod(10)
                    .Build();

                var customer = new OrganisationBuilder(session).WithName("customer").WithLocale(singleton.DefaultLocale).Build();
                var supplier = new OrganisationBuilder(session).WithName("supplier").WithLocale(singleton.DefaultLocale).Build();
                var purchaser = new PersonBuilder(session).WithLastName("purchaser").WithUserName("purchaser").Build();
                var salesrep = new PersonBuilder(session).WithLastName("salesRep").WithUserName("salesRep").Build();
                var orderProcessor =
                    new PersonBuilder(session).WithLastName("orderProcessor").WithUserName("orderProcessor").Build();

                new CustomerRelationshipBuilder(session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new SupplierRelationshipBuilder(session).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(purchaser).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(salesrep).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(orderProcessor).WithEmployer(internalOrganisation).Build();

                new SalesRepRelationshipBuilder(session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithSalesRepresentative(salesrep).Build();

                session.Derive(true);

                var administrators = new UserGroups(session).Administrators;
                administrators.AddMember(administrator);

                var usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(session).Operations.UserGroupWhereRole);
                var userGroup = usergroups.First;

                userGroup.AddMember(orderProcessor);

                usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(session).Procurement.UserGroupWhereRole);
                userGroup = usergroups.First;

                userGroup.AddMember(purchaser);

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        fullXml = stringWriter.ToString();
                    }
                }
            }
        }
Exemple #4
0
        public static void Setup(IDatabase database)
        {
            CultureInfo.CurrentCulture   = new CultureInfo("en-GB");
            CultureInfo.CurrentUICulture = new CultureInfo("en-GB");

            using (var session = database.CreateSession())
            {
                new Setup(session, null).Apply();

                var administrator = new Users(session).GetUser("administrator");
                session.SetUser(administrator);

                var singleton = session.GetSingleton();

                new UserGroups(session).Administrators.AddMember(administrator);

                singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build();

                session.Derive();
                session.Commit();

                var belgium = new Countries(session).CountryByIsoCode["BE"];
                var euro    = belgium.Currency;

                var bank = new BankBuilder(session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build();

                var ownBankAccount = new OwnBankAccountBuilder(session)
                                     .WithBankAccount(new BankAccountBuilder(session).WithBank(bank)
                                                      .WithCurrency(euro)
                                                      .WithIban("BE68539007547034")
                                                      .WithNameOnAccount("Koen")
                                                      .Build())
                                     .WithDescription("Main bank account")
                                     .Build();

                var postalBoundary = new PostalBoundaryBuilder(session).WithLocality("Mechelen").WithCountry(belgium).Build();
                var postalAddress  = new PostalAddressBuilder(session).WithAddress1("Kleine Nieuwedijkstraat 2").WithPostalBoundary(postalBoundary).Build();

                var internalOrganisation = new OrganisationBuilder(session)
                                           .WithIsInternalOrganisation(true)
                                           .WithDoAccounting(false)
                                           .WithName("internalOrganisation")
                                           .WithPreferredCurrency(new Currencies(session).CurrencyByCode["EUR"])
                                           .WithIncomingShipmentNumberPrefix("incoming shipmentno: ")
                                           .WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ")
                                           .WithPurchaseOrderNumberPrefix("purchase orderno: ")
                                           .WithDefaultCollectionMethod(ownBankAccount)
                                           .WithSubAccountCounter(new CounterBuilder(session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build())
                                           .Build();

                internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                              .WithUseAsDefault(true)
                                                              .WithContactMechanism(postalAddress)
                                                              .WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence)
                                                              .WithContactPurpose(new ContactMechanismPurposes(session).BillingAddress)
                                                              .Build());

                var facility = new FacilityBuilder(session)
                               .WithFacilityType(new FacilityTypes(session).Warehouse)
                               .WithName("facility")
                               .WithOwner(internalOrganisation)
                               .Build();

                singleton.Settings.DefaultFacility = facility;

                var collectionMethod = new PaymentMethods(session).Extent().First;

                new StoreBuilder(session)
                .WithName("store")
                .WithBillingProcess(new BillingProcesses(session).BillingForShipmentItems)
                .WithInternalOrganisation(internalOrganisation)
                .WithOutgoingShipmentNumberPrefix("shipmentno: ")
                .WithSalesInvoiceNumberPrefix("invoiceno: ")
                .WithSalesOrderNumberPrefix("orderno: ")
                .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
                .WithDefaultCarrier(new Carriers(session).Fedex)
                .WithCreditLimit(500)
                .WithPaymentGracePeriod(10)
                .WithDefaultCollectionMethod(collectionMethod)
                .WithIsImmediatelyPicked(false)
                .Build();

                new ProductCategoryBuilder(session).WithName("Primary Category").Build();

                var customer       = new OrganisationBuilder(session).WithName("customer").WithLocale(singleton.DefaultLocale).Build();
                var supplier       = new OrganisationBuilder(session).WithName("supplier").WithLocale(singleton.DefaultLocale).Build();
                var purchaser      = new PersonBuilder(session).WithLastName("purchaser").WithUserName("purchaser").Build();
                var salesrep       = new PersonBuilder(session).WithLastName("salesRep").WithUserName("salesRep").Build();
                var orderProcessor = new PersonBuilder(session).WithLastName("orderProcessor").WithUserName("orderProcessor").Build();

                new CustomerRelationshipBuilder(session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new SupplierRelationshipBuilder(session).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(purchaser).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(salesrep).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(orderProcessor).WithEmployer(internalOrganisation).Build();

                new SalesRepRelationshipBuilder(session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithSalesRepresentative(salesrep).Build();

                var vatRate21 = new VatRateBuilder(session).WithRate(21).Build();

                var good1 = new NonUnifiedGoodBuilder(session)
                            .WithProductIdentification(new ProductNumberBuilder(session)
                                                       .WithIdentification("1")
                                                       .WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build())
                            .WithVatRate(vatRate21)
                            .WithName("good1")
                            .WithUnitOfMeasure(new UnitsOfMeasure(session).Piece)
                            .WithPart(new NonUnifiedPartBuilder(session)
                                      .WithProductIdentification(new PartNumberBuilder(session)
                                                                 .WithIdentification("1")
                                                                 .WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build())
                                      .WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build())
                            .Build();

                var good2 = new NonUnifiedGoodBuilder(session)
                            .WithProductIdentification(new ProductNumberBuilder(session)
                                                       .WithIdentification("2")
                                                       .WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build())
                            .WithVatRate(vatRate21)
                            .WithName("good2")
                            .WithUnitOfMeasure(new UnitsOfMeasure(session).Piece)
                            .WithPart(new NonUnifiedPartBuilder(session)
                                      .WithProductIdentification(new PartNumberBuilder(session)
                                                                 .WithIdentification("2")
                                                                 .WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build())
                                      .WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build())
                            .Build();

                var good3 = new NonUnifiedGoodBuilder(session)
                            .WithProductIdentification(new ProductNumberBuilder(session)
                                                       .WithIdentification("3")
                                                       .WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build())
                            .WithVatRate(vatRate21)
                            .WithName("good3")
                            .WithUnitOfMeasure(new UnitsOfMeasure(session).Piece)
                            .WithPart(new NonUnifiedPartBuilder(session)
                                      .WithProductIdentification(new PartNumberBuilder(session)
                                                                 .WithIdentification("3")
                                                                 .WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build())
                                      .WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build())
                            .Build();

                var catMain = new ProductCategoryBuilder(session).WithName("main cat").Build();

                var cat1 = new ProductCategoryBuilder(session)
                           .WithName("cat for good1")
                           .WithParent(catMain)
                           .WithProduct(good1)
                           .Build();

                var cat2 = new ProductCategoryBuilder(session)
                           .WithName("cat for good2")
                           .WithParent(catMain)
                           .WithProduct(good2)
                           .WithProduct(good3)
                           .Build();

                session.Derive();
                session.Commit();
            }
        }
Exemple #5
0
        public void GivenPostalBoundary_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var country = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var postalBoundary = new PostalBoundaryBuilder(this.DatabaseSession).WithLocality("Mechelen").WithCountry(country).Build();
            this.DatabaseSession.Derive();
            this.DatabaseSession.Commit();

            new PostalAddressBuilder(this.DatabaseSession).Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithAddress1("address1").Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithPostalBoundary(postalBoundary).Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithAddress1("address1").WithPostalBoundary(postalBoundary).Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemple #6
0
        public void GivenPostalBoundary_WhenDeriving_ThenFormattedFullAddressIsSet()
        {
            var country = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var postalBoundary = new PostalBoundaryBuilder(this.DatabaseSession).WithLocality("Mechelen").WithCountry(country).Build();
            this.DatabaseSession.Derive();
            this.DatabaseSession.Commit();

            var address = new PostalAddressBuilder(this.DatabaseSession).WithAddress1("Haverwerf 15").Build();

            this.DatabaseSession.Derive(false);

            Assert.AreEqual("Haverwerf 15", address.FormattedFullAddress);

            address.Address2 = "address2";

            this.DatabaseSession.Derive(false);

            Assert.AreEqual("Haverwerf 15<br />address2", address.FormattedFullAddress);

            address.RemoveAddress2();

            address.PostalBoundary = postalBoundary;

            this.DatabaseSession.Derive(true);

            Assert.AreEqual("Haverwerf 15<br />Mechelen<br />Belgium", address.FormattedFullAddress);

            address.PostalBoundary.PostalCode = "2800";

            this.DatabaseSession.Derive(true);

            Assert.AreEqual("Haverwerf 15<br />2800 Mechelen<br />Belgium", address.FormattedFullAddress);
        }
Exemple #7
0
        public void GivenPostalBoundary_WhenDeriving_ThenCountryIsDerived()
        {
            var country = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE");
            var postalBoundary = new PostalBoundaryBuilder(this.DatabaseSession).WithLocality("locality").WithCountry(country).Build();

            var address = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(postalBoundary)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.IsNull(address.PostalCode);
            Assert.IsNull(address.City);
            Assert.AreEqual(country, address.Country);
        }