Пример #1
0
        public void Constructor_ShouldSetStatusToNotSent()
        {
            // Act
            var recipient = new Recipient();

            // Assert
            Assert.AreEqual(SendingStatus.NotSent, recipient.Status);
        }
Пример #2
0
        public void Constructor_ShouldSetEmail()
        {
            // Act
            var recipient = new Recipient("*****@*****.**");

            // Assert
            Assert.AreEqual("*****@*****.**", recipient.Email);
        }
Пример #3
0
        public void MarkAsSentMethod_ShouldChangeStatusToSuccess()
        {
            // Arrange
            var recipient = new Recipient();

            // Act
            recipient.MarkAsSent(new DateTime());

            // Assert
            Assert.AreEqual(SendingStatus.Success, recipient.Status);
        }
Пример #4
0
        public void MarkAsFailedMethod_ShouldSetExceptionMessage()
        {
            // Arrange
            var recipient = new Recipient();

            // Act
            recipient.MarkAsFailed("sending failed", new DateTime());

            // Assert
            Assert.AreEqual("sending failed", recipient.Exception);
        }
Пример #5
0
        public void MarkAsFailedMethod_ShouldChangeStatusToFailed()
        {
            // Arrange
            var recipient = new Recipient();

            // Act
            recipient.MarkAsFailed("sending failed", new DateTime());

            // Assert
            Assert.AreEqual(SendingStatus.Failed, recipient.Status);
        }
Пример #6
0
        public void MarkAsFailedMethod_ShouldSetLastAttemptDate()
        {
            // Arrange
            var recipient = new Recipient();
            var failedDate = new DateTime(2015, 1, 1);

            // Act
            recipient.MarkAsFailed("sending failed", failedDate);

            // Assert
            Assert.AreEqual(failedDate, recipient.LastAttemptDate);
        }
        public void RunMethod_ShouldMarkRecipientAsSent()
        {
            // Arrange
            var stubRepository = new Mock<IRepository>();
            var stubMailHelper = new Mock<IMailHelper>();
            var stubRecipient = new Recipient();

            stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient);

            // Act
            var bulkMailSender = new BulkSender(stubRepository.Object, stubMailHelper.Object);
            bulkMailSender.Run();

            // Assert
            Assert.AreEqual(SendingStatus.Success, stubRecipient.Status);
        }
        public void RunMethod_ShouldSetLastAttemptDate_IfSendingWasNotSuccessful()
        {
            // Arrange
            var stubRepository = new Mock<IRepository>();
            var stubMailHelper = new Mock<IMailHelper>();
            var stubRecipient = new Recipient();

            stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient);
            stubMailHelper.Setup(mh => mh.SendEmail(It.IsAny<string>())).Throws(new Exception());

            // Act
            var bulkMailSender = new BulkSender(stubRepository.Object, stubMailHelper.Object);
            bulkMailSender.Run();

            // Assert
            Assert.IsNotNull(stubRecipient.LastAttemptDate);
        }
        public void RunMethod_ShouldSendEmailToFirstUnsentAddress()
        {
            // Arrange
            var stubRepository = new Mock<IRepository>();
            var mockMailHelper = new Mock<IMailHelper>();
            var stubRecipient = new Recipient("*****@*****.**");

            stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient);
            mockMailHelper.Setup(mh => mh.SendEmail("*****@*****.**")).Verifiable();

            // Act
            var bulkMailSender = new BulkSender(stubRepository.Object, mockMailHelper.Object);
            bulkMailSender.Run();

            // Assert
            mockMailHelper.Verify();
        }
Пример #10
0
        public void UpdateMethod_ShouldCallContextSaveChanges()
        {
            // Arrange
            var mockContext = new Mock<Context>();
            var stubRecipient = new Recipient("*****@*****.**");

            mockContext.Setup(c => c.SaveChanges()).Verifiable();

            // Act
            var repository = new Repository(mockContext.Object);
            repository.Update(stubRecipient);

            // Assert
            mockContext.Verify();
        }
Пример #11
0
        public void UpdateMethod_ShouldChangeEntityStateToModified()
        {
            // Arrange
            var stubContext = new Mock<Context>();
            var stubRecipient = new Recipient("*****@*****.**");

            // Act
            var repository = new Repository(stubContext.Object);
            repository.Update(stubRecipient);

            // Assert
            Assert.AreEqual(EntityState.Modified, stubContext.Object.Entry(stubRecipient).State);
        }
Пример #12
0
        public void RunMethod_ShouldUpdateRecipientInDatabase_IfSendingWasSuccesful()
        {
            // Arrange
            var mockRepository = new Mock<IRepository>();
            var stubMailHelper = new Mock<IMailHelper>();
            var stubRecipient = new Recipient();

            mockRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient);
            mockRepository.Setup(r => r.Update(stubRecipient)).Verifiable();

            // Act
            var bulkMailSender = new BulkSender(mockRepository.Object, stubMailHelper.Object);
            bulkMailSender.Run();

            // Assert
            mockRepository.Verify();
        }
Пример #13
0
        public void MarkAsSentMethod_ShouldSetLastAttemptDate()
        {
            // Arrange
            var recipient = new Recipient();
            var successDate = new DateTime(2015, 1, 1);

            // Act
            recipient.MarkAsSent(successDate);

            // Assert
            Assert.AreEqual(successDate, recipient.LastAttemptDate);
        }
Пример #14
0
 public void Update(Recipient recipient)
 {
     _context.Entry(recipient).State = EntityState.Modified;
     Save();
 }