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); }
public void Cache() { var person = new PersonBuilder(this.Session).WithFirstName("John").Build(); var stringTemplate = new StringTemplateBuilder(this.Session).WithBody( @"main(this) ::= << Hello $this.FirstName$! >>").Build(); for (var i = 0; i < NrOfRuns; i++) { var result = stringTemplate.Apply(new Dictionary<string, object> { { "this", person } }); Assert.AreEqual("Hello John!", result); } stringTemplate.Body = @"main(this) ::= << Hi $this.FirstName$! >>"; this.Session.Derive(); for (var i = 0; i < NrOfRuns; i++) { var result = stringTemplate.Apply(new Dictionary<string, object> { { "this", person } }); Assert.AreEqual("Hi John!", result); } }
public void GivenCurrentUserIsKnown_WhenAccessingFaceToFaceCommunicationWithOwner_ThenOwnerSecurityTokenIsApplied() { Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("user"), new string[0]); var user = new PersonBuilder(this.DatabaseSession).WithLastName("user").WithUserName("user").Build(); var owner = new PersonBuilder(this.DatabaseSession).WithLastName("owner").Build(); var participant1 = new PersonBuilder(this.DatabaseSession).WithLastName("participant1").Build(); var participant2 = new PersonBuilder(this.DatabaseSession).WithLastName("participant2").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var communication = new FaceToFaceCommunicationBuilder(this.DatabaseSession) .WithOwner(owner) .WithSubject("subject") .WithParticipant(participant1) .WithParticipant(participant2) .WithActualStart(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, communication.SecurityTokens.Count); Assert.Contains(Singleton.Instance(this.DatabaseSession).DefaultSecurityToken, communication.SecurityTokens); Assert.Contains(owner.OwnerSecurityToken, communication.SecurityTokens); }
public void GivenOrganisation_WhenCurrentUserIsContactForOrganisation_ThenCustomerPermissionsAreGranted() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var organisation = new OrganisationBuilder(this.DatabaseSession).WithName("organisation").Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("Customer").WithUserName("customer").Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithCustomer(organisation).WithInternalOrganisation(internalOrganisation).Build(); new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(customer).WithOrganisation(organisation).WithFromDate(DateTime.UtcNow).Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("customer", "Forms"), new string[0]); var acl = new AccessControlList(organisation, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanRead(Organisations.Meta.Name)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.Name)); Assert.IsTrue(acl.CanRead(Organisations.Meta.LegalForm)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.LegalForm)); Assert.IsTrue(acl.CanRead(Organisations.Meta.LogoImage)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.LogoImage)); Assert.IsTrue(acl.CanRead(Organisations.Meta.Locale)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.Locale)); Assert.IsFalse(acl.CanRead(Organisations.Meta.OwnerSecurityToken)); Assert.IsFalse(acl.CanWrite(Organisations.Meta.OwnerSecurityToken)); }
public void GivenNextSalesRep_WhenEmploymentAndSalesRepRelationshipAreCreated_ThenSalesRepIsAddedToUserGroup() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var usergroups = internalOrganisation.UserGroupsWhereParty; usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Sales.UserGroupWhereRole); var salesRepUserGroup = usergroups.First; this.DatabaseSession.Derive(true); Assert.AreEqual(1, salesRepUserGroup.Members.Count); Assert.Contains(new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "salesRep"), salesRepUserGroup.Members); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").WithUserName("salesRep2").Build(); new EmploymentBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithEmployee(salesrep2) .WithEmployer(internalOrganisation) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithCustomer(customer) .WithSalesRepresentative(salesrep2) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, salesRepUserGroup.Members.Count); Assert.IsTrue(salesRepUserGroup.Members.Contains(salesrep2)); }
public void GivenCustomerRelationshipBuilder_WhenBuild_ThenSubAccountNumerIsValidElevenTestNumber() { var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; internalOrganisation.SubAccountCounter.Value = 1000; this.DatabaseSession.Commit(); var customer1 = new PersonBuilder(this.DatabaseSession).WithLastName("customer1").Build(); var customerRelationship1 = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1007, customerRelationship1.SubAccountNumber); var customer2 = new PersonBuilder(this.DatabaseSession).WithLastName("customer2").Build(); var customerRelationship2 = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1015, customerRelationship2.SubAccountNumber); var customer3 = new PersonBuilder(this.DatabaseSession).WithLastName("customer3").Build(); var customerRelationship3 = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer3).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1023, customerRelationship3.SubAccountNumber); }
public void GivenPerson_WhenDeriving_ThenThereAreNoRequiredRelations() { var builder = new PersonBuilder(this.Session); builder.Build(); Assert.IsFalse(this.Session.Derive().HasErrors); }
public void GivenorganisationContactRelationship_WhenDeriving_ThenRequiredRelationsMustExist() { var contact = new PersonBuilder(this.DatabaseSession).WithLastName("organisationContact").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); var builder = new OrganisationContactRelationshipBuilder(this.DatabaseSession); var relationship = builder.Build(); this.DatabaseSession.Derive(); Assert.IsTrue(relationship.Strategy.IsDeleted); this.DatabaseSession.Rollback(); builder.WithContact(contact); relationship = builder.Build(); this.DatabaseSession.Derive(); Assert.IsTrue(relationship.Strategy.IsDeleted); this.DatabaseSession.Rollback(); builder.WithOrganisation(new OrganisationBuilder(this.DatabaseSession).WithName("organisation").WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale).Build()); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void TestInvoices() { var departmentA = new DepartmentBuilder(this.Session).Build(); var departmentB = new DepartmentBuilder(this.Session).Build(); var accountantA = new PersonBuilder(this.Session).WithFirstName("Accountant").WithLastName("A").Build(); var accountantB = new PersonBuilder(this.Session).WithFirstName("Accountant").WithLastName("B").Build(); departmentA.AddAccountant(accountantA); departmentB.AddAccountant(accountantB); var invoiceA = new InvoiceBuilder(this.Session).Build(); var invoiceB = new InvoiceBuilder(this.Session).Build(); departmentA.AddInvoice(invoiceA); departmentB.AddInvoice(invoiceB); this.Session.Derive(); // Accountant A var aclAccountatAInvoiceA = new AccessControlList(invoiceA, accountantA); var aclAccountatAInvoiceB = new AccessControlList(invoiceB, accountantA); aclAccountatAInvoiceA.CanWrite(Invoice.Meta.Total).ShouldBeTrue(); aclAccountatAInvoiceB.CanWrite(Invoice.Meta.Total).ShouldBeFalse(); // Accountant B var aclAccountatBInvoiceA = new AccessControlList(invoiceA, accountantB); var aclAccountatBInvoiceB = new AccessControlList(invoiceB, accountantB); aclAccountatBInvoiceA.CanWrite(Invoice.Meta.Total).ShouldBeFalse(); aclAccountatBInvoiceB.CanWrite(Invoice.Meta.Total).ShouldBeTrue(); }
public void TestEmployeesCanRead() { var employeeRole = new Roles(this.Session).Employee; var employees = new UserGroupBuilder(this.Session) .WithName("Employees") .Build(); var john = new PersonBuilder(this.Session).WithFirstName("John").WithLastName("Doe").Build(); employees.AddMember(john); var invoice = new InvoiceBuilder(this.Session).Build(); var singleton = Singleton.Instance(this.Session); var defaultSecurityToken = singleton.DefaultSecurityToken; var accessControl = new AccessControlBuilder(this.Session) .WithRole(employeeRole) .WithObject(defaultSecurityToken) .WithSubjectGroup(employees) .Build(); var acl = new AccessControlList(invoice, john); acl.CanRead(Invoice.Meta.Total).ShouldBeTrue(); }
// // GET: /Home/ public ActionResult Index() { new PersonService("some").Process2().Process(); var person = new PersonBuilder() .WithFirstName("dean") .WithFirstName("seb") .WithActiveLoans(10).Create(); return View(); }
public void WhenDeletingUserThenLoginShouldAlsoBeDeleted() { var user = new PersonBuilder(this.Session).WithUserName("User").WithLastName("User").Build(); var login = new LoginBuilder(this.Session).WithUser(user).WithProvider("MyProvider").WithKey("XXXYYYZZZ").Build(); this.Session.Derive(); user.Delete(); this.Session.Derive(); Assert.IsTrue(login.Strategy.IsDeleted); }
public void GivenActiveCustomerRelationship_WhenDeriving_ThenInternalOrganisationCustomersContainsCustomer() { var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(internalOrganisation) .Build(); this.DatabaseSession.Derive(true); Assert.Contains(customer, internalOrganisation.Customers); }
public void GivenActiveEmployment_WhenDeriving_ThenInternalOrganisationEmployeesContainsEmployee() { var employee = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var employer = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new EmploymentBuilder(this.DatabaseSession) .WithEmployee(employee) .WithEmployer(employer) .Build(); this.DatabaseSession.Derive(true); Assert.Contains(employee, employer.Employees); }
public data_using_default_person_builder() { _personBuilder = new PersonBuilder(DataContainer); _emailBuilder = new EmailBuilder(DataContainer); _builder = new Builder<MyPerson>() .With(x => { var person = _personBuilder.Build(); var emails = _emailBuilder.WithPerson(person).Build(1, 3).ToArray(); x.Name = person.FullName; x.Emails = emails.Select(e => e.Address); }); }
private void CreateUser(IdentityUser identityUser) { using (var session = this.Database.CreateSession()) { var person = new PersonBuilder(session) .WithUserName(identityUser.UserName) .WithUserEmail(identityUser.Email) .WithUserEmailConfirmed(identityUser.EmailConfirmed) .WithUserPasswordHash(identityUser.PasswordHash) .Build(); session.Derive(); identityUser.MapFrom(person); session.Commit(); } }
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 SetUp() { var configuration = new Databases.Memory.IntegerId.Configuration { ObjectFactory = Config.ObjectFactory, WorkspaceFactory = new WorkspaceFactory() }; Config.Default = new Databases.Memory.IntegerId.Database(configuration); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("nl-BE"); var database = Config.Default; database.Init(); using (var session = database.CreateSession()) { new Setup(session).Apply(); session.Commit(); using (var stringWriter = new StringWriter()) { using (var writer = new XmlTextWriter(stringWriter)) { database.Save(writer); MinimalXml = 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 administrators = new UserGroups(session).Administrators; administrators.AddMember(administrator); session.Derive(true); session.Commit(); using (var stringWriter = new StringWriter()) { using (var writer = new XmlTextWriter(stringWriter)) { database.Save(writer); DefaultXml = stringWriter.ToString(); } } } }
public void GivenCurrentUserIsUnknown_WhenAccessingFaceToFaceCommunicationWithoutOwner_ThenDefaultSecurityTokenIsApplied() { var participant1 = new PersonBuilder(this.DatabaseSession).WithLastName("participant1").Build(); var participant2 = new PersonBuilder(this.DatabaseSession).WithLastName("participant2").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var communication = new FaceToFaceCommunicationBuilder(this.DatabaseSession) .WithSubject("subject") .WithParticipant(participant1) .WithParticipant(participant2) .WithActualStart(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, communication.SecurityTokens.Count); Assert.Contains(Singleton.Instance(this.DatabaseSession).DefaultSecurityToken, communication.SecurityTokens); }
public void DeniedPermissions() { var readOrganisationName = this.FindPermission(Organisations.Meta.Name, Operation.Read); var databaseRole = new RoleBuilder(this.DatabaseSession).WithName("Role").WithPermission(readOrganisationName).Build(); var person = new PersonBuilder(this.DatabaseSession).WithFirstName("John").WithLastName("Doe").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); new AccessControlBuilder(this.DatabaseSession).WithRole(databaseRole).WithSubject(person).Build(); this.DatabaseSession.Commit(); var sessions = new ISession[] { this.DatabaseSession, this.CreateWorkspaceSession() }; foreach (var session in sessions) { session.Commit(); var organisation = new OrganisationBuilder(session).WithName("Organisation").Build(); var token = new SecurityTokenBuilder(session).Build(); organisation.AddSecurityToken(token); var role = (Role)session.Instantiate(new Roles(this.DatabaseSession).FindBy(Roles.Meta.Name, "Role")); var accessControl = (AccessControl)session.Instantiate(role.AccessControlsWhereRole.First); accessControl.AddObject(token); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); var accessList = new AccessControlList(organisation, person); Assert.IsTrue(accessList.CanRead(Organisations.Meta.Name)); organisation.AddDeniedPermission(readOrganisationName); accessList = new AccessControlList(organisation, person); Assert.IsFalse(accessList.CanRead(Organisations.Meta.Name)); session.Rollback(); } }
public void GivenNoAccessControlWhenCreatingAAccessControlWithoutATokenThenAccessControlIsInvalid() { var role = new RoleBuilder(this.DatabaseSession).WithName("Role").Build(); var user = new PersonBuilder(this.DatabaseSession).WithUserName("user").WithLastName("Doe").Build(); new AccessControlBuilder(this.DatabaseSession) .WithSubject(user) .WithRole(role) .Build(); var derivationLog = this.DatabaseSession.Derive(); Assert.IsTrue(derivationLog.HasErrors); Assert.AreEqual(1, derivationLog.Errors.Length); var derivationError = derivationLog.Errors[0]; Assert.AreEqual(1, derivationError.Relations.Length); Assert.AreEqual(typeof(DerivationErrorRequired), derivationError.GetType()); Assert.IsTrue(new ArrayList(derivationError.RoleTypes).Contains((RoleType)AccessControls.Meta.Objects)); }
public void GivenFaxCommunication_WhenDeriving_ThenInvolvedPartiesAreDerived() { var owner = new PersonBuilder(this.DatabaseSession).WithLastName("owner").Build(); var originator = new PersonBuilder(this.DatabaseSession).WithLastName("originator").Build(); var receiver = new PersonBuilder(this.DatabaseSession).WithLastName("receiver").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var communication = new FaxCommunicationBuilder(this.DatabaseSession) .WithSubject("subject") .WithOwner(owner) .WithOriginator(originator) .WithReceiver(receiver) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(3, communication.InvolvedParties.Count); Assert.Contains(owner, communication.InvolvedParties); Assert.Contains(originator, communication.InvolvedParties); Assert.Contains(receiver, communication.InvolvedParties); }
public void GivenPhoneCommunication_WhenDeriving_ThenInvolvedPartiesAreDerived() { var owner = new PersonBuilder(this.DatabaseSession).WithLastName("owner").Build(); var caller = new PersonBuilder(this.DatabaseSession).WithLastName("caller").Build(); var receiver = new PersonBuilder(this.DatabaseSession).WithLastName("receiver").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var communication = new PhoneCommunicationBuilder(this.DatabaseSession) .WithSubject("Hello world!") .WithOwner(owner) .WithCaller(caller) .WithReceiver(receiver) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(3, communication.InvolvedParties.Count); Assert.Contains(owner, communication.InvolvedParties); Assert.Contains(caller, communication.InvolvedParties); Assert.Contains(receiver, communication.InvolvedParties); }
public void GivenAnAccessListWithWriteOperationsWhenUsingTheHasWriteOperationBeforeAnyOtherMehodThenHasWriteOperationReturnTrue() { var guest = new PersonBuilder(this.DatabaseSession).WithUserName("guest").WithLastName("Guest").Build(); var administrator = new PersonBuilder(this.DatabaseSession).WithUserName("admin").WithLastName("Administrator").Build(); Singleton.Instance(this.DatabaseSession).Guest = guest; new UserGroups(this.DatabaseSession).FindBy(UserGroups.Meta.Name, "Administrators").AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var sessions = new ISession[] { this.CreateWorkspaceSession(), this.DatabaseSession }; foreach (var session in sessions) { session.Commit(); AccessControlledObject aco = new OrganisationBuilder(session).Build(); var accessList = new AccessControlList(aco, administrator); Assert.IsTrue(accessList.HasWriteOperation); session.Rollback(); } }
public void GivenSupplierContactRelationship_WhenContactForOrganisationEnds_ThenContactIsRemovedfromSupplierContactsUserGroup() { this.InstantiateObjects(this.DatabaseSession); var contact2 = new PersonBuilder(this.DatabaseSession).WithLastName("contact2").Build(); var contactRelationship2 = new OrganisationContactRelationshipBuilder(this.DatabaseSession) .WithOrganisation(this.supplier) .WithContact(contact2) .WithFromDate(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, this.supplierRelationship.Supplier.SupplierContactUserGroup.Members.Count); Assert.IsTrue(this.supplierRelationship.Supplier.SupplierContactUserGroup.Members.Contains(this.contact)); contactRelationship2.ThroughDate = DateTime.UtcNow.AddDays(-1); this.DatabaseSession.Derive(true); Assert.AreEqual(1, this.supplierRelationship.Supplier.SupplierContactUserGroup.Members.Count); Assert.IsTrue(this.supplierRelationship.Supplier.SupplierContactUserGroup.Members.Contains(this.contact)); Assert.IsFalse(this.supplierRelationship.Supplier.SupplierContactUserGroup.Members.Contains(contact2)); }
public void GivenOrderItemForProductWithoutCategory_WhenDerivingSalesRep_ThenSalesRepForCustomerIsSelected() { this.InstantiateObjects(this.DatabaseSession); var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build(); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build(); var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build(); var productCategoryParent = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build(); var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(productCategoryParent).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep1) .WithCustomer(this.order.ShipToCustomer) .WithProductCategory(childProductCategory) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep2) .WithCustomer(this.order.ShipToCustomer) .WithProductCategory(productCategoryParent) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep3) .WithCustomer(this.order.ShipToCustomer) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .Build(); var orderItem = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(orderItem); this.DatabaseSession.Derive(true); Assert.AreEqual(orderItem.SalesRep, salesrep3); }
public void GivenOrderItem_WhenObjectStateIsRejected_ThenItemMayNotBeCancelledOrRejectedOrDeleted() { var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.DatabaseSession).Administrators; administrators.AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); item.Reject(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Rejected, item.CurrentObjectState); var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanExecute(SalesOrderItems.Meta.Cancel)); Assert.IsFalse(acl.CanExecute(SalesOrderItems.Meta.Reject)); }
public void GivenOrderItem_WhenObjectStateIsPartiallyShipped_ThenProductChangeIsNotAllowed() { var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.DatabaseSession).Administrators; administrators.AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]); var inventoryItem = (NonSerializedInventoryItem)this.part.InventoryItemsWherePart[0]; inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(1).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); this.order.Confirm(); this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)this.order.ShipToAddress.ShipmentsWhereShipToAddress[0]; var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); var package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); shipment.Ship(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).PartiallyShipped, item.CurrentObjectState); var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanWrite(SalesOrderItems.Meta.Product)); }
public void Create_POST_GivenModelStateIsValid_ShouldSaveLendingEntryToDB() { //---------------Set up test pack------------------- var item = new ItemBuilder().WithRandomProps().Build(); var person = new PersonBuilder().WithRandomProps().Build(); var mappingEngine = Substitute.For<IMappingEngine>(); var itemsRepository = Substitute.For<IItemsRepository>(); var personRepository = Substitute.For<IPersonRepository>(); var lendingRepository = Substitute.For<ILendingRepository>(); var lending = new LendingBuilder().WithRandomProps().Build(); var viewModel = new LendingViewModelBuilder().WithRandomProps().Build(); mappingEngine.Map<LendingViewModel, Lending>(viewModel).Returns(lending); itemsRepository.GetById(viewModel.ItemId).Returns(item); personRepository.GetById(viewModel.PersonId).Returns(person); var controller = CreateLendingController(lendingRepository, mappingEngine, personRepository, itemsRepository); Lending savedLending = null; lendingRepository.When(x => x.Save(Arg.Any<Lending>())).Do(info => savedLending = (Lending)info[0]); //---------------Assert Precondition---------------- Assert.IsTrue(controller.ModelState.IsValid); //---------------Execute Test ---------------------- var result = controller.Create(viewModel) as ViewResult; //---------------Test Result ----------------------- Assert.AreEqual(lending.LedingId, savedLending.LedingId); Assert.AreEqual(lending.ItemId, savedLending.ItemId); Assert.AreEqual(lending.PersonId, savedLending.PersonId); }
public void Create_POST_GivenPersonIdIsNotNull_ShouldSetPersonName() { //---------------Set up test pack------------------- var item = new ItemBuilder().WithRandomProps().Build(); var person = new PersonBuilder().WithRandomProps().Build(); var mappingEngine = Substitute.For<IMappingEngine>(); var itemsRepository = Substitute.For<IItemsRepository>(); var personRepository = Substitute.For<IPersonRepository>(); var lending = new LendingBuilder().WithRandomProps().Build(); var viewModel = new LendingViewModelBuilder().WithRandomProps().Build(); mappingEngine.Map<LendingViewModel, Lending>(viewModel).Returns(lending); itemsRepository.GetById(viewModel.ItemId).Returns(item); personRepository.GetById(viewModel.PersonId).Returns(person); var controller = CreateLendingController(null, mappingEngine, personRepository, itemsRepository); //---------------Assert Precondition---------------- Assert.IsTrue(controller.ModelState.IsValid); //---------------Execute Test ---------------------- var result = controller.Create(viewModel) as ViewResult; //---------------Test Result ----------------------- Assert.AreEqual(lending.PersonName, person.FirstName); }