public void Submit_POCO_Insert5Cities() { CityDomainContext dc = new CityDomainContext(TestURIs.Cities); for (int i = 1; i <= 5; i++) { dc.Cities.Add(new City() { Name = "Redmond" + new string('x', i), CountyName = "King", StateName = "WA" }); } SubmitOperation so = dc.SubmitChanges(); EnqueueConditional(delegate { return(so.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void Composition_Inheritance_HierarchyQuery() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); // 3 parents, each with 4 children Assert.AreEqual(15, lo.AllEntities.Count(), "Unexpected number of entities in hierarchy"); Assert.AreEqual(3, ctxt.CI_Parents.Count, "Expected this many total parent entities"); foreach (CI_Parent p in ctxt.CI_Parents) { VerifyHierarchy(p); IEnumerable <CI_Child> baseChildren = p.Children.Where(c => c.GetType() == typeof(CI_Child)); Assert.AreEqual(2, baseChildren.Count(), "Wrong number of child entities"); IEnumerable <CI_AdoptedChild> adoptedChildren = p.Children.OfType <CI_AdoptedChild>(); Assert.AreEqual(2, adoptedChildren.Count(), "Wrong number of adopted child entities"); } }); EnqueueTestComplete(); }
public void Submit_POCO_Insert5Simple() { TestProvider_Scenarios dc = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); for (int i = 0; i < 5; i++) { dc.POCONoValidations.Add(new POCONoValidation() { ID = i, A = "A" + i, B = "B" + i, C = "C" + i, D = "D" + i, E = "E" + i }); } SubmitOperation so = dc.SubmitChanges(); EnqueueConditional(delegate { return(so.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
/// <summary> /// Verify successful completion of an update operation /// </summary> private void VerifySuccess(CompositionInheritanceScenarios ctxt, SubmitOperation so, IEnumerable <Entity> expectedUpdates) { // verify operation completed successfully TestHelperMethods.AssertOperationSuccess(so); // verify that all operations were executed EntityChangeSet cs = so.ChangeSet; VerifyOperationResults(cs.AddedEntities, expectedUpdates); // verify that all changes have been accepted cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.IsEmpty); }
public void InvokeOperation_ReturnsEntityCollection() { TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); InvokeOperation invoke = provider.ReturnsEntityCollection_Online(3, TestHelperMethods.DefaultOperationAction, null); EnqueueConditional(() => invoke.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(invoke); IEnumerable <MixedType> mts = invoke.Value as IEnumerable <MixedType>; Assert.AreEqual(3, mts.Count()); }); EnqueueTestComplete(); }
public void Query_POCO_AllCities() { CityDomainContext dc = new CityDomainContext(TestURIs.Cities); var query = dc.GetCitiesQuery(); LoadOperation lo = dc.Load(query, false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() > 0); }); EnqueueTestComplete(); }
public void Query_Take50Products() { Catalog catalog = CreateDomainContext(); var query = catalog.GetProductsQuery().OrderBy(p => p.Name).Take(50); LoadOperation lo = catalog.Load(query, false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() == 50); }); EnqueueTestComplete(); }
public void Invoke_RoundtripString() { TestProvider_Scenarios dc = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); string str = "Hello, World!"; InvokeOperation <string> io = dc.ReturnsString_Online(str); this.EnqueueCompletion(() => io); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(io); Assert.AreEqual(str, io.Value); }); EnqueueTestComplete(); }
public void InvokeOperation_ReturnsEntity() { TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); MixedType mt = new MixedType(); InvokeOperation invoke = provider.ReturnsEntity_Online(mt, "MixedType_Other", TestHelperMethods.DefaultOperationAction, null); EnqueueConditional(() => invoke.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(invoke); mt = invoke.Value as MixedType; Assert.IsNotNull(mt); Assert.AreEqual("MixedType_Other", mt.ID); }); EnqueueTestComplete(); }
public void Query_NoResults() { Catalog catalog = CreateDomainContext(); var query = catalog.GetProductsQuery().Where(p => p.ProductID < 0); LoadOperation lo = catalog.Load(query, false); EnqueueConditional(delegate { return(lo.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() == 0); }); EnqueueTestComplete(); }
public void Query_POCO_NoResults() { CityDomainContext dc = new CityDomainContext(TestURIs.Cities); var query = dc.GetCitiesQuery().Where(c => c.Name == "-"); LoadOperation lo = dc.Load(query, false); EnqueueConditional(delegate { return(lo.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() == 0); }); EnqueueTestComplete(); }
public void Composition_Inheritance_Add_Derived_Child_To_Derived_Parent() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); CI_SpecialParent parent = null; SubmitOperation so = null; IEnumerable <Entity> expectedUpdates = null; LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); parent = ctxt.CI_Parents.OfType <CI_SpecialParent>().First(); CI_AdoptedChild newChild = new CI_AdoptedChild() { Age = 5, }; parent.Children.Add(newChild); Assert.AreSame(parent, ((Entity)newChild).Parent); EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Count == 1, "wrong modified count"); Assert.IsTrue(cs.AddedEntities.Count == 1, "wrong added count"); Assert.IsTrue(cs.RemovedEntities.Count == 0, "wrong removed count"); Assert.IsTrue(cs.ModifiedEntities.Contains(parent)); Assert.IsTrue(cs.AddedEntities.Contains(newChild)); // verify that original associations are set up correctly IEnumerable <ChangeSetEntry> entityOps = ChangeSetBuilder.Build(cs); this.ValidateEntityOperationAssociations(entityOps); expectedUpdates = cs.Where(p => p.HasChildChanges || p.HasPropertyChanges).ToArray(); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); EnqueueConditional(() => so.IsComplete); EnqueueCallback(delegate { this.VerifySuccess(ctxt, so, expectedUpdates); }); EnqueueTestComplete(); }
public void Association_Inheritance_HierarchyQuery() { AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); // Master, 2 D1's, 2 D2's, 1 D3 and 1 D4 Assert.AreEqual(7, lo.AllEntities.Count(), "Unexpected number of entities in hierarchy"); AI_MasterDerived master = ctxt.AI_Masters.OfType <AI_MasterDerived>().FirstOrDefault(); Assert.IsNotNull(master, "expected 1 master"); // Confirm the single-value relations AI_DetailDerived3 d3 = master.DetailDerived3; Assert.IsNotNull(d3, "no master.D3"); Assert.AreSame(master, d3.Master, "wrong master.D3"); AI_DetailDerived4 d4 = master.DetailDerived4; Assert.IsNotNull(d4, "no master.D4"); Assert.AreSame(master, d4.Master, "wrong master.D4"); // Confirm the multi-value relations Assert.AreEqual(2, master.DetailDerived1s.Count, "wrong number of D1's"); Assert.AreEqual(2, master.DetailDerived2s.Count, "wrong number of D2's"); foreach (AI_DetailDerived1 d1 in master.DetailDerived1s) { Assert.AreSame(master, d1.Master, "D1.Master not root master"); } foreach (AI_DetailDerived2 d2 in master.DetailDerived2s) { Assert.AreSame(master, d2.Master, "D1.Master not root master"); } }); EnqueueTestComplete(); }
public void Association_Inheritance_Modify_MultipleValue_Derived_Association() { AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false); SubmitOperation so = null; this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); AI_MasterDerived master = ctxt.AI_Masters.OfType <AI_MasterDerived>().FirstOrDefault(); Assert.IsNotNull(master, "expected 1 master"); // Verify we can remove one derived from the list AI_DetailDerived1 d1 = master.DetailDerived1s.First(); master.DetailDerived1s.Remove(d1); Assert.AreEqual(1, master.DetailDerived1s.Count, "master.D1s.Remove didn't work"); AI_DetailDerived1 newD1 = new AI_DetailDerived1(); newD1.ID = 9999; master.DetailDerived1s.Add(newD1); Assert.AreEqual(2, master.DetailDerived1s.Count, "master.D1s.Add didn't work"); AI_DetailDerived2 newD2 = new AI_DetailDerived2(); newD2.ID = 99999; master.DetailDerived2s.Add(newD2); Assert.AreEqual(3, master.DetailDerived2s.Count, "master.D2s.Add didn't work"); so = ctxt.SubmitChanges(); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void Composition_Inheritance_Update_Base_Child_On_Base_Parent() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); CI_Parent parent = null; SubmitOperation so = null; IEnumerable <Entity> expectedUpdates = null; LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); parent = ctxt.CI_Parents.First(p => p.GetType() == typeof(CI_Parent)); CI_Child existingChild = parent.Children.First(c => c.GetType() == typeof(CI_Child)); Assert.AreSame(parent, ((Entity)existingChild).Parent); // update derived comp child existingChild.Age++;; EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Count == 2, "wrong modified count"); Assert.IsTrue(cs.RemovedEntities.Count == 0, "wrong removed count"); Assert.IsTrue(cs.ModifiedEntities.Contains(parent)); Assert.IsTrue(cs.ModifiedEntities.Contains(existingChild)); // verify that original associations are set up correctly IEnumerable <ChangeSetEntry> entityOps = ChangeSetBuilder.Build(cs); this.ValidateEntityOperationAssociations(entityOps); expectedUpdates = cs.Where(p => p.HasChildChanges || p.HasPropertyChanges).ToArray(); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { this.VerifySuccess(ctxt, so, expectedUpdates); }); EnqueueTestComplete(); }
public void Association_Inheritance_Modify_Singleton_Derived_Association() { AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false); SubmitOperation so = null; this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); AI_MasterDerived master = ctxt.AI_Masters.OfType <AI_MasterDerived>().FirstOrDefault(); Assert.IsNotNull(master, "expected one master"); AI_DetailDerived3 d3 = master.DetailDerived3; Assert.IsNotNull(d3, "no master.D3"); Assert.AreSame(master, d3.Master, "wrong master.D3"); // Verify we can unset it master.DetailDerived3 = null; Assert.IsNull(master.DetailDerived3, "could not reset master.D4"); AI_DetailDerived3 newD3 = new AI_DetailDerived3(); newD3.ID = 99; master.DetailDerived3 = newD3; AI_DetailDerived4 newD4 = new AI_DetailDerived4(); newD4.ID = 999; master.DetailDerived4 = newD4; so = ctxt.SubmitChanges(); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void Cities_LoadStates_TestEnums() { CityDomainContext dp = new CityDomainContext(TestURIs.Cities); SubmitOperation so = null; LoadOperation lo = dp.Load(dp.GetStatesQuery().Where(s => s.TimeZone == Cities.TimeZone.Pacific), false); this.EnqueueCompletion(() => lo); EnqueueCallback(() => { if (lo.Error != null) { Assert.Fail("LoadOperation.Error: " + lo.Error.Message); } // verify the TimeZones were serialized to the client properly State state = dp.States.Single(p => p.Name == "WA"); Assert.AreEqual(Cities.TimeZone.Pacific, state.TimeZone); Assert.IsFalse(dp.States.Any(p => p.Name == "OH")); // Now test update state.TimeZone = state.TimeZone = Cities.TimeZone.Central; Assert.AreEqual(EntityState.Modified, state.EntityState); EntityChangeSet cs = dp.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Contains(state)); so = dp.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); this.EnqueueCompletion(() => so); EnqueueCallback(() => { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void DomainContext_Submit_CUDOperationMethodValidation() { CityDomainContext ctxt = new CityDomainContext(TestURIs.Cities); LoadOperation lo = ctxt.Load(ctxt.GetCitiesQuery(), false); SubmitOperation so = null; this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); // update City[] cities = ctxt.Cities.Where(p => p.GetType() == typeof(City)).ToArray(); City city = cities[0]; city.ZoneID = 693; // custom method city.AssignCityZone("Z1"); // delete City deletedCity = new City() { Name = "Issaquah", CountyName = "King", StateName = "WA", ZoneID = 693 }; ctxt.Cities.Attach(deletedCity); ctxt.Cities.Remove(deletedCity); // insert City newCity = new City() { Name = "Sylvannia", CountyName = "Lucas", StateName = "OH" }; newCity.ZoneID = 693; ctxt.Cities.Add(newCity); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { DomainOperationException ex = so.Error as DomainOperationException; Assert.IsNotNull(ex); Assert.AreEqual(OperationErrorStatus.ValidationFailed, ex.Status); Assert.AreEqual(Resource.DomainContext_SubmitOperationFailed_Validation, ex.Message); EntityChangeSet cs = so.ChangeSet; City city = (City)cs.AddedEntities.Single(); Assert.AreEqual("CityMethodValidator.ValidateMethod Failed (InsertCity)!", city.ValidationErrors.Single().ErrorMessage); city = (City)cs.ModifiedEntities.Single(); ValidationResult[] validationResults = city.ValidationErrors.ToArray(); Assert.AreEqual("CityMethodValidator.ValidateMethod Failed (UpdateCity)!", validationResults[0].ErrorMessage); Assert.AreEqual("CityMethodValidator.ValidateMethod Failed (AssignCityZone)!", validationResults[1].ErrorMessage); city = (City)cs.RemovedEntities.Single(); Assert.AreEqual("CityMethodValidator.ValidateMethod Failed (DeleteCity)!", city.ValidationErrors.Single().ErrorMessage); }); EnqueueTestComplete(); }
public void SerializeEntityWithCustomDataContract() { TestDomainServices.MockCustomerDomainContext context = new TestDomainServices.MockCustomerDomainContext(TestURIs.MockCustomers); SubmitOperation submit = null; LoadOperation <TestDomainServices.MockReport> load = context.Load(context.GetReportsQuery(), false); this.EnqueueConditional(() => load.IsComplete); this.EnqueueCallback(() => { TestHelperMethods.AssertOperationSuccess(load); // Ensure DataContract(Name, Namespace) on entity matches. Assert.AreEqual(3, load.Entities.Count(), "GetReportsQuery must return 3 reports"); int numReportBodies = 0; string reportsResult = load.Entities.Aggregate <TestDomainServices.MockReport, string>(string.Empty, (result, mockReport) => { StringBuilder sb = new StringBuilder(); Action <bool, string, object> appendIf = (emit, property, value) => { if (emit) { sb.Append(string.Format("{0} is {1}", property, value)); } }; // Ensure entity CLR properties code gen correlates with surrogate layer DataMember(Name, ...) sb.Append(string.Format("CustomerId is {0}", mockReport.CustomerId)); appendIf(mockReport.Customer != null, "Customer", mockReport.Customer); appendIf(mockReport.ReportElementFieldId == 0, "ReportElementFieldId", mockReport.ReportElementFieldId); appendIf(mockReport.ReportTitle == null, "ReportTitle", mockReport.ReportTitle); // Ensure complex type CLR properties code gen correlates with surrogate layer DataMember(Name, ...) var reportBody = mockReport.ReportBody; if (reportBody != null) { numReportBodies++; appendIf(reportBody.TimeEntered.Year != 1970, "TimeEntered", reportBody.TimeEntered); appendIf(reportBody.Report == null, "Report", reportBody.Report); } // Ensure entity projection properties code gen correlates with surrogate layer DataMember(Name, ...) appendIf(mockReport.State == null, "State", mockReport.State); appendIf(mockReport.Start == null, "Start", mockReport.Start); if (!string.IsNullOrEmpty(result)) { result += " "; } return(result + sb.ToString()); }); Assert.AreEqual("CustomerId is 1 CustomerId is 2 CustomerId is 3", reportsResult); // Ensure DataContract(Name, Namespace) on complex types matches. Assert.AreEqual(2, numReportBodies, "GetReportsQuery must return 2 report bodies"); // Update a report (entity properties and complex type properties) to ensure it is serialized to the server correctly TestDomainServices.MockReport reportToChange = load.Entities.First(); reportToChange.ReportTitle = reportToChange.ReportTitle + "!"; reportToChange.ReportBody.Report = reportToChange.ReportBody.Report + "!"; reportToChange.ReportBody.TimeEntered = DateTime.Now; reportToChange.MockReportCustomMethod(); submit = context.SubmitChanges(); }); this.EnqueueConditional(() => submit.IsComplete); this.EnqueueCallback(() => { // No errors means the server found all the data was correct. TestHelperMethods.AssertOperationSuccess(submit); }); this.EnqueueTestComplete(); }