public void GivenInternalOrganisationWithCustomFiscalYearStartMonthAndNotExistActualAccountingPeriod_WhenStartingNewFiscalYear_ThenAccountingPeriodsAreCreated() { this.InstantiateObjects(this.DatabaseSession); var organisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithFiscalYearStartMonth(05) .WithFiscalYearStartDay(15) .WithPartyContactMechanism(this.billingAddress) .Build(); organisation.AppsStartNewFiscalYear(); var fromDate = DateTimeFactory.CreateDate(DateTime.UtcNow.Year, 05, 15).Date; var month = organisation.ActualAccountingPeriod; Assert.AreEqual(1, month.PeriodNumber); Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Month, month.TimeFrequency); Assert.AreEqual(fromDate, month.FromDate); Assert.AreEqual(fromDate.AddMonths(1).AddSeconds(-1).Date, month.ThroughDate); Assert.IsTrue(month.ExistParent); var trimester = month.Parent; Assert.AreEqual(1, trimester.PeriodNumber); Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Trimester, trimester.TimeFrequency); Assert.AreEqual(fromDate, trimester.FromDate); Assert.AreEqual(fromDate.AddMonths(3).AddSeconds(-1).Date, trimester.ThroughDate); Assert.IsTrue(trimester.ExistParent); var semester = trimester.Parent; Assert.AreEqual(1, semester.PeriodNumber); Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Semester, semester.TimeFrequency); Assert.AreEqual(fromDate, semester.FromDate); Assert.AreEqual(fromDate.AddMonths(6).AddSeconds(-1).Date, semester.ThroughDate); Assert.IsTrue(semester.ExistParent); var year = semester.Parent; Assert.AreEqual(1, year.PeriodNumber); Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Year, year.TimeFrequency); Assert.AreEqual(fromDate, year.FromDate); Assert.AreEqual(fromDate.AddMonths(12).AddSeconds(-1).Date, year.ThroughDate); Assert.IsFalse(year.ExistParent); Assert.IsTrue(organisation.ExistActualAccountingPeriod); Assert.Contains(organisation.ActualAccountingPeriod, organisation.AccountingPeriods); Assert.Contains(trimester, organisation.AccountingPeriods); Assert.Contains(semester, organisation.AccountingPeriods); Assert.Contains(year, organisation.AccountingPeriods); }
public void GivenInternalOrganisationWithActiveActualAccountingPeriod_WhenStartingNewFiscalYear_ThenNothingHappens() { this.InstantiateObjects(this.DatabaseSession); var organisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithFiscalYearStartMonth(05) .WithFiscalYearStartDay(15) .WithPartyContactMechanism(this.billingAddress) .Build(); organisation.AppsStartNewFiscalYear(); Assert.AreEqual(4, this.DatabaseSession.Extent<AccountingPeriod>().Count); organisation.AppsStartNewFiscalYear(); Assert.AreEqual(4, this.DatabaseSession.Extent<AccountingPeriod>().Count); }
public void GivenPurchaseInvoice_WhenGettingInvoiceNumberWithoutFormat_ThenInvoiceNumberShouldBeReturned() { var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("org") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithDefaultPaymentMethod(ownBankAccount) .WithPreferredCurrency(euro) .Build(); var invoice1 = new PurchaseInvoiceBuilder(this.DatabaseSession) .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.DatabaseSession).PurchaseInvoice) .WithBilledToInternalOrganisation(internalOrganisation) .Build(); Assert.AreEqual("1", invoice1.InvoiceNumber); var invoice2 = new PurchaseInvoiceBuilder(this.DatabaseSession) .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.DatabaseSession).PurchaseInvoice) .WithBilledToInternalOrganisation(internalOrganisation) .Build(); Assert.AreEqual("2", invoice2.InvoiceNumber); }
public void GivenPickListCreatedByOrderProcessor_WhenCurrentUserInAnotherOrderProcessorUserGroup_ThenAccessIsDenied() { var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("own account") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var address1 = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billingAddress = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(address1) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var orderProcessor2 = new PersonBuilder(this.DatabaseSession).WithLastName("orderProcessor2").WithUserName("orderProcessor2").Build(); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("employer2") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithEmployeeRole(new Roles(this.DatabaseSession).Operations) .WithDefaultPaymentMethod(ownBankAccount) .WithPreferredCurrency(euro) .WithPartyContactMechanism(billingAddress) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var usergroups = internalOrganisation.UserGroupsWhereParty; usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Operations.UserGroupWhereRole); var orderProcessorUserGroup = usergroups.First; new EmploymentBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithEmployee(orderProcessor2) .WithEmployer(internalOrganisation) .Build(); orderProcessorUserGroup.AddMember(orderProcessor2); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]); var pickList = new PickListBuilder(this.DatabaseSession).Build(); this.DatabaseSession.Derive(true); var acl = new AccessControlList(pickList, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanWrite(PickLists.Meta.Picker)); Assert.IsTrue(acl.CanRead(PickLists.Meta.Picker)); Assert.IsTrue(acl.CanExecute(PickLists.Meta.Cancel)); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor2", "Forms"), new string[0]); acl = new AccessControlList(pickList, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.HasReadOperation); }
public void GivenCustomerShipment_WhenDeriving_ThenBillFromContactMechanismMustExist() { var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("own account") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var address1 = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billingAddress = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(address1) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithName("internalOrganisation") .WithPreferredCurrency(euro) .WithDefaultPaymentMethod(ownBankAccount) .Build(); internalOrganisation.AddPartyContactMechanism(billingAddress); this.DatabaseSession.Derive(true); var shipment1 = new CustomerShipmentBuilder(this.DatabaseSession) .WithBillFromInternalOrganisation(internalOrganisation) .WithShipToParty(customer) .WithShipToAddress(new PostalAddresses(this.DatabaseSession).Extent().First) .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(address1, shipment1.BillFromContactMechanism); }
public void GivenPurchaseShipment_WhenGettingShipmentNumberWithoutFormat_ThenShipmentNumberShouldBeReturned() { var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession).Build(); var shipment1 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipToParty(internalOrganisation).Build(); Assert.AreEqual("1", shipment1.ShipmentNumber); var shipment2 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipToParty(internalOrganisation).Build(); Assert.AreEqual("2", shipment2.ShipmentNumber); }
public void GivenPurchaseShipment_WhenGettingShipmentNumberWithFormat_ThenFormattedShipmentNumberShouldBeReturned() { var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession).Build(); internalOrganisation.IncomingShipmentNumberPrefix = "the format is "; var shipment1 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipToParty(internalOrganisation).Build(); Assert.AreEqual("the format is 1", shipment1.ShipmentNumber); var shipment2 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipToParty(internalOrganisation).Build(); Assert.AreEqual("the format is 2", shipment2.ShipmentNumber); }
public void GivenInternalOrganisation_WhenBuildWithout_ThenInvoiceSequenceIsEqualRestartOnFiscalYear() { this.InstantiateObjects(this.DatabaseSession); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithDefaultPaymentMethod(this.ownBankAccount) .WithPartyContactMechanism(this.billingAddress) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(new InvoiceSequences(this.DatabaseSession).FindBy(UniquelyIdentifiables.Meta.UniqueId, InvoiceSequences.RestartOnFiscalYearId), internalOrganisation.InvoiceSequence); }
public void GivenPurchaseOrder_WhenGettingOrderNumberWithoutFormat_ThenOrderNumberShouldBeReturned() { var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession).Build(); var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var order1 = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).WithBillToPurchaser(internalOrganisation).Build(); Assert.AreEqual("1", order1.OrderNumber); var order2 = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).WithBillToPurchaser(internalOrganisation).Build(); Assert.AreEqual("2", order2.OrderNumber); }
public void GivenInternalOrganisation_WhenPreferredCurrencyIsChanged_ThenValidationErrorIsTrhown() { this.InstantiateObjects(this.DatabaseSession); var organisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithDefaultPaymentMethod(this.ownBankAccount) .WithPartyContactMechanism(this.billingAddress) .Build(); this.DatabaseSession.Derive(true); Assert.IsNotNull(organisation.PreviousCurrency); organisation.PreferredCurrency = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "GBP"); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); organisation.PreferredCurrency = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenInternalOrganisation_WhenOperationsRoleIsUsed_ThenOperationsUserGroupIsDerived() { this.InstantiateObjects(this.DatabaseSession); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithDefaultPaymentMethod(this.ownBankAccount) .WithPartyContactMechanism(this.billingAddress) .Build(); this.DatabaseSession.Derive(true); var name = string.Format("{0} for {1})", new Roles(this.DatabaseSession).Administrator.Name, internalOrganisation.Name); var userGroup = new UserGroups(this.DatabaseSession).FindBy(UserGroups.Meta.Name, name); Assert.IsNotNull(userGroup); }
public void GivenInternalOrganisation_WhenDeriving_ThenRequiredRelationsMustExist() { this.InstantiateObjects(this.DatabaseSession); var builder = new InternalOrganisationBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithPaymentMethod(this.ownBankAccount); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithName("Organisation"); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithPartyContactMechanism(this.billingAddress); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenInternalOrganisation_WhenDefaultPaymentMethodIsSet_ThenPaymentMethodIsAddedToCollectionPaymentMethods() { this.InstantiateObjects(this.DatabaseSession); var organisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithDefaultPaymentMethod(this.ownBankAccount) .WithPartyContactMechanism(this.billingAddress) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, organisation.PaymentMethods.Count); Assert.AreEqual(ownBankAccount, organisation.PaymentMethods.First); }
public void GivenInternalOrganisation_WhenBuildWithout_ThenPreferredCurrencyIsEqualInternalOrganisationPreferredCurrency() { this.InstantiateObjects(this.DatabaseSession); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(this.euro) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithDefaultPaymentMethod(this.ownBankAccount) .WithPartyContactMechanism(this.billingAddress) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation.PreferredCurrency, internalOrganisation.PreferredCurrency); }
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(); } } } }
public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserInAnotherProcurementLevel1RoleUserGroup_ThenAccessIsDenied() { var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var purchaser2 = new PersonBuilder(this.DatabaseSession).WithLastName("purchaser2").WithUserName("purchaser2").Build(); var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("new internalOrganisation") .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithDefaultPaymentMethod(ownBankAccount) .WithPreferredCurrency(euro) .WithPartyContactMechanism(billToMechelen) .Build(); var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); new EmploymentBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithEmployee(purchaser2) .WithEmployer(internalOrganisation) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser", "Forms"), new string[0]); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).WithShipToBuyer(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanWrite(PurchaseOrders.Meta.Comment)); Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.Comment)); Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm)); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser2", "Forms"), new string[0]); acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.HasReadOperation); }
public void GivenSalesInvoiceCreatedBySalesRep_WhenCurrentUserInAnotherSalesRepUserGroup_ThenAccessIsDenied() { var salesRep2 = new PersonBuilder(this.DatabaseSession).WithUserName("salesRep2").WithLastName("salesRep2").Build(); var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession) .WithLocality("Mechelen") .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE")) .Build()) .Build(); var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var internalOrganisation2 = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("internalOrganisation2") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithEmployeeRole(new Roles(this.DatabaseSession).Sales) .WithDefaultPaymentMethod(ownBankAccount) .WithPreferredCurrency(euro) .WithPartyContactMechanism(billToMechelen) .Build(); var facility = new WarehouseBuilder(this.DatabaseSession).WithName("facility").WithOwner(internalOrganisation2).Build(); internalOrganisation2.DefaultFacility = facility; new StoreBuilder(this.DatabaseSession) .WithName("store") .WithDefaultFacility(facility) .WithOwner(internalOrganisation2) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .WithCreditLimit(500) .WithPaymentGracePeriod(10) .Build(); new EmploymentBuilder(this.DatabaseSession).WithEmployee(salesRep2).WithEmployer(internalOrganisation2).WithFromDate(DateTime.UtcNow).Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer2) .WithInternalOrganisation(internalOrganisation2) .WithFromDate(DateTime.UtcNow) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesRep2) .WithCustomer(customer2) .WithInternalOrganisation(internalOrganisation2) .WithFromDate(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("salesRep2", "Forms"), new string[0]); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithBilledFromInternalOrganisation(internalOrganisation2) .WithBillToCustomer(customer2) .WithBillToContactMechanism(contactMechanism) .Build(); this.DatabaseSession.Derive(true); var acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanWrite(SalesInvoices.Meta.Comment)); Assert.IsTrue(acl.CanRead(SalesInvoices.Meta.Comment)); Assert.IsTrue(acl.CanExecute(SalesInvoices.Meta.Send)); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("salesRep", "Forms"), new string[0]); acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.HasReadOperation); }
public void GivenCustomerRelationship_WhenDeriving_ThenSubAccountNumberMustBeUniqueWithinInternalOrganisation() { var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var address1 = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billingAddress = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(address1) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var internalOrganisation2 = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("internalOrganisation2") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithPartyContactMechanism(billingAddress) .WithDefaultPaymentMethod(ownBankAccount) .WithPreferredCurrency(euro) .Build(); var customerRelationship2 = new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer2) .WithInternalOrganisation(internalOrganisation2) .WithFromDate(DateTime.UtcNow) .Build(); customerRelationship2.SubAccountNumber = 19; Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenAccountingPeriod_WhenMonthInNextQuarterIsAdded_ThenPeriodsForMonthAndForQuarterAreAdded() { var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("own account") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var organisation = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("Internal") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithPreferredCurrency(euro) .WithDefaultPaymentMethod(ownBankAccount) .Build(); organisation.AppsStartNewFiscalYear(); Assert.AreEqual(4, this.DatabaseSession.Extent<AccountingPeriod>().Count); organisation.ActualAccountingPeriod.AddNextMonth(); Assert.AreEqual(5, this.DatabaseSession.Extent<AccountingPeriod>().Count); organisation.ActualAccountingPeriod.AddNextMonth(); Assert.AreEqual(6, this.DatabaseSession.Extent<AccountingPeriod>().Count); var fourthMonth = organisation.ActualAccountingPeriod.AddNextMonth(); Assert.AreEqual(8, this.DatabaseSession.Extent<AccountingPeriod>().Count); Assert.AreEqual(organisation.ActualAccountingPeriod.PeriodNumber + 3, fourthMonth.PeriodNumber); Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Month, fourthMonth.TimeFrequency); Assert.AreEqual(organisation.ActualAccountingPeriod.FromDate.AddMonths(3).Date, fourthMonth.FromDate); Assert.AreEqual(organisation.ActualAccountingPeriod.FromDate.AddMonths(4).AddSeconds(-1).Date, fourthMonth.ThroughDate); Assert.IsTrue(fourthMonth.ExistParent); Assert.Contains(fourthMonth, organisation.AccountingPeriods); var secondQuarter = fourthMonth.Parent; Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.PeriodNumber + 1, secondQuarter.PeriodNumber); Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Trimester, secondQuarter.TimeFrequency); Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.FromDate.AddMonths(3).Date, secondQuarter.FromDate); Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.FromDate.AddMonths(6).AddSeconds(-1).Date, secondQuarter.ThroughDate); Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.Parent, secondQuarter.Parent); Assert.Contains(secondQuarter, organisation.AccountingPeriods); }