public void Put(Guid manageId, ManagePollMiscRequest updateRequest) { using (var context = _contextFactory.CreateContext()) { Poll poll = PollByManageId(manageId, context); if (!ModelState.IsValid) { ThrowError(HttpStatusCode.BadRequest, ModelState); } if (poll.InviteOnly != updateRequest.InviteOnly) { poll.InviteOnly = updateRequest.InviteOnly; _metricHandler.HandleInviteOnlyChangedEvent(poll.InviteOnly, poll.UUID); } if (poll.NamedVoting != updateRequest.NamedVoting) { poll.NamedVoting = updateRequest.NamedVoting; _metricHandler.HandleNamedVotingChangedEvent(poll.NamedVoting, poll.UUID); } if (poll.ChoiceAdding != updateRequest.ChoiceAdding) { poll.ChoiceAdding = updateRequest.ChoiceAdding; _metricHandler.HandleChoiceAddingChangedEvent(poll.ChoiceAdding, poll.UUID); } poll.LastUpdatedUtc = DateTime.UtcNow; context.SaveChanges(); } }
public void SettingExistingMiscSettingsDoesNotGenerateMetrics() { // Arrange IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>(); Poll existingPoll = CreatePoll(); existingPolls.Add(existingPoll); existingPoll.NamedVoting = false; existingPoll.InviteOnly = false; existingPoll.ChoiceAdding = false; IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls); ManagePollMiscRequest request = new ManagePollMiscRequest { InviteOnly = false, NamedVoting = false, ChoiceAdding = false }; Mock <IMetricHandler> metricHandler = new Mock <IMetricHandler>(); ManageMiscController controller = CreateManageExpiryController(contextFactory, metricHandler.Object); // Act controller.Put(PollManageGuid, request); // Assert metricHandler.Verify(m => m.HandleInviteOnlyChangedEvent(It.IsAny <bool>(), It.IsAny <Guid>()), Times.Never()); metricHandler.Verify(m => m.HandleNamedVotingChangedEvent(It.IsAny <bool>(), It.IsAny <Guid>()), Times.Never()); metricHandler.Verify(m => m.HandleChoiceAddingChangedEvent(It.IsAny <bool>(), It.IsAny <Guid>()), Times.Never()); }
public void AlteringMiscConfigGeneratesMetrics() { // Arrange IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>(); Poll existingPoll = CreatePoll(); existingPolls.Add(existingPoll); existingPoll.NamedVoting = false; existingPoll.InviteOnly = false; existingPoll.ChoiceAdding = false; IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls); ManagePollMiscRequest request = new ManagePollMiscRequest { InviteOnly = true, NamedVoting = true, ChoiceAdding = true }; Mock <IMetricHandler> metricHandler = new Mock <IMetricHandler>(); ManageMiscController controller = CreateManageExpiryController(contextFactory, metricHandler.Object); // Act controller.Put(PollManageGuid, request); // Assert metricHandler.Verify(m => m.HandleInviteOnlyChangedEvent(true, existingPoll.UUID), Times.Once()); metricHandler.Verify(m => m.HandleNamedVotingChangedEvent(true, existingPoll.UUID), Times.Once()); metricHandler.Verify(m => m.HandleChoiceAddingChangedEvent(true, existingPoll.UUID), Times.Once()); }
public void UnknownManageId_ReturnsNotFound() { IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>(); IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls); ManagePollMiscRequest request = new ManagePollMiscRequest { }; ManageMiscController controller = CreateManageExpiryController(contextFactory, new Mock <IMetricHandler>().Object); controller.Put(Guid.NewGuid(), request); }
public void SetMiscConfig_SetsMiscSettings() { IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>(); Poll existingPoll = CreatePoll(); existingPolls.Add(existingPoll); existingPoll.NamedVoting = false; existingPoll.InviteOnly = false; existingPoll.ChoiceAdding = false; IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls); ManagePollMiscRequest request = new ManagePollMiscRequest { InviteOnly = true, NamedVoting = true, ChoiceAdding = true }; ManageMiscController controller = CreateManageExpiryController(contextFactory, new Mock <IMetricHandler>().Object); controller.Put(PollManageGuid, request); Assert.IsTrue(existingPoll.InviteOnly); Assert.IsTrue(existingPoll.NamedVoting); Assert.IsTrue(existingPoll.ChoiceAdding); }