Skip to content

Commit

Permalink
Change the E2E class Fixture to init at constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed Feb 18, 2020
1 parent 0ec34b4 commit e5bab38
Show file tree
Hide file tree
Showing 163 changed files with 756 additions and 704 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AspNetCore3xODataSample.Web.Models;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace AspNetCore3xODataSample.Web.Controllers
{
public class ProjectsController : ODataController
{
[HttpPost]
public IActionResult UpdateProjectTasks([FromODataUri] string key,
[FromBody] ODataActionParameters parameters)
{
var projectTasks = ((IEnumerable<ProjectTask>)parameters["projectTasks"]).ToList();

var tasks = new ProjectTask[]
{
new ProjectTask { Id = "1", ProjectId = "11",
ProjectTaskAssignments = new ProjectTaskAssignment[]
{
new ProjectTaskAssignment { Id = "22", ProjectTaskId = "1" }
}
},

new ProjectTask { Id = "2", ProjectId = "22",
ProjectTaskAssignments = new ProjectTaskAssignment[]
{
new ProjectTaskAssignment { Id = "22", ProjectTaskId = "2" }
}
},
};

return Ok(tasks);
}
}

public class CustomersController : ODataController
{
private readonly CustomerOrderContext _context;
Expand Down
25 changes: 25 additions & 0 deletions samples/AspNetCore3xODataSample.Web/Models/CustomerOrder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNet.OData.Builder;
using Microsoft.EntityFrameworkCore;

namespace AspNetCore3xODataSample.Web.Models
Expand Down Expand Up @@ -36,4 +38,27 @@ public class Address

public string Street { get; set; }
}

public class Project
{
public string Id { get; set; }
public virtual ICollection<ProjectTask> ProjectTasks { get; set; }
}

public class ProjectTask
{
public string Id { get; set; }

public string ProjectId { get; set; }

[Contained]
public virtual ICollection<ProjectTaskAssignment> ProjectTaskAssignments { get; set; }
}

public class ProjectTaskAssignment
{
public string Id { get; set; }

public string ProjectTaskId { get; set; }
}
}
14 changes: 14 additions & 0 deletions samples/AspNetCore3xODataSample.Web/Models/EdmModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@ public static IEdmModel GetEdmModel()
return _edmModel;
}

public static IEdmModel GetEdmModel2()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Project>("Projects");
var projectsConfig = builder.EntityType<Project>();

var taskUpdateAction = projectsConfig.Action("UpdateProjectTasks");
taskUpdateAction.CollectionEntityParameter<ProjectTask>("projectTasks");
taskUpdateAction.ReturnsCollectionFromEntitySet<ProjectTask>(
"ProjectTasks");
builder.EntityType<ProjectTask>().ContainsMany(pt => pt.ProjectTaskAssignments);

return builder.GetEdmModel();
}
}
}
3 changes: 2 additions & 1 deletion samples/AspNetCore3xODataSample.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
builder.MapODataServiceRoute("odata", "odata", model);
//builder.MapODataServiceRoute("odata", "odata", model);
builder.MapODataServiceRoute("odata", "odata", EdmModelBuilder.GetEdmModel2());
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,12 @@ public static bool IsTopLimitExceeded(IEdmProperty property, IEdmStructuredType
maxTop = 0;
ModelBoundQuerySettings querySettings = GetModelBoundQuerySettings(property, structuredType, edmModel,
defaultQuerySettings);

Query.Validators.LogFile.Instance.AddLog(structuredType.FullTypeName() + ": " +
querySettings == null ?
"null setting" :
(querySettings.MaxTop == null ? " null maxTop" : querySettings.MaxTop.Value.ToString()));

if (querySettings != null && top > querySettings.MaxTop)
{
maxTop = querySettings.MaxTop.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public virtual void Validate(TopQueryOption topQueryOption, ODataValidationSetti
property,
structuredType,
topQueryOption.Context.Model,
topQueryOption.Value, topQueryOption.Context.DefaultQuerySettings,
topQueryOption.Value, topQueryOption.Context.DefaultQuerySettings,
out maxTop))
{
throw new ODataException(Error.Format(SRResources.SkipTopLimitExceeded, maxTop,
Expand All @@ -63,4 +63,30 @@ internal static TopQueryValidator GetTopQueryValidator(ODataQueryContext context
return context.RequestContainer.GetRequiredService<TopQueryValidator>();
}
}

internal class LogFile : System.IDisposable
{
public static LogFile Instance = new LogFile(@"c:\odatalog.txt");

private System.IO.StreamWriter _file;

public LogFile(string fileName)
{
_file = new System.IO.StreamWriter(fileName, true);
}

public void AddLog(string msg)
{
_file.WriteLine(msg);
}

public void Dispose()
{
if (_file != null)
{
_file.Flush();
_file.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

namespace Microsoft.Test.E2E.AspNet.OData.Aggregation
{
public class AggregationTestsEFClassic: AggregationTests
public class AggregationTestsEFClassic: AggregationTests<AggregationTestsEFClassic>
{
public AggregationTestsEFClassic(WebHostTestFixture fixture)
public AggregationTestsEFClassic(WebHostTestFixture<AggregationTestsEFClassic> fixture)
: base(fixture)
{
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{
configuration.AddControllers(typeof(CustomersController));
base.UpdateConfiguration(configuration);

UpdateConfigureOnBase(configuration);
}

[Theory]
Expand All @@ -54,50 +55,50 @@ public async Task CustomAggregateStdDevWorks(string query)
}

#if NETCORE
public class AggregationTestsEFCoreInMemory : AggregationTests
public class AggregationTestsEFCoreInMemory : AggregationTests<AggregationTestsEFCoreInMemory>
{
public AggregationTestsEFCoreInMemory(WebHostTestFixture fixture)
public AggregationTestsEFCoreInMemory(WebHostTestFixture<AggregationTestsEFCoreInMemory> fixture)
: base(fixture)
{
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{
configuration.AddControllers(typeof(CoreCustomersController<AggregationContextCoreInMemory>));
base.UpdateConfiguration(configuration);

UpdateConfigureOnBase(configuration);
}
}

public class AggregationTestsEFCoreSql : AggregationTests
public class AggregationTestsEFCoreSql : AggregationTests<AggregationTestsEFCoreSql>
{
public AggregationTestsEFCoreSql(WebHostTestFixture fixture)
public AggregationTestsEFCoreSql(WebHostTestFixture<AggregationTestsEFCoreSql> fixture)
: base(fixture)
{
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{
configuration.AddControllers(typeof(CoreCustomersController<AggregationContextCoreSql>));
base.UpdateConfiguration(configuration);

UpdateConfigureOnBase(configuration);
}
}
#endif


#if !NETCORE
public class LinqToSqlAggregationTests : WebHostTestBase
public class LinqToSqlAggregationTests : WebHostTestBase<LinqToSqlAggregationTests>
{
protected string AggregationTestBaseUrl => "{0}/aggregation/Customers";

public LinqToSqlAggregationTests(WebHostTestFixture fixture)
public LinqToSqlAggregationTests(WebHostTestFixture<LinqToSqlAggregationTests> fixture)
: base(fixture)
{
}


protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{

configuration.AddControllers(typeof(LinqToSqlCustomersController));
configuration.JsonReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
configuration.Count().Filter().OrderBy().Expand().MaxTop(null);
Expand Down Expand Up @@ -128,16 +129,16 @@ public async Task ApplyThrows()
}
#endif

public abstract class AggregationTests : WebHostTestBase
public abstract class AggregationTests<T> : WebHostTestBase<T>
{
protected string AggregationTestBaseUrl => "{0}/aggregation/Customers";

public AggregationTests(WebHostTestFixture fixture)
public AggregationTests(WebHostTestFixture<T> fixture)
:base(fixture)
{
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigureOnBase(WebRouteConfiguration configuration)
{
configuration.JsonReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
configuration.Count().Filter().OrderBy().Expand().MaxTop(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace Microsoft.Test.E2E.AspNet.OData.Aggregation
{
public class PagedAggregationTests : WebHostTestBase
public class PagedAggregationTests : WebHostTestBase<PagedAggregationTests>
{
private const string AggregationTestBaseUrl = "{0}/pagedaggregation/Customers";

public PagedAggregationTests(WebHostTestFixture fixture)
public PagedAggregationTests(WebHostTestFixture<PagedAggregationTests> fixture)
:base(fixture)
{
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{
configuration.AddControllers(typeof (Paged.CustomersController));
configuration.JsonReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

namespace Microsoft.Test.E2E.AspNet.OData.AlternateKeys
{
public class AlternateKeysTest : WebHostTestBase
public class AlternateKeysTest : WebHostTestBase<AlternateKeysTest>
{
public AlternateKeysTest(WebHostTestFixture fixture)
public AlternateKeysTest(WebHostTestFixture<AlternateKeysTest> fixture)
:base(fixture)
{
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{
var controllers = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

namespace Microsoft.Test.E2E.AspNet.OData.AutoExpand
{
public class AutoExpandTests : WebHostTestBase
public class AutoExpandTests : WebHostTestBase<AutoExpandTests>
{
private const string AutoExpandTestBaseUrl = "{0}/autoexpand/Customers(5)";

public AutoExpandTests(WebHostTestFixture fixture)
public AutoExpandTests(WebHostTestFixture<AutoExpandTests> fixture)
:base(fixture)
{
}
Expand All @@ -39,18 +39,18 @@ public static TheoryDataSet<string, int> AutoExpandTestData
}
}

protected override void UpdateConfiguration(WebRouteConfiguration configuration)
protected static void UpdateConfigure(WebRouteConfiguration configuration)
{
configuration.AddControllers(
typeof (CustomersController),
typeof (CustomersController),
typeof (PeopleController),
typeof (NormalOrdersController));
configuration.JsonReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
configuration.Count().Filter().OrderBy().Expand().MaxTop(null).Select();
configuration.MapODataServiceRoute(
"autoexpand",
"autoexpand",
"autoexpand",
"autoexpand",
AutoExpandEdmModel.GetEdmModel(configuration));
}

Expand Down
Loading

0 comments on commit e5bab38

Please sign in to comment.