diff --git a/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/ETags/JsonETagsTests.cs b/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/ETags/JsonETagsTests.cs index 2450cfa821..be30e3fdc8 100644 --- a/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/ETags/JsonETagsTests.cs +++ b/test/E2ETest/Microsoft.Test.E2E.AspNet.OData/ETags/JsonETagsTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text.RegularExpressions; @@ -133,47 +134,60 @@ public async Task ModelBuilderTest() collection.Elements.Select(e => ((IEdmPathExpression) e).PathSegments.Single())); } - [Fact] - public async Task JsonWithDifferentMetadataLevelsHaveSameETagsTest() + [Theory] + [InlineData("application/json")] // default metadata level + [InlineData("application/json;odata.metadata=full")] + [InlineData("application/json;odata.metadata=minimal")] + public async Task JsonWithDifferentMetadataLevelsHaveSameETagsTest(string metadataLevel) { string requestUri = this.BaseAddress + "/odata/ETagsCustomers"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri); - request.Headers.Accept.ParseAdd("application/json"); + request.Headers.Accept.ParseAdd(metadataLevel); HttpResponseMessage response = await this.Client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); var jsonResult = await response.Content.ReadAsObject(); - var jsonETags = jsonResult.GetValue("value").Select(e => e["@odata.etag"].ToString()); - Assert.Equal(jsonETags.Count(), jsonETags.Distinct().Count()); + var jsonValue = jsonResult.GetValue("value") as JArray; + Assert.Equal(10, jsonValue.Count); - requestUri = this.BaseAddress + "/odata/ETagsCustomers"; - request = new HttpRequestMessage(HttpMethod.Get, requestUri); - request.Headers.Accept.ParseAdd("application/json;odata=nometadata"); - response = await this.Client.SendAsync(request); - Assert.True(response.IsSuccessStatusCode); - var jsonWithNometadataResult = await response.Content.ReadAsObject(); - var jsonWithNometadataETags = jsonWithNometadataResult.GetValue("value").Select(e => e["@odata.etag"].ToString()); - Assert.Equal(jsonWithNometadataETags.Count(), jsonWithNometadataETags.Distinct().Count()); - Assert.Equal(jsonETags, jsonWithNometadataETags); - - requestUri = this.BaseAddress + "/odata/ETagsCustomers"; - request = new HttpRequestMessage(HttpMethod.Get, requestUri); - request.Headers.Accept.ParseAdd("application/json;odata=fullmetadata"); - response = await this.Client.SendAsync(request); - Assert.True(response.IsSuccessStatusCode); - var jsonWithFullmetadataResult = await response.Content.ReadAsObject(); - var jsonWithFullmetadataETags = jsonWithFullmetadataResult.GetValue("value").Select(e => e["@odata.etag"].ToString()); - Assert.Equal(jsonWithFullmetadataETags.Count(), jsonWithFullmetadataETags.Distinct().Count()); - Assert.Equal(jsonETags, jsonWithFullmetadataETags); - - requestUri = this.BaseAddress + "/odata/ETagsCustomers"; - request = new HttpRequestMessage(HttpMethod.Get, requestUri); - request.Headers.Accept.ParseAdd("application/json;odata=minimalmetadata"); - response = await this.Client.SendAsync(request); + var expectedEtags = new Dictionary + { + { "0", ",MA==,Mi4w," }, + { "1", ",MA==,NC4w," }, + { "2", ",MA==,Ni4w," }, + { "3", ",MA==,OC4w," }, + { "4", ",MA==,MTAuMA==," }, + { "5", ",MA==,MTIuMA==," }, + { "6", ",MA==,MTQuMA==," }, + { "7", ",MA==,MTYuMA==," }, + { "8", ",MA==,MTguMA==," }, + { "9", ",MA==,MjAuMA==," }, + }; + + var jsonETags = jsonValue.Select(e => e["@odata.etag"]); + foreach (var etag in jsonValue) + { + Assert.Contains(expectedEtags[etag["Id"].ToString()], etag["@odata.etag"].ToString()); + } + } + + [Fact] + public async Task JsonWithNoneMetadataLevelsNotIncludeETags() + { + string requestUri = this.BaseAddress + "/odata/ETagsCustomers"; + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri); + request.Headers.Accept.ParseAdd("application/json;odata.metadata=none"); + HttpResponseMessage response = await this.Client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); - var jsonWithMinimalmetadataResult = await response.Content.ReadAsObject(); - var jsonWithMinimalmetadataETags = jsonWithMinimalmetadataResult.GetValue("value").Select(e => e["@odata.etag"].ToString()); - Assert.Equal(jsonWithMinimalmetadataETags.Count(), jsonWithMinimalmetadataETags.Distinct().Count()); - Assert.Equal(jsonETags, jsonWithMinimalmetadataETags); + var jsonResult = await response.Content.ReadAsObject(); + var jsonValue = jsonResult.GetValue("value") as JArray; + Assert.Equal(10, jsonValue.Count()); + + foreach (var item in jsonValue) + { + JObject itemObject = item as JObject; + Assert.NotNull(itemObject); + Assert.DoesNotContain("@odata.etag", itemObject.Properties().Select(p => p.Name)); + } } } } \ No newline at end of file