public void ShouldUnsubscribe() { // Arrange. var strategy = new UnsubscribeStrategy( _mockLogger.Object, _mockCandidateRepository.Object, _mockSaveCandidateStrategy.Object, new Mock <IServiceBus>().Object); var candidateId = Guid.NewGuid(); var subscriberId = Guid.NewGuid(); var candidate = BuildSubscribedCandidate(candidateId); _mockCandidateRepository.Setup(mock => mock .GetBySubscriberId(subscriberId, true)) .Returns(candidate); // Act. var unsubscribed = strategy.Unsubscribe(subscriberId, SubscriptionTypes.SavedSearchAlertsViaEmail); // Assert. unsubscribed.Should().BeTrue(); candidate.CommunicationPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.SavedSearchPreferences.Should().NotBeNull(); candidate.CommunicationPreferences.SavedSearchPreferences.EnableEmail.Should().BeFalse(); _mockSaveCandidateStrategy.Verify(mock => mock .SaveCandidate(candidate), Times.Once); _mockLogger.Verify(mock => mock .Info(It.IsAny <string>(), It.IsAny <object[]>()), Times.Once); }
public void ShouldFailToUnsubscribeIfCandidateNotFound() { // Arrange. var strategy = new UnsubscribeStrategy( _mockLogger.Object, _mockCandidateRepository.Object, _mockSaveCandidateStrategy.Object, new Mock <IServiceBus>().Object); // Act. _mockCandidateRepository.Setup(mock => mock .GetBySubscriberId(It.IsAny <Guid>(), true)) .Throws <NotImplementedException>(); var unsubscribed = strategy.Unsubscribe(new Guid(), SubscriptionTypes.SavedSearchAlertsViaEmail); // Assert. unsubscribed.Should().BeFalse(); _mockLogger.Verify(mock => mock .Error(It.IsAny <string>(), It.IsAny <Exception>(), It.IsAny <object[]>()), Times.Once); }