public void TestCustomMediaTypeGetFormatFromContentType() { var resolver = new MyMediaTypeResolver(); foreach (var payloadKind in Enum.GetValues(typeof(ODataPayloadKind)).Cast <ODataPayloadKind>()) { if (payloadKind == ODataPayloadKind.Unsupported) { continue; } string contentType = "text/x-A"; string expectedBoundary = null; ODataMediaType expectedMediaType = MyFormat.MediaTypeWithFormatA.MediaType; if (payloadKind == ODataPayloadKind.Batch) { expectedBoundary = "ba_" + Guid.NewGuid(); contentType += ";boundary=" + expectedBoundary; expectedMediaType = new ODataMediaType("text", "x-A", new KeyValuePair <string, string>("boundary", expectedBoundary)); } ODataMediaType mediaType; Encoding encoding; ODataPayloadKind selectedPayloadKind; ODataFormat actual = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { payloadKind }, resolver, out mediaType, out encoding, out selectedPayloadKind); Console.WriteLine(payloadKind); actual.ShouldBeEquivalentTo(MyFormat.Instance); mediaType.ShouldBeEquivalentTo(expectedMediaType); encoding.ShouldBeEquivalentTo(payloadKind == ODataPayloadKind.BinaryValue ? null : Encoding.UTF8); selectedPayloadKind.ShouldBeEquivalentTo(payloadKind); } }
public void TestCustomMediaTypeGetMediaTypesForPayloadKind() { var resolver = new MyMediaTypeResolver(); foreach (var payloadKind in Enum.GetValues(typeof(ODataPayloadKind)).Cast<ODataPayloadKind>()) { if (payloadKind == ODataPayloadKind.Unsupported) { continue; } var expected = MediaTypeCollection[(int)payloadKind].ToList(); expected.Insert(0, MyFormat.MediaTypeWithFormatA); var actual = resolver.GetMediaTypeFormats(payloadKind); VerifyMediaTypeFormats(actual, expected); } }
public void TestCustomMediaTypeGetFormatFromContentType() { var resolver = new MyMediaTypeResolver(); foreach (var payloadKind in Enum.GetValues(typeof(ODataPayloadKind)).Cast<ODataPayloadKind>()) { if (payloadKind == ODataPayloadKind.Unsupported) { continue; } string contentType = "text/x-A"; string expectedBoundary = null; ODataMediaType expectedMediaType = MyFormat.MediaTypeWithFormatA.MediaType; if (payloadKind == ODataPayloadKind.Batch) { expectedBoundary = "ba_" + Guid.NewGuid(); contentType += ";boundary=" + expectedBoundary; expectedMediaType = new ODataMediaType("text", "x-A", new KeyValuePair<string, string>("boundary", expectedBoundary)); } ODataMediaType mediaType; Encoding encoding; ODataPayloadKind selectedPayloadKind; string batchBoundary; ODataFormat actual = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { payloadKind }, resolver, out mediaType, out encoding, out selectedPayloadKind, out batchBoundary); Console.WriteLine(payloadKind); actual.ShouldBeEquivalentTo(MyFormat.Instance); mediaType.ShouldBeEquivalentTo(expectedMediaType); encoding.ShouldBeEquivalentTo(payloadKind == ODataPayloadKind.BinaryValue ? null : Encoding.UTF8); selectedPayloadKind.ShouldBeEquivalentTo(payloadKind); batchBoundary.ShouldBeEquivalentTo(expectedBoundary); } }
public void TestCustomMediaTypeGetMediaTypesForPayloadKind() { var resolver = new MyMediaTypeResolver(); foreach (var payloadKind in Enum.GetValues(typeof(ODataPayloadKind)).Cast<ODataPayloadKind>()) { if (payloadKind == ODataPayloadKind.Unsupported) { continue; } var expected = MediaTypeCollection[(int)payloadKind].ToList(); expected.Insert(0, MyFormat.MediaTypeWithFormatA); var actual = resolver.GetMediaTypeFormats(payloadKind); Console.WriteLine(payloadKind); actual.ShouldBeEquivalentTo(expected); } }