public async Task GetAllOrderedByAsync_ExpectAscendingOrder_And_IncludeCourses()
        {
            //Arrange
            await SetUpData();

            var firstUserName = User + "9";
            var lastUserName  = User + "1";

            //Act
            var courses = await CourseQueryRepository.GetAllAsync();

            var allUsers = await UserQueryRepository.GetAllAsync();

            for (var i = 0; i < courses.Count; i++)
            {
                courses[i].UserId = allUsers[i].Id;
            }

            await CourseCommandRepository.UpdateListAsync(courses);

            var teachers = await this.UserQueryRepository.GetAllOrderedByAsync(user => user.FirstName, Sort.Asc, user => user.Courses);

            //Assert
            Assert.Equal(firstUserName, teachers.First().FirstName);
            Assert.Equal(1, teachers.First().Courses.Count);
            Assert.Equal(lastUserName, teachers.Last().FirstName);
            Assert.Equal(1, teachers.Last().Courses.Count);
        }
Ejemplo n.º 2
0
        public async Task Add_CheckCount_ExpectTwo()
        {
            //Act
            await UserCommandRepository.AddAsync(new User { FirstName = "User1" });

            await UserCommandRepository.AddAsync(new User { FirstName = "User2" });

            var actualAmount = (await UserQueryRepository.GetAllAsync()).Count;

            //Assert
            Assert.Equal(2, actualAmount);
        }
Ejemplo n.º 3
0
        public async Task Delete_CheckCount_ExpectZero()
        {
            //Act
            await UserCommandRepository.AddAsync(new User { FirstName = "User1" });

            await UserCommandRepository.AddAsync(new User { FirstName = "User2" });

            var toDelete = await UserQueryRepository.GetAllAsync();

            await UserCommandRepository.DeleteAsync(toDelete.First());

            await UserCommandRepository.DeleteAsync(toDelete.Last());

            var actualAmount = (await UserQueryRepository.GetAllAsync()).Count;

            //Assert
            Assert.Equal(0, actualAmount);
        }
        public async Task GetFilteredtWithPagingAndOrderAsync_And_IncludeCourses_PageSizeIsNegative_ExpectArgumentException()
        {
            //Arrange
            await SetUpData();

            //Act
            var courses = await CourseQueryRepository.GetAllAsync();

            var allUsers = await UserQueryRepository.GetAllAsync();

            for (var i = 0; i < courses.Count; i++)
            {
                courses[i].UserId = allUsers[i].Id;
            }

            await CourseCommandRepository.UpdateListAsync(courses);

            //Assert
            await Assert.ThrowsAsync <ArgumentException>(() => this.UserQueryRepository.GetFilteredtWithPagingAndOrderAsync(t => t.FirstName.Contains(User), t => t.FirstName, 0, -1, Sort.Asc, t => t.Courses));
        }
Ejemplo n.º 5
0
        public async Task UpdateAllAsync_Expect_TeacherNamesChanged()
        {
            //Arrange
            var user1 = new User {
                FirstName = "user1"
            };
            var user2 = new User {
                FirstName = "user2"
            };
            var user3 = new User {
                FirstName = "user3"
            };
            var user4 = new User {
                FirstName = "user4"
            };
            var expectedTitle = "changed Name";

            //Act
            await UserCommandRepository.AddListAsync(new List <User> {
                user1, user2, user3, user4
            });

            var toChange = await UserQueryRepository.GetAllAsync();

            toChange.ForEach(teacher => teacher.FirstName = expectedTitle);

            var firstPairOfTeachers = toChange.Take(2).ToList();
            var scondPairOfTeachers = toChange.Skip(2).Take(2).ToList();
            await UserCommandRepository.UpdateListAsync(firstPairOfTeachers);

            await UserCommandRepository.UpdateListAsync(scondPairOfTeachers);

            var teachers = await UserQueryRepository.GetAllAsync();

            //Assert
            foreach (var teacher in teachers)
            {
                Assert.Equal(expectedTitle, teacher.FirstName);
            }
        }
Ejemplo n.º 6
0
        public async Task Update_Expect_TeacherNameChanged()
        {
            //Arrange
            var expectedName = "changed name";

            //Act
            await UserCommandRepository.AddAsync(new User { FirstName = "User1" });

            await UserCommandRepository.AddAsync(new User { FirstName = "User2" });

            var toChange = await UserQueryRepository.GetAllAsync();

            toChange.ForEach(teacher => teacher.FirstName = expectedName);
            await UserCommandRepository.UpdateAsync(toChange.First());

            await UserCommandRepository.UpdateAsync(toChange.Last());

            var result = await UserQueryRepository.GetAllAsync();

            //Assert
            Assert.Equal(expectedName, result.First().FirstName);
            Assert.Equal(expectedName, result.Last().FirstName);
        }
        public async Task GetAllAsync_AllUser_Expect20_And_IncludeCourse()
        {
            //Arrange
            await SetUpData();

            var courses = await CourseQueryRepository.GetAllAsync();

            var allUsers = await UserQueryRepository.GetAllAsync();

            for (var i = 0; i < courses.Count; i++)
            {
                courses[i].UserId = allUsers[i].Id;
            }

            await CourseCommandRepository.UpdateListAsync(courses);

            //Act
            var result = await this.UserQueryRepository.GetAllAsync(t => t.Courses);

            //Assert
            Assert.Equal(20, result.Count);
            Assert.Equal(1, result.First().Courses.Count);
        }
        public async Task GetFilteredtWithPagingAndOrderAsync_ExpectAscendingOrder_And_IncludeCourses()
        {
            //Arrange
            await SetUpData();

            var siteOneFirstUserName = User + "9";
            var SiteOneLastUserName  = User + "5";
            var siteTwoFirstUserName = User + "4";
            var SiteTwoLastUserName  = User + "19";

            //Act
            var courses = await CourseQueryRepository.GetAllAsync();

            var allUsers = await UserQueryRepository.GetAllAsync();

            for (var i = 0; i < courses.Count; i++)
            {
                courses[i].UserId = allUsers[i].Id;
            }

            await CourseCommandRepository.UpdateListAsync(courses);

            var teacherSite1 = await this.UserQueryRepository.GetFilteredtWithPagingAndOrderAsync(t => t.FirstName.Contains(User), t => t.FirstName, 0, 5, Sort.Asc, t => t.Courses);

            var teacherSite2 = await this.UserQueryRepository.GetFilteredtWithPagingAndOrderAsync(t => t.FirstName.Contains(User), t => t.FirstName, 1, 5, Sort.Asc, t => t.Courses);

            //Assert
            Assert.Equal(5, teacherSite1.Count);
            Assert.Equal(siteOneFirstUserName, teacherSite1.First().FirstName);
            Assert.Equal(SiteOneLastUserName, teacherSite1.Last().FirstName);
            Assert.Equal(1, teacherSite1.Last().Courses.Count);

            Assert.Equal(5, teacherSite2.Count);
            Assert.Equal(siteTwoFirstUserName, teacherSite2.First().FirstName);
            Assert.Equal(SiteTwoLastUserName, teacherSite2.Last().FirstName);
            Assert.Equal(1, teacherSite2.Last().Courses.Count);
        }
Ejemplo n.º 9
0
        public async Task AddList_CheckCount_ExpectTwo()
        {
            //Arrange
            var user1 = new User {
                FirstName = "User1"
            };
            var user2 = new User {
                FirstName = "User2"
            };

            //Act
            await UserCommandRepository.AddListAsync(new List <User> {
                user1
            });

            await UserCommandRepository.AddListAsync(new List <User> {
                user2
            });

            var actualAmount = (await UserQueryRepository.GetAllAsync()).Count;

            //Assert
            Assert.Equal(2, actualAmount);
        }