Beispiel #1
0
        private TestUserRepository CreateUserRepository(int currentUserId)
        {
            var repo = new TestUserRepository();

            repo.SetCurrentUser(new TGuid(currentUserId).ToGuid().ToString());
            return(repo);
        }
        private TestEventRepository CreateFilledEventRepository(TestUserRepository userRepo)
        {
            var repo   = CreateTestEventRepository();
            var users  = userRepo.GetUsersByRole(RoleType.Manager);
            var @event = CreateEvent(new TGuid(0).ToGuid().ToString());

            @event.Id = 1;
            repo.Events.Add(@event);
            var workEvent = CreateEvent(new TGuid(2).ToGuid().ToString());

            workEvent.Id = 2;
            repo.Events.Add(workEvent);
            foreach (var user in users)
            {
                repo.EventsUsers.Add(new WorkEventUserRelation(@event.Id, user.Id)
                {
                    State = EventState.New
                });
                repo.EventsUsers.Add(new WorkEventUserRelation(workEvent.Id, user.Id)
                {
                    State = EventState.Seen
                });
            }
            return(repo);
        }
Beispiel #3
0
        public void UserHasRole_Should_Return_False_IfUserDoes_NotHaveRole()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1"
                }, new Role()
                {
                    RoleName = "Role2"
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            bool userHasRole = service.UserHasRole("TestUser", "Admin");

            // Assert
            Assert.IsFalse(userHasRole, "Expected False. User Does not have Admin Role");
        }
Beispiel #4
0
        public void UserHasRole_Should_Return_True_IfUserHasRole()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1"
                }, new Role()
                {
                    RoleName = "Role2"
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            bool userHasRole = service.UserHasRole("TestUser", "Role1");

            // Assert
            Assert.IsTrue(userHasRole, "Expected True.User has Role1");
        }
Beispiel #5
0
        public void GetUserRoles_Should_Return_All_User_Roles()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1"
                }, new Role()
                {
                    RoleName = "Role2"
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            var userRoles = service.GetUserRoles("TestUser");

            // Assert
            Assert.IsTrue(userRoles.Length == 2, "Expected to return 2 roles");
            Assert.IsTrue(userRoles[0] == "role1");
            Assert.IsTrue(userRoles[1] == "role2");
        }
Beispiel #6
0
        public void UserEdit()
        {
            //Init
            var repository = new TestUserRepository();
            var service    = new ManagementService();

            //Given
            var user = TestUserRepository.GenerateUser();

            repository.Users.Add(user);
            var edit = new UserEdit
            {
                UserId  = "TESTMETHOD",
                NewRole = TimeTableRole.Management
            };

            //When
            var updatedUser = service.EditUser(repository, edit);

            //Then
            var newuser = repository.Users[0];

            Assert.AreEqual(TimeTableRole.Management, newuser.Role, "Role was not updated");
            Assert.AreEqual("Management", newuser.RoleString, "RoleString was not updated");
        }
Beispiel #7
0
        public async Task MaintenanceBooking()
        {
            //Init
            var classroomRepo = new TestClassroomRepository();
            var userRepo      = new TestUserRepository();
            var bookingRepo   = new TestBookingRepository();

            var managementService = new ManagementService();
            var bookingService    = new BookingService(bookingRepo, classroomRepo);

            var notifier = new TestNotifier();

            //Given
            var user    = TestUserRepository.GenerateUser();
            var booking = new Booking
            {
                Classroom  = "H.1.110",
                Week       = 25,
                WeekDay    = 2,
                StartBlock = 1,
                EndBlock   = 10,
                Type       = BookingType.Maintenance,
                Owner      = user.UserId,
            };

            //When
            var actualBookingResult = await managementService.MaintenanceBooking(classroomRepo, bookingRepo, userRepo,
                                                                                 bookingService, booking, user.UserId, notifier);

            //Then
            Assert.AreEqual(BookingAvailability.Success, actualBookingResult);
        }
Beispiel #8
0
        public TestUserForm(TestUserRepository testUserRepository)
        {
            InitializeComponent();

            _testUserRepository = testUserRepository;

            Init();
        }
Beispiel #9
0
        public void SetUp()
        {
            userRepository = new TestUserRepository();
            taskRepository = new TestTaskRepository();
            selector       = new TestTaskGeneratorSelector();

            application = new QuizService(userRepository, taskRepository, selector, NullLogger <QuizService> .Instance, new Random());
        }
Beispiel #10
0
 public OneItemConfigurationForm(OneItemConfigurationState oneItemConfigurationMode,
                                 TestUserRepository userRepository)
 {
     InitializeComponent();
     _oneItemConfiguration = OneItemConfigurationFactory.GetOneItemConfiguration(oneItemConfigurationMode,
                                                                                 userRepository);
     _oneItemConfiguration.SetConfiguraionLabel(oneItemConfigurationLabel);
     _oneItemConfiguration.SetConfiguraionTextBox(oneItemConfigurationTextBox);
 }
        public void GetDetailsTest()
        {
            TestUserRepository repository = new TestUserRepository();
            var        controller         = GetUserController(repository);
            User       user   = GetTestUser();
            ViewResult result = (ViewResult)controller.Details(user.Id);

            Assert.AreEqual("Details", result.ViewName);
        }
        public void UpdateLastLoginTest()
        {
            TestUserRepository repository = new TestUserRepository();
            User user = GetTestUser();

            user.Last_Login = DateTime.Now.Date;
            bool result = repository.UpdateLastLogin(user);

            Assert.IsTrue(result);
        }
Beispiel #13
0
        public void UserRepository_Should_Return_Users()
        {
            // Arange
            IUserRepository repository = new TestUserRepository();

            // Act
            var users = repository.GetAllUsers();

            // Assert
            Assert.IsNotNull(users);
        }
        public void PostRegisterTest()
        {
            TestUserRepository repository = new TestUserRepository();
            UserController     controller = new UserController(repository);
            User user = GetTestUser();

            controller.Register(user);
            IEnumerable <User> users = repository.GetAllTestUsers();

            Assert.IsTrue(users.Contains(user));
        }
Beispiel #15
0
        public void GetUserWithID_Should_Return_Null_For_FalseID()
        {
            // Arrange
            var repository = new TestUserRepository();

            // Act
            var user = repository.GetUser(20);

            // Assert
            Assert.IsNull(user);
        }
Beispiel #16
0
        public void TestUserRepository_Should_Return_15Users()
        {
            // Arange
            IUserRepository repository = new TestUserRepository();

            // Act
            var users = repository.GetAllUsers();

            // Assert
            Assert.AreEqual(15, users.Count());
        }
Beispiel #17
0
        public void GetUser_ShouldReturn_Null_ForFalse_UserName()
        {
            // Arrange
            IUserRepository repository = new TestUserRepository();

            // Act
            User user = repository.GetUser("BOGUS");

            // Assert
            Assert.IsNull(user);
        }
        public void PostDeleteTest()
        {
            TestUserRepository testRepository = new TestUserRepository();
            UserController     usercontroller = GetUserController(testRepository);
            int  id   = 1;
            User user = TestUserRepository._db.SingleOrDefault(b => b.Id == id);

            usercontroller.PostDelete(id);
            IEnumerable <User> users = testRepository.GetAllTestUsers();

            Assert.IsFalse(users.Contains(user));
        }
        public void PostEditTest()
        {
            User user = new User();
            TestUserRepository testRepository = new TestUserRepository();
            UserController     usercontroller = GetUserController(testRepository);

            user = GetTestUser();
            usercontroller.Edit(user);
            IEnumerable <User> users = testRepository.GetAllTestUsers();

            Assert.IsTrue(users.Contains(user));
        }
Beispiel #20
0
        public void GetUser_ShouldReturn_UserObject_ForTrue_UserName()
        {
            // Arrange
            IUserRepository repository = new TestUserRepository();

            // Act
            User user = repository.GetUser("UserName1");

            // Assert
            Assert.IsNotNull(user);
            Assert.AreEqual("UserName1", user.UserName);
        }
Beispiel #21
0
        private AuthorizationController GetMockRepositoryController()
        {
            var userRepository  = new TestUserRepository();
            var rolesRepository = new TestRolesRepository();

            var userService  = new UserService(userRepository);
            var rolesService = new RolesService(userRepository, rolesRepository);

            var controller = new AuthorizationController(userService, rolesService);

            return(controller);
        }
Beispiel #22
0
        public void GetUserWithID_Should_Return_User_For_TrueID()
        {
            // Arrange
            var repository = new TestUserRepository();

            // Act
            var user = repository.GetUser(1);

            // Assert
            Assert.IsNotNull(user);
            Assert.AreEqual(user.UserName, "UserName1");
            Assert.AreEqual(user.Password, "Password1");
        }
        public void PostLoginTest()
        {
            TestUserRepository testRepository = new TestUserRepository();
            UserController     usercontroller = GetUserController(testRepository);
            User user = new User()
            {
                First_Name = "f_name", Last_Name = "l_name", EmailID = "*****@*****.**", Password = "******", Last_Login = DateTime.Now, Joined_Date = DateTime.Now
            };

            usercontroller.Login(user);
            int actual = UserRepository.count;

            Assert.AreEqual(0, actual);
        }
        /// <summary>
        /// СОздание тестовых рабочих элементов. Для каждого ГИП по проекту. В каждом проекте - 2 стадии
        /// В каждой стадии по 4 раздела для каждого РН. В каждом разделе:
        /// Если раздел не в работе, то по заданию для каждого исполнителя в том же состоянии, что и раздел.
        /// Если раздел в работе, то по 10 заданий для каждого исполнителя в разных состояниях (на одно состояние одно задание, созданное РН
        /// и одно задание созданное самим исполнителем) Задания со статусом новые - без исполнителя.
        /// </summary>
        /// <param name="userRepo"></param>
        /// <returns></returns>
        public static TestWorkItemRepository CreateFilledWorkItemRepository(TestUserRepository userRepo)
        {
            var workItemRepository = new TestWorkItemRepository(userRepo);
            var mainEngeneers      = userRepo.GetUsersByRole(Resources.MainProjectEngineer).ToList();

            for (int i = 0; i < mainEngeneers.Count; i++)
            {
                var project = CreateWorkItem(workItemRepository.WorkItems, i, WorkItemType.Project, mainEngeneers[i], mainEngeneers[i], WorkItemState.AtWork);
                workItemRepository.WorkItems.Add(project);
                AddStagesForProject(project, workItemRepository, userRepo, mainEngeneers, mainEngeneers[i]);
            }

            return(workItemRepository);
        }
Beispiel #25
0
        public void DeteUser_Should_Delete_ApropriateUser()
        {
            // Arrange
            var repository   = new TestUserRepository();
            var userToDelete = repository.GetUser(1);

            // Act
            repository.DeleteUser(userToDelete);
            var userDeleted = repository.GetUser(1);

            // Assert
            Assert.AreEqual(repository.GetAllUsers().Count(), 14);
            Assert.IsNull(userDeleted);
        }
Beispiel #26
0
        public async Task MaintenanceBookingWithRealBlocking()
        {
            //Init
            var classroomRepo = new TestClassroomRepository();
            var userRepo      = new TestUserRepository();
            var bookingRepo   = new TestBookingRepository();

            var managementService = new ManagementService();
            var bookingService    = new BookingService(bookingRepo, classroomRepo);

            var notifier = new TestNotifier();

            //Given
            var user  = TestUserRepository.GenerateUser();
            var user2 = TestUserRepository.GenerateUser("TESTUSER2", TimeTableRole.Management);

            userRepo.Users.Add(user);
            userRepo.Users.Add(user2);

            var bookingBlocking = new Booking
            {
                Classroom  = "H.1.110",
                Week       = 25,
                WeekDay    = 2,
                StartBlock = 2,
                EndBlock   = 4,
                Type       = 0,
                Owner      = user2.UserId,
            };

            bookingRepo.Bookings.Add(bookingBlocking);


            //When
            var booking = new Booking
            {
                Classroom  = "H.1.110",
                Week       = 25,
                WeekDay    = 2,
                StartBlock = 1,
                EndBlock   = 10,
                Type       = BookingType.Maintenance,
                Owner      = user.UserId,
            };
            var actualBookingResult = await managementService.MaintenanceBooking(classroomRepo, bookingRepo, userRepo,
                                                                                 bookingService, booking, user.UserId, notifier);

            //Then
            Assert.AreEqual(BookingAvailability.Booked, actualBookingResult);
        }
        public void AmountOfUsers()
        {
            //Init
            var repo    = new TestUserRepository();
            var service = new StatisticsService();

            //When
            repo.Users.Add(TestUserRepository.GenerateUser());
            repo.Users.Add(TestUserRepository.GenerateUser());

            var amount = service.AmountOfUsers(repo);

            //Then
            Assert.AreEqual(2, amount, "Amount of users differs from expected");
        }
        public void DisplayFullList()
        {
            var testRepo = new TestUserRepository();
            var app      = new HandyDandyApplication(testRepo);
            var data     = string.Empty;

            using (var writer = new StringWriter())
            {
                app.DisplayUsers(writer);
                data = writer.ToString();
            }

            var lines = data.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.True(lines.Length == 3);
        }
Beispiel #29
0
        public void DeteUser_Should_ThrowExceptionFor_InvalidUser()
        {
            // Arrange
            var repository   = new TestUserRepository();
            var userToDelete = new User()
            {
                UserID = 22
            };

            // Act
            try
            {
                repository.DeleteUser(userToDelete);
                Assert.Fail();
            }
            catch (Exception ex) {}
        }
        public static IOneItemConfiguration GetOneItemConfiguration(OneItemConfigurationState state,
                                                                    TestUserRepository testUserRepository)
        {
            switch (state)
            {
            case OneItemConfigurationState.NewDescription:
                return(new OneItemConfigurationDescripiton(testUserRepository));

            case OneItemConfigurationState.NewPassword:
                return(new OneItemConfigurationPassword(testUserRepository));

            case OneItemConfigurationState.UserToSearch:
                return(new OneItemConfigurationSearchUsers(testUserRepository));

            default:
                throw new Exception("OneItemConfiguration Value Unespected");
            }
        }
 public TestImplementation(TestUserRepository userRepository, ILdapManager ldapManagerObj)
 {
     _userRepository = userRepository;
     _ldapManagerObj = ldapManagerObj;
 }