コード例 #1
0
        public async void LunchRepository_GetUsersOfTeamAsync_ReturnsNullWhenTeamNotFound()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);

            // act
            IEnumerable <UserDto> result = await target.GetUsersOfTeamAsync(1);

            // assert
            Assert.Null(result);
        }
コード例 #2
0
        public async void LunchRepository_GetUsersOfTeamAsync_ReturnsListOfUsersFromTeam()
        {
            // arrange
            LunchContext    context = GetContext();
            LunchRepository target  = new LunchRepository(context);
            TeamEntity      team    = context.Teams.Add(new TeamEntity
            {
                Name = "bob's team"
            }).Entity;
            UserEntity user = context.Users.Add(new UserEntity
            {
                Name = "bob"
            }).Entity;
            UserEntity user2 = context.Users.Add(new UserEntity
            {
                Name = "lilTimmy"
            }).Entity;

            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = user.Id,
                TeamId = team.Id
            });
            context.UserTeams.Add(new UserTeamEntity
            {
                UserId = user2.Id,
                TeamId = team.Id
            });
            context.SaveChanges();


            // act
            List <UserDto> result = (await target.GetUsersOfTeamAsync(team.Id)).ToList();

            // assert
            Assert.Equal(2, result.Count());
            Assert.Equal("bob", result[0].Name);
            Assert.Equal("lilTimmy", result[1].Name);
        }