Exemplo n.º 1
0
        public void TestSelectWorkgroupThrowsExceptionIfCurrentUserNotFound()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
                var users = new List <User>();
                for (int i = 0; i < 3; i++)
                {
                    users.Add(CreateValidEntities.User(i + 1));
                    users[i].SetIdTo((i + 1).ToString());
                }
                UserRepository2.Expect(a => a.Queryable).Return(users.AsQueryable()).Repeat.Any();
                thisFar = true;
                #endregion Arrange

                #region Act
                Controller.SelectWorkgroup();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("Sequence contains no matching element", ex.Message);
                throw;
            }
        }
Exemplo n.º 2
0
        public void TestSelectWorkgroupReturnsViewWhenNoWorkgroupsFound()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2");
            SetupRoles();
            var users = new List <User>();
            for (int i = 0; i < 3; i++)
            {
                users.Add(CreateValidEntities.User(i + 1));
                users[i].SetIdTo((i + 1).ToString());
                users[i].WorkgroupPermissions = new List <WorkgroupPermission>();
            }
            UserRepository2.Expect(a => a.Queryable).Return(users.AsQueryable()).Repeat.Any();

            #endregion Arrange

            #region Act
            var result = Controller.SelectWorkgroup()
                         .AssertViewRendered()
                         .WithViewData <IEnumerable <Workgroup> >();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
            #endregion Assert
        }
Exemplo n.º 3
0
        public void TestSelectWorkgroupReturnsViewWhenMultipleWorkgroupsForUserFound()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            SetupRoles();

            var users = new List <User>();
            users.Add(CreateValidEntities.User(2));
            users[0].SetIdTo("Me");
            var permissions = new List <WorkgroupPermission>();
            for (int i = 0; i < 5; i++)
            {
                permissions.Add(CreateValidEntities.WorkgroupPermission(i + 1));
                permissions[i].Role      = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Requester);
                permissions[i].Workgroup = CreateValidEntities.Workgroup(i + 1);
            }
            permissions[0].Role = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Admin);
            permissions[2].Workgroup.IsActive       = false; //Don't use
            permissions[3].Workgroup.Administrative = true;  //Can't request
            users[0].WorkgroupPermissions           = permissions;
            UserRepository2.Expect(a => a.Queryable).Return(users.AsQueryable()).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = Controller.SelectWorkgroup()
                         .AssertViewRendered()
                         .WithViewData <IEnumerable <Workgroup> >();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("Name2", result.ElementAt(0).Name);
            Assert.AreEqual("Name5", result.ElementAt(1).Name);
            #endregion Assert
        }
Exemplo n.º 4
0
        public void TestSelectWorkgroupRedirectsWhenExactlyOneWorkgroup()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            SetupRoles();

            var users = new List <User>();
            users.Add(CreateValidEntities.User(2));
            users[0].SetIdTo("Me");
            var permissions = new List <WorkgroupPermission>();
            for (int i = 0; i < 5; i++)
            {
                permissions.Add(CreateValidEntities.WorkgroupPermission(i + 1));
                permissions[i].Role      = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Requester);
                permissions[i].Workgroup = CreateValidEntities.Workgroup(i + 1);
                permissions[i].Workgroup.SetIdTo(i + 1);
            }
            permissions[0].Role = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Admin);
            permissions[2].Workgroup.IsActive       = false; //Don't use
            permissions[3].Workgroup.Administrative = true;  //Can't request
            permissions[4].Workgroup.IsActive       = false;
            users[0].WorkgroupPermissions           = permissions;
            UserRepository2.Expect(a => a.Queryable).Return(users.AsQueryable()).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = Controller.SelectWorkgroup()
                         .AssertActionRedirect()
                         .ToAction <OrderController>(a => a.Request(2));
            #endregion Act

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