public void GetFirstUnsentAddress_ShouldReturnFirstRecipientWithNotSentStatus_IfItExistsInDatabase()
        {
            // Arrange
            var stubContext = new Mock<Context>();

            var stubRecipients = new List<Recipient>
            {
                new Recipient("*****@*****.**"),
                new Recipient("*****@*****.**"),
                new Recipient("*****@*****.**"),
            }.AsQueryable();
            stubRecipients.First().MarkAsSent(DateTime.Now);

            var stubDbSet = new Mock<DbSet<Recipient>>();
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Provider).Returns(stubRecipients.Provider);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Expression).Returns(stubRecipients.Expression);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.ElementType).Returns(stubRecipients.ElementType);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.GetEnumerator()).Returns(stubRecipients.GetEnumerator());

            stubContext.Setup(c => c.Recipients).Returns(stubDbSet.Object);

            // Act
            var repository = new Repository(stubContext.Object);
            var recipient = repository.GetFirstUnsentAddress();

            // Assert
            Assert.AreEqual("*****@*****.**", recipient.Email);
        }
        public void GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase()
        {
            // Arrange
            var stubContext = new Mock<Context>();

            var stubRecipients = new List<Recipient>
            {
                new Recipient("*****@*****.**"),
                new Recipient("*****@*****.**"),
                new Recipient("*****@*****.**"),
            }.AsQueryable();
            stubRecipients.ElementAt(0).MarkAsSent(DateTime.Now);
            stubRecipients.ElementAt(1).MarkAsSent(DateTime.Now);
            stubRecipients.ElementAt(2).MarkAsFailed("sending failed", DateTime.Now);

            var stubDbSet = new Mock<DbSet<Recipient>>();
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Provider).Returns(stubRecipients.Provider);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Expression).Returns(stubRecipients.Expression);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.ElementType).Returns(stubRecipients.ElementType);
            stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.GetEnumerator()).Returns(stubRecipients.GetEnumerator());

            stubContext.Setup(c => c.Recipients).Returns(stubDbSet.Object);

            // Act
            var repository = new Repository(stubContext.Object);
            var recipient = repository.GetFirstUnsentAddress();

            // Assert
            Assert.IsNull(recipient);
        }
        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();
        }
        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);
        }