コード例 #1
0
        public async Task <string> ReadTemplateAsync(string templateName)
        {
            var templatePath = pathManager.GetEmailTemplatePath(templateName);

            if (!File.Exists(templatePath))
            {
                throw new StreetwoodException(ErrorCode.EmailTemplateNotExists(templateName));
            }

            var emailTemplate = await File.ReadAllTextAsync(templatePath);

            return(emailTemplate);
        }
コード例 #2
0
        public void ReadTemplateAsync_Should_Throw_Exception_WithCode_EmailTemplateNotExists()
        {
            // arrange
            pathManager.Setup(s => s.GetEmailTemplatePath(It.IsAny <string>()))
            .Returns("./Resources/Emails/WrongTemplate.html");
            var templateName = "NewOrder.html";
            var sut          = new EmailTemplatesManager(pathManager.Object);

            //act
            Func <Task <string> > result = async() => await sut.ReadTemplateAsync(templateName);

            // assert
            result.Should().Throw <StreetwoodException>()
            .Which.ErrorCode.Should().BeEquivalentTo(ErrorCode.EmailTemplateNotExists(templateName));
        }
コード例 #3
0
ファイル: EmailTemplatesManager.cs プロジェクト: eabaje/Salon
        public async Task <string> ReadTemplateAsync(string templateName)
        {
            var templatePath = pathManager.GetEmailTemplatePath(templateName);

            if (!File.Exists(templatePath))
            {
                throw new SalonException(ErrorCode.EmailTemplateNotExists(templateName));
            }

            var emailTemplate = await File.ReadAllTextAsync(templatePath);

            if (string.IsNullOrEmpty(emailTemplate))
            {
                throw new Exception($"Cannot read email template from path: '{templateName}'.");
            }

            return(emailTemplate);
        }