Skip to content

Commit

Permalink
fix issue 505 in EntityFramework Provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsking committed Sep 1, 2016
1 parent f7fafd6 commit 4090457
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void SetValues(DbEntityEntry dbEntry, DataModificationItem item, Type re
propertyPair.Key));
}

value = Activator.CreateInstance(type);
value = propertyEntry.CurrentValue;
SetValues(value, type, dic);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Microsoft.OData.Client;
using Microsoft.OData.Core;
using Microsoft.OData.Service.Sample.Trippin.Models;
using Newtonsoft.Json;
using Xunit;

namespace Microsoft.OData.Service.Sample.Tests
Expand Down Expand Up @@ -295,11 +297,11 @@ public void CURDComputedImmutableProperty()
// Query the updated entity
this.TestClientContext.Detach(employee);
employee = this.TestClientContext.Orders.Where(e => e.PersonId == personId && e.OrderId == orderId).First();

// both computed property and immutable property should not have new value
Assert.Equal(400, employee.Price);
Assert.NotEqual("ShouldBeIgnored2", employee.ComputedProperty);

// Immutable property has value set during insert.
Assert.NotEqual("ShouldBeIgnored2", employee.ImmutableProperty);
Assert.Equal("ShouldNotBeIgnored", employee.ImmutableProperty);
Expand Down Expand Up @@ -409,9 +411,9 @@ public void UQProperty()
Assert.Equal("Cooper", lastName);

// Update a property
Dictionary<string, string> headers = new Dictionary<string, string>()
Dictionary<string, string> headers = new Dictionary<string, string>()
{
{ "Content-Type", "application/json" }
{ "Content-Type", "application/json" }
};

HttpWebRequestMessage request = new HttpWebRequestMessage(
Expand Down Expand Up @@ -566,12 +568,12 @@ public void QueryOptions()
// skip
people2 = this.TestClientContext.People.Skip((int)(personId - 1)).ToList();
Assert.Equal(personId, people2.First().PersonId);

// count
var countQuery = this.TestClientContext.People.IncludeTotalCount().Skip(1).Take(2) as DataServiceQuery<Person>;
var response = countQuery.Execute() as QueryOperationResponse<Person>;
Assert.Equal(response.TotalCount, 14);

// count with expand
countQuery = this.TestClientContext.People.IncludeTotalCount().Expand("Friends").Skip(1).Take(2) as DataServiceQuery<Person>;
response = countQuery.Execute() as QueryOperationResponse<Person>;
Expand Down Expand Up @@ -638,7 +640,7 @@ public void FilterBuiltInDateFunctions()
Assert.True(flight1.All(f => f.StartsAt.Second == startDate.Second));

// Following built-in functions are not supported now.
// fractionalseconds
// fractionalseconds
// date
// time
// totaloffsetminutes
Expand Down Expand Up @@ -1119,5 +1121,32 @@ public void ConventionBasedChangeSetAuthorizerTest()
"The current user does not have permission to delete entities from the EntitySet 'Trips'.",
clientException.Message);
}

[Fact]
public void TestPatchSuccessfully()
{
// Get origin content.
var uriStringAfterServiceRoot = "Orders(PersonId=1, OrderId=1)";
var originContent = default(string);
Action<string> getContent = p => originContent = p;
TestGetPayload(uriStringAfterServiceRoot, getContent);

// Patch it.
var changedDescription = "TestDescription";
var changedNormalProperty = "TestNormalProperty";
string patchContent =
string.Format(
"{{\n \"Description\": \"{0}\",\n \"NormalOrderDetail\": {{\n \"NormalProperty\": \"{1}\"\n }}\n}}",
changedDescription,
changedNormalProperty);
TestPatchStatusCodeIs(uriStringAfterServiceRoot, patchContent, HttpStatusCode.NoContent);

// Test patch results.
dynamic content = JsonConvert.DeserializeObject(originContent);
content.Description = changedDescription;
content.NormalOrderDetail.NormalProperty = changedNormalProperty;
string changedContent = JsonConvert.SerializeObject(content);
TestGetPayloadContains(uriStringAfterServiceRoot, changedContent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public OrderDetail()

public string NormalProperty { get; set; }

public string AnotherNormalProperty { get; set; }

public string ComputedProperty { get; set; }

public string ImmutableProperty { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,11 @@ public static void ResetDataSource()
OrderId = 1,
Description = "Person 1 Order 1",
Price = 200,
NormalOrderDetail = new OrderDetail(),
NormalOrderDetail = new OrderDetail()
{
NormalProperty = "NormalProperty",
AnotherNormalProperty = "AnotherNormalProperty"
},
ComputedOrderDetail = new OrderDetail(),
ImmutableOrderDetail = new OrderDetail()
},
Expand Down

0 comments on commit 4090457

Please sign in to comment.