예제 #1
0
        public void GetResourceContext_Yields_Right_Type_For_LazyLoadingProxy()
        {
            // Arrange
            var resourceGraphBuilder = new ResourceGraphBuilder(new JsonApiOptions(), NullLoggerFactory.Instance);

            resourceGraphBuilder.Add <Bar>();
            var resourceGraph  = (ResourceGraph)resourceGraphBuilder.Build();
            var proxyGenerator = new ProxyGenerator();

            // Act
            var proxy  = proxyGenerator.CreateClassProxy <Bar>();
            var result = resourceGraph.GetResourceContext(proxy.GetType());

            // Assert
            Assert.Equal(typeof(Bar), result.ResourceType);
        }
예제 #2
0
        public void Adding_DbContext_Members_That_Do_Not_Implement_IIdentifiable_Logs_Warning()
        {
            // Arrange
            var loggerFactory        = new FakeLoggerFactory();
            var resourceGraphBuilder = new ResourceGraphBuilder(new JsonApiOptions(), loggerFactory);

            resourceGraphBuilder.Add(typeof(TestContext));

            // Act
            resourceGraphBuilder.Build();

            // Assert
            Assert.Single(loggerFactory.Logger.Messages);
            Assert.Equal(LogLevel.Warning, loggerFactory.Logger.Messages[0].LogLevel);
            Assert.Equal("Entity 'UnitTests.Internal.ResourceGraphBuilderTests+TestContext' does not implement 'IIdentifiable'.", loggerFactory.Logger.Messages[0].Text);
        }
        protected IResourceGraph BuildGraph()
        {
            var resourceGraphBuilder = new ResourceGraphBuilder(new JsonApiOptions(), NullLoggerFactory.Instance);

            resourceGraphBuilder.Add <TestResource>("testResource");
            resourceGraphBuilder.Add <TestResourceWithList>("testResource-with-list");
            // one to one relationships
            resourceGraphBuilder.Add <OneToOnePrincipal>("oneToOnePrincipals");
            resourceGraphBuilder.Add <OneToOneDependent>("oneToOneDependents");
            resourceGraphBuilder.Add <OneToOneRequiredDependent>("oneToOneRequiredDependents");
            // one to many relationships
            resourceGraphBuilder.Add <OneToManyPrincipal>("oneToManyPrincipals");
            resourceGraphBuilder.Add <OneToManyDependent>("oneToManyDependents");
            resourceGraphBuilder.Add <OneToManyRequiredDependent>("oneToMany-requiredDependents");
            // collective relationships
            resourceGraphBuilder.Add <MultipleRelationshipsPrincipalPart>("multiPrincipals");
            resourceGraphBuilder.Add <MultipleRelationshipsDependentPart>("multiDependents");

            resourceGraphBuilder.Add <Article>();
            resourceGraphBuilder.Add <Person>();
            resourceGraphBuilder.Add <Blog>();
            resourceGraphBuilder.Add <Food>();
            resourceGraphBuilder.Add <Song>();

            return(resourceGraphBuilder.Build());
        }
 private static void BuildCollectiveRelationships(ResourceGraphBuilder resourceGraphBuilder)
 {
     resourceGraphBuilder.Add <MultipleRelationshipsPrincipalPart>("multiPrincipals");
     resourceGraphBuilder.Add <MultipleRelationshipsDependentPart>("multiDependents");
 }
 private static void BuildOneToManyRelationships(ResourceGraphBuilder resourceGraphBuilder)
 {
     resourceGraphBuilder.Add <OneToManyPrincipal>("oneToManyPrincipals");
     resourceGraphBuilder.Add <OneToManyDependent>("oneToManyDependents");
     resourceGraphBuilder.Add <OneToManyRequiredDependent>("oneToMany-requiredDependents");
 }
        private IResourceGraph BuildGraph()
        {
            var resourceGraphBuilder = new ResourceGraphBuilder(new JsonApiOptions(), NullLoggerFactory.Instance);

            resourceGraphBuilder.Add <TestResource>("testResource");
            resourceGraphBuilder.Add <TestResourceWithList>("testResource-with-list");

            BuildOneToOneRelationships(resourceGraphBuilder);
            BuildOneToManyRelationships(resourceGraphBuilder);
            BuildCollectiveRelationships(resourceGraphBuilder);

            resourceGraphBuilder.Add <Article>();
            resourceGraphBuilder.Add <Person>();
            resourceGraphBuilder.Add <Blog>();
            resourceGraphBuilder.Add <Food>();
            resourceGraphBuilder.Add <Song>();

            resourceGraphBuilder.Add <TestResourceWithAbstractRelationship>();
            resourceGraphBuilder.Add <BaseModel>();
            resourceGraphBuilder.Add <FirstDerivedModel>();
            resourceGraphBuilder.Add <SecondDerivedModel>();

            return(resourceGraphBuilder.Build());
        }