Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void CreatePoll()
        {
            Model.Poll     dummyPoll     = new Model.Poll(3712, 1, "Question?", false);
            Model.Proposal dummyProposal = dummyPoll.AddProposal(string.Empty);
            _poll = new Model.Poll(3712, 1, "Question?", false);

            _guests.Add(_poll.AddGuest(2, dummyProposal));
            _guests.Add(_poll.AddGuest(3, dummyProposal));
            _guests.Add(_poll.AddGuest(4, dummyProposal));

            {
                Model.Proposal p = _poll.AddProposal("Proposal 1");
                p.ProposalId = 1;
            }

            {
                Model.Proposal p = _poll.AddProposal("Proposal 2");
                p.ProposalId = 2;
            }

            {
                Model.Proposal p = _poll.AddProposal("Proposal 3");
                p.ProposalId = 3;
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        public void Save()
        {
            using (var db = new ezFixUpDataContext())
            {
                var poll = new Model.Poll
                                    {
                                        p_id = ID,
                                        p_title = Title,
                                        p_startdate = StartDate,
                                        p_enddate = EndDate,
                                        p_showresultsuntil = ShowResultsUntil
                                    };
                if (ID == 0)
                    db.Polls.InsertOnSubmit(poll);
                else
                {
                    db.Polls.Attach(poll, true);
                }

                db.SubmitChanges();

                if (ID == 0)
                    ID = poll.p_id;
            }            
        }