Skip to content

Commit

Permalink
QueryEntityInstance etc. test cases work in VS2015
Browse files Browse the repository at this point in the history
Resolve #409
  • Loading branch information
congysu committed Dec 11, 2015
1 parent c0ff06e commit 58a1c54
Show file tree
Hide file tree
Showing 3 changed files with 589 additions and 567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,82 +182,94 @@ public void QueryEntityNavigationWithImplicitKeys()
[TestMethod]
public void MergeProjectionAndQueryOptionTest()
{
this.RunOnAtomAndJsonFormats(
this.CreateContext,
(contextWrapper) =>
{
var query = from p in contextWrapper.Context.Product.AddQueryOption("$select", "ProductId")
where p.ProductId == -10
select new Product() { Description = p.Description, Photos = p.Photos };

Uri uri = ((DataServiceQuery<Product>)query).RequestUri;
Assert.AreEqual("?$expand=Photos&$select=Description,ProductId", uri.Query);
Assert.IsTrue(query.ToList().Count == 1);
});
this.RunOnAtomAndJsonFormats(CreateContext, MergeProjectionAndQueryOptionTest);
}

private static void MergeProjectionAndQueryOptionTest(
DataServiceContextWrapper<DefaultContainer> contextWrapper)
{
var query = from p in contextWrapper.Context.Product.AddQueryOption("$select", "ProductId")
where p.ProductId == -10
select new Product() { Description = p.Description, Photos = p.Photos };

Uri uri = ((DataServiceQuery<Product>)query).RequestUri;
Assert.AreEqual("?$expand=Photos&$select=Description,ProductId", uri.Query);
Assert.IsTrue(query.ToList().Count == 1);
}

[TestMethod]
public void DataServiceCollectionSubQueryTrackingItems()
{
this.RunOnAtomAndJsonFormats(
this.CreateContext,
(contextWrapper) =>
this.RunOnAtomAndJsonFormats(CreateContext, DataServiceCollectionSubQueryTrackingItems);
}

private static void DataServiceCollectionSubQueryTrackingItems(
DataServiceContextWrapper<DefaultContainer> contextWrapper)
{
var query = from p in contextWrapper.Context.Customer
where p.Name != null
select new Customer()
{
var query = from p in contextWrapper.Context.Customer
where p.Name != null
select new Customer()
{
Name = p.Name,
Orders = new DataServiceCollection<Order>(
from r in p.Orders
select new Order()
{
OrderId = r.OrderId,
CustomerId = r.CustomerId
})
};
var tmpResult0 = query.ToList()[0];
DataServiceCollection<Order> collection = tmpResult0.Orders; // the collection tracking items
int tmpCount = collection.Count;
collection.Load(contextWrapper.Context.Execute(collection.Continuation)); // for testing newly loaded item's tracking
Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page.");
bool someItemNotTracked = false;
tmpResult0.Orders.ToList().ForEach(s =>
{
EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State;
s.CustomerId = s.CustomerId + 1;
state = contextWrapper.Context.GetEntityDescriptor(s).State;
someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked;
});
Assert.IsFalse(someItemNotTracked, "All items should have been tracked.");
});
Name = p.Name,
Orders = new DataServiceCollection<Order>(
from r in p.Orders
select new Order()
{
OrderId = r.OrderId,
CustomerId = r.CustomerId
})
};
var tmpResult0 = query.ToList()[0];
DataServiceCollection<Order> collection = tmpResult0.Orders; // the collection tracking items
int tmpCount = collection.Count;
collection.Load(contextWrapper.Context.Execute(collection.Continuation));

// for testing newly loaded item's tracking
Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page.");
bool someItemNotTracked = false;
tmpResult0.Orders.ToList().ForEach(s =>
{
EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State;
s.CustomerId = s.CustomerId + 1;
state = contextWrapper.Context.GetEntityDescriptor(s).State;
someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked;
});
Assert.IsFalse(someItemNotTracked, "All items should have been tracked.");
}

[TestMethod]
public void DataServiceCollectionTrackingItems()
{
this.RunOnAtomAndJsonFormats(this.CreateContext, (contextWrapper) =>
{
var query = from p in contextWrapper.Context.Customer
where p.CustomerId > -100000 // try to get many for paging
select new Customer()
{
CustomerId = p.CustomerId,
Name = p.Name
};
DataServiceCollection<Customer> collection = new DataServiceCollection<Customer>(query); // the collection to track items
int tmpCount = collection.Count;
collection.Load(contextWrapper.Context.Execute(collection.Continuation)); // for testing newly loaded item's tracking
Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page.");
bool someItemNotTracked = false;
collection.ToList().ForEach(s =>
this.RunOnAtomAndJsonFormats(CreateContext, DataServiceCollectionTrackingItems);
}

private static void DataServiceCollectionTrackingItems(
DataServiceContextWrapper<DefaultContainer> contextWrapper)
{
var query = from p in contextWrapper.Context.Customer
where p.CustomerId > -100000
// try to get many for paging
select new Customer()
{
s.Name = "value to test tracking";
EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State;
someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked;
});
Assert.IsFalse(someItemNotTracked, "All items should have been tracked.");
CustomerId = p.CustomerId,
Name = p.Name
};
DataServiceCollection<Customer> collection = new DataServiceCollection<Customer>(query);

// the collection to track items
int tmpCount = collection.Count;
collection.Load(contextWrapper.Context.Execute(collection.Continuation));

// for testing newly loaded item's tracking
Assert.IsTrue(collection.Count > tmpCount, "Should have loaded another page.");
bool someItemNotTracked = false;
collection.ToList().ForEach(s =>
{
s.Name = "value to test tracking";
EntityStates state = contextWrapper.Context.GetEntityDescriptor(s).State;
someItemNotTracked = (state == EntityStates.Unchanged) || someItemNotTracked;
});
Assert.IsFalse(someItemNotTracked, "All items should have been tracked.");
}

[TestMethod]
Expand Down
Loading

0 comments on commit 58a1c54

Please sign in to comment.