Esempio n. 1
0
        public void TestReroutePurchaserWhenValid2()
        {
            #region Arrange
            SetupRoles();
            new FakeUsers(12, UserRepository);
            var orders = new List <Order>();
            orders.Add(CreateValidEntities.Order(1));
            orders[0].StatusCode.SetIdTo(OrderStatusCode.Codes.AccountManager);
            orders[0].Approvals.Add(CreateValidEntities.Approval(1));
            orders[0].Approvals[0].StatusCode.SetIdTo(OrderStatusCode.Codes.AccountManager);
            orders[0].Approvals[0].User = CreateValidEntities.User(99);
            orders[0].Workgroup.SetIdTo(2);
            orders[0].Approvals.Add(CreateValidEntities.Approval(1));
            orders[0].Approvals[0].StatusCode.SetIdTo(OrderStatusCode.Codes.Purchaser);
            orders[0].Approvals[0].User = CreateValidEntities.User(99);
            orders[0].Workgroup.Permissions.Add(CreateValidEntities.WorkgroupPermission(1));
            orders[0].Workgroup.Permissions.Add(CreateValidEntities.WorkgroupPermission(12));
            orders[0].Workgroup.Permissions[0].User    = UserRepository.Queryable.Single(a => a.Id == "1");
            orders[0].Workgroup.Permissions[0].Role    = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Purchaser);
            orders[0].Workgroup.Permissions[1].User    = UserRepository.Queryable.Single(a => a.Id == "12");
            orders[0].Workgroup.Permissions[1].Role    = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Purchaser);
            orders[0].Workgroup.Permissions[1].IsAdmin = true;
            new FakeOrders(0, OrderRepository, orders);


            //var orderPeeps = new List<OrderPeep>();
            //for (int i = 0; i < 12; i++)
            //{
            //    orderPeeps.Add(CreateValidEntities.OrderPeep(i + 1));
            //    orderPeeps[i].OrderId = 1;
            //    orderPeeps[i].WorkgroupId = 2;
            //    orderPeeps[i].OrderStatusCodeId = OrderStatusCode.Codes.Purchaser;
            //    orderPeeps[i].UserId = (i + 1).ToString();
            //}
            //orderPeeps[1].UserId = "99";
            //orderPeeps[2].OrderStatusCodeId = OrderStatusCode.Codes.AccountManager;
            //orderPeeps[3].OrderId = 9;
            //orderPeeps[4].WorkgroupId = 1;
            //orderPeeps[5].OrderStatusCodeId = OrderStatusCode.Codes.Approver;
            //orderPeeps[6].OrderStatusCodeId = OrderStatusCode.Codes.Requester;
            //orderPeeps[7].OrderStatusCodeId = OrderStatusCode.Codes.Cancelled;
            //orderPeeps[8].OrderStatusCodeId = OrderStatusCode.Codes.Complete;
            //orderPeeps[9].UserId = "1";
            //orderPeeps[10].UserId = "1";

            //new FakeOrderPeeps(0, OrderPeepRepository, orderPeeps);

            //var peeps = new List<OrderPeep>();
            //for (int i = 0; i < 10; i++)
            //{
            //    peeps.Add(CreateValidEntities.OrderPeep(i + 1));
            //    peeps[i].OrderId = 1;
            //    peeps[i].WorkgroupId = 2;
            //}
            #endregion Arrange

            #region Act
            var result = Controller.ReroutePurchaser(1, "1")
                         .AssertActionRedirect()
                         .ToAction <OrderController>(a => a.Review(1));
            #endregion Act

            #region Assert
            Assert.AreEqual("Order  rerouted to purchaser FirstName1 LastName1", Controller.Message);
            ApprovalRepository.AssertWasCalled(a => a.EnsurePersistent(orders[0].Approvals[0]));
            OrderService.AssertWasCalled(a => a.ReRouteSingleApprovalForExistingOrder(orders[0].Approvals[0], UserRepository.Queryable.Single(b => b.Id == "1")));

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RouteValues["id"]);
            #endregion Assert
        }