Esempio n. 1
0
        public void ShouldCloneandQueueThrowsNoTo()
        {
            DateTime now          = DateTime.Now;
            string   environment  = "mock environment";
            string   bodyPrefix   = "Mock Body for";
            string   expectedBody = $"{bodyPrefix} {environment}";
            Email    email        = new Email()
            {
                Id              = Guid.Parse("93895b38-cc48-47a3-b592-c02691521b28"),
                CreatedBy       = "Mocked Created By",
                CreatedDateTime = now,
                UpdatedBy       = "Mocked Updated By",
                UpdatedDateTime = now,
                Subject         = "Mock Subject",
                Body            = expectedBody,
                From            = "*****@*****.**",
            };
            Guid emailId           = Guid.Parse("389425bc-0380-467f-b003-e03cfa871f83");
            var  mockLogger        = new Mock <ILogger <EmailQueueService> >();
            var  mockJobclient     = new Mock <IBackgroundJobClient>();
            var  mockEmailDelegate = new Mock <IEmailDelegate>();

            mockEmailDelegate.Setup(s => s.GetEmail(It.IsAny <Guid>())).Returns(email);
            var mockMessagingVerificationDelegate = new Mock <IMessagingVerificationDelegate>();
            var mockWebHosting = new Mock <IWebHostEnvironment>();
            IEmailQueueService emailService = new EmailQueueService(
                mockLogger.Object,
                mockJobclient.Object,
                mockEmailDelegate.Object,
                mockMessagingVerificationDelegate.Object,
                mockWebHosting.Object);

            Assert.Throws <ArgumentNullException>(() => emailService.CloneAndQueue(emailId, true));
        }
        public void ShouldCloneandQueueThrowsNoEmail()
        {
            Guid emailId           = Guid.Parse("389425bc-0380-467f-b003-e03cfa871f83");
            var  mockLogger        = new Mock <ILogger <EmailQueueService> >();
            var  mockJobclient     = new Mock <IBackgroundJobClient>();
            var  mockEmailDelegate = new Mock <IEmailDelegate>();

            mockEmailDelegate.Setup(s => s.GetEmail(It.IsAny <Guid>())).Returns <Email>(null);
            var mockWebHosting = new Mock <IWebHostEnvironment>();
            IEmailQueueService emailService = new EmailQueueService(
                mockLogger.Object,
                mockJobclient.Object,
                mockEmailDelegate.Object,
                mockWebHosting.Object);

            Assert.Throws <ArgumentException>(() => emailService.CloneAndQueue(emailId, true));
        }
Esempio n. 3
0
        public void ShouldCloneandQueue()
        {
            DateTime now           = DateTime.Now;
            string   environment   = "mock environment";
            string   bodyPrefix    = "Mock Body for";
            string   expectedBody  = $"{bodyPrefix} {environment}";
            Email    expectedEmail = new Email()
            {
                Id      = Guid.Parse("93895b38-cc48-47a3-b592-c02691521b28"),
                From    = "*****@*****.**",
                To      = "*****@*****.**",
                Subject = "Mock Subject",
                Body    = expectedBody,
            };
            Guid expectedNewEmailId        = Guid.Parse("389425bc-0380-467f-b003-e03cfa871f83");
            Dictionary <string, string> kv = new Dictionary <string, string>();

            kv.Add("environment", environment);
            var mockLogger        = new Mock <ILogger <EmailQueueService> >();
            var mockJobclient     = new Mock <IBackgroundJobClient>();
            var mockEmailDelegate = new Mock <IEmailDelegate>();

            mockEmailDelegate.Setup(s => s.GetEmail(It.IsAny <Guid>())).Returns(expectedEmail);
            mockEmailDelegate.Setup(s => s.InsertEmail(It.IsAny <Email>(), true)).Callback <Email, bool>((email, b) => email.Id = expectedNewEmailId);
            var mockMessagingVerificationDelegate = new Mock <IMessagingVerificationDelegate>();
            var mockWebHosting = new Mock <IWebHostEnvironment>();
            IEmailQueueService emailService = new EmailQueueService(
                mockLogger.Object,
                mockJobclient.Object,
                mockEmailDelegate.Object,
                mockMessagingVerificationDelegate.Object,
                mockWebHosting.Object);

            emailService.CloneAndQueue(expectedEmail.Id, true);
            mockJobclient.Verify(x => x.Create(
                                     It.Is <Job>(job => job.Method.Name == "SendEmail" && job.Args[0] is Guid),
                                     It.IsAny <EnqueuedState>()));
            mockEmailDelegate.Verify(x => x.InsertEmail(It.Is <Email>(email =>
                                                                      email.Id == expectedNewEmailId &&
                                                                      email.From == expectedEmail.From &&
                                                                      email.To == expectedEmail.To &&
                                                                      email.Subject == expectedEmail.Subject &&
                                                                      email.Body == expectedEmail.Body), true));
        }