Skip to content

Commit

Permalink
Fix EF7 build and UT.
Browse files Browse the repository at this point in the history
  • Loading branch information
rayao committed May 3, 2016
1 parent 29eda53 commit 180f902
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
22 changes: 0 additions & 22 deletions src/Microsoft.Restier.EntityFramework7/Model/ModelProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,6 @@ private static IDictionary<Type, EdmPrimitiveTypeKind>
{ typeof(TimeSpan), EdmPrimitiveTypeKind.Duration }
};

private static ModelProducer instance = new ModelProducer();

private ModelProducer()
{
}

/// <summary>
/// Gets the single instance of this model producer.
/// </summary>
public static IModelBuilder Instance
{
get
{
if (instance == null)
{
instance = new ModelProducer();
}

return instance;
}
}

/// <summary>
/// Asynchronously produces a base model.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ private static object ConvertToEfValue(Type type, object value)
return (TimeSpan)timeOfDayValue;
}

// In case key is long type, when put an entity, key value will be from key parsing which is type of int
if (value is int && type == typeof(long))
{
return Convert.ToInt64(value, CultureInfo.InvariantCulture);
}

return value;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.Restier.WebApi/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ internal static class ServiceCollectionExtensions
{
public static IServiceCollection AddWebApiServices<T>(this IServiceCollection services)
{
if (services.HasService<RestierQueryExecutor>())
{
// Avoid applying multiple times to a same service collection.
return services;
}

RestierModelExtender.ApplyTo(services, typeof(T));
RestierOperationModelBuilder.ApplyTo(services, typeof(T));

Expand Down
19 changes: 8 additions & 11 deletions test/Microsoft.Restier.EntityFramework7.Tests/DateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public async Task VerifyQuery()
{
await PopulateData(1);

using (var response = await ODataTestHelpers.GetResponse(@"http://local/api/Prim/Dates(1)", HttpMethod.Get, null, RegisterApi))
using (var response = await ODataTestHelpers
.GetResponseNoContentValidation(@"http://local/api/Prim/Dates(1)", HttpMethod.Get, null, RegisterApi, HttpStatusCode.OK))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var s = await response.Content.ReadAsStringAsync();
Assert.NotNull(s);
}
}

Expand All @@ -64,9 +62,9 @@ public async Task VerifyChange()

string newOrderContent = JsonConvert.SerializeObject(newObj);
StringContent content = new StringContent(newOrderContent, UTF8Encoding.Default, "application/json");
using (var response = await ODataTestHelpers.GetResponse(@"http://local/api/Prim/Dates(42)", HttpMethod.Put, content, RegisterApi))
using (var response = await ODataTestHelpers
.GetResponseNoContentValidation(@"http://local/api/Prim/Dates(42)", HttpMethod.Put, content, RegisterApi, HttpStatusCode.NoContent))
{
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
using (var ctx = new PrimitivesContext())
{
var item42 = ctx.Dates.First(e => e.RowId == 42);
Expand All @@ -89,9 +87,9 @@ public async Task VerifyChange()

string newOrderContent = JsonConvert.SerializeObject(newObj);
StringContent content = new StringContent(newOrderContent, UTF8Encoding.Default, "application/json");
using (var response = await ODataTestHelpers.GetResponse(@"http://local/api/Prim/Dates", HttpMethod.Post, content, RegisterApi))
using (var response = await ODataTestHelpers
.GetResponseNoContentValidation(@"http://local/api/Prim/Dates", HttpMethod.Post, content, RegisterApi, HttpStatusCode.Created))
{
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
var ret = await response.Content.ReadAsAsync<DateItem>();
Assert.Equal(new DateTime(2016, 1, 4), ret.DateProperty);
Assert.Equal(new TimeSpan(8, 9, 10), ret.TODProperty);
Expand All @@ -116,10 +114,9 @@ public async Task VerifyChange()

string newOrderContent = JsonConvert.SerializeObject(newObj);
StringContent content = new StringContent(newOrderContent, UTF8Encoding.Default, "application/json");
using (var response = await ODataTestHelpers.GetResponse(@"http://local/api/Prim/Dates(1024)", new HttpMethod("Patch"), content, RegisterApi))
using (var response = await ODataTestHelpers
.GetResponseNoContentValidation(@"http://local/api/Prim/Dates(1024)", new HttpMethod("Patch"), content, RegisterApi, HttpStatusCode.NoContent))
{
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

using (var ctx = new PrimitivesContext())
{
var ret = ctx.Dates.First(e => e.RowId == 1024);
Expand Down

0 comments on commit 180f902

Please sign in to comment.