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);
        }
Esempio n. 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));
        }
Esempio n. 3
0
        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);
        }