Example #1
0
        public void CanGenerateRdfFromRepository()
        {
            var repoDir = Path.Combine(_tmpDir, "quince");

            Directory.CreateDirectory(repoDir);
            var repo         = new DynamicFileStore(repoDir, 100);
            var defaultGraph = new Graph();
            var parser       = new NQuadsParser();

            using (var reader = File.OpenText(Path.Join("data", "test1.nq")))
            {
                parser.Parse(reader, t => repo.Assert(t.Subject, t.Predicate, t.Object, t.GraphUri), defaultGraph);
            }

            repo.Flush();
            var mockQuinceFactory = new Mock <IQuinceStoreFactory>();

            mockQuinceFactory.Setup(x => x.MakeQuinceStore(It.IsAny <string>())).Returns(repo);
            var rdfGeneratorMock = new Mock <ITripleCollectionHandler>();

            rdfGeneratorMock.Setup(x => x.HandleTripleCollection(It.Is <IList <Triple> >(c =>
                                                                                         c.All(t => (t.Subject as IUriNode).Uri.ToString().Equals("http://example.org/id/resource/s/s0"))))).Verifiable();
            var fileGeneratorFactoryMock = new Mock <IFileGeneratorFactory>();

            fileGeneratorFactoryMock.Setup(x => x.MakeRdfFileGenerator(It.IsAny <IResourceFileMapper>(),
                                                                       It.IsAny <IEnumerable <Uri> >(), It.IsAny <IProgressLog>(), It.IsAny <int>())).Returns(rdfGeneratorMock.Object);

            var rdfResourceFileMapper = new ResourceFileMapper(
                new ResourceMapEntry(new Uri("http://example.org/id/"), "data"));
            var htmlResourceFileMapper = new ResourceFileMapper(
                new ResourceMapEntry(new Uri("http://example.org/id/"), "doc"));
            var ddRepository = new DataDockRepository(
                _tmpDir, new Uri("http://example.org/"), new MockProgressLog(),
                mockQuinceFactory.Object, fileGeneratorFactoryMock.Object,
                rdfResourceFileMapper, htmlResourceFileMapper, _uriService);

            ddRepository.GenerateRdf(new[] { new Uri("http://example.org/g/g1") });

            // Should be invoked to generate files for subject IRIs
            rdfGeneratorMock.Verify(x => x.HandleTripleCollection(It.Is <IList <Triple> >(c =>
                                                                                          c.All(t => (t.Subject as IUriNode).Uri.ToString().Equals("http://example.org/id/resource/s/s0")))),
                                    Times.Once);
            // Should not be invoked to generate files for object IRIs
            rdfGeneratorMock.Verify(x => x.HandleTripleCollection(It.Is <IList <Triple> >(
                                                                      c => c.Any(t => (t.Subject as IUriNode).Uri.ToString().Equals("http://example.org/id/resource/o/o0")))), Times.Never);
        }
        public BaseDataDockRepositorySpec()
        {
            var runId = DateTime.UtcNow.Ticks.ToString();

            _testDir = Directory.CreateDirectory(runId);
            RepoPath = _testDir.FullName;

            QuinceStore = new MockQuinceStore();
            var quinceStoreFactory = new Mock <IQuinceStoreFactory>();

            quinceStoreFactory.Setup(x => x.MakeQuinceStore(RepoPath)).Returns(QuinceStore);
            FileGeneratorFactory = new Mock <IFileGeneratorFactory>();
            MockRdfFileGenerator = new Mock <ITripleCollectionHandler>();
            MockRdfFileGenerator.Setup(x => x.HandleTripleCollection(It.IsAny <IList <Triple> >())).Returns(true)
            .Verifiable();
            MockHtmlFileGenerator = new Mock <IResourceStatementHandler>();
            MockHtmlFileGenerator.Setup(x => x.HandleResource(
                                            It.IsAny <INode>(), It.IsAny <IList <Triple> >(), It.IsAny <IList <Triple> >()))
            .Returns(true);
            FileGeneratorFactory.Setup(x => x.MakeRdfFileGenerator(
                                           It.IsAny <IResourceFileMapper>(),
                                           It.IsAny <IEnumerable <Uri> >(), It.IsAny <IProgressLog>(), It.IsAny <int>()))
            .Returns(MockRdfFileGenerator.Object);
            FileGeneratorFactory.Setup(x => x.MakeHtmlFileGenerator(
                                           It.IsAny <IDataDockUriService>(),
                                           It.IsAny <IResourceFileMapper>(), It.IsAny <IViewEngine>(), It.IsAny <IProgressLog>(),
                                           It.IsAny <int>(),
                                           It.IsAny <Dictionary <string, object> >()))
            .Returns(MockHtmlFileGenerator.Object);
            MockProgressLog = new MockProgressLog();

            var uriService = new DataDockUriService("http://datadock.io/");

            BaseUri = new Uri("http://datadock.io/test/repo/");
            var rdfResourceMapper = new ResourceFileMapper(
                new ResourceMapEntry(new Uri(BaseUri, "id"), "data"));
            var htmlResourceMapper = new ResourceFileMapper(
                new ResourceMapEntry(new Uri(BaseUri, "id"), "doc"));


            Repo = new DataDockRepository(RepoPath, BaseUri, MockProgressLog,
                                          quinceStoreFactory.Object, FileGeneratorFactory.Object,
                                          rdfResourceMapper, htmlResourceMapper, uriService);
        }