-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move more tests from EndToEnd tests to Client.Test (#454)
* Move all EntityTests but 1 from EndToEnd to "Client.Tests" * move EntityConflictTests from E2E * move 2 more test classes
- Loading branch information
1 parent
63883b0
commit daa304e
Showing
7 changed files
with
193 additions
and
59 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/OpenRiaServices.Client/Test/Client.Test/Data/DomainClients/City.partial.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,81 @@ | ||
extern alias SSmDsClient; | ||
|
||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Cities | ||
{ | ||
[CustomValidation(typeof(City), "ValidateCity")] | ||
public partial class City | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of a <see cref="City"/> using the specified | ||
/// state name, which can be invalid. | ||
/// </summary> | ||
/// <param name="stateName"> | ||
/// The state name to use for initialization. This can be | ||
/// an invalid value, as validation won't be performed. | ||
/// </param> | ||
public City(string stateName) | ||
{ | ||
this._stateName = stateName; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets whether or not the entity-level validation for ValidateCity should fail. | ||
/// </summary> | ||
internal bool ThrowValidationExceptions { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a callback to be used whenever the ValidateProperty method is invoked. | ||
/// </summary> | ||
internal Action<ValidationContext> ValidatePropertyCallback { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a callback to be used whenever the ValidateCity validation method is invoked. | ||
/// </summary> | ||
internal Action<ValidationContext> ValidateCityCallback { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the count of calls to the ValidateCity method, which is an | ||
/// entity-level validation methods. | ||
/// </summary> | ||
internal int ValidateCityCallCount { get; set; } | ||
|
||
protected override void ValidateProperty(ValidationContext context, object value) | ||
{ | ||
this.ValidatePropertyCallback?.Invoke(context); | ||
|
||
if (this.ThrowValidationExceptions) | ||
{ | ||
System.ComponentModel.DataAnnotations.Validator.ValidateProperty(value, context); | ||
} | ||
else | ||
{ | ||
base.ValidateProperty(context, value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the entity-level custom validation should fail. | ||
/// </summary> | ||
public bool MakeEntityValidationFail { get; set; } | ||
|
||
public static ValidationResult ValidateCity(City entity, ValidationContext validationContext) | ||
{ | ||
entity.ValidateCityCallback?.Invoke(validationContext); | ||
|
||
// Increment our call counter | ||
++entity.ValidateCityCallCount; | ||
|
||
// And if we're supposed to fail, return the failure result | ||
if (entity.MakeEntityValidationFail) | ||
{ | ||
return new ValidationResult("MakeEntityValidationFail is true"); | ||
} | ||
|
||
// Otherwise return success | ||
return ValidationResult.Success; | ||
} | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
112 changes: 112 additions & 0 deletions
112
src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/EntityTestsE2E.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,112 @@ | ||
extern alias SSmDsClient; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Cities; | ||
using DataTests.AdventureWorks.LTS; | ||
using Microsoft.Silverlight.Testing; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenRiaServices.Silverlight.Testing; | ||
|
||
namespace OpenRiaServices.Client.Test | ||
{ | ||
using Resource = SSmDsClient::OpenRiaServices.Client.Resource; | ||
using TestDescription = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute; | ||
|
||
[TestClass] | ||
public class EntityTestsE2E : UnitTestBase | ||
{ | ||
[TestMethod] | ||
[Asynchronous] | ||
[TestDescription("Verifies that entity child and parent relationships are restored after RejectChanges is called.")] | ||
[WorkItem(720495)] | ||
public void Entity_RejectChanges_ParentAssociationRestored() | ||
{ | ||
List<Employee> employeeList = new List<Employee>(); | ||
ConfigurableEntityContainer container = new ConfigurableEntityContainer(); | ||
container.CreateSet<Employee>(EntitySetOperations.All); | ||
ConfigurableDomainContext catalog = new ConfigurableDomainContext(new WebDomainClient<TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.EFCore_Catalog), container); | ||
|
||
var load = catalog.Load(catalog.GetEntityQuery<Employee>("GetEmployees"), throwOnError:false); | ||
this.EnqueueCompletion(() => load); | ||
this.EnqueueCallback(() => | ||
{ | ||
Assert.AreEqual(null, load.Error); | ||
|
||
Employee parent, child; | ||
parent = container.GetEntitySet<Employee>().OrderByDescending(e => e.Reports.Count).First(); | ||
|
||
while (parent != null) | ||
{ | ||
// Track parent, get a report from it | ||
employeeList.Add(parent); | ||
child = parent.Reports.OrderByDescending(e => e.Reports.Count).FirstOrDefault(); | ||
|
||
// Track child | ||
if (child == null) | ||
{ | ||
break; | ||
} | ||
|
||
// Remove child and continue | ||
parent.Reports.Remove(child); | ||
parent = child; | ||
} | ||
|
||
// By rejecting changes, our parent<=>child relationships should be restored. | ||
catalog.RejectChanges(); | ||
|
||
// Unwind, walking up management chain | ||
foreach (Employee employee in employeeList.Reverse<Employee>()) | ||
{ | ||
Assert.AreSame(parent, employee, "Expected parent relationship to be restored."); | ||
parent = employee.Manager; | ||
Assert.IsTrue(parent.Reports.Contains(employee), "Expected child relationship to be restored."); | ||
} | ||
}); | ||
this.EnqueueTestComplete(); | ||
} | ||
|
||
private class TestCityContainer : EntityContainer | ||
{ | ||
public TestCityContainer() | ||
{ | ||
CreateEntitySet<City>(EntitySetOperations.Add | EntitySetOperations.Edit | EntitySetOperations.Remove); | ||
CreateEntitySet<County>(EntitySetOperations.Add | EntitySetOperations.Edit | EntitySetOperations.Remove); | ||
} | ||
} | ||
} | ||
|
||
public class ConfigurableDomainContext : DomainContext | ||
{ | ||
private readonly EntityContainer _entityContainer; | ||
|
||
public ConfigurableDomainContext(DomainClient client, EntityContainer entityContainer) | ||
: base(client) | ||
{ | ||
this._entityContainer = entityContainer; | ||
} | ||
|
||
public EntityQuery<TEntity> GetEntityQuery<TEntity>(string queryName) where TEntity : Entity | ||
{ | ||
return this.CreateQuery<TEntity>(queryName, null, false, false); | ||
} | ||
|
||
protected override EntityContainer CreateEntityContainer() | ||
{ | ||
return this._entityContainer; | ||
} | ||
} | ||
|
||
public class ConfigurableEntityContainer : EntityContainer | ||
{ | ||
public void CreateSet<TEntity>(EntitySetOperations operations) where TEntity : Entity, new() | ||
{ | ||
base.CreateEntitySet<TEntity>(operations); | ||
} | ||
} | ||
|
||
} |