public void TestInitialize() { CityData cityData = new CityData(); _cities = cityData.Cities; _citiesWithInfo = cityData.CitiesWithInfo; // Root cities eliminates any derived types _rootCities = _cities.Where(c => c.GetType() == typeof(City)).ToList(); }
public void GroupIsNotAppliedUntilAutoloadCompletes() { CityData cities = new CityData(); this.LoadDomainDataSourceControl(); this.LoadCities(0, true); this.EnqueueCallback(() => { Assert.IsTrue(cities.Cities.Select(c => c.Name).SequenceEqual(this._view.Cast<City>().Select(c => c.Name)), "The view order should be equal to the Cities order."); this._collectionView.GroupDescriptions.Add(new PropertyGroupDescription("StateName")); Assert.IsTrue(cities.Cities.Select(c => c.Name).SequenceEqual(this._view.Cast<City>().Select(c => c.Name)), "The view order should still be equal to the Cities order."); }); this.AssertLoadedData(); this.EnqueueCallback(() => { this.ResetLoadState(); AssertHelper.AssertSequenceSorting(this._view.Cast<City>().Select(c => c.StateName), ListSortDirection.Ascending, "The view order should now be sorted in the ascending direction."); }); EnqueueTestComplete(); }
public void GroupingWithProgressiveLoading() { int totalCityCount = new CityData().Cities.Count; EnqueueCallback(() => { // By using a loadsize of 1, we know the number of loads to be performed is equal to the // total city count + 1 (the load that will determine that there are no more records). this._dds.LoadSize = 1; this._dds.QueryName = "GetCities"; this._dds.DomainContext = new CityDomainContext(); this._dds.GroupDescriptors.Add(new GroupDescriptor("Name")); this._asyncEventFailureMessage = "First Progressive Load"; this._dds.Load(); }); this.AssertLoadingData(totalCityCount + 1, true); EnqueueCallback(() => { this.ResetLoadState(); Assert.AreEqual<int>(totalCityCount, this._view.Count, "The count should match the total city count after allowing the first progressive load to finish"); AssertHelper.AssertSequenceSorting(this._view.Cast<City>().Select(c => c.Name), ListSortDirection.Ascending, "Cities should be sorted by Name after the first progressive load"); this._dds.GroupDescriptors[0].PropertyPath = "StateName"; // Calling Refresh will test that the load of FirstItems is deferred properly this._collectionView.Refresh(); }); this.AssertLoadingData(totalCityCount + 1, true); EnqueueCallback(() => { this.ResetLoadState(); Assert.AreEqual<int>(totalCityCount, this._view.Count, "The count should match the total city count after allowing the second progressive load to finish"); AssertHelper.AssertSequenceSorting(this._view.Cast<City>().Select(c => c.StateName), ListSortDirection.Ascending, "Cities should be sorted by StateName after the second progressive load"); }); EnqueueTestComplete(); }
public void PageIndexClearedWhenPagingGetsDisabled() { this.LoadDomainDataSourceControl(); int allEntities = new CityData().Cities.Count; int iteration = 0; EventHandler<LoadedDataEventArgs> pagingEnabled = (s, e) => { ++iteration; // When paging is enabled, the PageIndex should be 0 and the the View should have the number of entities matching the PageSize Assert.AreEqual<int>(0, this._view.PageIndex, "PageIndex with Paging enabled. Iteration: " + iteration.ToString()); Assert.AreEqual<int>(this._view.PageSize, this._view.Cast<City>().Count(), "View count with Paging enabled. Iteration: " + iteration.ToString()); }; EventHandler<LoadedDataEventArgs> pagingDisabled = (s, e) => { ++iteration; // When paging is disabled, the PageIndex should be -1 and all entities should be in the view Assert.AreEqual<int>(-1, this._view.PageIndex, "PageIndex with Paging disabled. Iteration: " + iteration.ToString()); Assert.AreEqual<int>(allEntities, this._view.Cast<City>().Count(), "View count with Paging disabled. Iteration: " + iteration.ToString()); }; this._dds.LoadedData += pagingEnabled; this.LoadCities(5, true); EnqueueCallback(() => { this._dds.LoadedData -= pagingEnabled; this._dds.LoadedData += pagingDisabled; this._view.PageSize = 0; }); this.AssertLoadingData(); this.AssertPageChanged(); EnqueueCallback(() => { this.ResetLoadState(); this.ResetPageChanged(); this._dds.LoadedData -= pagingDisabled; this._dds.LoadedData += pagingEnabled; this._view.PageSize = 1; }); this.AssertLoadingData(); this.AssertPageChanged(); EnqueueCallback(() => { this.ResetLoadState(); this.ResetPageChanged(); Assert.AreEqual<int>(0, this._view.PageIndex); }); EnqueueTestComplete(); }
public void PagingPastEndTwiceCancelsSecondLoad() { CityDomainContext context = new CityDomainContext(); int pageSize = 6; int cityCount = new CityData().Cities.Count; int lastPageIndex = (cityCount / pageSize) - ((cityCount % pageSize == 0) ? 1 : 0); EnqueueCallback(() => { this._dds.PageSize = pageSize; this._dds.QueryName = "GetCitiesQuery"; this._dds.DomainContext = context; this._dds.Load(); }); this.AssertLoadingData(); this.AssertPageChanged(); EnqueueCallback(() => { this.ResetLoadState(); this.ResetPageChanged(); // We need to make sure the second load caused by paging past the last page is cancelable. // To do this, we'll load 4 times. The first is caused by moving past the last page. The second // is automatically started when the first load does not return any entities and shifts back to // the last page. The third and fourth move past and back again and are started such that the // third load cancels the second. this._dds.LoadingData += (sender, e) => { // We only want to reload once to cancel the second load attempt if (this._ddsLoadingData == 2) { this._view.MoveToPage(lastPageIndex + 2); } }; this._dds.LoadedData += (sender, e) => { Assert.IsTrue((this._ddsLoadedData == 2) == e.Cancelled, "Only the second load should have been canceled."); }; this._view.MoveToPage(lastPageIndex + 1); }); this.AssertLoadingData(4); EnqueueTestComplete(); }
public void DoubleLoadCancelsLoadAlreadyInProgress() { bool isFirst = true; EventHandler<LoadedDataEventArgs> firstLoadedDataIsCancelled = (s, e) => { Assert.AreEqual<bool>(isFirst, e.Cancelled, "Cancelled should be true for the first load"); isFirst = false; }; EnqueueCallback(() => { this._ddsLoadingDataExpected = 2; this._ddsLoadedDataExpected = 2; this._dds.AutoLoad = false; this._dds.QueryName = "GetCities"; this._dds.DomainContext = new CityDomainContext(); this._dds.LoadedData += firstLoadedDataIsCancelled; this._dds.Load(); this._dds.FilterDescriptors.Add(new FilterDescriptor("StateName", FilterOperator.IsEqualTo, "WA")); this._dds.Load(); }); this.AssertLoadedData(2); EnqueueCallback(() => { int expectedCount = new CityData().Cities.Count(c => c.StateName == "WA"); Assert.AreEqual(expectedCount, this._view.Count); }); EnqueueTestComplete(); }
public void AutoLoadData() { EnqueueCallback(() => { Assert.IsFalse(this._dds.AutoLoad); }); this.LoadDomainDataSourceControl(); EnqueueCallback(() => { Assert.IsTrue(this._dds.AutoLoad); this._dds.QueryName = "GetCitiesQuery"; this._dds.DomainContext = new CityDomainContext(); }); this.AssertLoadedData(); EnqueueCallback(() => { int expectedCount = new CityData().Cities.Count; Assert.AreEqual(expectedCount, this._view.Count); }); EnqueueTestComplete(); }
public void UnhandledSubmitOperationError() { CityDomainContext cities = new CityDomainContext(TestURIs.Cities); CityData data = new CityData(); cities.Cities.LoadEntities(data.Cities.ToArray()); City city = cities.Cities.First(); city.ZoneID = 1; Assert.IsTrue(cities.EntityContainer.HasChanges); SubmitOperation submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, null); DomainOperationException expectedException = null; DomainOperationException ex = new DomainOperationException("Submit Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); try { submit.Complete(ex); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed, ex.Message), expectedException.Message); Assert.AreEqual(ex.StackTrace, expectedException.StackTrace); Assert.AreEqual(ex.Status, expectedException.Status); Assert.AreEqual(ex.ErrorCode, expectedException.ErrorCode); Assert.AreEqual(false, submit.IsErrorHandled); // now test again with conflicts expectedException = null; IEnumerable<ChangeSetEntry> entries = ChangeSetBuilder.Build(cities.EntityContainer.GetChanges()); ChangeSetEntry entry = entries.First(); entry.ValidationErrors = new ValidationResultInfo[] { new ValidationResultInfo("Foo", new string[] { "Bar" }) }; submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, null); try { submit.Complete(OperationErrorStatus.Conflicts); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed_Conflicts), expectedException.Message); // now test again with validation errors expectedException = null; entries = ChangeSetBuilder.Build(cities.EntityContainer.GetChanges()); entry = entries.First(); entry.ConflictMembers = new string[] { "ZoneID" }; submit = new SubmitOperation(cities.EntityContainer.GetChanges(), null, null, null); try { submit.Complete(OperationErrorStatus.ValidationFailed); } catch (DomainOperationException e) { expectedException = e; } // verify the exception properties Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.DomainContext_SubmitOperationFailed_Validation, ex.Message), expectedException.Message); }
public void EditingQueryParameterWithProgressiveLoading() { IEnumerable<City> cities = new CityData().Cities; int citiesInWA = cities.Count(c => c.StateName == "WA"); int citiesinOH = cities.Count(c => c.StateName == "OH"); EnqueueCallback(() => { // By using a loadsize of 1, we know the number of loads to be performed is equal to the // expected city count + 1 (the load that will determine that there are no more records). this._dds.LoadSize = 1; this._dds.QueryName = "GetCitiesInState"; this._dds.QueryParameters.Add(new Parameter { ParameterName = "state", Value = "WA" }); this._dds.DomainContext = new CityDomainContext(); this._asyncEventFailureMessage = "First Progressive Load"; this._dds.Load(); }); this.AssertLoadingData(citiesInWA + 1, true); EnqueueCallback(() => { this.ResetLoadState(); Assert.AreEqual<int>(citiesInWA, this._view.Count, "The count should match the number of WA cities after the first progressive load"); Assert.IsTrue(this._view.Cast<City>().All(c => c.StateName == "WA"), "All cities should be in WA after the first progressive load"); this._dds.QueryParameters[0].Value = "OH"; // Calling Refresh will test that the load of FirstItems is deferred properly this._collectionView.Refresh(); }); this.AssertLoadingData(citiesinOH + 1, true); EnqueueCallback(() => { this.ResetLoadState(); Assert.AreEqual<int>(citiesinOH, this._view.Count, "The count should match the number of OH cities after the second progressive load"); Assert.IsTrue(this._view.Cast<City>().All(c => c.StateName == "OH"), "All cities should be in OH after the second progressive load"); }); EnqueueTestComplete(); }
public void Cities_ShouldSupportLongQueries() { LoadOperation<Zip> lo = null; const int zipToFind = 98053; const int QUERY_ITERATIONS = 50; EnqueueCallback(() => { CityDomainContext dp = new CityDomainContext(TestURIs.Cities); // Abs URI so runs on desktop too // Generate a really long query // The load will result in a query where just the query part has length > 3000 var query = dp.GetZipsQuery(); // Create a query with QUERY_ITERATIONS where statements checking a range of QUERY_ITERATIONS each // this should in the end if simplified result in Code = zipToFind (zipToFind - 1 < Code <= zipToFind) for (int i = 0; i < QUERY_ITERATIONS; ++i) { int min = zipToFind + i - QUERY_ITERATIONS; int max = zipToFind + i; query = query.Where(c => min < c.Code && c.Code <= max); } lo = dp.Load(query, false); }); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(() => { if (lo.Error != null) Assert.Fail("LoadOperation.Error: " + lo.Error.Message); var expected = new CityData().Zips.Single(z => z.Code == zipToFind); Assert.AreEqual(1, lo.Entities.Count(), "Wrong number of entities returned"); var returned = lo.Entities.Single(); Assert.AreEqual(expected.Code, returned.Code); Assert.AreEqual(expected.FourDigit, returned.FourDigit); Assert.AreEqual(expected.CityName, returned.CityName); Assert.AreEqual(expected.CountyName, returned.CountyName); Assert.AreEqual(expected.StateName, returned.StateName); }); EnqueueTestComplete(); }
public void Cities_Cities_In_County_Serialized_Query() { CityDomainContext dp = new CityDomainContext(TestURIs.Cities); // Abs URI so runs on desktop too // Pass the query to the server to select only cities in King county var cityQuery = dp.GetCitiesQuery().Where(c => c.CountyName == "King"); LoadOperation lo = dp.Load(cityQuery, false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(() => { if (lo.Error != null) Assert.Fail("LoadOperation.Error: " + lo.Error.Message); IEnumerable<City> expected = new CityData().Cities.Where(c => c.CountyName == "King"); AssertSame(expected, dp.Cities); }); EnqueueTestComplete(); }
public void Cities_Cities_In_State_Parameterized_Query() { CityDomainContext dp = new CityDomainContext(TestURIs.Cities); // Abs URI so runs on desktop too LoadOperation lo = dp.Load(dp.GetCitiesInStateQuery("WA"), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(() => { if (lo.Error != null) Assert.Fail("LoadOperation.Error: " + lo.Error.Message); IEnumerable<City> expected = new CityData().Cities.Where(c => c.StateName.Equals("WA")); AssertSame(expected, dp.Cities); // Validate a [Editable(false)] property deserialized properly foreach (City c in dp.Cities) Assert.AreEqual(c.CountyName, c.CalculatedCounty); }); EnqueueTestComplete(); }
public void Cities_TestLoad() { CityDomainContext dp = new CityDomainContext(TestURIs.Cities); // Abs URI so runs on desktop too LoadOperation lo = dp.Load(dp.GetCitiesQuery(), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(() => { if (lo.Error != null) Assert.Fail("LoadOperation.Error: " + lo.Error.Message); IEnumerable<City> expected = new CityData().Cities; AssertSame(expected, dp.Cities); }); EnqueueTestComplete(); }
public void EditingMovesItemToFirstAndLastPositions() { CityData cities = new CityData(); this.LoadDomainDataSourceControl(); this.LoadSortedCities("Name", 0, true); this.EnqueueCallback(() => { this.ResetLoadState(); AssertHelper.AssertSequenceSorting(this._view.Cast<City>().Select(c => c.Name), ListSortDirection.Ascending, "The view order should now be sorted in the ascending direction."); City city = (City)this._view[3]; this._editableCollectionView.EditItem(city); city.Name = "AAA" + this._view.Cast<City>().First().Name; this._editableCollectionView.CommitEdit(); Assert.AreEqual(this._view.Cast<City>().First(), city, "The city should have moved to the first position in the view."); this._editableCollectionView.EditItem(city); city.Name = this._view.Cast<City>().Last().Name + "ZZZ"; this._editableCollectionView.CommitEdit(); Assert.AreEqual(this._view.Cast<City>().Last(), city, "The city should have moved to the last position in the view."); // Test the second to last item city = (City)this._view[this._view.Count - 2]; this._editableCollectionView.EditItem(city); city.Name = this._view.Cast<City>().Last().Name + "ZZZ"; this._editableCollectionView.CommitEdit(); Assert.AreEqual(this._view.Cast<City>().Last(), city, "The second-to-last city should have moved to the last position in the view."); }); EnqueueTestComplete(); }