コード例 #1
0
        public void ShouldGetPropertyIfItHasOne()
        {
            var resource = new SomeResource { Id = 123 };

            Assert.AreEqual(123, resource.GetProperty("Id"));
            Assert.IsNull(resource.GetProperty("CrazyProperty"));
        }
コード例 #2
0
 public void ShouldSerializeAllDataInResource()
 {
     var resource = new SomeResource {Amount = 123.45, Name = "John Doe"};
     
     var xml = serializer.Serialize(resource);
     Assert.That(xml.Contains("<Name>John Doe</Name>"));
     Assert.That(xml.Contains("<Amount>123.45</Amount>"));
 }
コード例 #3
0
        public void ShouldSerializeAsResource()
        {
            var resource = new SomeResource {Amount = 123.45, Name = "John Doe"};
            
            var json = serializer.Serialize(resource);

            Assert.That(json.Contains("\"Name\":\"John Doe\""));
            Assert.That(json.Contains("\"Amount\":123.45"));
        }
コード例 #4
0
        public void ShouldSerializeAsResource()
        {
            var resource = new SomeResource {Amount = 123.45, Name = "John Doe", UpdatedAt = new DateTime(2012,7,29)};
            
            var json = serializer.Serialize(resource);

            Assert.That(json.Contains("\"Name\":\"John Doe\""));
            Assert.That(json.Contains("\"Amount\":123.45"));
            Assert.That(json.Contains("\"UpdatedAt\":\"2012-07-29T00:00:00\""));
        }
コード例 #5
0
        public void ShouldConvertToAnArrayOfResources()
        {
            var resource = new SomeResource();
            var list = new List<SomeResource> {resource};

            var array = list.AsResourceArray();

            Assert.AreEqual(1, array.Length);
            Assert.AreEqual(resource, array[0]);
        }
コード例 #6
0
        public void ShouldBuildResourceRepresentation()
        {
            var resource = new SomeResource();
            
            serializer.Setup(s => s.Serialize(resource)).Returns(SerializedResource());
            hypermedia.Setup(h => h.Inject(SerializedResource(), relations.Object, requestInfo.Object)).Returns(HypermediaResource());

            var builder = new RestfulieMarshaller(relationsFactory.Object, serializer.Object, hypermedia.Object);
            var representation = builder.Build(resource, requestInfo.Object);

            serializer.VerifyAll();
            hypermedia.VerifyAll();

            Assert.AreEqual(HypermediaResource(), representation);
        }
コード例 #7
0
        public void ShouldUnmarshallResource()
        {
            var filter = new ActAsRestfulie(acceptHeader.Object, contentType.Object, requestInfoFactory.Object,
                                            chooser.Object, resolver.Object);

            var resource = new SomeResource { Amount = 123, Name = "Some name" };

            resolver.SetupGet(r => r.HasResource).Returns(true);
            resolver.SetupGet(r => r.ParameterName).Returns("Resource");
            resolver.SetupGet(r => r.ParameterType).Returns(typeof (SomeResource));

            unmarshaller.Setup(u => u.Build(It.IsAny<string>(), typeof(SomeResource))).Returns(resource);
            contentType.Setup(m => m.GetMediaType(It.IsAny<string>())).Returns(mediaType.Object);

            filter.OnActionExecuting(actionExecutingContext);

            Assert.AreEqual(resource, actionExecutingContext.ActionParameters["Resource"]);
        }
コード例 #8
0
        public void ShouldSerializeAResource()
        {
            var date = new DateTime(2010, 10, 10);
            var resource = new SomeResource {Name = "John Doe", Amount = 123.45, Id = 123, UpdatedAt = date};
            var atom = serializer.Serialize(resource);

            const string expectedResult =
                "<entry xmlns=\"http://www.w3.org/2005/Atom\">\r\n"+
                "  <title>(title)</title>\r\n"+
                "  <id>(entry-url)</id>\r\n"+
                "  <updated>2010-10-10T00:00:00.000</updated>\r\n"+
                "  <content type=\"application/xml\" xmlns=\"\">\r\n"+
                "    <SomeResource>\r\n"+
                "      <Name>John Doe</Name>\r\n"+
                "      <Amount>123.45</Amount>\r\n"+
                "      <Id>123</Id>\r\n"+
                "      <UpdatedAt>2010-10-10T00:00:00</UpdatedAt>\r\n"+
                "    </SomeResource>\r\n"+
                "  </content>\r\n"+
                "</entry>";

            Assert.AreEqual(expectedResult, atom);
        }
コード例 #9
0
 public virtual ActionResult ActionWithResource(SomeResource resource)
 {
     return(new OK(resource));
 }
コード例 #10
0
 public virtual ActionResult ActionWithResource(SomeResource resource)
 {
     return new OK(resource);
 }