private Context CreateContext() { var conf = new Configuration(); var sampleClassMapping = new ResourceMapping<SampleClass>(c => c.Id, "http://sampleClass/{id}"); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("nestedValue", c => c.NestedValue); var nestedClassMapping = new ResourceMapping<NestedClass>(c => c.Id, "nested/{id}"); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("someNestedValue", c => c.SomeNestedValue); var linkMapping = new LinkMapping<SampleClass, NestedClass>() { RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedValue, ResourceIdGetter = c => c.NestedValueId }; sampleClassMapping.Relationships.Add(linkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); return new Context { Configuration = conf, RoutePrefix = appUrl }; }
private IConfiguration CreateConfiguration() { var mapping = new ResourceMapping <SampleClass, DummyController>(c => c.Id); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); var nullableMapping = new ResourceMapping <SampleClassWithNullableProperty, DummyController>(c => c.Id); nullableMapping.ResourceType = "sampleClassesWithNullableProperty"; nullableMapping.AddPropertyGetter("someValue", c => c.SomeValue); nullableMapping.AddPropertyGetter("date", c => c.DateTime); var derivedMapping = new ResourceMapping <DerivedClass, DummyController>(c => c.Id); derivedMapping.ResourceType = "derivedClasses"; derivedMapping.AddPropertyGetter("someValue", c => c.SomeValue); derivedMapping.AddPropertyGetter("date", c => c.DateTime); derivedMapping.AddPropertyGetter("derivedProperty", c => c.DerivedProperty); var config = new NJsonApi.Configuration(); config.AddMapping(mapping); config.AddMapping(nullableMapping); config.AddMapping(derivedMapping); return(config); }
private Context CreateContext() { var conf = new Configuration(); var sampleClassMapping = new ResourceMapping <SampleClass>(c => c.Id, "http://sampleClass/{id}"); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("nestedValue", c => c.NestedValue); var nestedClassMapping = new ResourceMapping <NestedClass>(c => c.Id, "nested/{id}"); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("someNestedValue", c => c.SomeNestedValue); var linkMapping = new LinkMapping <SampleClass, NestedClass>() { RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedValue, ResourceIdGetter = c => c.NestedValueId }; sampleClassMapping.Relationships.Add(linkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); return(new Context { Configuration = conf, RoutePrefix = appUrl }); }
private IConfiguration CreateConfiguration() { var mapping = new ResourceMapping <SampleClass, DummyController>(c => c.Id); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); var config = new NJsonApi.Configuration(); config.AddMapping(mapping); return(config); }
private Context CreateContext() { var conf = new NJsonApi.Configuration(); var mapping = new ResourceMapping <SampleClass>(c => c.Id, "http://sampleClass/{id}"); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); conf.AddMapping(mapping); return(new Context(conf, new Uri("http://fakehost:1234/", UriKind.Absolute))); }
private Context CreateContext() { var conf = new NJsonApi.Configuration(); var mapping = new ResourceMapping <SampleClass>(c => c.Id, "http://sampleClass/{id}"); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); conf.AddMapping(mapping); var requestUri = new Uri("http://fakeUri:1234/fakecontroller"); return(new Context(conf, requestUri)); }
private IConfiguration CreateConfigurationForListType() { var mapping = new ResourceMapping <SampleListClass, DummyController>(c => c.Id); mapping.ResourceType = "sampleListClasses"; mapping.AddPropertyGetter("simpleAttribute", c => c.SimpleAttribute); mapping.AddPropertyGetter("listAttribute", c => c.ListAttribute); var config = new NJsonApi.Configuration(); config.AddMapping(mapping); return(config); }
private Context CreateContext() { var conf = new Configuration(); var sampleClassMapping = new ResourceMapping <SampleClass>(c => c.Id, "http://sampleClass/{id}"); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("date", c => c.DateTime); var nestedClassMapping = new ResourceMapping <NestedClass>(c => c.Id, "http://nestedclass/{id}"); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("nestedText", c => c.NestedText); var deeplyNestedMapping = new ResourceMapping <DeeplyNestedClass>(c => c.Id, "http://deep/{id}"); deeplyNestedMapping.ResourceType = "deeplyNestedClasses"; deeplyNestedMapping.AddPropertyGetter("value", c => c.Value); var linkMapping = new LinkMapping <SampleClass, NestedClass>() { IsCollection = true, RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedClass, }; var deepLinkMapping = new LinkMapping <NestedClass, DeeplyNestedClass>() { RelationshipName = "deeplyNestedValues", ResourceMapping = deeplyNestedMapping, ResourceGetter = c => c.DeeplyNestedClass }; sampleClassMapping.Relationships.Add(linkMapping); nestedClassMapping.Relationships.Add(deepLinkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); conf.AddMapping(deeplyNestedMapping); return(new Context { Configuration = conf, RoutePrefix = string.Empty }); }
private Context CreateContext() { var conf = new Configuration(); var mapping = new ResourceMapping <SampleClass>(c => c.Id, "http://sampleClass/{id}"); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); conf.AddMapping(mapping); return(new Context { Configuration = conf }); }
private IConfiguration CreateConfiguration() { var mapping = new ResourceMapping <SampleClass, DummyController>(c => c.Id); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); var mappingWithMeta = new ResourceMapping <SampleClassWithObjectMetadata, DummyController>(c => c.Id); mappingWithMeta.ResourceType = "sampleClassesWithMeta"; mappingWithMeta.AddPropertyGetter("someValue", c => c.SomeValue); var mappingWithRelationshipMeta = new ResourceMapping <SampleClassWithRelationshipMetadata, DummyController>(c => c.Id); mappingWithRelationshipMeta.ResourceType = "sampleClassWithRelationshipMetadata"; mappingWithRelationshipMeta.AddPropertyGetter("someValue", c => c.SomeValue); var mappingWithRelatedClassesWithRelationshipMeta = new ResourceMapping <SampleClassWithRelatedClassesWithRelationshipMetadata, DummyController>(c => c.Id); mappingWithRelatedClassesWithRelationshipMeta.ResourceType = "sampleClassWithRelatedClassesWithRelationshipMetadata"; var relMapSingle = new RelationshipMapping <SampleClassWithRelatedClassesWithRelationshipMetadata, SampleClassWithRelationshipMetadata>(); relMapSingle.RelationshipName = "relatedObject"; relMapSingle.IsCollection = false; relMapSingle.RelatedProperty = new PropertyHandle <SampleClassWithRelatedClassesWithRelationshipMetadata, SampleClassWithRelationshipMetadata>(o => o.RelatedObject); relMapSingle.ResourceGetter = o => o.RelatedObject; relMapSingle.ResourceMapping = mappingWithRelationshipMeta; mappingWithRelatedClassesWithRelationshipMeta.Relationships.Add(relMapSingle); var relMapCollection = new RelationshipMapping <SampleClassWithRelatedClassesWithRelationshipMetadata, IList <SampleClassWithRelationshipMetadata> >(); relMapCollection.RelationshipName = "relatedObjects"; relMapCollection.IsCollection = true; relMapCollection.RelatedProperty = new PropertyHandle <SampleClassWithRelatedClassesWithRelationshipMetadata, IList <SampleClassWithRelationshipMetadata> >(o => o.RelatedObjects); relMapCollection.ResourceGetter = o => o.RelatedObjects; relMapCollection.ResourceMapping = mappingWithRelationshipMeta; mappingWithRelatedClassesWithRelationshipMeta.Relationships.Add(relMapCollection); var config = new NJsonApi.Configuration(); config.AddMapping(mapping); config.AddMapping(mappingWithMeta); config.AddMapping(mappingWithRelationshipMeta); config.AddMapping(mappingWithRelatedClassesWithRelationshipMeta); return(config); }
private Context CreateOneToManyConfigurationContext() { var conf = new Configuration(); var sampleClassMapping = new ResourceMapping <SampleClass>(c => c.Id, "http://sampleClass/{id}"); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); var nestedClassMapping = new ResourceMapping <NestedClass>(c => c.Id, "http://nested/{id}"); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("someNestedValue", c => c.SomeNestedValue); var linkMapping = new LinkMapping <SampleClass, NestedClass>() { RelatedBaseResourceType = "nestedClasses", RelationshipName = "nestedValues", ResourceGetter = c => c.NestedClasses, ResourceMapping = nestedClassMapping, IsCollection = true, }; sampleClassMapping.Relationships.Add(linkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); return(new Context { Configuration = conf, RequestUri = new Uri("http://route") }); }
private IConfiguration CreateConfiguration() { var conf = new NJsonApi.Configuration(); var sampleClassMapping = new ResourceMapping <SampleClass, DummyController>(c => c.Id); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("date", c => c.DateTime); sampleClassMapping.AddPropertyGetter("complexAttribute", c => c.ComplexAttribute); sampleClassMapping.AddPropertyGetter("listAttribute", c => c.ListAttribute); var nestedClassMapping = new ResourceMapping <NestedClass, DummyController>(c => c.Id); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("nestedText", c => c.NestedText); var deeplyNestedMapping = new ResourceMapping <DeeplyNestedClass, DummyController>(c => c.Id); deeplyNestedMapping.ResourceType = "deeplyNestedClasses"; deeplyNestedMapping.AddPropertyGetter("value", c => c.Value); var linkMapping = new RelationshipMapping <SampleClass, NestedClass>() { IsCollection = true, RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedClass, }; var deepLinkMapping = new RelationshipMapping <NestedClass, DeeplyNestedClass>() { RelationshipName = "deeplyNestedValues", ResourceMapping = deeplyNestedMapping, ResourceGetter = c => c.DeeplyNestedClass }; sampleClassMapping.Relationships.Add(linkMapping); nestedClassMapping.Relationships.Add(deepLinkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); conf.AddMapping(deeplyNestedMapping); return(conf); }
private Context CreateContext() { var conf = new Configuration(); var sampleClassMapping = new ResourceMapping<SampleClass>(c => c.Id, "http://sampleClass/{id}"); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("date", c => c.DateTime); var nestedClassMapping = new ResourceMapping<NestedClass>(c => c.Id, "http://nestedclass/{id}"); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("nestedText", c => c.NestedText); var deeplyNestedMapping = new ResourceMapping<DeeplyNestedClass>(c => c.Id, "http://deep/{id}"); deeplyNestedMapping.ResourceType = "deeplyNestedClasses"; deeplyNestedMapping.AddPropertyGetter("value", c => c.Value); var linkMapping = new LinkMapping<SampleClass, NestedClass>() { IsCollection = true, RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedClass, }; var deepLinkMapping = new LinkMapping<NestedClass, DeeplyNestedClass>() { RelationshipName = "deeplyNestedValues", ResourceMapping = deeplyNestedMapping, ResourceGetter = c => c.DeeplyNestedClass }; sampleClassMapping.Relationships.Add(linkMapping); nestedClassMapping.Relationships.Add(deepLinkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); conf.AddMapping(deeplyNestedMapping); return new Context { Configuration = conf, RoutePrefix = string.Empty }; }
public void Creates_configuration_mapping() { // Arrange var sampleMapping = new ResourceMapping <Post, PostsController>(c => c.Id) { ResourceType = "posts" }; sampleMapping.AddPropertyGetter("value", c => c.Title); var conf = new NJsonApi.Configuration(); // Act conf.AddMapping(sampleMapping); // Assert Assert.True(conf.IsResourceRegistered(typeof(Post))); Assert.NotNull(conf.GetMapping(typeof(Post))); Assert.False(conf.IsResourceRegistered(typeof(Author))); Assert.Null(conf.GetMapping(typeof(Author))); }
public void Creates_configuration_mapping() { // Arrange var sampleMapping = new ResourceMapping<Post, PostsController>(c => c.Id, "sample_{id}") { ResourceType = "posts" }; sampleMapping.AddPropertyGetter("value", c => c.Title); var conf = new NJsonApi.Configuration(); // Act conf.AddMapping(sampleMapping); // Assert Assert.True(conf.IsMappingRegistered(typeof(Post))); Assert.NotNull(conf.GetMapping(typeof(Post))); Assert.False(conf.IsMappingRegistered(typeof(Author))); Assert.Null(conf.GetMapping(typeof(Author))); }
public void Creates_configuration_mapping() { // Arrange var sampleMapping = new ResourceMapping<SampleClass>(c => c.Id, "sample_{id}") { ResourceType = "sampleClasses" }; sampleMapping.AddPropertyGetter("value", c => c.Value); var conf = new Configuration(); // Act conf.AddMapping(sampleMapping); // Assert conf.IsMappingRegistered(typeof(SampleClass)).ShouldBeTrue(); conf.GetMapping(typeof(SampleClass)).ShouldNotBeNull(); conf.IsMappingRegistered(typeof(NestedClass)).ShouldBeFalse(); conf.GetMapping(typeof(NestedClass)).ShouldBeNull(); }
public void Creates_configuration_mapping() { // Arrange var sampleMapping = new ResourceMapping <SampleClass>(c => c.Id, "sample_{id}") { ResourceType = "sampleClasses" }; sampleMapping.AddPropertyGetter("value", c => c.Value); var conf = new Configuration(); // Act conf.AddMapping(sampleMapping); // Assert conf.IsMappingRegistered(typeof(SampleClass)).ShouldBeTrue(); conf.GetMapping(typeof(SampleClass)).ShouldNotBeNull(); conf.IsMappingRegistered(typeof(NestedClass)).ShouldBeFalse(); conf.GetMapping(typeof(NestedClass)).ShouldBeNull(); }
private Context CreateContext() { var conf = new Configuration(); var mapping = new ResourceMapping<SampleClass>(c => c.Id, "http://sampleClass/{id}"); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); conf.AddMapping(mapping); return new Context { Configuration = conf, RoutePrefix = string.Empty }; }
private IConfiguration CreateConfiguration() { var mapping = new ResourceMapping<SampleClass, DummyController>(c => c.Id, "http://sampleClass/{id}"); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); var config = new NJsonApi.Configuration(); config.AddMapping(mapping); return config; }