Skip to content

Commit e7dbb22

Browse files
committed
Fix the metadata level in ETag E2E test
1 parent b92f2df commit e7dbb22

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/ETags/JsonETagsTests.cs

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System.Collections.Generic;
45
using System.Linq;
56
using System.Net.Http;
67
using System.Text.RegularExpressions;
@@ -133,47 +134,60 @@ public async Task ModelBuilderTest()
133134
collection.Elements.Select(e => ((IEdmPathExpression) e).PathSegments.Single()));
134135
}
135136

136-
[Fact]
137-
public async Task JsonWithDifferentMetadataLevelsHaveSameETagsTest()
137+
[Theory]
138+
[InlineData("application/json")] // default metadata level
139+
[InlineData("application/json;odata.metadata=full")]
140+
[InlineData("application/json;odata.metadata=minimal")]
141+
public async Task JsonWithDifferentMetadataLevelsHaveSameETagsTest(string metadataLevel)
138142
{
139143
string requestUri = this.BaseAddress + "/odata/ETagsCustomers";
140144
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
141-
request.Headers.Accept.ParseAdd("application/json");
145+
request.Headers.Accept.ParseAdd(metadataLevel);
142146
HttpResponseMessage response = await this.Client.SendAsync(request);
143147
Assert.True(response.IsSuccessStatusCode);
144148
var jsonResult = await response.Content.ReadAsObject<JObject>();
145-
var jsonETags = jsonResult.GetValue("value").Select(e => e["@odata.etag"].ToString());
146-
Assert.Equal(jsonETags.Count(), jsonETags.Distinct().Count());
149+
var jsonValue = jsonResult.GetValue("value") as JArray;
150+
Assert.Equal(10, jsonValue.Count);
147151

148-
requestUri = this.BaseAddress + "/odata/ETagsCustomers";
149-
request = new HttpRequestMessage(HttpMethod.Get, requestUri);
150-
request.Headers.Accept.ParseAdd("application/json;odata=nometadata");
151-
response = await this.Client.SendAsync(request);
152-
Assert.True(response.IsSuccessStatusCode);
153-
var jsonWithNometadataResult = await response.Content.ReadAsObject<JObject>();
154-
var jsonWithNometadataETags = jsonWithNometadataResult.GetValue("value").Select(e => e["@odata.etag"].ToString());
155-
Assert.Equal(jsonWithNometadataETags.Count(), jsonWithNometadataETags.Distinct().Count());
156-
Assert.Equal(jsonETags, jsonWithNometadataETags);
157-
158-
requestUri = this.BaseAddress + "/odata/ETagsCustomers";
159-
request = new HttpRequestMessage(HttpMethod.Get, requestUri);
160-
request.Headers.Accept.ParseAdd("application/json;odata=fullmetadata");
161-
response = await this.Client.SendAsync(request);
162-
Assert.True(response.IsSuccessStatusCode);
163-
var jsonWithFullmetadataResult = await response.Content.ReadAsObject<JObject>();
164-
var jsonWithFullmetadataETags = jsonWithFullmetadataResult.GetValue("value").Select(e => e["@odata.etag"].ToString());
165-
Assert.Equal(jsonWithFullmetadataETags.Count(), jsonWithFullmetadataETags.Distinct().Count());
166-
Assert.Equal(jsonETags, jsonWithFullmetadataETags);
167-
168-
requestUri = this.BaseAddress + "/odata/ETagsCustomers";
169-
request = new HttpRequestMessage(HttpMethod.Get, requestUri);
170-
request.Headers.Accept.ParseAdd("application/json;odata=minimalmetadata");
171-
response = await this.Client.SendAsync(request);
152+
var expectedEtags = new Dictionary<string, string>
153+
{
154+
{ "0", ",MA==,Mi4w," },
155+
{ "1", ",MA==,NC4w," },
156+
{ "2", ",MA==,Ni4w," },
157+
{ "3", ",MA==,OC4w," },
158+
{ "4", ",MA==,MTAuMA==," },
159+
{ "5", ",MA==,MTIuMA==," },
160+
{ "6", ",MA==,MTQuMA==," },
161+
{ "7", ",MA==,MTYuMA==," },
162+
{ "8", ",MA==,MTguMA==," },
163+
{ "9", ",MA==,MjAuMA==," },
164+
};
165+
166+
var jsonETags = jsonValue.Select(e => e["@odata.etag"]);
167+
foreach (var etag in jsonValue)
168+
{
169+
Assert.Contains(expectedEtags[etag["Id"].ToString()], etag["@odata.etag"].ToString());
170+
}
171+
}
172+
173+
[Fact]
174+
public async Task JsonWithNoneMetadataLevelsNotIncludeETags()
175+
{
176+
string requestUri = this.BaseAddress + "/odata/ETagsCustomers";
177+
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
178+
request.Headers.Accept.ParseAdd("application/json;odata.metadata=none");
179+
HttpResponseMessage response = await this.Client.SendAsync(request);
172180
Assert.True(response.IsSuccessStatusCode);
173-
var jsonWithMinimalmetadataResult = await response.Content.ReadAsObject<JObject>();
174-
var jsonWithMinimalmetadataETags = jsonWithMinimalmetadataResult.GetValue("value").Select(e => e["@odata.etag"].ToString());
175-
Assert.Equal(jsonWithMinimalmetadataETags.Count(), jsonWithMinimalmetadataETags.Distinct().Count());
176-
Assert.Equal(jsonETags, jsonWithMinimalmetadataETags);
181+
var jsonResult = await response.Content.ReadAsObject<JObject>();
182+
var jsonValue = jsonResult.GetValue("value") as JArray;
183+
Assert.Equal(10, jsonValue.Count());
184+
185+
foreach (var item in jsonValue)
186+
{
187+
JObject itemObject = item as JObject;
188+
Assert.NotNull(itemObject);
189+
Assert.DoesNotContain("@odata.etag", itemObject.Properties().Select(p => p.Name));
190+
}
177191
}
178192
}
179193
}

0 commit comments

Comments
 (0)