예제 #1
0
        public void GetAllParticipants_ShouldThrow_IfUserIsNotCreator()
        {
            var coursesRepoBuilder = new CoursesRepositoryBuilder();
            var courseRepo         = coursesRepoBuilder
                                     .WithAll()
                                     .Build();

            var coursesUsersRepoBuilder = new CoursesUsersRepositoryBuilder();
            var coursUserRepo           = coursesUsersRepoBuilder
                                          .WithAll()
                                          .Build();

            var sut = new CoursesService(coursUserRepo, courseRepo, null, Mapper);

            var user = new GoUser {
                Id = "9"
            };

            var ex = Assert.Throws <ArgumentException>(() => sut.GetAllParticipants("1", user));

            Assert.Equal("You can not add results!", ex.Message);

            coursesRepoBuilder.CoursesRepoMock.Verify();
            coursesUsersRepoBuilder.CoursesUsersRepoMock.Verify();
        }
예제 #2
0
        public void GetAllParticipants_ShouldReturn_All_UsersResultsViewModels()
        {
            var coursesRepoBuilder = new CoursesRepositoryBuilder();
            var courseRepo         = coursesRepoBuilder
                                     .WithAll()
                                     .Build();

            var coursesUsersRepoBuilder = new CoursesUsersRepositoryBuilder();
            var coursUserRepo           = coursesUsersRepoBuilder
                                          .WithAll()
                                          .Build();

            var usersRepoBuilder = new GoUserRepositoryBuilder();
            var userRepo         = usersRepoBuilder
                                   .WithAll()
                                   .Build();

            var sut = new CoursesService(coursUserRepo, courseRepo, userRepo, Mapper);

            var user = new GoUser {
                Id = "7"
            };

            var actual = sut.GetAllParticipants("1", user);

            var expected = new List <UsersResultsViewModel>
            {
                new UsersResultsViewModel
                {
                    CourseId      = "1",
                    ParticipantId = "8",
                    Participant   = new GoUserViewModel {
                        Id = "8", FirstName = "Niki",
                    },
                    Result = StatusParticitant.Successfully
                },
                new UsersResultsViewModel
                {
                    CourseId      = "1",
                    ParticipantId = "9",
                    Participant   = new GoUserViewModel {
                        Id = "9", FirstName = "Pelin"
                    },
                    Result = StatusParticitant.Successfully
                },
                new UsersResultsViewModel
                {
                    CourseId      = "1",
                    ParticipantId = "11",
                    Participant   = new GoUserViewModel {
                        Id = "11", FirstName = "Koni"
                    },
                    Result = StatusParticitant.Unsuccessfully
                }
            }.AsQueryable();

            var usersFromActual   = actual.Select(x => x.Participant).ToList();
            var usersFromExpected = expected.Select(x => x.Participant).ToList();

            Assert.Equal(expected, actual, new UsersResultsViewModelComparer());
            Assert.Equal(usersFromExpected, usersFromActual, new GoUserViewModelComparer());

            coursesRepoBuilder.CoursesRepoMock.Verify();
            coursesUsersRepoBuilder.CoursesUsersRepoMock.Verify();
            usersRepoBuilder.UsersRepoMock.Verify();
        }