public void TestExplicitSetup()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;
            model.Add(typeof(ResourceNode <Ship>), false).AddSubType(1, typeof(ShipResource));
            model.Add(typeof(ResourceNode <SomeType>), false).AddSubType(1, typeof(SomeResource));

            var obj1 = new ShipResource {
                Value = new Ship {
                    Foo = 123
                }
            };
            var obj2 = new SomeResource {
                Value = new SomeType {
                    Bar = "abc"
                }
            };

            Test(model, obj1, obj2, "Runtime");

            model.Compile("SO9408133_TestExplicitSetup", "SO9408133_TestExplicitSetup.dll");
            PEVerify.AssertValid("SO9408133_TestExplicitSetup.dll");

            model.CompileInPlace();
            Test(model, obj1, obj2, "CompileInPlace");
            Test(model.Compile(), obj1, obj2, "Compile");
        }
Ejemplo n.º 2
0
 public static void Main()
 {
     using (var resource = new SomeResource())
     {
         resource.Foo();
     }
 }
        public void TestImplicitSetup()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;

            var obj1 = new ShipResource {
                Value = new Ship {
                    Foo = 123
                }
            };
            var obj2 = new SomeResource {
                Value = new SomeType {
                    Bar = "abc"
                }
            };

            Test(model, obj1, obj2, "Runtime");

            model.Compile("SO9408133_TestImplicitSetup", "SO9408133_TestImplicitSetup.dll");
            PEVerify.AssertValid("SO9408133_TestImplicitSetup.dll");

            model.CompileInPlace();
            Test(model, obj1, obj2, "CompileInPlace");
            Test(model.Compile(), obj1, obj2, "Compile");
        }
        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);
        }
Ejemplo n.º 5
0
 public void Intercept(IInvocation invocation)     // implements the IInterceptor interface
 {
     using (var someThing = new SomeResource())
     {
         invocation.Proceed();
     }
 }
Ejemplo n.º 6
0
        public void ShouldGetPropertyIfItHasOne()
        {
            var resource = new SomeResource {
                Id = 123
            };

            Assert.AreEqual(123, resource.GetProperty("Id"));
            Assert.IsNull(resource.GetProperty("CrazyProperty"));
        }
Ejemplo n.º 7
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>"));
        }
Ejemplo n.º 8
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]);
        }
Ejemplo n.º 9
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\""));
        }
Ejemplo n.º 10
0
        private void Test(TypeModel model, ShipResource obj1, SomeResource obj2, string caption)
        {
            try
            {
                var clone1 = (ShipResource)model.DeepClone(obj1);
                var clone2 = (SomeResource)model.DeepClone(obj2);

                Assert.Equal(obj1.Value.Foo, clone1.Value.Foo); //, caption + ":Foo");
                Assert.Equal(obj2.Value.Bar, clone2.Value.Bar); //, caption + ":Bar");
            } catch (Exception ex)
            {
                throw new Exception(caption + ":" + ex.Message, ex);
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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"]);
        }
Ejemplo n.º 13
0
    public static void Main()
    {
        SomeResource a = new SomeResource("First");

        a.Consume();

        Run();

        Console.WriteLine("Before garbage-collection {0} resource is in generation:{1}", a.Id, GC.GetGeneration(a));
        GC.Collect();         //forcing garbage-collection
        GC.WaitForPendingFinalizers();
        Console.WriteLine("After garbage-collection {0} resource is in generation:{1}", a.Id, GC.GetGeneration(a));

        SomeResource c = new SomeResource("Third");

        c.Consume();
        c.Dispose();

        using (SomeResource d = new SomeResource("Fourth"))
        {
            d.Consume();
        }
    }
Ejemplo n.º 14
0
    private static void Run()
    {
        SomeResource b = new SomeResource("Second");

        b.Consume();
    }