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); }
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); }
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()); }
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()); }
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); }
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); }
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); }
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()); }
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); }
public PollsController(PollsService ps) { _ps = ps; }