public void GivenConfirmedOrderItemForGood_WhenOrderItemIsRemoved_ThenItemIsRemovedFromValidOrderItems() { this.InstantiateObjects(this.DatabaseSession); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate, 21)) .Build(); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.DatabaseSession.Derive(true); this.order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, this.order.ValidOrderItems.Count); item.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(0, this.order.ValidOrderItems.Count); }
public void GivenConfirmedOrderItemForGood_WhenOrderItemIsRemoved_ThenItemIsRemovedFromValidOrderItems() { this.InstantiateObjects(this.Session); var item = new PurchaseOrderItemBuilder(this.Session) .WithPart(this.finishedGood) .WithQuantityOrdered(3) .WithAssignedUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.Session.Derive(); this.order.SetReadyForProcessing(); this.Session.Derive(); Assert.Single(this.order.ValidOrderItems); item.Cancel(); this.Session.Derive(); Assert.Equal(0, this.order.ValidOrderItems.Count); }
public void GivenPurchaseOrder_WhenConfirming_ThenAllValidItemsAreInConfirmedState() { var supplier = new OrganisationBuilder(this.Session).WithName("customer2").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var order = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.Session).Exempt) .Build(); var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build(); var item2 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(2).Build(); var item3 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(3).Build(); var item4 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(4).Build(); order.AddPurchaseOrderItem(item1); order.AddPurchaseOrderItem(item2); order.AddPurchaseOrderItem(item3); order.AddPurchaseOrderItem(item4); this.Session.Derive(); order.Confirm(); this.Session.Derive(); item4.Cancel(); this.Session.Derive(); Assert.Equal(3, order.ValidOrderItems.Count); Assert.Contains(item1, order.ValidOrderItems); Assert.Contains(item2, order.ValidOrderItems); Assert.Contains(item3, order.ValidOrderItems); Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item1.PurchaseOrderItemState); Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item2.PurchaseOrderItemState); Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item3.PurchaseOrderItemState); Assert.Equal(new PurchaseOrderItemStates(this.Session).Cancelled, item4.PurchaseOrderItemState); }
public void GivenOrderItem_WhenObjectStateIsCancelled_ThenItemMayNotBeCancelledOrRejected() { 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(); this.Session.Commit(); item.Cancel(); this.Session.Derive(); Assert.Equal(new PurchaseOrderItemStates(this.Session).Cancelled, item.PurchaseOrderItemState); var acl = new AccessControlLists(this.Session.GetUser())[item]; Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject)); }
public void GivenOrderItem_WhenObjectStateIsCancelled_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); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21)) .Build(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); item.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Cancelled, item.CurrentObjectState); var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Cancel)); Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Reject)); Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Delete)); }
public void GivenPurchaseOrder_WhenConfirming_ThenAllValidItemsAreInConfirmedState() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt) .Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build(); var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build(); var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build(); var item4 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(4).Build(); order.AddPurchaseOrderItem(item1); order.AddPurchaseOrderItem(item2); order.AddPurchaseOrderItem(item3); order.AddPurchaseOrderItem(item4); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); item4.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(3, order.ValidOrderItems.Count); Assert.Contains(item1, order.ValidOrderItems); Assert.Contains(item2, order.ValidOrderItems); Assert.Contains(item3, order.ValidOrderItems); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item1.CurrentObjectState); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item2.CurrentObjectState); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item3.CurrentObjectState); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Cancelled, item4.CurrentObjectState); }