Skip to content

Commit e5bab38

Browse files
committed
Change the E2E class Fixture to init at constructor
1 parent 0ec34b4 commit e5bab38

File tree

163 files changed

+756
-704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+756
-704
lines changed

samples/AspNetCore3xODataSample.Web/Controllers/CustomersController.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
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;
45
using System.Collections.Generic;
56
using System.Linq;
7+
using System.Threading.Tasks;
68
using AspNetCore3xODataSample.Web.Models;
79
using Microsoft.AspNet.OData;
810
using Microsoft.AspNetCore.Mvc;
911
using Microsoft.EntityFrameworkCore;
1012

1113
namespace AspNetCore3xODataSample.Web.Controllers
1214
{
15+
public class ProjectsController : ODataController
16+
{
17+
[HttpPost]
18+
public IActionResult UpdateProjectTasks([FromODataUri] string key,
19+
[FromBody] ODataActionParameters parameters)
20+
{
21+
var projectTasks = ((IEnumerable<ProjectTask>)parameters["projectTasks"]).ToList();
22+
23+
var tasks = new ProjectTask[]
24+
{
25+
new ProjectTask { Id = "1", ProjectId = "11",
26+
ProjectTaskAssignments = new ProjectTaskAssignment[]
27+
{
28+
new ProjectTaskAssignment { Id = "22", ProjectTaskId = "1" }
29+
}
30+
},
31+
32+
new ProjectTask { Id = "2", ProjectId = "22",
33+
ProjectTaskAssignments = new ProjectTaskAssignment[]
34+
{
35+
new ProjectTaskAssignment { Id = "22", ProjectTaskId = "2" }
36+
}
37+
},
38+
};
39+
40+
return Ok(tasks);
41+
}
42+
}
43+
1344
public class CustomersController : ODataController
1445
{
1546
private readonly CustomerOrderContext _context;

samples/AspNetCore3xODataSample.Web/Models/CustomerOrder.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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;
45
using System.Collections.Generic;
56
using System.ComponentModel.DataAnnotations.Schema;
7+
using Microsoft.AspNet.OData.Builder;
68
using Microsoft.EntityFrameworkCore;
79

810
namespace AspNetCore3xODataSample.Web.Models
@@ -36,4 +38,27 @@ public class Address
3638

3739
public string Street { get; set; }
3840
}
41+
42+
public class Project
43+
{
44+
public string Id { get; set; }
45+
public virtual ICollection<ProjectTask> ProjectTasks { get; set; }
46+
}
47+
48+
public class ProjectTask
49+
{
50+
public string Id { get; set; }
51+
52+
public string ProjectId { get; set; }
53+
54+
[Contained]
55+
public virtual ICollection<ProjectTaskAssignment> ProjectTaskAssignments { get; set; }
56+
}
57+
58+
public class ProjectTaskAssignment
59+
{
60+
public string Id { get; set; }
61+
62+
public string ProjectTaskId { get; set; }
63+
}
3964
}

samples/AspNetCore3xODataSample.Web/Models/EdmModelBuilder.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,19 @@ public static IEdmModel GetEdmModel()
2323
return _edmModel;
2424
}
2525

26+
public static IEdmModel GetEdmModel2()
27+
{
28+
var builder = new ODataConventionModelBuilder();
29+
builder.EntitySet<Project>("Projects");
30+
var projectsConfig = builder.EntityType<Project>();
31+
32+
var taskUpdateAction = projectsConfig.Action("UpdateProjectTasks");
33+
taskUpdateAction.CollectionEntityParameter<ProjectTask>("projectTasks");
34+
taskUpdateAction.ReturnsCollectionFromEntitySet<ProjectTask>(
35+
"ProjectTasks");
36+
builder.EntityType<ProjectTask>().ContainsMany(pt => pt.ProjectTaskAssignments);
37+
38+
return builder.GetEdmModel();
39+
}
2640
}
2741
}

samples/AspNetCore3xODataSample.Web/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4444
{
4545
builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
4646

47-
builder.MapODataServiceRoute("odata", "odata", model);
47+
//builder.MapODataServiceRoute("odata", "odata", model);
48+
builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel2());
4849
});
4950
}
5051
}

src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ public static bool IsTopLimitExceeded(IEdmProperty property, IEdmStructuredType
509509
maxTop = 0;
510510
ModelBoundQuerySettings querySettings = GetModelBoundQuerySettings(property, structuredType, edmModel,
511511
defaultQuerySettings);
512+
513+
Query.Validators.LogFile.Instance.AddLog(structuredType.FullTypeName() + ": " +
514+
querySettings == null ?
515+
"null setting" :
516+
(querySettings.MaxTop == null ? " null maxTop" : querySettings.MaxTop.Value.ToString()));
517+
512518
if (querySettings != null && top > querySettings.MaxTop)
513519
{
514520
maxTop = querySettings.MaxTop.Value;

src/Microsoft.AspNet.OData.Shared/Query/Validators/TopQueryValidator.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public virtual void Validate(TopQueryOption topQueryOption, ODataValidationSetti
4545
property,
4646
structuredType,
4747
topQueryOption.Context.Model,
48-
topQueryOption.Value, topQueryOption.Context.DefaultQuerySettings,
48+
topQueryOption.Value, topQueryOption.Context.DefaultQuerySettings,
4949
out maxTop))
5050
{
5151
throw new ODataException(Error.Format(SRResources.SkipTopLimitExceeded, maxTop,
@@ -63,4 +63,30 @@ internal static TopQueryValidator GetTopQueryValidator(ODataQueryContext context
6363
return context.RequestContainer.GetRequiredService<TopQueryValidator>();
6464
}
6565
}
66+
67+
internal class LogFile : System.IDisposable
68+
{
69+
public static LogFile Instance = new LogFile(@"c:\odatalog.txt");
70+
71+
private System.IO.StreamWriter _file;
72+
73+
public LogFile(string fileName)
74+
{
75+
_file = new System.IO.StreamWriter(fileName, true);
76+
}
77+
78+
public void AddLog(string msg)
79+
{
80+
_file.WriteLine(msg);
81+
}
82+
83+
public void Dispose()
84+
{
85+
if (_file != null)
86+
{
87+
_file.Flush();
88+
_file.Dispose();
89+
}
90+
}
91+
}
6692
}

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Aggregation/AggregationTests.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
namespace Microsoft.Test.E2E.AspNet.OData.Aggregation
1919
{
20-
public class AggregationTestsEFClassic: AggregationTests
20+
public class AggregationTestsEFClassic: AggregationTests<AggregationTestsEFClassic>
2121
{
22-
public AggregationTestsEFClassic(WebHostTestFixture fixture)
22+
public AggregationTestsEFClassic(WebHostTestFixture<AggregationTestsEFClassic> fixture)
2323
: base(fixture)
2424
{
2525
}
2626

27-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
27+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
2828
{
2929
configuration.AddControllers(typeof(CustomersController));
30-
base.UpdateConfiguration(configuration);
30+
31+
UpdateConfigureOnBase(configuration);
3132
}
3233

3334
[Theory]
@@ -54,50 +55,50 @@ public async Task CustomAggregateStdDevWorks(string query)
5455
}
5556

5657
#if NETCORE
57-
public class AggregationTestsEFCoreInMemory : AggregationTests
58+
public class AggregationTestsEFCoreInMemory : AggregationTests<AggregationTestsEFCoreInMemory>
5859
{
59-
public AggregationTestsEFCoreInMemory(WebHostTestFixture fixture)
60+
public AggregationTestsEFCoreInMemory(WebHostTestFixture<AggregationTestsEFCoreInMemory> fixture)
6061
: base(fixture)
6162
{
6263
}
6364

64-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
65+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
6566
{
6667
configuration.AddControllers(typeof(CoreCustomersController<AggregationContextCoreInMemory>));
67-
base.UpdateConfiguration(configuration);
68+
69+
UpdateConfigureOnBase(configuration);
6870
}
6971
}
7072

71-
public class AggregationTestsEFCoreSql : AggregationTests
73+
public class AggregationTestsEFCoreSql : AggregationTests<AggregationTestsEFCoreSql>
7274
{
73-
public AggregationTestsEFCoreSql(WebHostTestFixture fixture)
75+
public AggregationTestsEFCoreSql(WebHostTestFixture<AggregationTestsEFCoreSql> fixture)
7476
: base(fixture)
7577
{
7678
}
7779

78-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
80+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
7981
{
8082
configuration.AddControllers(typeof(CoreCustomersController<AggregationContextCoreSql>));
81-
base.UpdateConfiguration(configuration);
83+
84+
UpdateConfigureOnBase(configuration);
8285
}
8386
}
8487
#endif
8588

8689

8790
#if !NETCORE
88-
public class LinqToSqlAggregationTests : WebHostTestBase
91+
public class LinqToSqlAggregationTests : WebHostTestBase<LinqToSqlAggregationTests>
8992
{
9093
protected string AggregationTestBaseUrl => "{0}/aggregation/Customers";
9194

92-
public LinqToSqlAggregationTests(WebHostTestFixture fixture)
95+
public LinqToSqlAggregationTests(WebHostTestFixture<LinqToSqlAggregationTests> fixture)
9396
: base(fixture)
9497
{
9598
}
9699

97-
98-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
100+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
99101
{
100-
101102
configuration.AddControllers(typeof(LinqToSqlCustomersController));
102103
configuration.JsonReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
103104
configuration.Count().Filter().OrderBy().Expand().MaxTop(null);
@@ -128,16 +129,16 @@ public async Task ApplyThrows()
128129
}
129130
#endif
130131

131-
public abstract class AggregationTests : WebHostTestBase
132+
public abstract class AggregationTests<T> : WebHostTestBase<T>
132133
{
133134
protected string AggregationTestBaseUrl => "{0}/aggregation/Customers";
134135

135-
public AggregationTests(WebHostTestFixture fixture)
136+
public AggregationTests(WebHostTestFixture<T> fixture)
136137
:base(fixture)
137138
{
138139
}
139140

140-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
141+
protected static void UpdateConfigureOnBase(WebRouteConfiguration configuration)
141142
{
142143
configuration.JsonReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
143144
configuration.Count().Filter().OrderBy().Expand().MaxTop(null);

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/Aggregation/PagedAggregationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313

1414
namespace Microsoft.Test.E2E.AspNet.OData.Aggregation
1515
{
16-
public class PagedAggregationTests : WebHostTestBase
16+
public class PagedAggregationTests : WebHostTestBase<PagedAggregationTests>
1717
{
1818
private const string AggregationTestBaseUrl = "{0}/pagedaggregation/Customers";
1919

20-
public PagedAggregationTests(WebHostTestFixture fixture)
20+
public PagedAggregationTests(WebHostTestFixture<PagedAggregationTests> fixture)
2121
:base(fixture)
2222
{
2323
}
2424

25-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
25+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
2626
{
2727
configuration.AddControllers(typeof (Paged.CustomersController));
2828
configuration.JsonReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/AlternateKeys/AlternateKeysTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
namespace Microsoft.Test.E2E.AspNet.OData.AlternateKeys
2121
{
22-
public class AlternateKeysTest : WebHostTestBase
22+
public class AlternateKeysTest : WebHostTestBase<AlternateKeysTest>
2323
{
24-
public AlternateKeysTest(WebHostTestFixture fixture)
24+
public AlternateKeysTest(WebHostTestFixture<AlternateKeysTest> fixture)
2525
:base(fixture)
2626
{
2727
}
2828

29-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
29+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
3030
{
3131
var controllers = new[]
3232
{

test/E2ETest/Microsoft.Test.E2E.AspNet.OData/AutoExpand/AutoExpandTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
namespace Microsoft.Test.E2E.AspNet.OData.AutoExpand
1717
{
18-
public class AutoExpandTests : WebHostTestBase
18+
public class AutoExpandTests : WebHostTestBase<AutoExpandTests>
1919
{
2020
private const string AutoExpandTestBaseUrl = "{0}/autoexpand/Customers(5)";
2121

22-
public AutoExpandTests(WebHostTestFixture fixture)
22+
public AutoExpandTests(WebHostTestFixture<AutoExpandTests> fixture)
2323
:base(fixture)
2424
{
2525
}
@@ -39,18 +39,18 @@ public static TheoryDataSet<string, int> AutoExpandTestData
3939
}
4040
}
4141

42-
protected override void UpdateConfiguration(WebRouteConfiguration configuration)
42+
protected static void UpdateConfigure(WebRouteConfiguration configuration)
4343
{
4444
configuration.AddControllers(
45-
typeof (CustomersController),
45+
typeof (CustomersController),
4646
typeof (PeopleController),
4747
typeof (NormalOrdersController));
4848
configuration.JsonReferenceLoopHandling =
4949
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
5050
configuration.Count().Filter().OrderBy().Expand().MaxTop(null).Select();
5151
configuration.MapODataServiceRoute(
52-
"autoexpand",
53-
"autoexpand",
52+
"autoexpand",
53+
"autoexpand",
5454
AutoExpandEdmModel.GetEdmModel(configuration));
5555
}
5656

0 commit comments

Comments
 (0)