public void CreatesTheTargetDirectoryForTheOutputHtml() { var directory = new DirectoryInfo(Path.Combine("tmp", "data", "nested", "path")); if (directory.Exists) { directory.Delete(true); } var viewEngineMock = new Mock <IViewEngine>(); viewEngineMock.Setup(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), null)).Verifiable(); var resourceMapperMock = new Mock <IResourceFileMapper>(); var s = new Uri("http://datadock.io/test/repo/data/nested/path/s0"); resourceMapperMock.Setup(x => x.GetPathFor(s)).Returns(Path.Combine("tmp", "data", "nested", "path", "s0")).Verifiable(); var templateVariables = new Dictionary <string, object>(); var htmlGenerator = new HtmlFileGenerator(_uriService, resourceMapperMock.Object, viewEngineMock.Object, new MockProgressLog(), 100, templateVariables); htmlGenerator.HandleResource(_g.CreateUriNode(s), GetMockTripleCollection(s), GetMockObjectTripleCollection(s)); viewEngineMock.Verify(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), It.IsAny <Dictionary <string, object> >()), Times.Exactly(1)); resourceMapperMock.Verify(); directory = new DirectoryInfo(Path.Combine("tmp", "data", "nested", "path")); directory.Exists.Should().BeTrue(because: $"The target directory {directory.FullName} should exist"); }
public void WritesTheRenderedTextToTheTargetHtmlFile() { var file = new FileInfo(Path.Combine("tmp", "data", "s1.html")); if (file.Exists) { file.Delete(); } var viewEngineMock = new Mock <IViewEngine>(); viewEngineMock.Setup(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), It.IsAny <Dictionary <string, object> >())).Returns("Results of the render").Verifiable(); var resourceMapperMock = new Mock <IResourceFileMapper>(); var s = new Uri("http://datadock.io/test/repo/data/s1"); resourceMapperMock.Setup(x => x.GetPathFor(s)).Returns(Path.Combine("tmp", "data", "s1")).Verifiable(); var templateVariables = new Dictionary <string, object>(); var htmlGenerator = new HtmlFileGenerator(_uriService, resourceMapperMock.Object, viewEngineMock.Object, new MockProgressLog(), 100, templateVariables); htmlGenerator.HandleResource(_g.CreateUriNode(s), GetMockTripleCollection(s), GetMockObjectTripleCollection(s)); viewEngineMock.Verify(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), It.IsAny <Dictionary <string, object> >()), Times.Exactly(1)); file = new FileInfo(Path.Combine("tmp", "data", "s1.html")); file.Exists.Should().BeTrue(); File.ReadAllText(file.FullName).Should().Be("Results of the render"); }
public void GeneratesNothingWhenTheSubjectIsABlankNode() { var viewEngineMock = new Mock <IViewEngine>(); viewEngineMock.Setup(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), null)).Verifiable(); var resourceMapperMock = new Mock <IResourceFileMapper>(); resourceMapperMock.Setup(x => x.GetPathFor(null)).Returns((string)null).Verifiable(); var tripleCollection = GetMockTripleCollection(null); var templateVariables = new Dictionary <string, object>(); var htmlGenerator = new HtmlFileGenerator(_uriService, resourceMapperMock.Object, viewEngineMock.Object, new MockProgressLog(), 100, templateVariables); htmlGenerator.HandleResource(tripleCollection[0].Subject, tripleCollection, new List <Triple>()); resourceMapperMock.Verify(x => x.GetPathFor(null), Times.Never); viewEngineMock.Verify(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), null), Times.Never); }
public void GeneratesNothingWhenTheRepositoryUriIsNotABaseUriOfTheSubject() { var viewEngineMock = new Mock <IViewEngine>(); viewEngineMock.Setup(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), null)).Verifiable(); var resourceMapperMock = new Mock <IResourceFileMapper>(); var s = new Uri("http://datadock.io/someother/repo/data/s0"); resourceMapperMock.Setup(x => x.GetPathFor(s)).Returns((string)null).Verifiable(); var templateVariables = new Dictionary <string, object>(); var htmlGenerator = new HtmlFileGenerator(_uriService, resourceMapperMock.Object, viewEngineMock.Object, new MockProgressLog(), 100, templateVariables); htmlGenerator.HandleResource(_g.CreateUriNode(s), GetMockTripleCollection(s), GetMockObjectTripleCollection(s)); resourceMapperMock.Verify(); viewEngineMock.Verify(x => x.Render(It.IsAny <Uri>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >(), null), Times.Never); }