public void GivenPurchaseInvoice_WhenObjectStateIsCreated_ThenCheckTransitions() { var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); this.Session.Derive(); this.Session.Commit(); User user = this.Administrator; this.Session.SetUser(user); var invoice = new PurchaseInvoiceBuilder(this.Session) .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session).PurchaseInvoice) .WithBilledFrom(supplier) .Build(); this.Session.Derive(); var acl = new AccessControlLists(this.Session.GetUser())[invoice]; Assert.Equal(new PurchaseInvoiceStates(this.Session).Created, invoice.PurchaseInvoiceState); Assert.False(acl.CanExecute(M.PurchaseInvoice.Approve)); Assert.False(acl.CanExecute(M.PurchaseInvoice.Reject)); Assert.False(acl.CanExecute(M.PurchaseInvoice.Reopen)); Assert.False(acl.CanExecute(M.PurchaseInvoice.SetPaid)); Assert.False(acl.CanExecute(M.PurchaseInvoice.Revise)); Assert.False(acl.CanExecute(M.PurchaseInvoice.FinishRevising)); Assert.False(acl.CanExecute(M.PurchaseInvoice.CreateSalesInvoice)); }
public void SalesOrder() { var customer = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("customer").Build(); new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).WithInternalOrganisation(this.InternalOrganisation).Build(); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); this.Session.Derive(); var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First(); this.Session.SetUser(employee); var order = new SalesOrderBuilder(this.Session) .WithTakenBy(this.InternalOrganisation) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithAssignedShipToAddress(new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); this.Session.Derive(); Assert.Equal(new SalesOrderStates(this.Session).Provisional, order.SalesOrderState); var acl = new AccessControlLists(employee)[order]; Assert.False(acl.CanExecute(M.SalesOrder.DoTransfer)); Assert.False(acl.CanWrite(M.SalesOrder.Description)); Assert.True(acl.CanRead(M.SalesOrder.Description)); }
public void WorkTask_StateCompleted() { var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workTask = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); this.Session.Derive(); workTask.Complete(); this.Session.Derive(); Assert.Equal(new WorkEffortStates(this.Session).Completed, workTask.WorkEffortState); User user = this.Administrator; this.Session.SetUser(user); var acl = new AccessControlLists(this.Administrator)[workTask]; Assert.True(acl.CanExecute(M.WorkEffort.Invoice)); Assert.False(acl.CanExecute(M.WorkEffort.Cancel)); Assert.False(acl.CanExecute(M.WorkEffort.Reopen)); Assert.False(acl.CanExecute(M.WorkEffort.Complete)); }
public void BaseOnDerive(ObjectOnDerive method) { var derivation = method.Derivation; var session = this.Session(); if (this.ExistFrom && this.ExistInternalOrganisation && !this.ExistTo) { var acl = new AccessControlLists(session.GetUser())[this.From]; if (!acl.CanExecute(M.SalesOrder.DoTransfer)) { derivation.Validation.AddError(this, this.Meta.To, "No rights to transfer salesorder"); } else { this.To = this.From.Clone(this.From.Meta.SalesOrderItems); this.To.TakenBy = this.InternalOrganisation; // TODO: Make sure 'from' customer is also a customer in 'to' internal organisation if (!this.To.TakenBy.ActiveCustomers.Contains(this.To.BillToCustomer)) { new CustomerRelationshipBuilder(this.Strategy.Session) .WithInternalOrganisation(this.To.TakenBy) .WithCustomer(this.To.BillToCustomer) .Build(); } //TODO: ShipToCustomer this.From.SalesOrderState = new SalesOrderStates(this.strategy.Session).Transferred; } } }
public void GivenOrderItem_WhenObjectStateIsRejected_ThenItemCanBeDeleted() { var administrator = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.Session).Administrators; administrators.AddMember(administrator); this.Session.Derive(); this.Session.Commit(); this.InstantiateObjects(this.Session); User user = this.Administrator; this.Session.SetUser(user); var item = new PurchaseOrderItemBuilder(this.Session) .WithPart(this.finishedGood) .WithQuantityOrdered(3) .WithAssignedUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.Session.Derive(); item.Reject(); this.Session.Derive(); Assert.Equal(new PurchaseOrderItemStates(this.Session).Rejected, item.PurchaseOrderItemState); var acl = new AccessControlLists(this.Session.GetUser())[item]; Assert.True(acl.CanExecute(M.PurchaseOrderItem.Delete)); }
public void WorkTask_StateFinished() { var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billToMechelen = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress) .WithUseAsDefault(true) .Build(); var customer = new OrganisationBuilder(this.Session).WithName("Org1").WithPartyContactMechanism(billToMechelen).Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(internalOrganisation).Build(); this.Session.Derive(); var workTask = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(DateTimeFactory.CreateDateTime(this.Session.Now())) .WithThroughDate(DateTimeFactory.CreateDateTime(this.Session.Now().AddHours(1))) .WithTimeFrequency(new TimeFrequencies(this.Session).Hour) .WithWorkEffort(workTask) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); this.Session.Derive(); workTask.Complete(); this.Session.Derive(); workTask.Invoice(); this.Session.Derive(); Assert.Equal(new WorkEffortStates(this.Session).Finished, workTask.WorkEffortState); User user = this.Administrator; this.Session.SetUser(user); var acl = new AccessControlLists(this.Administrator)[workTask]; Assert.False(acl.CanExecute(M.WorkEffort.Invoice)); Assert.False(acl.CanExecute(M.WorkEffort.Cancel)); Assert.False(acl.CanExecute(M.WorkEffort.Reopen)); Assert.False(acl.CanExecute(M.WorkEffort.Complete)); }
public void Person() { var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First(); this.Session.SetUser(employee); var acl = new AccessControlLists(employee)[employee]; Assert.True(acl.CanRead(M.Person.FirstName)); Assert.False(acl.CanWrite(M.Person.FirstName)); }
public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenItemMayNotBeCancelledOrRejectedOrDeleted() { var administrator = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.Session).Administrators; administrators.AddMember(administrator); this.Session.Derive(); this.Session.Commit(); this.InstantiateObjects(this.Session); User user = this.Administrator; this.Session.SetUser(user); var item = new PurchaseOrderItemBuilder(this.Session) .WithPart(this.finishedGood) .WithQuantityOrdered(20) .WithAssignedUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.order.SetReadyForProcessing(); this.Session.Derive(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(this.order.TakenViaSupplier).Build(); this.Session.Derive(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).WithQuantity(10).WithUnitPurchasePrice(1).Build(); shipment.AddShipmentItem(shipmentItem); this.Session.Derive(); new ShipmentReceiptBuilder(this.Session) .WithQuantityAccepted(3) .WithShipmentItem(shipmentItem) .WithOrderItem(item) .WithFacility(shipmentItem.StoredInFacility) .Build(); this.Session.Derive(); var acl = new AccessControlLists(this.Session.GetUser())[item]; Assert.Equal(new PurchaseOrderItemShipmentStates(this.Session).PartiallyReceived, item.PurchaseOrderItemShipmentState); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete)); }
public void Good() { var good = new Goods(this.Session).Extent().First(); var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First(); this.Session.SetUser(employee); var acl = new AccessControlLists(employee)[good]; Assert.True(acl.CanRead(M.Good.Name)); Assert.False(acl.CanWrite(M.Good.Name)); }
public void UserGroup() { var userGroup = new UserGroups(this.Session).Administrators; var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First(); this.Session.SetUser(employee); var acl = new AccessControlLists(employee)[userGroup]; Assert.True(acl.CanRead(M.UserGroup.Members)); Assert.False(acl.CanWrite(M.UserGroup.Members)); }
public void GivenPickList_WhenObjectStateIsCreated_ThenCheckTransitions() { var store = this.Session.Extent <Store>().First; store.IsImmediatelyPicked = false; User user = this.Administrator; this.Session.SetUser(user); var pickList = new PickListBuilder(this.Session).Build(); this.Session.Derive(); var acl = new AccessControlLists(this.Session.GetUser())[pickList]; Assert.True(acl.CanExecute(M.PickList.Cancel)); }
public void GivenOrderItem_WhenObjectShipmentStateIsReceived_ThenReceiveIsNotAllowed() { var administrator = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.Session).Administrators; administrators.AddMember(administrator); this.Session.Derive(); this.Session.Commit(); this.InstantiateObjects(this.Session); User user = this.Administrator; this.Session.SetUser(user); var item = new PurchaseOrderItemBuilder(this.Session) .WithPart(this.finishedGood) .WithQuantityOrdered(3) .WithAssignedUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.order.SetReadyForProcessing(); this.Session.Derive(); this.order.QuickReceive(); this.Session.Derive(); var shipment = (PurchaseShipment)item.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem; shipment.Receive(); this.Session.Derive(); Assert.True(item.PurchaseOrderItemShipmentState.IsReceived); var acl = new AccessControlLists(this.Session.GetUser())[item]; Assert.False(acl.CanExecute(M.PurchaseOrderItem.QuickReceive)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete)); }
public void WorkTask_StateCancelled_TimeEntry() { var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workTask = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); this.Session.Derive(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(internalOrganisation).Build(); this.Session.Derive(); var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(DateTimeFactory.CreateDateTime(this.Session.Now())) .WithTimeFrequency(new TimeFrequencies(this.Session).Hour) .WithWorkEffort(workTask) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); this.Session.Derive(); workTask.Cancel(); this.Session.Derive(); Assert.Equal(new WorkEffortStates(this.Session).Cancelled, workTask.WorkEffortState); User user = this.Administrator; this.Session.SetUser(user); var acl = new AccessControlLists(this.Administrator)[timeEntry]; Assert.False(acl.CanWrite(M.TimeEntry.AmountOfTime)); }
public void WorkTask_StateFinished() { var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billToMechelen = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress) .WithUseAsDefault(true) .Build(); var customer = new OrganisationBuilder(this.Session).WithName("Org1").WithPartyContactMechanism(billToMechelen).Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workTask = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); this.Session.Derive(); workTask.Complete(); this.Session.Derive(); workTask.Invoice(); this.Session.Derive(); Assert.Equal(new WorkEffortStates(this.Session).Finished, workTask.WorkEffortState); User user = this.Administrator; this.Session.SetUser(user); var acl = new AccessControlLists(this.Administrator)[workTask]; Assert.False(acl.CanExecute(M.WorkEffort.Invoice)); Assert.False(acl.CanExecute(M.WorkEffort.Cancel)); Assert.False(acl.CanExecute(M.WorkEffort.Reopen)); Assert.False(acl.CanExecute(M.WorkEffort.Complete)); }
public void WorkTaskNewInSession() { var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workTask = new WorkTaskBuilder(this.Session).WithName("worktask").WithCustomer(customer).Build(); this.Session.Derive(); var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First(); this.Session.SetUser(employee); Assert.True(workTask.Strategy.IsNewInSession); var acl = new AccessControlLists(employee)[workTask]; Assert.True(acl.CanRead(M.WorkTask.Name)); Assert.True(acl.CanWrite(M.WorkTask.Name)); }
public void GivenLoggedUserIsAdministrator_WhenAccessingSingleton_ThenLoggedInUserIsGrantedAccess() { var existingAdministrator = this.Administrator; var secondAdministrator = new PersonBuilder(this.Session).WithLastName("second admin").Build(); Assert.False(secondAdministrator.IsAdministrator()); var internalOrganisation = this.InternalOrganisation; this.Session.Derive(); User user = this.Administrator; this.Session.SetUser(user); var acl = new AccessControlLists(existingAdministrator)[internalOrganisation]; Assert.True(acl.CanRead(M.Organisation.Name)); acl = new AccessControlLists(existingAdministrator)[internalOrganisation]; Assert.True(acl.CanWrite(M.Organisation.Name)); var administrators = new UserGroups(this.Session).Administrators; administrators.AddMember(secondAdministrator); this.Session.Derive(); Assert.True(secondAdministrator.IsAdministrator()); acl = new AccessControlLists(existingAdministrator)[internalOrganisation]; Assert.True(acl.CanRead(M.Organisation.Name)); acl = new AccessControlLists(existingAdministrator)[internalOrganisation]; Assert.True(acl.CanWrite(M.Organisation.Name)); }
public void SalesInvoice() { var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var contactMechanism = new PostalAddressBuilder(this.Session) .WithAddress1("Haverwerf 15") .WithLocality("Mechelen") .WithCountry(new Countries(this.Session).FindBy(M.Country.IsoCode, "BE")) .Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var salesInvoice = new SalesInvoiceBuilder(this.Session).WithBillToCustomer(customer).WithAssignedBillToContactMechanism(contactMechanism).Build(); this.Session.Derive(); var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First(); this.Session.SetUser(employee); Assert.True(salesInvoice.Strategy.IsNewInSession); var acl = new AccessControlLists(employee)[salesInvoice]; Assert.True(acl.CanRead(M.SalesInvoice.Description)); Assert.False(acl.CanWrite(M.SalesInvoice.Description)); this.Session.Commit(); Assert.False(salesInvoice.Strategy.IsNewInSession); acl = new AccessControlLists(employee)[salesInvoice]; Assert.True(acl.CanRead(M.SalesInvoice.Description)); Assert.False(acl.CanWrite(M.SalesInvoice.Description)); }
public void GivenShipmentItem_WhenProcessed_ThenDeleteIsNotAllowed() { var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var shipToAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1"); new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good1.Part).Build(); User user = this.Administrator; this.Session.SetUser(user); var customer = new PersonBuilder(this.Session).WithLastName("customer").Build(); var shipment = new CustomerShipmentBuilder(this.Session) .WithShipToParty(customer) .WithShipToAddress(shipToAddress) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithGood(good1).WithQuantity(10).Build(); shipment.AddShipmentItem(shipmentItem); this.Session.Derive(); shipment.Pick(); this.Session.Derive(); var acl = new AccessControlLists(this.Session.GetUser())[shipmentItem]; Assert.Equal(new ShipmentItemStates(this.Session).Picking, shipmentItem.ShipmentItemState); Assert.False(acl.CanExecute(M.ShipmentItem.Delete)); var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = this.OrderProcessor; pickList.SetPicked(); this.Session.Derive(); acl = new AccessControlLists(this.Session.GetUser())[shipmentItem]; Assert.Equal(new ShipmentItemStates(this.Session).Picked, shipmentItem.ShipmentItemState); Assert.False(acl.CanExecute(M.ShipmentItem.Delete)); var package = new ShipmentPackageBuilder(this.Session).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem item in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(item).WithQuantity(shipmentItem.Quantity).Build()); } this.Session.Derive(); shipment.SetPacked(); this.Session.Derive(); acl = new AccessControlLists(this.Session.GetUser())[shipmentItem]; Assert.Equal(new ShipmentItemStates(this.Session).Packed, shipmentItem.ShipmentItemState); Assert.False(acl.CanExecute(M.ShipmentItem.Delete)); shipment.Ship(); this.Session.Derive(); acl = new AccessControlLists(this.Session.GetUser())[shipmentItem]; Assert.Equal(new ShipmentItemStates(this.Session).Shipped, shipmentItem.ShipmentItemState); Assert.False(acl.CanExecute(M.ShipmentItem.Delete)); }