Ejemplo n.º 1
0
        public void GivenSalesOrder_WhenObjectStateIsFinished_ThenCheckTransitions()
        {
            var customer = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("customer").Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

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

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();

            this.DatabaseSession.Derive(true);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("customer", "Forms"), new string[0]);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            order.Finish();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Finished, order.CurrentObjectState);
            var acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanExecute(SalesOrders.Meta.Confirm));
            Assert.IsFalse(acl.CanExecute(SalesOrders.Meta.Cancel));
            Assert.IsFalse(acl.CanExecute(SalesOrders.Meta.Reject));
            Assert.IsFalse(acl.CanExecute(SalesOrders.Meta.Approve));
            Assert.IsFalse(acl.CanExecute(SalesOrders.Meta.Continue));
            Assert.IsFalse(acl.CanExecute(SalesOrders.Meta.Hold));
        }