public async Task create_poll() { using (PollContext pollContext = TestHelpers.CreatePollContext()) { PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext); PollRepository sut = new PollRepository(pollContextAccessor); // We should create user for create poll associated with this user UserRepository userRepository = new UserRepository(pollContextAccessor); string email = $"{Guid.NewGuid()}@test.org"; string nickname = $"Test-{Guid.NewGuid()}"; User user = new User(0, email, nickname, "hash", false); Result userCreated = await userRepository.Create(user); Model.Poll poll = new Model.Poll(0, user.UserId, "Question?", false); Result creationStatus = await sut.Create(poll); userCreated.IsSuccess.Should().BeTrue(); creationStatus.IsSuccess.Should().BeTrue(); Result <Model.Poll> foundPoll = await sut.FindById(poll.PollId); foundPoll.IsSuccess.Should().BeTrue(); foundPoll.Value.AuthorId.Should().Be(poll.AuthorId); foundPoll.Value.PollId.Should().Be(poll.PollId); foundPoll.Value.Question.Should().Be(poll.Question); foundPoll.Value.IsDeleted.Should().BeFalse(); await TestHelpers.PollService.DeletePoll(pollContext, sut, poll.PollId); await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, user.UserId); } }
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); } }
public async Task deleted_user_cannot_create_poll() // Nicolas { using (PollContext pollContext = TestHelpers.CreatePollContext()) { PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext); UserRepository userRepository = new UserRepository(pollContextAccessor); PollRepository pollRepository = new PollRepository(pollContextAccessor); Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, $"test-{Guid.NewGuid()}@test.fr", $"Test-{Guid.NewGuid()}", "validpassword"); Result <User> userGuest = await TestHelpers.UserService.CreateUser(userRepository, $"test-{Guid.NewGuid()}@test.fr", $"Test-{Guid.NewGuid()}", "validpassword"); Result res = await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId); res.IsSuccess.Should().BeTrue(); Result <Poll> pollRes = await TestHelpers.PollService.CreatePoll(pollContext, pollRepository, userRepository, new NewPollDto() { AuthorId = user.Value.UserId, Question = "A question", Proposals = new string[] { "Proposal A", "Proposal B" }, GuestNicknames = new string[] { userGuest.Value.Nickname } }); pollRes.Error.Should().Be(Errors.AccountDeleted); } }
public async Task create_poll() { using (PollContext pollContext = TestHelpers.CreatePollContext()) { var pollContextAccessor = new PollContextAccessor(pollContext); var userRepository = new UserRepository(pollContextAccessor); var sut = new PollRepository(pollContextAccessor); var userService = TestHelpers.UserService; // create the user that'll later be the poll author var email = $"{Guid.NewGuid()}@test.org"; var nickname = $"Test-{Guid.NewGuid()}"; await userService.CreateUser( userRepository, email, nickname, "test-hash" ); var author = await userService.FindByNickname(userRepository, nickname); // create the guests that'll be used to create the poll var guest1 = await TestHelpers.UserService.CreateUser( userRepository, $"{Guid.NewGuid()}@test.org", $"Test-{Guid.NewGuid()}", "test-hash" ); var guest2 = await TestHelpers.UserService.CreateUser( userRepository, $"{Guid.NewGuid()}@test.org", $"Test-{Guid.NewGuid()}", "test-hash" ); var poll = new Model.Poll(0, author.Value.UserId, "question?", false); poll.AddGuest(guest1.Value.UserId, await sut.GetNoProposal()); poll.AddGuest(guest2.Value.UserId, await sut.GetNoProposal()); poll.AddProposal("P1"); poll.AddProposal("P2"); var result = await sut.Create(poll); result.IsSuccess.Should().BeTrue(); poll.PollId.Should().NotBe(0); var createdPoll = await sut.FindById(poll.PollId); createdPoll.Value.PollId.Should().Be(poll.PollId); await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, author.Value.UserId); await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, guest1.Value.UserId); await TestHelpers.UserService.DeleteUser(pollContext, userRepository, sut, guest2.Value.UserId); } }
public async Task can_create_account_with_weird_valid_email(string email) // Nicolas { using (PollContext pollContext = TestHelpers.CreatePollContext()) { PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext); UserRepository userRepository = new UserRepository(pollContextAccessor); string nickname = $"Test-{Guid.NewGuid()}"; pollContext.Database.BeginTransaction(); Result <User> user = await TestHelpers.UserService.CreateUser(userRepository, email, nickname, "validpassword"); pollContext.Database.RollbackTransaction(); user.IsSuccess.Should().BeTrue(); } }
public async Task create_poll_with_invalid_authorId_should_return_an_error() { using (PollContext pollContext = TestHelpers.CreatePollContext()) { var pollContextAccessor = new PollContextAccessor(pollContext); var userRepository = new UserRepository(pollContextAccessor); var sut = new PollRepository(pollContextAccessor); var userService = TestHelpers.UserService; var poll = new Model.Poll(0, -424, "question?", false); var result = await sut.Create(poll); result.IsSuccess.Should().BeFalse(); } }
public async Task heavy_load_test() // Nicolas { using (PollContext pollContext = TestHelpers.CreatePollContext()) { PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext); UserRepository userRepository = new UserRepository(pollContextAccessor); int load = 2_000; // I started with 1M then 20k but it was too slow... Task <Result <User> >[] tasks = new Task <Result <User> > [load]; for (int i = 0; i < load; i++) { tasks[i] = TestHelpers.UserService.CreateUser(userRepository, $"test-{Guid.NewGuid()}@test.fr", $"Test-{Guid.NewGuid()}", "validpassword"); } await Task.WhenAll(tasks); tasks.Select(s => s.Result.IsSuccess).Should().NotContain(false); } }
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); } }
public async Task create_user() { using (PollContext pollContext = TestHelpers.CreatePollContext()) { PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext); UserRepository sut = new UserRepository(pollContextAccessor); string email = $"{Guid.NewGuid()}@test.org"; string nickname = $"Test-{Guid.NewGuid()}"; Result <User> user = User.Create(email, nickname, "test-hash"); Result creationStatus = await sut.Create(user.Value); creationStatus.IsSuccess.Should().BeTrue(); Result <User> foundUser = await sut.FindByEmail(email); foundUser.IsSuccess.Should().BeTrue(); foundUser.Value.Should().BeEquivalentTo(user.Value); PollRepository pollRepository = new PollRepository(pollContextAccessor); await TestHelpers.UserService.DeleteUser(pollContext, sut, pollRepository, foundUser.Value.UserId); } }
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); } }
public async Task create_user() { using (PollContext pollContext = TestHelpers.CreatePollContext()) { PollContextAccessor pollContextAccessor = new PollContextAccessor(pollContext); UserRepository 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"); user.IsSuccess.Should().BeTrue(); user.Value.Email.Should().Be(email); user.Value.Nickname.Should().Be(nickname); user = await TestHelpers.UserService.FindByNickname(userRepository, nickname); user.IsSuccess.Should().BeTrue(); PollRepository pollRepository = new PollRepository(pollContextAccessor); await TestHelpers.UserService.DeleteUser(pollContext, userRepository, pollRepository, user.Value.UserId); } }