Пример #1
0
        public async Task create_poll()
        {
            IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>();

            IPollRepository pollRepository = Substitute.For <IPollRepository>();

            pollRepository.Create(Arg.Any <Poll>()).Returns(Task.FromResult(Result.CreateSuccess()));

            IUserRepository userRepository = Substitute.For <IUserRepository>();

            userRepository.Create(Arg.Any <User>()).Returns(Task.FromResult(Result.CreateSuccess()));
            User user = new User(1234, "*****@*****.**", "toto", "passwordhash", false);

            userRepository.FindById(Arg.Any <int>()).Returns(Task.FromResult(Result.CreateSuccess(user)));
            userRepository.FindByNickname(Arg.Any <string>()).Returns(Task.FromResult(Result.CreateSuccess(user)));

            NewPollDto newPollDto = new NewPollDto();

            newPollDto.AuthorId       = 1234;
            newPollDto.Question       = "Question?";
            newPollDto.GuestNicknames = new string[] { "Guest1" };
            newPollDto.Proposals      = new string[] { "P1", "P2" };
            PollService sut = new PollService();

            Result <Poll> poll = await sut.CreatePoll(unitOfWork, pollRepository, userRepository, newPollDto);

            poll.IsSuccess.Should().BeTrue();
        }
Пример #2
0
        public async Task guest_add_answer_to_proposal()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                var pollRepository = new PollRepository(pollContextAccessor);
                var userRepository = new UserRepository(pollContextAccessor);


                string email    = $"test-{Guid.NewGuid()}@test.fr";
                string nickname = $"Test-{Guid.NewGuid()}";

                Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, email, nickname, "validpassword");

                Result <User> guest = await TestHelpers.UserService.CreateUser(userRepository, $"{email}-guest", $"{nickname}-guest", "validpassword");

                var pollDto = new NewPollDto
                {
                    AuthorId       = user.Value.UserId,
                    Question       = "Test-Question ",
                    GuestNicknames = new[] { guest.Value.Nickname },
                    Proposals      = new[] { "proposal1", "proposal2" },
                };
                var pollCreated = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, pollDto);

                var addAnswer = await TestHelpers.PollService.Answer(pollContext, pollRepository, pollCreated.Value.PollId, guest.Value.UserId, pollCreated.Value.Proposals[0].ProposalId);

                addAnswer.IsSuccess.Should().BeTrue();
                await TestHelpers.PollService.DeletePoll(pollContext, pollRepository, pollCreated.Value.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, guest.Value.UserId);
            }
        }
Пример #3
0
        public async Task create_poll()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                var pollRepository = new PollRepository(pollContextAccessor);
                var userRepository = new UserRepository(pollContextAccessor);


                string email    = $"test-{Guid.NewGuid()}@test.fr";
                string nickname = $"Test-{Guid.NewGuid()}";

                Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, email, nickname, "validpassword");

                Result <User> guest = await TestHelpers.UserService.CreateUser(userRepository, $"{email}-guest", $"{nickname}-guest", "validpassword");

                var pollDto = new NewPollDto
                {
                    AuthorId       = user.Value.UserId,
                    Question       = "Test-Question ",
                    GuestNicknames = new[] { guest.Value.Nickname },
                    Proposals      = new[] { "proposal1", "proposal2" }
                };
                var pollCreated = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, pollDto);

                pollCreated.IsSuccess.Should().BeTrue();
                pollCreated.Value.Guests.Should().HaveCount(pollDto.GuestNicknames.Length);
                pollCreated.Value.Proposals.Should().HaveCount(pollDto.Proposals.Length);
                pollCreated.Value.AuthorId.Should().Be(pollDto.AuthorId);
                pollCreated.Value.Question.Should().Be(pollDto.Question);

                var poll = await TestHelpers.PollService.FindById(pollRepository, pollCreated.Value.PollId);

                poll.IsSuccess.Should().BeTrue();

                await TestHelpers.PollService.DeletePoll(pollContext, pollRepository, pollCreated.Value.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, guest.Value.UserId);
            }
        }
Пример #4
0
        public async Task create_poll()
        {
            using (PollContext pollContext = TestHelpers.CreatePollContext())
            {
                PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext);
                PollRepository      pollRepository      = new PollRepository(pollContextAccessor);
                UserRepository      userRepository      = new UserRepository(pollContextAccessor);

                // We should create Author user for create poll associated with this user
                string        emailAuthor       = $"{Guid.NewGuid()}@test.org";
                string        nicknameAuthor    = $"Test-{Guid.NewGuid()}";
                Result <User> userAuthorCreated = await TestHelpers.UserService.CreateUser(userRepository, emailAuthor, nicknameAuthor, "hashpassword");

                // We should create Guest user for create poll associated with this user
                string        emailGuest       = $"{Guid.NewGuid()}@test.org";
                string        nicknameGuest    = $"Test-{Guid.NewGuid()}";
                Result <User> userGuestCreated = await TestHelpers.UserService.CreateUser(userRepository, emailGuest, nicknameGuest, "hashpassword");

                NewPollDto newPollDto = new NewPollDto();
                newPollDto.AuthorId       = userAuthorCreated.Value.UserId;
                newPollDto.Question       = "Question?";
                newPollDto.GuestNicknames = new string[] { userGuestCreated.Value.Nickname };
                newPollDto.Proposals      = new string[] { "P1", "P2" };

                Result <Poll> poll = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, newPollDto);


                poll.IsSuccess.Should().BeTrue();
                Result <Poll> foundPoll = await TestHelpers.PollService.FindById(pollRepository, poll.Value.PollId);

                poll.Should().BeEquivalentTo(foundPoll);

                await TestHelpers.PollService.DeletePoll(pollContext, pollRepository, poll.Value.PollId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, userAuthorCreated.Value.UserId);

                await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, userGuestCreated.Value.UserId);
            }
        }