public async Task ComplexTypeSerializesAsOData() { // Arrange string routeName = "OData"; IEdmModel model = GetSampleModel(); var request = RequestFactory.Create("Get", "http://localhost/property", opt => opt.AddRouteComponents(routeName, model)); request.ODataFeature().Model = model; request.ODataFeature().RoutePrefix = routeName; var payload = new ODataPayloadKind[] { ODataPayloadKind.Resource }; var formatter = ODataFormatterHelpers.GetOutputFormatter(payload); Address address = new Address { Street = "abc", City = "efg", State = "opq", ZipCode = "98029", CountryOrRegion = "Mars" }; var content = ODataFormatterHelpers.GetContent(address, formatter, ODataMediaTypes.ApplicationJsonODataMinimalMetadata); // Act & Assert string actual = await ODataFormatterHelpers.GetContentResult(content, request); Assert.Equal("{\"@odata.context\":\"http://localhost/OData/$metadata#Microsoft.AspNetCore.OData.Tests.Formatter.Models.Address\"," + "\"Street\":\"abc\"," + "\"City\":\"efg\"," + "\"State\":\"opq\"," + "\"ZipCode\":\"98029\"," + "\"CountryOrRegion\":\"Mars\"}", actual); }
public ODataResourceSetDeserializerTests() { _model = GetEdmModel(); _customerType = _model.GetEdmTypeReference(typeof(Customer)).AsEntity(); _customersType = new EdmCollectionTypeReference(new EdmCollectionType(_customerType)); _serializerProvider = ODataFormatterHelpers.GetSerializerProvider(); _deserializerProvider = ODataFormatterHelpers.GetDeserializerProvider(); }
public async Task ReadAsync_ThrowsArgumentNull_ReadContext() { // Arrange var deserializer = new ODataResourceSetDeserializer(_deserializerProvider); ODataMessageReader reader = ODataFormatterHelpers.GetMockODataMessageReader(); // Act & Assert await ExceptionAssert.ThrowsArgumentNullAsync(() => deserializer.ReadAsync(reader, null, null), "readContext"); }
public async Task ReadAsync_Throws_ArgumentMustBeOfType() { // Arrange var deserializer = new ODataResourceSetDeserializer(_deserializerProvider); ODataMessageReader reader = ODataFormatterHelpers.GetMockODataMessageReader(); ODataDeserializerContext context = new ODataDeserializerContext { Model = EdmCoreModel.Instance }; IEdmTypeReference edmType = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))); // Act & Assert await ExceptionAssert.ThrowsAsync <ArgumentException>( () => deserializer.ReadAsync(reader, typeof(IList <int>), context), "The argument must be of type 'Complex or Entity'. (Parameter 'edmType')"); }
public async Task EntityTypeSerializesAsODataEntry() { // Arrange const string routeName = "OData"; IEdmEntitySet entitySet = _model.EntityContainer.FindEntitySet("employees"); ODataPath path = new ODataPath(new EntitySetSegment(entitySet)); var request = RequestFactory.Create("Get", "http://localhost/property", opt => opt.AddModel(routeName, _model)); request.ODataFeature().Model = _model; request.ODataFeature().Path = path; request.ODataFeature().PrefixName = routeName; var payload = new ODataPayloadKind[] { ODataPayloadKind.Resource }; var formatter = ODataFormatterHelpers.GetOutputFormatter(payload); Employee employee = new Employee { EmployeeID = 8, Birthday = new System.DateTimeOffset(2020, 9, 10, 1, 2, 3, System.TimeSpan.Zero), EmployeeName = "Ssa", HomeAddress = null }; var content = ODataFormatterHelpers.GetContent(employee, formatter, ODataMediaTypes.ApplicationJsonODataMinimalMetadata); // Act & Assert string actual = await ODataFormatterHelpers.GetContentResult(content, request); Assert.Equal("{\"@odata.context\":\"http://localhost/OData/$metadata#employees/$entity\"," + "\"EmployeeID\":8," + "\"EmployeeName\":\"Ssa\"," + "\"BaseSalary\":0," + "\"Birthday\":\"2020-09-10T01:02:03Z\"," + "\"WorkCompanyId\":0," + "\"HomeAddress\":null" + "}", actual); }
public void ReadInline_Calls_ReadInlineForEachDeltaItem() { IODataDeserializerProvider provider = ODataFormatterHelpers.GetDeserializerProvider(); }