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 ;
45using System . Linq ;
56using System . Net . Http ;
67using System . Text . RegularExpressions ;
@@ -133,47 +134,64 @@ 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," }, // DeleteUpdatedEntryWithIfMatchETagsTests will change #"0" customer
155+ // { "1", ",MA==,NC4w," }, // PutUpdatedEntryWithIfMatchETagsTests will change #"1"customer
156+ // { "2", ",MA==,Ni4w," }, // PatchUpdatedEntryWithIfMatchETagsTest will change #"2" cusotmer
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+ string key = etag [ "Id" ] . ToString ( ) ;
170+ if ( expectedEtags . TryGetValue ( key , out string etagValue ) )
171+ {
172+ Assert . Contains ( etagValue , etag [ "@odata.etag" ] . ToString ( ) ) ;
173+ }
174+ }
175+ }
176+
177+ [ Fact ]
178+ public async Task JsonWithNoneMetadataLevelsNotIncludeETags ( )
179+ {
180+ string requestUri = this . BaseAddress + "/odata/ETagsCustomers" ;
181+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , requestUri ) ;
182+ request . Headers . Accept . ParseAdd ( "application/json;odata.metadata=none" ) ;
183+ HttpResponseMessage response = await this . Client . SendAsync ( request ) ;
172184 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 ) ;
185+ var jsonResult = await response . Content . ReadAsObject < JObject > ( ) ;
186+ var jsonValue = jsonResult . GetValue ( "value" ) as JArray ;
187+ Assert . Equal ( 10 , jsonValue . Count ( ) ) ;
188+
189+ foreach ( var item in jsonValue )
190+ {
191+ JObject itemObject = item as JObject ;
192+ Assert . NotNull ( itemObject ) ;
193+ Assert . DoesNotContain ( "@odata.etag" , itemObject . Properties ( ) . Select ( p => p . Name ) ) ;
194+ }
177195 }
178196 }
179197}
0 commit comments