当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.Resource方法代码示例

本文整理汇总了C#中ConfigurationBuilder.Resource方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.Resource方法的具体用法?C# ConfigurationBuilder.Resource怎么用?C# ConfigurationBuilder.Resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.Resource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WithAllProperties_maps_properly

        public void WithAllProperties_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new DefaultPropertyScanningConvention())
                .WithConvention(new CamelCaseLinkNameConvention())
                .WithConvention(new PluralizedCamelCaseTypeConvention())
                .WithConvention(new SimpleLinkedIdConvention());

            //Act
            builder
                .Resource<Post>()
                .WithAllProperties();

            builder.Resource<Author>();
            builder.Resource<Comment>();

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));

            //Assert
            postMapping.Relationships.Count.ShouldEqual(2);
            postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "authors").ShouldNotBeNull();
            postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "comments").ShouldNotBeNull();
            postMapping.PropertyGetters.Count.ShouldEqual(2);
            postMapping.PropertySetters.Count.ShouldEqual(2);
            postMapping.IdGetter.ShouldNotBeNull();
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:29,代码来源:ConfigurationBuilderTest.cs

示例2: WithSimpleProperty_maps_properly

        public void WithSimpleProperty_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            var post = new Post() { Title = "test" };

            //Act
            builder
                .Resource<Post, PostsController>()
                .WithSimpleProperty(p => p.Title);

            var configuration = builder.Build();
            var mapping = configuration.GetMapping(typeof(Post));

            //Assert
            Assert.Equal(mapping.PropertyGetters.Count, 1);
            Assert.Equal(mapping.PropertySetters.Count, 1);

            var getter = mapping.PropertyGetters.Single().Value;
            var setter = mapping.PropertySetters.Single().Value;

            Assert.Equal(((string)getter(post)), "test");

            setter(post, "works");
            Assert.Equal(post.Title, "works");
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:26,代码来源:ConfigurationBuilderTest.cs

示例3: BuildConfiguration

        public static Configuration BuildConfiguration()
        {
            var configBuilder = new ConfigurationBuilder();

            configBuilder
                .Resource<World>()
                .WithAllProperties()
                .WithLinkTemplate("/worlds/{id}");

            configBuilder
                .Resource<Continent>()
                .WithAllProperties()
                .WithLinkTemplate("/continents/{id}");

            var nJsonApiConfig = configBuilder.Build();
            return nJsonApiConfig;
        }
开发者ID:jacek-gorgon,项目名称:NJsonApi,代码行数:17,代码来源:NJsonApiConfiguration.cs

示例4: BuildConfiguration

        public static Configuration BuildConfiguration()
        {
            var configBuilder = new ConfigurationBuilder();

            configBuilder
                .Resource<Article, ArticlesController>()
                .WithAllProperties();

            configBuilder
                .Resource<Person, PeopleController>()
                .WithAllProperties();

            configBuilder
                .Resource<Comment, CommentsController>()
                .WithAllProperties();
            
            var nJsonApiConfig = configBuilder.Build();
            return nJsonApiConfig;
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:19,代码来源:NJsonApiConfiguration.cs

示例5: Resource_creates_mapping

        public void Resource_creates_mapping()
        {
            //Arrange
            var builder = new ConfigurationBuilder();

            //Act
            builder.Resource<Post>();

            var result = builder.Build();

            //Assert
            result.IsMappingRegistered(typeof(Post)).ShouldBeTrue();
            result.GetMapping(typeof(Post)).ShouldNotBeNull();
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:14,代码来源:ConfigurationBuilderTest.cs

示例6: Resource_creates_mapping

        public void Resource_creates_mapping()
        {
            //Arrange
            var builder = new ConfigurationBuilder();

            //Act
            builder.Resource<Post, PostsController>();

            var result = builder.Build();

            //Assert
            Assert.True(result.IsMappingRegistered(typeof(Post)));
            Assert.NotNull(result.GetMapping(typeof(Post)));
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:14,代码来源:ConfigurationBuilderTest.cs

示例7: WithIdSelector_maps_properly

        public void WithIdSelector_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            var post = new Post { Id = 4 };

            //Act
            builder
                .Resource<Post, PostsController>()
                .WithIdSelector(p => p.Id);

            var configuration = builder.Build();
            var mapping = configuration.GetMapping(typeof(Post));

            //Assert
            Assert.NotNull(mapping.IdGetter);
            Assert.Equal(mapping.IdGetter(post), 4);
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:18,代码来源:ConfigurationBuilderTest.cs

示例8: WithLinkedResource_uses_conventions

        public void WithLinkedResource_uses_conventions()
        {
            //Arrange
            const string testResourceType = "testResourceType";
            const string testLinkName = "testLinkName";
            Expression<Func<Post, object>> testIdExpression = p => 4;

            var builder = new ConfigurationBuilder();

            var linkNameConventionMock = A.Fake<ILinkNameConvention>();
            A.CallTo(() => linkNameConventionMock.GetLinkNameFromExpression(A<Expression<Func<Post, Author>>>._)).Returns(testLinkName);

            var resourceTypeMock = A.Fake<IResourceTypeConvention>();
            A.CallTo(() => resourceTypeMock.GetResourceTypeFromRepresentationType(A<Type>._)).Returns(testResourceType);

            var linkedIdConventionMock = A.Fake<ILinkIdConvention>();
            A.CallTo(() => linkedIdConventionMock.GetIdExpression(A<Expression<Func<Post, Author>>>._)).Returns(testIdExpression);

            builder
                .WithConvention(linkNameConventionMock)
                .WithConvention(resourceTypeMock)
                .WithConvention(linkedIdConventionMock);

            //Act
            builder
                .Resource<Post>()
                .WithLinkedResource(p => p.Author);

            builder
                .Resource<Author>()
                .WithResourceType(testResourceType);

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));
            var link = postMapping.Relationships.Single();

            //Assert
            link.RelationshipName.ShouldEqual(testLinkName);
            link.RelatedBaseResourceType.ShouldEqual(testResourceType);
            link.RelatedResourceId(new Post()).ShouldEqual(4);
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:41,代码来源:ConfigurationBuilderTest.cs

示例9: WithLinkedResource_maps_properly

        public void WithLinkedResource_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new CamelCaseLinkNameConvention())
                .WithConvention(new PluralizedCamelCaseTypeConvention())
                .WithConvention(new SimpleLinkedIdConvention());

            var post = new Post();
            var author = new Author
            {
                Posts = new List<Post> { post }
            };

            post.Author = author;
            post.AuthorId = 4;

            //Act
            builder
                .Resource<Post>()
                .WithLinkedResource(p => p.Author);

            builder
                .Resource<Author>()
                .WithLinkedResource(a => a.Posts);

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));
            var authorMapping = configuration.GetMapping(typeof(Author));

            //Assert
            postMapping.Relationships.Count.ShouldEqual(1);

            var linkToAuthor = postMapping.Relationships.Single();

            linkToAuthor.IsCollection.ShouldBeFalse();
            linkToAuthor.RelationshipName.ShouldEqual("author");
            linkToAuthor.ParentType.ShouldEqual(typeof(Post));
            linkToAuthor.RelatedBaseType.ShouldEqual(typeof(Author));
            linkToAuthor.RelatedResource(post).ShouldBeSameAs(author);
            linkToAuthor.RelatedResourceId(post).ShouldEqual(4);
            linkToAuthor.ResourceMapping.ShouldBeSameAs(authorMapping);

            authorMapping.Relationships.Count.ShouldEqual(1);
            var linkToPosts = authorMapping.Relationships.Single();

            linkToPosts.IsCollection.ShouldBeTrue();
            linkToPosts.RelationshipName.ShouldEqual("posts");
            linkToPosts.RelatedBaseType.ShouldEqual(typeof(Post));
            linkToPosts.ParentType.ShouldEqual(typeof(Author));
            linkToPosts.RelatedResource(author).ShouldBeSameAs(author.Posts);
            linkToPosts.RelatedResourceId.ShouldBeNull();
            linkToPosts.ResourceMapping.ShouldBeSameAs(postMapping);
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:55,代码来源:ConfigurationBuilderTest.cs

示例10: WithIdSelector_maps_properly

        public void WithIdSelector_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            var post = new Post { Id = 4 };

            //Act
            builder
                .Resource<Post>()
                .WithIdSelector(p => p.Id);

            var configuration = builder.Build();
            var mapping = configuration.GetMapping(typeof(Post));

            //Assert
            mapping.IdGetter.ShouldNotBeNull();
            mapping.IdGetter(post).ShouldEqual(4);
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:18,代码来源:ConfigurationBuilderTest.cs

示例11: WithComplexObjectTest

        public void WithComplexObjectTest()
        {
            //Arrange
            const int authorId = 5;
            const string authorName = "Valentin";
            const int postId = 6;
            const string postTitle = "The measure of a man";
            const string commentBody = "Comment body";
            const int commentId = 7;
            var author = new Author() { Id = authorId, Name = authorName };
            var post = new Post() { Id = postId, Title = postTitle, Author = author };
            var comment = new Comment() { Id = commentId, Body = commentBody, Post = post };
            post.Replies = new List<Comment>() { comment };
            author.Posts = new List<Post>() { post };

            var configurationBuilder = new ConfigurationBuilder();

            //Act
            var resourceConfigurationForPost = configurationBuilder
                .Resource<Post>()
                .WithSimpleProperty(p => p.Title)
                .WithIdSelector(p => p.Id)
                .WithLinkedResource(p => p.Replies);
            var resourceConfigurationForAuthor = configurationBuilder
                .Resource<Author>()
                .WithSimpleProperty(a => a.Name)
                .WithIdSelector(a => a.Id)
                .WithLinkedResource(a => a.Posts);
            var resourceConfigurationForComment = configurationBuilder
                .Resource<Comment>()
                .WithIdSelector(c => c.Id)
                .WithSimpleProperty(c => c.Body);
            var result = configurationBuilder.Build();

            //Assert
            resourceConfigurationForPost.ConstructedMetadata.Relationships.Count.ShouldEqual(1);
            resourceConfigurationForAuthor.ConstructedMetadata.Relationships.Count.ShouldEqual(1);
            configurationBuilder.ResourceConfigurationsByType.All(
                r => r.Value.ConstructedMetadata.Relationships.All(l => l.ResourceMapping != null));
            var authorLinks =
                 configurationBuilder.ResourceConfigurationsByType[
                     resourceConfigurationForAuthor.ConstructedMetadata.ResourceRepresentationType].ConstructedMetadata.Relationships;
            authorLinks.ShouldNotBeNull().Count.ShouldEqual(1);
            authorLinks[0].RelationshipName.ShouldEqual("posts");
            authorLinks[0].ResourceMapping.PropertyGetters.ShouldNotBeNull().Count.ShouldEqual(1);
            authorLinks[0].ResourceMapping.Relationships
                .ForEach(p => p.ResourceMapping.Relationships
                    .ForEach(c => c
                        .RelationshipName
                        .ShouldEqual(resourceConfigurationForComment.ConstructedMetadata.ResourceType)));
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:51,代码来源:ConfigurationBuilderTest.cs

示例12: WithAllSimpleProperties_maps_properly

        public void WithAllSimpleProperties_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new DefaultPropertyScanningConvention());

            const string testTitle = "test";
            var post = new Post
            {
                Id = 4,
                Title = testTitle
            };

            //Act
            builder
                .Resource<Post>()
                .WithAllSimpleProperties();

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));

            //Assert
            postMapping.IdGetter.ShouldNotBeNull();
            postMapping.IdGetter(post).ShouldEqual(4);
            postMapping.PropertyGetters.Count.ShouldEqual(2);
            postMapping.PropertySetters.Count.ShouldEqual(2);
            postMapping.PropertyGetters["title"](post).ShouldEqual(testTitle);
            postMapping.PropertyGetters.ContainsKey("authorId").ShouldBeTrue();
        }
开发者ID:FrontlineEducation,项目名称:Util-JsonApiSerializer,代码行数:30,代码来源:ConfigurationBuilderTest.cs

示例13: GIVEN_ModelWithSelfRefernce_WHEN_ValidateReservedWords_THEN_NotInfiniteLoop

        public void GIVEN_ModelWithSelfRefernce_WHEN_ValidateReservedWords_THEN_NotInfiniteLoop()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();

            // Act - Will not throw an infinite loop error
            configurationBuilder.Resource<ModelThatCausesInfiniteLoop, DummyController>();
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:8,代码来源:ConfigurationBuilderTest.cs

示例14: GIVEN_ValidModel_AND_ChildPropertyHasRervedWordProperties_WHEN_BuildConfiguration_THEN_Exception

        public void GIVEN_ValidModel_AND_ChildPropertyHasRervedWordProperties_WHEN_BuildConfiguration_THEN_Exception()
        {
            // Arrange
            var configurationBuilder = new ConfigurationBuilder();

            // Act - Exception!
            Assert.Throws<InvalidOperationException>(() => configurationBuilder.Resource<ValidModelWithBadChild, DummyController>());
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:8,代码来源:ConfigurationBuilderTest.cs

示例15: WithAllLinkedResources_maps_properly

        public void WithAllLinkedResources_maps_properly()
        {
            //Arrange
            var builder = new ConfigurationBuilder();
            builder
                .WithConvention(new DefaultPropertyScanningConvention())
                .WithConvention(new CamelCaseLinkNameConvention())
                .WithConvention(new PluralizedCamelCaseTypeConvention())
                .WithConvention(new SimpleLinkedIdConvention());
            
            //Act
            builder
                .Resource<Post, PostsController>()
                .WithAllLinkedResources();

            builder.Resource<Author, AuthorsController>();
            builder.Resource<Comment, CommentsController>();

            var configuration = builder.Build();
            var postMapping = configuration.GetMapping(typeof(Post));

            //Assert
            Assert.Equal(postMapping.Relationships.Count, 2);
            Assert.NotNull(postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "authors"));
            Assert.NotNull(postMapping.Relationships.SingleOrDefault(l => l.RelatedBaseResourceType == "comments"));
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:26,代码来源:ConfigurationBuilderTest.cs


注:本文中的ConfigurationBuilder.Resource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。