public void ChoiceAddingAllowedForPoll_AddsChoice() { const string optionName = "new option"; const string optionDescription = "description"; IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>(); IDbSet <Choice> options = DbSetTestHelper.CreateMockDbSet <Choice>(); polls.Add(new Poll() { UUID = PollManageGuid, ChoiceAdding = true }); IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, options); PollChoiceController controller = CreatePollChoiceController(contextFactory); ChoiceCreationRequestModel optionCreationRequestModel = new ChoiceCreationRequestModel() { Name = optionName, Description = optionDescription, }; controller.Post(PollManageGuid, optionCreationRequestModel); Assert.AreEqual(1, options.Count()); Assert.AreEqual(optionName, options.First().Name); Assert.AreEqual(optionDescription, options.First().Description); }
public void AddingChoiceGeneratesMetric() { // Arrange IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>(); var contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls); var metricHandler = new Mock <IMetricHandler>(); PollChoiceController controller = CreatePollChoiceController(contextFactory, metricHandler.Object); Poll existingPoll = new Poll() { Choices = new List <Choice>(), UUID = Guid.NewGuid(), ChoiceAdding = true }; polls.Add(existingPoll); ChoiceCreationRequestModel request = new ChoiceCreationRequestModel() { Name = "New Choice" }; // Act controller.Post(existingPoll.UUID, request); // Assert metricHandler.Verify(m => m.HandleChoiceAddedEvent(It.Is <Choice>(o => o.Name == "New Choice"), existingPoll.UUID), Times.Once()); }
public void NullRequest_ThrowsBadRequest() { IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>(); IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls); PollChoiceController controller = CreatePollChoiceController(contextFactory); controller.Post(PollManageGuid, null); }
public void UnknownPoll_ThrowsNotFound() { IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>(); IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls); PollChoiceController controller = CreatePollChoiceController(contextFactory); ChoiceCreationRequestModel optionCreationRequestModel = new ChoiceCreationRequestModel(); controller.Post(PollManageGuid, optionCreationRequestModel); }
public void ChoiceAddingNotAllowedForPoll_ThrowsMethodNotAllowed() { IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>(); polls.Add(new Poll() { UUID = PollManageGuid, ChoiceAdding = false }); IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls); PollChoiceController controller = CreatePollChoiceController(contextFactory); ChoiceCreationRequestModel optionCreationRequestModel = new ChoiceCreationRequestModel(); controller.Post(PollManageGuid, optionCreationRequestModel); }