-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #801 and Fix SingleResult 500 error
- Loading branch information
1 parent
5a14de6
commit 49f06d1
Showing
11 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
OData/test/E2ETest/WebStack.QA.Test.OData/SingleResult/SingleResultController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web.Http; | ||
using System.Web.OData; | ||
|
||
namespace WebStack.QA.Test.OData.SingleResultTest | ||
{ | ||
public class CustomersController : ODataController | ||
{ | ||
private readonly SingleResultContext _db = new SingleResultContext(); | ||
|
||
[EnableQuery] | ||
public SingleResult<Customer> Get(int key) | ||
{ | ||
ResetDataSource(); | ||
var db = new SingleResultContext(); | ||
return SingleResult.Create(db.Customers.Where(c => c.Id == key)); | ||
} | ||
|
||
public void Generate() | ||
{ | ||
for (int i = 1; i < 10; i++) | ||
{ | ||
var customer = new Customer | ||
{ | ||
Id = i, | ||
Orders = new List<Order> | ||
{ | ||
new Order | ||
{ | ||
Id = i, | ||
} | ||
} | ||
}; | ||
|
||
_db.Customers.Add(customer); | ||
} | ||
|
||
_db.SaveChanges(); | ||
} | ||
|
||
private void ResetDataSource() | ||
{ | ||
if (_db.Database.Exists()) | ||
{ | ||
_db.Database.Delete(); | ||
_db.Database.Create(); | ||
} | ||
|
||
Generate(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
OData/test/E2ETest/WebStack.QA.Test.OData/SingleResult/SingleResultDataModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Collections.Generic; | ||
using System.Data.Entity; | ||
|
||
namespace WebStack.QA.Test.OData.SingleResultTest | ||
{ | ||
public class SingleResultContext : DbContext | ||
{ | ||
public static string ConnectionString = | ||
@"Data Source=(LocalDb)\v11.0;Integrated Security=True;Initial Catalog=SingleResultTest"; | ||
|
||
public SingleResultContext() | ||
: base(ConnectionString) | ||
{ | ||
} | ||
|
||
public DbSet<Customer> Customers { get; set; } | ||
} | ||
|
||
public class Customer | ||
{ | ||
public int Id { get; set; } | ||
|
||
public List<Order> Orders { get; set; } | ||
} | ||
|
||
public class Order | ||
{ | ||
public int Id { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
OData/test/E2ETest/WebStack.QA.Test.OData/SingleResult/SingleResultEdmModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Web.Http; | ||
using System.Web.OData.Builder; | ||
using Microsoft.OData.Edm; | ||
|
||
namespace WebStack.QA.Test.OData.SingleResultTest | ||
{ | ||
public class SingleResultEdmModel | ||
{ | ||
public static IEdmModel GetEdmModel(HttpConfiguration configuration) | ||
{ | ||
var builder = new ODataConventionModelBuilder(configuration); | ||
builder.EntitySet<Customer>("Customers"); | ||
builder.EntitySet<Order>("Orders"); | ||
return builder.GetEdmModel(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
OData/test/E2ETest/WebStack.QA.Test.OData/SingleResult/SingleResultTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Web.Http; | ||
using System.Web.Http.Dispatcher; | ||
using System.Web.OData.Extensions; | ||
using Newtonsoft.Json.Linq; | ||
using Nuwa; | ||
using WebStack.QA.Test.OData.Common; | ||
using Xunit; | ||
|
||
namespace WebStack.QA.Test.OData.SingleResultTest | ||
{ | ||
public class SingleResultTests : ODataTestBase | ||
{ | ||
private const string BaseUrl = "{0}/singleresult/Customers"; | ||
|
||
[NuwaConfiguration] | ||
public static void UpdateConfiguration(HttpConfiguration configuration) | ||
{ | ||
configuration.Services.Replace( | ||
typeof(IAssembliesResolver), | ||
new TestAssemblyResolver(typeof (CustomersController))); | ||
configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; | ||
configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = | ||
Newtonsoft.Json.ReferenceLoopHandling.Ignore; | ||
configuration.Count().Filter().OrderBy().Expand().MaxTop(null); | ||
configuration.MapODataServiceRoute("singleresult", "singleresult", | ||
SingleResultEdmModel.GetEdmModel(configuration)); | ||
} | ||
|
||
[Fact] | ||
public void EmptySingleResultReturnsNotFound() | ||
{ | ||
// Arrange | ||
string queryUrl = string.Format(BaseUrl + "(100)", BaseAddress); | ||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, queryUrl); | ||
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=none")); | ||
HttpClient client = new HttpClient(); | ||
|
||
// Act | ||
HttpResponseMessage response = client.SendAsync(request).Result; | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters