public void Should_load_all_external_resources() { var id = new EntityId(new Uri(BaseUri, "#test")); var another = new EntityId(new Uri(BaseUri, "#another")); var graph = new Graph(); graph.Assert(graph.CreateUriNode(id.Uri), graph.CreateUriNode(new Uri(BaseUri, "predicate")), graph.CreateLiteralNode("test")); graph.Assert(graph.CreateUriNode(another.Uri), graph.CreateUriNode(new Uri(BaseUri, "predicate")), graph.CreateLiteralNode("test")); WebRequest request = null; Stream data = new MemoryStream(); SerializeTriples(graph, data); _strategy = new UrlMatchingResourceResolutionStrategy( CreateOntologyProvider(), new[] { typeof(IPerson).GetTypeInfo().Assembly }, new[] { BaseUri }, uri => request = CreateWebRequest(uri, data)); var result = _strategy.Resolve(id); _strategy.Resolve(another); result.Should().NotBeNull(); result.Context.Store.GetEntityQuads(id).Should().HaveCount(2); Mock.Get(request).Verify(instance => instance.GetResponseAsync(), Times.Once); }
public void Should_not_load_external_resource() { _strategy = new UrlMatchingResourceResolutionStrategy(CreateOntologyProvider(), null, new[] { BaseUri }); var result = _strategy.Resolve(new EntityId(new Uri("http://test.uri/"))); result.Should().BeNull(); }
/// <summary>Sets up the factory to use <see cref="BaseUriResolutionStrategyComposition" /> for resolving external resources.</summary> /// <remarks> /// This implementation checks if a resource's identifier matches given <paramref name="baseUris" /> /// and then resolves by making a <see cref="WebRequest" /> to resource's identifier. /// </remarks> /// <param name="factory">Target factory to be configured.</param> /// <param name="baseUris">Base Uris to match for external resources.</param> /// <returns>Given <paramref name="factory" />.</returns> public static EntityContextFactory WithUriMatchingResourceResulutionStrategy(this EntityContextFactory factory, IEnumerable <Uri> baseUris) { factory.WithDependencies <BaseUriResolutionStrategyComposition>(); var resolutionStrategy = new UrlMatchingResourceResolutionStrategy( factory.Ontologies, factory.MappingModelVisitors.OfType <BaseUriMappingModelVisitor>().First().MappingAssemblies, baseUris); return(factory.WithResourceResolutionStrategy(resolutionStrategy)); }
private static IEntityContext CreateEntityContext() { var entityContextFactory = new EntityContextFactory() .WithMetaGraphUri(MetaGraphUri) .WithMappings(builder => builder.FromAssemblyOf <IKnowSomething>()) .WithDefaultOntologies() .WithOntology(new IntegrationTestsBase.ChemOntology()) .WithOntology(new IntegrationTestsBase.LifeOntology()) .WithOntology(new TestOntologyProvider(false)) .WithNamedGraphSelector(new NamedGraphSelector()) .WithDependenciesInternal <BaseUriResolutionStrategyComposition>() .WithDotNetRDF(CreateTripleStore()); var resolutionStrategy = new UrlMatchingResourceResolutionStrategy( entityContextFactory.Ontologies, entityContextFactory.MappingModelVisitors.OfType <BaseUriMappingModelVisitor>().First().MappingAssemblies, BaseUris, CreateWebRequest); return(entityContextFactory .WithResourceResolutionStrategy(resolutionStrategy) .CreateContext()); }