public async Task Should_allocate_existing_user_with_allocations_does_not_exist_in_aad()
        {
            const int NUMBER_OF_USERS = 3;
            var       users           = CreateListOfUsers(UserType.Individual, NUMBER_OF_USERS);
            var       allocations     = CreateAllocations(users);

            allocations.Count.Should().Be(NUMBER_OF_USERS);

            QueryHandler
            .Setup(x => x.Handle <GetAllUsersByFilterQuery, List <UserDto> >(It.IsAny <GetAllUsersByFilterQuery>()))
            .ReturnsAsync(users);

            QueryHandler
            .SetupSequence(x =>
                           x.Handle <GetAllocationByUserIdQuery, Allocation>(It.IsAny <GetAllocationByUserIdQuery>()))
            .ReturnsAsync(allocations[0])
            .ReturnsAsync(allocations[1])
            .ReturnsAsync(allocations[2]);

            var user = users.First();

            QueryHandler
            .Setup(x => x.Handle <GetUserByIdQuery, UserDto>(It.IsAny <GetUserByIdQuery>()))
            .ReturnsAsync(user);

            MockUserApiService
            .Setup(x => x.CheckUserExistsInAAD(It.IsAny <string>()))
            .ReturnsAsync(false);

            var newUserResponse = new NewUserResponse
            {
                OneTimePassword = "******",
                UserId          = "1234",
                Username        = user.Username
            };

            MockUserApiService
            .Setup(x => x.CreateNewUserInAAD(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .ReturnsAsync(newUserResponse);

            const int NUMBER_OF_USER_GROUPS = 2;

            MockUserApiService
            .Setup(x => x.AddGroupsToUser(It.IsAny <UserDto>(), It.IsAny <string>()))
            .ReturnsAsync(NUMBER_OF_USER_GROUPS);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <AllocateByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            const int MINUTES = 1;

            var allocatedUser = await AllocationService.AllocateToService(user.UserType, user.Application, user.TestType, user.IsProdUser, MINUTES);

            allocatedUser.Should().BeEquivalentTo(user);
        }
Exemplo n.º 2
0
        public async Task Should_allocate_new_user_no_users_exist_user_exists_in_aad()
        {
            const string ALLOCATED_BY = EmailData.TEST_WEB_MANUAL_USER;

            var users = new List <UserDto>();

            QueryHandler
            .Setup(x => x.Handle <GetAllUsersByFilterQuery, List <UserDto> >(It.IsAny <GetAllUsersByFilterQuery>()))
            .ReturnsAsync(users);

            const int NUMBER = 1;

            QueryHandler
            .Setup(x =>
                   x.Handle <GetNextUserNumberByUserTypeQuery, Integer>(It.IsAny <GetNextUserNumberByUserTypeQuery>()))
            .ReturnsAsync(new Integer(NUMBER));

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewUserCommand>()))
            .Returns(Task.CompletedTask);

            var user = CreateNewUser(UserType.Individual, NUMBER);

            QueryHandler
            .Setup(x => x.Handle <GetUserByUserTypeAppAndNumberQuery, UserDto>(
                       It.IsAny <GetUserByUserTypeAppAndNumberQuery>()))
            .ReturnsAsync(user);

            var allocation = CreateAllocation(user);

            allocation.AllocatedBy = ALLOCATED_BY;

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewAllocationByUserIdCommand>()))
            .Returns(Task.FromResult(allocation));

            QueryHandler
            .Setup(x => x.Handle <GetUserByIdQuery, UserDto>(It.IsAny <GetUserByIdQuery>()))
            .ReturnsAsync(user);

            MockUserApiService
            .Setup(x => x.CheckUserExistsInAAD(It.IsAny <string>()))
            .ReturnsAsync(true);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <AllocateByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            const int MINUTES = 1;

            var allocatedUser = await AllocationService.AllocateToService(user.UserType, user.Application, user.TestType, user.IsProdUser, MINUTES, ALLOCATED_BY);

            allocatedUser.Should().BeEquivalentTo(user);
        }
        public async Task Should_allocate_existing_user_with_no_allocations_exists_in_aad()
        {
            const int NUMBER_OF_USERS = 3;
            var       users           = CreateListOfUsers(UserType.Individual, NUMBER_OF_USERS);

            QueryHandler
            .Setup(x => x.Handle <GetAllUsersByFilterQuery, List <UserDto> >(It.IsAny <GetAllUsersByFilterQuery>()))
            .ReturnsAsync(users);

            var allocations = CreateAllocations(users);

            QueryHandler
            .SetupSequence(x =>
                           x.Handle <GetAllocationByUserIdQuery, Allocation>(It.IsAny <GetAllocationByUserIdQuery>()))
            .ReturnsAsync((Allocation)null)
            .ReturnsAsync(allocations[0])
            .ReturnsAsync((Allocation)null)
            .ReturnsAsync(allocations[1])
            .ReturnsAsync((Allocation)null)
            .ReturnsAsync(allocations[2]);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewAllocationByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            var user = users.First();

            QueryHandler
            .Setup(x => x.Handle <GetUserByIdQuery, UserDto>(It.IsAny <GetUserByIdQuery>()))
            .ReturnsAsync(user);

            MockUserApiService
            .Setup(x => x.CheckUserExistsInAAD(It.IsAny <string>()))
            .ReturnsAsync(true);

            var recentUser = new RecentUser(user.Username);

            QueryHandler
            .Setup(
                x => x.Handle <GetRecentUserByUsernameQuery, RecentUser>(It.IsAny <GetRecentUserByUsernameQuery>()))
            .ReturnsAsync(recentUser);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <AllocateByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            const int MINUTES = 1;

            var allocatedUser = await AllocationService.AllocateToService(user.UserType, user.Application, user.TestType, user.IsProdUser, MINUTES);

            allocatedUser.Should().BeEquivalentTo(user);
        }
Exemplo n.º 4
0
        public async Task Should_allocate_new_user_for_test_type(TestType testType)
        {
            var users = new List <UserDto>();

            QueryHandler
            .Setup(x => x.Handle <GetAllUsersByFilterQuery, List <UserDto> >(It.IsAny <GetAllUsersByFilterQuery>()))
            .ReturnsAsync(users);

            const int NUMBER = 1;

            QueryHandler
            .Setup(x =>
                   x.Handle <GetNextUserNumberByUserTypeQuery, Integer>(It.IsAny <GetNextUserNumberByUserTypeQuery>()))
            .ReturnsAsync(new Integer(NUMBER));

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewUserCommand>()))
            .Returns(Task.CompletedTask);

            var user = CreateNewUser(testType, NUMBER);

            QueryHandler
            .Setup(x => x.Handle <GetUserByUserTypeAppAndNumberQuery, UserDto>(
                       It.IsAny <GetUserByUserTypeAppAndNumberQuery>()))
            .ReturnsAsync(user);

            var allocation = CreateAllocation(user);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewAllocationByUserIdCommand>()))
            .Returns(Task.FromResult(allocation));

            QueryHandler
            .Setup(x => x.Handle <GetUserByIdQuery, UserDto>(It.IsAny <GetUserByIdQuery>()))
            .ReturnsAsync(user);

            MockUserApiService
            .Setup(x => x.CheckUserExistsInAAD(It.IsAny <string>()))
            .ReturnsAsync(true);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <AllocateByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            const int MINUTES = 1;

            var allocatedUser = await AllocationService.AllocateToService(user.UserType, user.Application, user.TestType, user.IsProdUser, MINUTES);

            allocatedUser.Should().BeEquivalentTo(user);
        }
Exemplo n.º 5
0
        public async Task Should_allocate_new_user_all_users_allocated_user_exists_in_aad()
        {
            const int      NUMBER_OF_USERS = 3;
            const UserType USER_TYPE       = UserType.Individual;
            var            users           = CreateListOfUsers(USER_TYPE, NUMBER_OF_USERS);
            var            allocations     = CreateAllocations(users);

            allocations.Count.Should().Be(NUMBER_OF_USERS);
            AllocateAllUsers(allocations);

            QueryHandler
            .Setup(x => x.Handle <GetAllUsersByFilterQuery, List <UserDto> >(It.IsAny <GetAllUsersByFilterQuery>()))
            .ReturnsAsync(users);

            QueryHandler
            .SetupSequence(x =>
                           x.Handle <GetAllocationByUserIdQuery, Allocation>(It.IsAny <GetAllocationByUserIdQuery>()))
            .ReturnsAsync(allocations[0])
            .ReturnsAsync(allocations[1])
            .ReturnsAsync(allocations[2]);

            var number = users.Count + 1;

            QueryHandler
            .Setup(x =>
                   x.Handle <GetNextUserNumberByUserTypeQuery, Integer>(It.IsAny <GetNextUserNumberByUserTypeQuery>()))
            .ReturnsAsync(new Integer(number));

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewUserCommand>()))
            .Returns(Task.CompletedTask);

            var user = CreateNewUser(USER_TYPE, number);

            QueryHandler
            .Setup(x => x.Handle <GetUserByUserTypeAppAndNumberQuery, UserDto>(
                       It.IsAny <GetUserByUserTypeAppAndNumberQuery>()))
            .ReturnsAsync(user);

            var allocation = CreateAllocation(user);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewAllocationByUserIdCommand>()))
            .Returns(Task.FromResult(allocation));

            QueryHandler
            .Setup(x => x.Handle <GetUserByIdQuery, UserDto>(It.IsAny <GetUserByIdQuery>()))
            .ReturnsAsync(user);

            MockUserApiService
            .Setup(x => x.CheckUserExistsInAAD(It.IsAny <string>()))
            .ReturnsAsync(true);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <AllocateByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            const int MINUTES = 1;

            var allocatedUser = await AllocationService.AllocateToService(user.UserType, user.Application, user.TestType, user.IsProdUser, MINUTES);

            allocatedUser.Should().BeEquivalentTo(user);
        }
Exemplo n.º 6
0
        public async Task Should_allocate_new_user_no_users_exist_does_not_exist_in_aad()
        {
            var users = new List <UserDto>();

            QueryHandler
            .Setup(x => x.Handle <GetAllUsersByFilterQuery, List <UserDto> >(It.IsAny <GetAllUsersByFilterQuery>()))
            .ReturnsAsync(users);

            const int NUMBER = 1;

            QueryHandler
            .Setup(x =>
                   x.Handle <GetNextUserNumberByUserTypeQuery, Integer>(It.IsAny <GetNextUserNumberByUserTypeQuery>()))
            .ReturnsAsync(new Integer(NUMBER));

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewUserCommand>()))
            .Returns(Task.CompletedTask);

            var user = CreateNewUser(UserType.Individual, NUMBER);

            QueryHandler
            .Setup(x => x.Handle <GetUserByUserTypeAppAndNumberQuery, UserDto>(
                       It.IsAny <GetUserByUserTypeAppAndNumberQuery>()))
            .ReturnsAsync(user);

            var allocation = CreateAllocation(user);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <CreateNewAllocationByUserIdCommand>()))
            .Returns(Task.FromResult(allocation));

            QueryHandler
            .Setup(x => x.Handle <GetUserByIdQuery, UserDto>(It.IsAny <GetUserByIdQuery>()))
            .ReturnsAsync(user);

            MockUserApiService
            .Setup(x => x.CheckUserExistsInAAD(It.IsAny <string>()))
            .ReturnsAsync(false);

            var newUserResponse = new NewUserResponse
            {
                OneTimePassword = "******",
                UserId          = "1234",
                Username        = user.Username
            };

            MockUserApiService
            .Setup(x => x.CreateNewUserInAAD(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()))
            .ReturnsAsync(newUserResponse);

            const int NUMBER_OF_USER_GROUPS = 2;

            MockUserApiService
            .Setup(x => x.AddGroupsToUser(It.IsAny <UserDto>(), It.IsAny <string>()))
            .ReturnsAsync(NUMBER_OF_USER_GROUPS);

            CommandHandler
            .Setup(x => x.Handle(It.IsAny <AllocateByUserIdCommand>()))
            .Returns(Task.CompletedTask);

            const int MINUTES = 1;

            var allocatedUser = await AllocationService.AllocateToService(user.UserType, user.Application, user.TestType, user.IsProdUser, MINUTES);

            allocatedUser.Should().BeEquivalentTo(user);
        }