Exemplo n.º 1
0
        public IActionResult Get(int id)
        {
            var a  = StaticPersistentStore.Articles.Single(w => w.Id == id);
            var md = new TopLevelDocument <Article>(a);

            md.GetMetaData().Add("response created", DateTime.Now);
            md.GetMetaData().Add("response created by", this.GetType());
            md.Links.Add("link1", new SimpleLink(new Uri("http://localhost")));
            return(new ObjectResult(md));
        }
Exemplo n.º 2
0
        public IActionResult Get()
        {
            var a  = StaticPersistentStore.Articles;
            var md = new TopLevelDocument <List <Article> >(a);

            md.GetMetaData().Add("response created", DateTime.Now);
            md.GetMetaData().Add("response created by", this.GetType());
            md.Links.Add("link1", new SimpleLink(new Uri("http://localhost")));
            return(Ok(md));
        }
        public void TopLevelDocument_using_ctor_string_ok()
        {
            // Arrange
            const string testString = "Test String";

            // Act
            var sut = new TopLevelDocument <string>(testString);

            // Assert
            Assert.Equal(sut.Value, testString);
            Assert.Empty(sut.GetMetaData());
        }
        public void TopLevelDocument_add_metadata_ok()
        {
            // Arrange
            const string testString = "Test String";

            // Act
            var sut = new TopLevelDocument <string>(testString);

            sut.GetMetaData().Add("meta1", "value1");

            // Assert
            Assert.Equal("value1", sut.GetMetaData()["meta1"]);
        }
        public void TopLevelDocument_add_simple_links_ok()
        {
            // Arrange
            const string testString = "Test String";
            var          link       = new SimpleLink();

            // Act
            var sut = new TopLevelDocument <string>(testString);

            sut.Links.Add("link1", link);

            // Assert
            Assert.Same(link, sut.Links["link1"]);
        }
        public void TopLevelDocument_add_result_collection_ok()
        {
            // Arrange
            var testsStrings = new List <string>()
            {
                "test1", "test2"
            };

            // Act
            var sut = new TopLevelDocument <List <string> >(testsStrings);

            // Assert
            Assert.Equal(sut.Value, testsStrings);
            Assert.Empty(sut.GetMetaData());
        }
        public void Creates_CompoundDocument_for_TopLevelDocument_single_not_nested_class_and_properly_map_type()
        {
            // Arrange
            var context = CreateContext();
            TopLevelDocument <SampleClass> objectToTransform = CreateObjectToTransform();
            var transfomer = new JsonApiTransformerBuilder()
                             .With(CreateConfiguration())
                             .Build();

            // Act
            CompoundDocument result = transfomer.Transform(objectToTransform, context);

            // Assert
            var transformedObject = result.Data as SingleResource;

            Assert.Equal(transformedObject.Type, "sampleClasses");
        }
Exemplo n.º 8
0
        public IHttpActionResult Get()
        {
            var a  = StaticPersistentStore.Articles;
            var md = new TopLevelDocument <List <Article> >(a);

            md.GetMetaData().Add("response created", DateTime.Now);
            md.GetMetaData().Add("response created by", this.GetType());
            md.Links.Add("link1", new SimpleLink(new Uri("http://localhost")));

            md.Links.Add("link2", new SimpleLink(new Uri("http://localhost")));

            var complexLink = new LinkObject(new Uri("http://localhost/complex/"));

            complexLink.Meta.Add("linkmeta", "linkmetavalue");
            md.Links.Add("complexLink", complexLink);

            return(Ok(md));
        }
        public void Creates_CompoundDocument_for_TopLevelDocument_single_not_nested_class_and_properly_map_properties()
        {
            // Arrange
            var context = CreateContext();
            TopLevelDocument <SampleClass> objectToTransform = CreateObjectToTransform();
            var transfomer = new JsonApiTransformerBuilder()
                             .With(CreateConfiguration())
                             .Build();

            // Act
            CompoundDocument result = transfomer.Transform(objectToTransform, context);

            // Assert
            var transformedObject = result.Data as SingleResource;

            Assert.Equal(transformedObject.Attributes["someValue"], objectToTransform.Value.SomeValue);
            Assert.Equal(transformedObject.Attributes["date"], objectToTransform.Value.DateTime);
            Assert.Equal(transformedObject.Attributes.Count, 2);
        }
Exemplo n.º 10
0
        public void TopLevelDocument_add_link_objects_ok()
        {
            // Arrange
            const string testString = "Test String";
            var          meta       = new MetaData();

            meta.Add("about", "this");
            var link       = new SimpleLink();
            var linkObject = new LinkObject {
                Link = link, Meta = meta
            };

            // Act
            var sut = new TopLevelDocument <string>(testString);

            sut.Links.Add("link2", linkObject);

            // Assert
            Assert.Same(linkObject, sut.Links["link2"]);
        }
Exemplo n.º 11
0
        public void Creates_CompoundDocument_for_TopLevelDocument_single_not_nested_class_and_properly_map_metadata()
        {
            // Arrange
            const string pagingValue = "1";
            const string countValue  = "2";

            var context = CreateContext();
            TopLevelDocument <SampleClass> objectToTransform = CreateObjectToTransform();

            objectToTransform.GetMetaData().Add("Paging", pagingValue);
            objectToTransform.GetMetaData().Add("Count", countValue);
            var transfomer = new JsonApiTransformerBuilder()
                             .With(CreateConfiguration())
                             .Build();

            // Act
            CompoundDocument result = transfomer.Transform(objectToTransform, context);

            // Assert
            var transformedObjectMetadata = result.Meta;

            Assert.Equal(transformedObjectMetadata["Paging"], pagingValue);
            Assert.Equal(transformedObjectMetadata["Count"], countValue);
        }
Exemplo n.º 12
0
        public void Creates_CompoundDocument_for_TopLevelDocument_single_not_nested_class_and_properly_map_links()
        {
            // Arrange
            SimpleLink linkSome  = new SimpleLink(new Uri("http://somehost/"));
            SimpleLink linkOther = new SimpleLink(new Uri("http://otherhost/"));

            var context = CreateContext();
            TopLevelDocument <SampleClass> objectToTransform = CreateObjectToTransform();

            objectToTransform.Links.Add("linkSome", linkSome);
            objectToTransform.Links.Add("linkOther", linkOther);
            var transfomer = new JsonApiTransformerBuilder()
                             .With(CreateConfiguration())
                             .Build();

            // Act
            CompoundDocument result = transfomer.Transform(objectToTransform, context);

            // Assert
            var transformedObjectLinks = result.Links;

            Assert.Same(linkSome, transformedObjectLinks["linkSome"]);
            Assert.Same(linkOther, transformedObjectLinks["linkOther"]);
        }