コード例 #1
0
        public async Task <RecentUser> SeedRecentUser(string username)
        {
            await using var db = new TestApiDbContext(_dbContextOptions);
            var recentUser = new RecentUser(username);
            await db.RecentUsers.AddAsync(recentUser);

            await db.SaveChangesAsync();

            return(recentUser);
        }
        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);
        }
コード例 #3
0
        public async Task Handle(CreateNewRecentUserByUsernameCommand command)
        {
            var recentUser = await _context.RecentUsers
                             .SingleOrDefaultAsync(x => x.Username == command.Username);

            if (recentUser != null)
            {
                throw new RecentUserAlreadyExistsException(command.Username);
            }

            recentUser = new RecentUser(command.Username);

            await _context.RecentUsers.AddAsync(recentUser);

            await _context.SaveChangesAsync();
        }