public void CombineSingleTemplateAndLayoutAndMultipleIncludesWithJsonDataCorrectly() { // arrange const string layoutContent = @"<html><body>@Include(""header"") @RenderBody()</body></html>"; const string productContent = @"@{Layout = ""layout"";}Hello, @Model.Title<br />@Include(""footer"")"; const string headerContent = "Greetings!<br />"; const string footerContent = "Detail: @Model.Description"; const string simpleProductData = "{\"Description\":\"Simple Product Data\", \"Title\":\"A nice test product\"}"; const string expectedResult = "<html><body>Greetings!<br /> Hello, A nice test product<br />Detail: Simple Product Data</body></html>"; var mockContentRepository = new Mock<IContentRepository>(); mockContentRepository.Setup(c => c.GetContent(It.Is<string>(n => n.Equals("layout")))).Returns(layoutContent); mockContentRepository.Setup(c => c.GetContent(It.Is<string>(n => n.Equals("product")))).Returns(productContent); mockContentRepository.Setup(c => c.GetContent(It.Is<string>(n => n.Equals("footer")))).Returns(footerContent); mockContentRepository.Setup(c => c.GetContent(It.Is<string>(n => n.Equals("header")))).Returns(headerContent); var mockDataRepository = new Mock<IDataRepository>(); mockDataRepository.Setup(d => d.GetData(It.IsAny<string>())).Returns(simpleProductData); // act var renderer = new RenderHtmlPage(mockContentRepository.Object, mockDataRepository.Object); var result = renderer.BuildContentResult("product", "1"); // assert Assert.AreEqual(result, expectedResult); }
public override void Run() { var cloudConnectionString = CloudConfigurationManager.GetSetting("Microsoft.Storage.ConnectionString"); IContentRepository content = new BlobStorageContentRepository(cloudConnectionString, "content"); IDataRepository data = new BlobStorageDataRespository(cloudConnectionString, "data"); IUploader uploader = new BlobStorageUploader(cloudConnectionString, "output"); var productIds = new[] { "1", "2", "3", "4", "5" }; var renderer = new RenderHtmlPage(content, data); foreach (var productId in productIds) { var result = renderer.BuildContentResult("product", productId); uploader.SaveContentToLocation(result, productId); } }
static void Main() { const string workingRoot = "../../files"; IContentRepository content = new FileSystemContentRepository(workingRoot + "/content"); IDataRepository data = new FileSystemDataRepository(workingRoot + "/data"); IUploader uploader = new FileSystemUploader(workingRoot + "/output"); var productIds = new[] {"1", "2", "3", "4", "5"}; var renderer = new RenderHtmlPage(content, data); foreach (var productId in productIds) { var result = renderer.BuildContentResult("product", productId); uploader.SaveContentToLocation(result, productId); } }
public void CombineSingleRazorTemplateWithJsonDataCorrectly() { // arrange const string plainContent = "<html><body>@Model.Description</body></html>"; const string simpleProductData = "{\"Description\":\"Simple Product Data\"}"; const string expectedResult = "<html><body>Simple Product Data</body></html>"; var mockContentRepository = new Mock<IContentRepository>(); mockContentRepository.Setup(c => c.GetContent(It.IsAny<string>())).Returns(plainContent); var mockDataRepository = new Mock<IDataRepository>(); mockDataRepository.Setup(d => d.GetData(It.IsAny<string>())).Returns(simpleProductData); // act var renderer = new RenderHtmlPage(mockContentRepository.Object, mockDataRepository.Object); var result = renderer.BuildContentResult("product", "1"); // assert Assert.AreEqual(result, expectedResult); }
public void CombineSingleTemplateAndLayoutWithJsonDataCorrectly() { // arrange const string layoutContent = "<html><body>@RenderBody()</body></html>"; const string productContent = @"@{Layout = ""layout"";}Hello, @Model.Description"; const string simpleProductData = "{\"Description\":\"Simple Product Data\"}"; const string expectedResult = "<html><body>Hello, Simple Product Data</body></html>"; var mockContentRepository = new Mock<IContentRepository>(); mockContentRepository.Setup(c => c.GetContent(It.Is<string>(n => n.Equals("layout")))).Returns(layoutContent); mockContentRepository.Setup(c => c.GetContent(It.Is<string>(n => n.Equals("product")))).Returns(productContent); var mockDataRepository = new Mock<IDataRepository>(); mockDataRepository.Setup(d => d.GetData(It.IsAny<string>())).Returns(simpleProductData); // act var renderer = new RenderHtmlPage(mockContentRepository.Object, mockDataRepository.Object); var result = renderer.BuildContentResult("product", "1"); // assert Assert.AreEqual(result, expectedResult); }