Exemplo n.º 1
0
        public void EditPollShoudEditTitleInPoll()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            var model = new UpdateDeletePollViewModel
            {
                Title = "Edited"
            };

            var poll = new Poll
            {
                Title = "New"
            };

            dbContext.Polls.Add(poll);
            dbContext.SaveChanges();

            var pollToEdit = dbContext.Polls.First();

            service.EditPoll(pollToEdit, model);

            Assert.Equal("Edited", pollToEdit.Title);
        }
Exemplo n.º 2
0
        public void GetPollsParticipantsShouldReturnAllParticipantsFromPoll()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            dbContext.Polls.Add(new Poll());
            var user = new LessplasticUser
            {
                UserName = "******"
            };
            var secondUser = new LessplasticUser
            {
                UserName = "******"
            };

            dbContext.Users.Add(user);
            dbContext.Users.Add(secondUser);
            dbContext.SaveChanges();

            var poll = dbContext.Polls.First();

            service.AddParticipant(poll, "test");
            service.AddParticipant(poll, "test2");

            var participants = service.GetPollsParticipants(poll.Id);

            Assert.Equal(2, participants.Length);
        }
Exemplo n.º 3
0
        public void CreatePollShouldCreatePoll()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            var model = new PollViewModel
            {
                Title   = "something",
                Answers = "Da, Ne, Moje"
            };

            service.CreatePoll(model);

            Assert.Equal(1, dbContext.Polls.Count());
        }
Exemplo n.º 4
0
        public void DeletePollShouldDeletePollFromDatabase()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            dbContext.Polls.Add(new Poll());
            dbContext.Polls.Add(new Poll());
            dbContext.Polls.Add(new Poll());
            dbContext.SaveChanges();

            var poll = dbContext.Polls.First();

            service.DeletePoll(poll);

            Assert.Equal(2, dbContext.Polls.Count());
        }
Exemplo n.º 5
0
        public void GetPollsShouldReturnAllPollsInDatabase()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            dbContext.Polls.Add(new Poll());
            dbContext.Polls.Add(new Poll());
            dbContext.Polls.Add(new Poll());
            dbContext.Polls.Add(new Poll());
            dbContext.Polls.Add(new Poll());
            dbContext.SaveChanges();

            var returnedPolls = service.GetPolls();

            Assert.Equal(5, returnedPolls.Length);
        }
Exemplo n.º 6
0
        public void GetPollsAnswersShouldReturnAllAnswersFromPoll()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            var model = new PollViewModel
            {
                Title   = "something",
                Answers = "Da, Ne, Moje"
            };

            service.CreatePoll(model);

            var answers = service.GetPollsAnswers(1);

            Assert.Equal(3, answers.Length);
        }
Exemplo n.º 7
0
        public void GetPollShouldReturnPollById()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            var poll = new Poll
            {
                Title = "Test"
            };

            dbContext.Polls.Add(poll);
            dbContext.SaveChanges();

            var returnedPoll = service.GetPoll(1);

            Assert.Equal(poll.Title, returnedPoll.Title);
        }
Exemplo n.º 8
0
        public void AddParticipantShouldAddParticipantToPoll()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            dbContext.Polls.Add(new Poll());
            var user = new LessplasticUser
            {
                UserName = "******"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var poll = dbContext.Polls.First();

            service.AddParticipant(poll, "test");

            Assert.Equal(1, dbContext.PollsUsers.Count());
        }
Exemplo n.º 9
0
        public void IncrementVotersShouldIncrementOnTheGivenAnswerItsVotersProperty()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new PollsService(dbContext);

            var model = new PollViewModel
            {
                Title   = "something",
                Answers = "Da, Ne, Moje"
            };

            service.CreatePoll(model);

            service.IncrementVoters(1, 1);

            var firstAnswer = dbContext.Answers.First();

            Assert.Equal("Da", firstAnswer.Name);
            Assert.Equal(1, firstAnswer.Voters);
        }
Exemplo n.º 10
0
 public PollsController(PollsService ps)
 {
     _ps = ps;
 }