Skip to content

Commit ec69a7b

Browse files
committed
Fix MixScenarioTest and Inheritance parallel running problem
1 parent 81078cb commit ec69a7b

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Common/Controllers/AsyncInMemoryODataController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Microsoft.Test.E2E.AspNet.OData.Common.Controllers
1313
{
14+
/// <summary>
15+
/// Pay attention to use this class when you create test cases in parallel.
16+
/// If multiple test cases rely on the same <typeparamref name="TEntity"/>, these test cases maybe conflict each other.
17+
/// So, do not use the same <typeparamref name="TEntity"/> in mulitple test cases.
18+
/// </summary>
1419
[ModelStateErrorHandling]
1520
public abstract class InMemoryODataController<TEntity, TKey> : TestODataController
1621
where TEntity : class

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public async Task GetEntryWithIfNoneMatchShouldReturnNotModifiedETagsTest()
4747
{
4848
string eTag;
4949

50+
// DeleteUpdatedEntryWithIfMatchETagsTests will change #"0" customer
51+
// PutUpdatedEntryWithIfMatchETagsTests will change #"1"customer
52+
// PatchUpdatedEntryWithIfMatchETagsTest will change #"2" customer
53+
// So, this case uses "4"
54+
int customerId = 4;
5055
var getUri = this.BaseAddress + "/odata/ETagsCustomers?$format=json";
5156
using (var response = await Client.GetAsync(getUri))
5257
{
@@ -56,11 +61,11 @@ public async Task GetEntryWithIfNoneMatchShouldReturnNotModifiedETagsTest()
5661
var result = json.GetValue("value") as JArray;
5762
Assert.NotNull(result);
5863

59-
eTag = result[0]["@odata.etag"].ToString();
64+
eTag = result[customerId]["@odata.etag"].ToString();
6065
Assert.False(String.IsNullOrEmpty(eTag));
6166
}
6267

63-
var getRequestWithEtag = new HttpRequestMessage(HttpMethod.Get, this.BaseAddress + "/odata/ETagsCustomers(0)");
68+
var getRequestWithEtag = new HttpRequestMessage(HttpMethod.Get, this.BaseAddress + "/odata/ETagsCustomers(" + customerId + ")");
6469
getRequestWithEtag.Headers.IfNoneMatch.ParseAdd(eTag);
6570
using (var response = await Client.SendAsync(getRequestWithEtag))
6671
{

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Formatter/MixScenarioTests.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using Microsoft.Test.E2E.AspNet.OData.Common.Execution;
1515
using Microsoft.Test.E2E.AspNet.OData.Common.Extensions;
1616
using Microsoft.Test.E2E.AspNet.OData.Common.Instancing;
17-
using Microsoft.Test.E2E.AspNet.OData.Common.Models.Vehicle;
1817
using Nop.Core.Domain.Blogs;
1918
using Xunit;
2019

@@ -60,7 +59,19 @@ public void ThrowExceptionInAction()
6059
}
6160
}
6261

63-
public class MixScenarioTests_ODataController : InMemoryODataController<Vehicle, int>
62+
[Key("Id")]
63+
public class MixVehicle
64+
{
65+
public int Id { get; set; }
66+
67+
public string Model { get; set; }
68+
69+
public string Name { get; set; }
70+
71+
public virtual int WheelCount { get; set; }
72+
}
73+
74+
public class MixScenarioTests_ODataController : InMemoryODataController<MixVehicle, int>
6475
{
6576
public MixScenarioTests_ODataController()
6677
: base("Id")
@@ -85,7 +96,7 @@ protected override void UpdateConfiguration(WebRouteConfiguration configuration)
8596
protected static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
8697
{
8798
var mb = configuration.CreateConventionModelBuilder();
88-
mb.EntitySet<Vehicle>("MixScenarioTests_OData");
99+
mb.EntitySet<MixVehicle>("MixScenarioTests_OData");
89100
return mb.GetEdmModel();
90101
}
91102

@@ -128,7 +139,7 @@ public MixScenarioTestsOData(WebHostTestFixture fixture)
128139
protected static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
129140
{
130141
var mb = configuration.CreateConventionModelBuilder();
131-
mb.EntitySet<Vehicle>("MixScenarioTests_OData");
142+
mb.EntitySet<MixVehicle>("MixScenarioTests_OData");
132143
return mb.GetEdmModel();
133144
}
134145

@@ -143,7 +154,7 @@ public async Task ODataCRUDShouldWorkAsync()
143154
await this.ClearRepositoryAsync(entitySetName);
144155

145156
// post new entity to repository
146-
var baseline = InstanceCreator.CreateInstanceOf<Vehicle>(rand);
157+
var baseline = InstanceCreator.CreateInstanceOf<MixVehicle>(rand);
147158
await PostNewEntityAsync(uri, baseline, entitySetName);
148159

149160
// get collection of entities from repository
@@ -178,23 +189,23 @@ await UpdateEntityAsync(
178189
Assert.Null(thirdVersion);
179190
}
180191

181-
private async Task<DataServiceResponse> PostNewEntityAsync(Uri baseAddress, Vehicle entity, string entitySetName)
192+
private async Task<DataServiceResponse> PostNewEntityAsync(Uri baseAddress, MixVehicle entity, string entitySetName)
182193
{
183194
var context = WriterClient(baseAddress, ODataProtocolVersion.V4);
184195
context.AddObject(entitySetName, entity);
185196

186197
return await context.SaveChangesAsync();
187198
}
188199

189-
private async Task<IEnumerable<Vehicle>> GetEntitiesAsync(Uri baseAddress, string entitySetName)
200+
private async Task<IEnumerable<MixVehicle>> GetEntitiesAsync(Uri baseAddress, string entitySetName)
190201
{
191202
var context = ReaderClient(baseAddress, ODataProtocolVersion.V4);
192-
var query = context.CreateQuery<Vehicle>(entitySetName);
203+
var query = context.CreateQuery<MixVehicle>(entitySetName);
193204

194205
return await query.ExecuteAsync();
195206
}
196207

197-
private async Task<DataServiceResponse> UpdateEntityAsync(Uri baseAddress, Vehicle from, Func<Vehicle, Vehicle> update, string entitySetName)
208+
private async Task<DataServiceResponse> UpdateEntityAsync(Uri baseAddress, MixVehicle from, Func<MixVehicle, MixVehicle> update, string entitySetName)
198209
{
199210
var context = WriterClient(baseAddress, ODataProtocolVersion.V4);
200211

@@ -205,7 +216,7 @@ private async Task<DataServiceResponse> UpdateEntityAsync(Uri baseAddress, Vehic
205216
return await context.SaveChangesAsync();
206217
}
207218

208-
private async Task<DataServiceResponse> DeleteEntityAsync(Uri baseAddress, Vehicle entity, string entitySetName)
219+
private async Task<DataServiceResponse> DeleteEntityAsync(Uri baseAddress, MixVehicle entity, string entitySetName)
209220
{
210221
var context = WriterClient(baseAddress, ODataProtocolVersion.V4);
211222
context.AttachTo(entitySetName, entity);

0 commit comments

Comments
 (0)