public void PicksUpOrdersLinkFromCustomer() { const string idProperty = @"""id"":42"; const string ordersLink = @"{""title"":null,""href"":""/customer/42/orders"",""rel"":""customer.orders"",""type"":""application/vnd.list.order+json""}"; const string selfLink = @"{""title"":null,""href"":""/customer/42"",""rel"":""self"",""type"":""application/vnd.customer+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new Customer { Id = 42 }); var target = new JsonMediaTypeHandler { JsonLinksFormatter = new SimpleJsonLinksFormatter() }; string json; using (var stream = new StringBuilderStream()) { target.Write <Customer>(content, stream).Wait(); json = stream.StringValue; } var jobj = JObject.Parse(json); var links = jobj["_links"] as JObject; Assert.NotNull(links); Assert.Equal(links["customer.orders"].ToString(), "/customer/42/orders"); Assert.Equal(links["self"].ToString(), "/customer/42"); }
public void SerializingListToJsonHasExpectedData() { const string expectedString = "{\"Customers\":[{\"Id\":42}]}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomersListHandler(), new CustomerList() { Customers = new List <Customer>() { new Customer { Id = 42 } } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Equal(expectedString, actual); }
public void PicksUpPathFromThing() { const string thingLink = @"{""title"":null,""href"":""/things?path=%2Ffoo%2Fbar"",""rel"":""self"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/foo/bar"), new ThingHandler(), new Thing { Path = "/foo/bar" }); var target = new JsonMediaTypeHandler { JsonLinksFormatter = new SimpleJsonLinksFormatter() }; string json; using (var stream = new StringBuilderStream()) { target.Write <Thing>(content, stream).Wait(); json = stream.StringValue; } var jobj = JObject.Parse(json); var links = jobj["_links"] as JObject; Assert.NotNull(links); Assert.Equal(links["self"].ToString(), "/things?path=%2Ffoo%2Fbar"); }
public void PicksUpOrdersLinkFromCustomers() { const string idProperty = @"""id"":42"; const string ordersLink = @"{""title"":null,""href"":""/customer/42/orders"",""rel"":""customer.orders"",""type"":""application/vnd.list.order+json""}"; const string selfLink = @"{""title"":null,""href"":""/customer/42"",""rel"":""self"",""type"":""application/vnd.customer+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new[] { new Customer { Id = 42 } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Contains(idProperty, actual); Assert.Contains(ordersLink, actual); Assert.Contains(selfLink, actual); }
public void WritesJsonWithEnum() { var content = new Content(new Uri("http://test.com/EnumCustomer/42"), new EnumCustomerHandler(), new[] { new EnumCustomer() { AnEnum = MyEnum.Ian } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); }
public void PicksUpOrdersLinkFromCustomers() { const string idProperty = @"""Id"":42"; const string ordersLink = @"{""Title"":null,""Href"":""/customer/42/orders"",""Rel"":""customer.orders"",""Type"":""application/vnd.list.order+json""}"; const string selfLink = @"{""Title"":null,""Href"":""/customer/42"",""Rel"":""self"",""Type"":""application/vnd.customer+json""}]}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new[] { new Customer { Id = 42 } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Contains(idProperty, actual); Assert.Contains(ordersLink, actual); Assert.Contains(selfLink, actual); }
public void PicksUpOrdersLinkFromCustomer() { const string idProperty = @"""id"":42"; const string ordersLink = @"{""title"":null,""href"":""/customer/42/orders"",""rel"":""customer.orders"",""type"":""application/vnd.list.order+json""}"; const string selfLink = @"{""title"":null,""href"":""/customer/42"",""rel"":""self"",""type"":""application/vnd.customer+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new Customer {Id = 42}); var target = new JsonMediaTypeHandler { JsonLinksFormatter = new SimpleJsonLinksFormatter() }; string json; using (var stream = new StringBuilderStream()) { target.Write<Customer>(content, stream).Wait(); json = stream.StringValue; } var jobj = JObject.Parse(json); var links = jobj["_links"] as JObject; Assert.NotNull(links); Assert.Equal(links["customer.orders"].ToString(), "/customer/42/orders"); Assert.Equal(links["self"].ToString(), "/customer/42"); }
public void PicksUpOrdersLinkFromCustomers() { const string idProperty = @"""Id"":42"; const string ordersLink = @"{""Title"":null,""Href"":""/customer/42/orders"",""Rel"":""customer.orders"",""Type"":""application/vnd.list.order+json""}"; const string selfLink = @"{""Title"":null,""Href"":""/customer/42"",""Rel"":""self"",""Type"":""application/vnd.customer+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new[] { new Customer { Id = 42 } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write <IEnumerable <Customer> >(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Contains(idProperty, actual); Assert.Contains(ordersLink, actual); Assert.Contains(selfLink, actual); }
public void SerializesCyrillicText() { const string russian = "Мыа алиё лаборамюз ед, ведят промпта элыктрам квюо ты."; var content = new Content(new Uri("http://test.com/customer/42"), new ThingHandler(), new Thing {Path = russian}); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write<Thing>(content, stream).Wait(); actual = stream.StringValue; } Assert.Contains(russian, actual); }
public void SerializingListToJsonHasExpectedData() { const string expectedString = "{\"Customers\":[{\"Id\":42,\"Orders\":null}]}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomersListHandler(), new CustomerList() { Customers = new List<Customer>() { new Customer { Id = 42 } } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write<CustomerList>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Equal(expectedString, actual); }
public void WritesJsonWithEnum() { var content = new Content(new Uri("http://test.com/EnumCustomer/42"), new EnumCustomerHandler(), new[] {new EnumCustomer() {AnEnum = MyEnum.Ian}}); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write<EnumCustomer>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); }
public void PicksUpContactsLinkFromCustomer() { const string contactsLink = @"{""title"":null,""href"":""/customer/42/contacts"",""rel"":""customer.contacts"",""type"":""application/vnd.contact+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new Customer {Id = 42}); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write<Customer>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Contains(contactsLink, actual); }
public void SerializesCyrillicText() { const string russian = "Мыа алиё лаборамюз ед, ведят промпта элыктрам квюо ты."; var content = new Content(new Uri("http://test.com/customer/42"), new ThingHandler(), new Thing { Path = russian }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write <Thing>(content, stream).Wait(); actual = stream.StringValue; } Assert.Contains(russian, actual); }
public void WritesJsonWithEnum() { var content = new Content(new Uri("http://test.com/EnumCustomer/42"), new EnumCustomerHandler(), new[] { new EnumCustomer() { AnEnum = MyEnum.Ian } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write <EnumCustomer>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); }
public void AddsSelfLinkToChildCollectionItems() { var customer = new Customer { Id = 42, Orders = new List <Order> { new Order { CustomerId = 42, Id = 54 } } }; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), customer); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); var jobj = JObject.Parse(actual); var orders = jobj["orders"] as JArray; Assert.NotNull(orders); var order = orders[0] as JObject; Assert.NotNull(order); var links = order["links"] as JArray; Assert.NotNull(links); var self = links.FirstOrDefault(jt => jt["rel"].Value <string>() == "self"); Assert.NotNull(self); Assert.Equal("/order/54", self["href"].Value <string>()); Assert.Equal("application/vnd.order+json", self["type"].Value <string>()); }
public void PicksUpPathFromThing() { const string thingLink = @"{""title"":null,""href"":""/things?path=%2Ffoo%2Fbar"",""rel"":""self"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/foo/bar"), new ThingHandler(), new Thing { Path = "/foo/bar" }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write <Thing>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Contains(thingLink, actual); }
public void PicksUpContactsLinkFromCustomer() { const string contactsLink = @"{""title"":null,""href"":""/customer/42/contacts"",""rel"":""customer.contacts"",""type"":""application/vnd.contact+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new Customer { Id = 42 }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write <Customer>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Contains(contactsLink, actual); }
public void SerializingListToJsonHasExpectedData() { const string expectedString = "{\"Customers\":[{\"Id\":42}]}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomersListHandler(), new CustomerList() { Customers = new List<Customer>() { new Customer { Id = 42 } } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Equal(expectedString, actual); }
public void PicksUpContactsLinkFromCustomer() { const string contactsLink = @"{""title"":null,""href"":""/customer/42/contacts"",""rel"":""customer.contacts"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new Customer { Id = 42 }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Contains(contactsLink, actual); }
public void PicksUpPathFromThing() { const string thingLink = @"{""title"":null,""href"":""/things?path=%2Ffoo%2Fbar"",""rel"":""self"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/foo/bar"), new ThingHandler(), new Thing {Path = "/foo/bar"}); var target = new JsonMediaTypeHandler { JsonLinksFormatter = new SimpleJsonLinksFormatter() }; string json; using (var stream = new StringBuilderStream()) { target.Write<Thing>(content, stream).Wait(); json = stream.StringValue; } var jobj = JObject.Parse(json); var links = jobj["_links"] as JObject; Assert.NotNull(links); Assert.Equal(links["self"].ToString(), "/things?path=%2Ffoo%2Fbar"); }
public void PicksUpOrdersLinkFromCustomers() { const string idProperty = @"""Id"":42"; const string ordersLink = @"{""Title"":null,""Href"":""/customer/42/orders"",""Rel"":""customer.orders"",""Type"":""application/vnd.list.order+json""}"; const string selfLink = @"{""Title"":null,""Href"":""/customer/42"",""Rel"":""self"",""Type"":""application/vnd.customer+json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new[] {new Customer {Id = 42}}); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write<IEnumerable<Customer>>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Contains(idProperty, actual); Assert.Contains(ordersLink, actual); Assert.Contains(selfLink, actual); }
public void SerializesCyrillicText() { const string russian = "Мыа алиё лаборамюз ед, ведят промпта элыктрам квюо ты."; var content = new Content(new Uri("http://test.com/customer/42"), new ThingHandler(), new Thing { Path = russian }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.Contains(russian, actual); }
public void SerializingListToJsonHasExpectedData() { const string expectedString = "{\"Customers\":[{\"Id\":42,\"Orders\":null}]}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomersListHandler(), new CustomerList() { Customers = new List <Customer>() { new Customer { Id = 42 } } }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write <CustomerList>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Equal(expectedString, actual); }
public void PicksUpContactsLinkFromCustomer() { const string contactsLink = @"{""title"":null,""href"":""/customer/42/contacts"",""rel"":""customer.contacts"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), new Customer { Id = 42 }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Contains(contactsLink, actual); }
public void PicksUpPathFromThing() { const string thingLink = @"{""title"":null,""href"":""/things?path=%2Ffoo%2Fbar"",""rel"":""self"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/foo/bar"), new ThingHandler(), new Thing { Path = "/foo/bar" }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Contains(thingLink, actual); }
public void PicksUpPathFromThing() { const string thingLink = @"{""title"":null,""href"":""/things?path=%2Ffoo%2Fbar"",""rel"":""self"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/foo/bar"), new ThingHandler(), new Thing {Path = "/foo/bar"}); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new StringBuilderStream()) { target.Write<Thing>(content, stream).Wait(); actual = stream.StringValue; } Assert.NotNull(actual); Assert.Contains(thingLink, actual); }
public void AddsSelfLinkToChildCollectionItems() { var customer = new Customer { Id = 42, Orders = new List<Order> {new Order {CustomerId = 42, Id = 54}} }; var content = new Content(new Uri("http://test.com/customer/42"), new CustomerHandler(), customer); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); var jobj = JObject.Parse(actual); var orders = jobj["orders"] as JArray; Assert.NotNull(orders); var order = orders[0] as JObject; Assert.NotNull(order); var links = order["links"] as JArray; Assert.NotNull(links); var self = links.FirstOrDefault(jt => jt["rel"].Value<string>() == "self"); Assert.NotNull(self); Assert.Equal("/order/54", self["href"].Value<string>()); Assert.Equal("application/vnd.order+json", self["type"].Value<string>()); }
public void PicksUpPathFromThing() { const string thingLink = @"{""title"":null,""href"":""/things?path=%2Ffoo%2Fbar"",""rel"":""self"",""type"":""application/json""}"; var content = new Content(new Uri("http://test.com/foo/bar"), new ThingHandler(), new Thing { Path = "/foo/bar" }); var target = new JsonMediaTypeHandler(); string actual; using (var stream = new NonClosingMemoryStream(new MemoryStream())) { target.Write(content, stream).Wait(); stream.Position = 0; using (var reader = new StreamReader(stream)) { actual = reader.ReadToEnd(); } stream.ForceDispose(); } Assert.NotNull(actual); Assert.Contains(thingLink, actual); }