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"); }
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); }
public void Intercept(IInvocation invocation) // implements the IInterceptor interface { using (var someThing = new SomeResource()) { invocation.Proceed(); } }
public void ShouldGetPropertyIfItHasOne() { var resource = new SomeResource { Id = 123 }; Assert.AreEqual(123, resource.GetProperty("Id")); Assert.IsNull(resource.GetProperty("CrazyProperty")); }
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>")); }
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]); }
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\"")); }
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); } }
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); }
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"]); }
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(); } }
private static void Run() { SomeResource b = new SomeResource("Second"); b.Consume(); }