Beispiel #1
0
        public async Task CleanInbox_CleansOneSpam()
        {
            // arrange
            var address = "*****@*****.**";
            var emails  = new[]
            {
                new Email {
                    Id = Guid.NewGuid(), From = "*****@*****.**", To = address
                },
                new Email {
                    Id = Guid.NewGuid(), From = "*****@*****.**", To = address
                }
            };

            var mockRepo = new Mock <IMessageRepository>();

            mockRepo.Setup(r => r.ListByRecipientAsync(address)).ReturnsAsync(emails);
            mockRepo.Setup(r => r.DeleteByIdAsync(It.IsAny <Guid>()));

            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(u => u.MessageRepository).Returns(mockRepo.Object);

            var cleaner = new InboxCleaner(mockUow.Object);

            // act
            await cleaner.CleanInboxAsync(address);

            // assert
            mockRepo.Verify(r => r.ListByRecipientAsync(address), Times.Once);
            mockRepo.Verify(r => r.DeleteByIdAsync(emails[0].Id), Times.Once); // would be nice to verify it was awaited
            mockRepo.VerifyNoOtherCalls();
            mockUow.Verify(u => u.SaveAsync());
            mockUow.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public async Task <IActionResult> CleanInbox(string address, [FromServices] InboxCleaner inboxCleaner)
        {
            var authorizationResult = await _authorizationService
                                      .AuthorizeAsync(user : User, resource : new[] { address }, policyName : "AllowedAddresses");

            if (!authorizationResult.Succeeded)
            {
                return(Forbid());
            }

            await inboxCleaner.CleanInboxAsync(address);

            return(NoContent());
        }
 public void Constructor_Accepts_Null()
 {
     var cleaner = new InboxCleaner(null);
 }