public void Entity_EndEditValidatesPropertyValues() { // Start with an entity that has required properties satisfied, but has // an invalid property value (for StateName) Cities.City city = new Cities.City("This is an invalid state name") { Name = "Redmond" }; IEditableObject editableCity = (IEditableObject)city; StringLengthAttribute template = new StringLengthAttribute(2); string expectedMember = "StateName"; string expectedError = template.FormatErrorMessage(expectedMember); // Begin the edit transaction editableCity.BeginEdit(); #if SILVERLIGHT // End the edit transaction, which performs property and entity-level validation editableCity.EndEdit(); Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit"); Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit"); Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit"); Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit"); #else ExceptionHelper.ExpectException <ValidationException>(delegate { ((IEditableObject)city).EndEdit(); }, expectedError); #endif }
public void CheckEntitySetProtectedProperty() { CityEntityContainer ec = new CityEntityContainer(); ec.LoadEntities(new Entity[] { new City { Name = "Redmond", CountyName = "King", StateName = "WA" }, new City { Name = "Bellevue", CountyName = "King", StateName = "WA" } }); EntitySet<City> es = ec.Cities; City c1 = ec.Cities.First(); Assert.AreEqual(c1.GetEntitySet(), es); ec.Cities.Detach(c1); Assert.IsNull(c1.GetEntitySet()); City c2 = new City() { Name = "NewCity", CountyName = "King", StateName = "WA" }; ec.Cities.Add(c2); Assert.AreEqual(c2.GetEntitySet(), es); City c3 = new City() { Name = "AnotherNewCity", CountyName = "King", StateName = "WA" }; ec.Cities.Attach(c3); Assert.AreEqual(c3.GetEntitySet(), es); City c4 = ec.Cities.Last(); ec.Cities.Remove(c4); Assert.IsNull(c4.GetEntitySet()); }
public void Entity_EndEditValidatesRequiredProperties() { // Start with an entity that doesn't have its required properties // satisfied (Name is required) Cities.City city = new Cities.City(); IEditableObject editableCity = (IEditableObject)city; RequiredAttribute template = new RequiredAttribute(); string expectedMemberName = "CityName"; string expectedError = template.FormatErrorMessage(expectedMemberName); // Begin the edit transaction editableCity.BeginEdit(); #if SILVERLIGHT string expectedMember = "Name"; // End the edit transaction, which performs property and entity-level validation editableCity.EndEdit(); Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit"); Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit"); Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit"); Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit"); #else ExceptionHelper.ExpectException <ValidationException>(delegate { ((IEditableObject)city).EndEdit(); }, expectedError); #endif }
public void CancelingCurrencyChangeIsRespectedOnCommitEdit() { City first = new City { Name = "1" }; City second = new City { Name = "2" }; MockEntityContainer ec = new MockEntityContainer(); ec.CreateSet<City>(EntitySetOperations.All); IPagedEntityList pagedList = new MockPagedEntityList(ec.GetEntitySet<City>(), null); PagedEntityCollectionView view = new PagedEntityCollectionView(pagedList, () => { }); view.Add(first); view.Add(second); bool canChangeCurrency = true; CurrentChangingEventHandler changingHandler = (sender, e) => { if (!canChangeCurrency) { Assert.IsTrue(e.IsCancelable, "Event should be cancelable when commiting an edit."); e.Cancel = true; } }; EventHandler changedHandler = (sender, e) => { if (!canChangeCurrency) { Assert.Fail("Currency changes should only occur when canChangeCurrency is true."); } }; view.CurrentChanging += changingHandler; view.CurrentChanged += changedHandler; view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); Assert.IsTrue(view.MoveCurrentTo(second), "We should be able to move current to the second item."); // Commit an edit but do not allow the currency to change canChangeCurrency = false; view.EditItem(second); second.Name = "0"; view.CommitEdit(); Assert.AreEqual(view[1], second, "The edited item should not have moved."); // Commit an edit and this time allow the currency to change canChangeCurrency = true; view.EditItem(second); second.Name = "00"; view.CommitEdit(); Assert.AreEqual(view[0], second, "The edited item should have moved to the first position in the view."); }
public void ResetIgnoresUntrackedAddedEntities() { PagedEntityCollection pagedCollection = new PagedEntityCollection(p => { return true; }); MockEntitySet cities = LoadCities(false, pagedCollection); City toAdd = new City { Name = "New City", StateName = "ST", CountyName = "County" }; cities.Add(toAdd); Assert.AreEqual<int>(cities.Count - 1, pagedCollection.Count, "pagedCollection.Count should be one less than cities.Count after adding the city to the cities set"); Assert.IsFalse(pagedCollection.Contains(toAdd), "pagedCollection should not contain the city added to the cities set before the Reset is raised"); cities.ResetCollection(); Assert.AreEqual<int>(cities.Count - 1, pagedCollection.Count, "pagedCollection.Count should be one less than cities.Count after resetting the collection"); Assert.IsFalse(pagedCollection.Contains(toAdd), "pagedCollection should not contain the city added to the cities set after resetting the collection"); }
public void TestDirectChangeset_Cities() { for (int i = 0; i < 100; i++) { CityDomainService ds = new CityDomainService(); DomainServiceContext dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew")), DomainOperationType.Submit); ds.Initialize(dsc); List<ChangeSetEntry> entries = new List<ChangeSetEntry>(); for (int j = 0; j < 500; j++) { City newCity = new City() { Name = "Toledo", CountyName = "Lucas", StateName = "OH" }; entries.Add(new ChangeSetEntry(j, newCity, null, DomainOperation.Insert)); } ChangeSetProcessor.Process(ds, entries); Assert.IsFalse(entries.Any(p => p.HasError)); } }
public void GroupingAddToExistingGroup() { EnqueueCallback(() => { this._dds.AutoLoad = false; this._dds.QueryName = "GetCitiesQuery"; this._dds.DomainContext = new CityDomainContext(); this._dds.GroupDescriptors.Add(new GroupDescriptor("StateName")); this._dds.SortDescriptors.Add(new SortDescriptor("Name", ListSortDirection.Ascending)); this._dds.Load(); }); this.AssertLoadingData(); EnqueueCallback(() => { this.ResetLoadState(); AssertHelper.AssertSequenceSorting(this._view.Cast<City>().Select(c => c.StateName), ListSortDirection.Ascending, "The cities should be sorted by state name after the initial load"); string existingStateName = this._view.Cast<City>().Last().StateName; City toAdd = new City { Name = "Added City", StateName = existingStateName, CountyName = "County" }; int originalCount = this._view.Count; this._view.Add(toAdd); Assert.AreEqual<int>(originalCount + 1, this._view.Count, "The count should increment by one after adding the city"); Assert.IsTrue(this._view.Contains(toAdd), "The added city should be in the view"); Assert.AreEqual<int>(this._view.IndexOf(toAdd), this._view.CurrentPosition, "CurrentPosition should match the index of the item added"); AssertHelper.AssertSequenceSorting(this._view.Cast<City>().Select(c => c.StateName), ListSortDirection.Ascending, "The cities should be sorted by state name after adding the city"); }); EnqueueTestComplete(); }
public void Validation_Cities_Fail_Set_ReadOnly_Property() { ExceptionHelper.ExpectInvalidOperationException(delegate() { City city = new City { CalculatedCounty = "King County" }; }, "The CalculatedCounty property is read only."); }
public void AssignCityZoneIfAuthorized(City city, string zoneName) { this.AssignCityZone(city, zoneName); }
public void AssignCityZone(City city, string zoneName) { if (zoneName.StartsWith("Zone")) { int zoneID = 0; if (int.TryParse(zoneName.Replace("Zone", ""), out zoneID)) { city.ZoneID = zoneID; } } city.ZoneName = zoneName; }
public void UpdateCity(City city) { System.Diagnostics.Debug.WriteLine("CityDomainService.UpdateCity(" + city.ToString() + ")"); this.DeleteCity(city); this._cityData.Cities.Add(city); }
public void ProcessCity(City city, string data) { }
public void AutoAssignCityZone(City city) { city.ZoneID++; city.ZoneName = string.Format("Auto_Zone{0}", city.ZoneID.ToString()); }
public string GetStateIfUser(City city) { return(city.StateName); }
public void GroupingAddToNewGroupWithinNewGroup() { this.LoadCitiesGroupedByStateThenCounty(); EnqueueCallback(() => { City toAdd = new City { Name = "Added City", StateName = "ST", CountyName = "County" }; int originalCount = this._view.Count; this._view.Add(toAdd); Assert.AreEqual<int>(originalCount + 1, this._view.Count, "The count should increment by one after adding the city"); Assert.IsTrue(this._view.Contains(toAdd), "The added city should be in the view"); Assert.AreEqual<int>(this._view.IndexOf(toAdd), this._view.CurrentPosition, "CurrentPosition should match the index of the item added"); this.AssertStateCountyCitySorting("After Add"); }); EnqueueTestComplete(); }
public void GroupingAddToExistingGroupWithinExistingGroup() { this.LoadCitiesGroupedByStateThenCounty(); EnqueueCallback(() => { // Find an existing state and county that has more than 1 city IEnumerable<City> cities = this._view.Cast<City>(); City reference = (from city in cities let state = city.StateName let county = city.CountyName let countyCities = cities.Where(c => c.StateName == state && c.CountyName == county).Distinct().Count() where countyCities > 1 orderby countyCities descending select city).FirstOrDefault(); if (reference == null) { Assert.Inconclusive("This test relies on a county with more than 1 city"); } // Force two of the existing elements to have city names such that we can insert in between them // This will test to ensure the new item isn't just put at the beginning or end, but rather // sorted correctly within the second-level group. IEnumerable<City> citiesInCounty = cities.Where(c => c.StateName == reference.StateName && c.CountyName == reference.CountyName); City first = citiesInCounty.ElementAt(0); this._editableCollectionView.EditItem(first); // Here we're using ApplyState to allow us to set a PK member w/o validation failure // since PK members cannot be changed. This test should really be based on an association // not involving PK, but the test is still valid this way. first.ApplyState(new Dictionary<string, object> { { "Name", "AAAAA" } }); this._editableCollectionView.CommitEdit(); City second = citiesInCounty.ElementAt(1); this._editableCollectionView.EditItem(second); second.ApplyState(new Dictionary<string, object> { { "Name", "ZZZZZ" } }); this._editableCollectionView.CommitEdit(); this.AssertStateCountyCitySorting("After splitting elements 0 and 1 apart"); City toAdd = new City { Name = "MMMMM", StateName = reference.StateName, CountyName = reference.CountyName }; int originalCount = this._view.Count; this._view.Add(toAdd); Assert.AreEqual<int>(originalCount + 1, this._view.Count, "The count should increment by one after adding the city"); Assert.IsTrue(this._view.Contains(toAdd), "The added city should be in the view"); Assert.AreEqual<int>(this._view.IndexOf(toAdd), this._view.CurrentPosition, "CurrentPosition should match the index of the item added"); this.AssertStateCountyCitySorting("After Add"); }); EnqueueTestComplete(); }
public void ProcessCity(City city, IntPtr intPtrArg) { }
public void ProcessCity(City city) { }
public void ProcessCity(City city, IEnumerable<City> ienumerableArg) { }
public string ProcessCity(City city) { return null; }
public void ProcessCity(City city, List<City> listArg) { }
public void DeleteCity(City city) { System.Diagnostics.Debug.WriteLine("CityDomainService.DeleteCity(" + city.ToString() + ")"); City cityInList = this._cityData.Cities.FirstOrDefault(c => string.Equals(c.Name, city.Name) && string.Equals(c.StateName, city.StateName) && string.Equals(c.CountyName, city.CountyName)); if (cityInList == null) { throw new InvalidOperationException("City must be in our list first: " + city); } this._cityData.Cities.Remove(cityInList); }
public void ProcessCity(City city, UIntPtr uintPtrArg) { }
public void ProcessCity(City city, byte[] data) { this.Invoked += "ProcessCity_"; this.InputData = data; }
public string GetStateIfUser(City city) { return city.StateName; }
public void ProcessCity(City city, County county) { }
public void GroupingEditItemToRemoveGroupAndCreateNewNestedGroup() { this.LoadCitiesGroupedByStateThenCounty(); EnqueueCallback(() => { City toAddAndEdit = new City { Name = "Add and Edit", StateName = "AA", CountyName = "County" }; this._view.Add(toAddAndEdit); Assert.IsTrue(this._view.Contains(toAddAndEdit), "After being added"); toAddAndEdit.StateName = "BB"; Assert.IsTrue(this._view.Contains(toAddAndEdit), "After being edited directly"); this.AssertStateCountyCitySorting("After being edited directly"); this._editableCollectionView.EditItem(toAddAndEdit); toAddAndEdit.StateName = "CC"; this._editableCollectionView.CommitEdit(); Assert.IsTrue(this._view.Contains(toAddAndEdit), "After being edited with EditItem/CommitEdit"); this.AssertStateCountyCitySorting("After being edited with EditItem/CommitEdit"); }); EnqueueTestComplete(); }
public string Process_EntityParam(City city) { return city.Name; }
public void GroupingAddAndRemoveItem() { EnqueueCallback(() => { this._dds.AutoLoad = false; this._dds.QueryName = "GetCitiesQuery"; this._dds.DomainContext = new CityDomainContext(); this._dds.GroupDescriptors.Add(new GroupDescriptor("StateName")); this._dds.Load(); }); this.AssertLoadingData(); EnqueueCallback(() => { this.ResetLoadState(); City toAddAndRemove = new City { Name = "Add and Remove", StateName = "ST", CountyName = "County" }; int originalCount = this._view.Count; this._view.Add(toAddAndRemove); Assert.AreEqual<int>(originalCount + 1, this._view.Count, "The count should increment by one after adding the city"); Assert.IsTrue(this._view.Contains(toAddAndRemove), "The added city should be in the view"); List<NotifyCollectionChangedEventArgs> actions = new List<NotifyCollectionChangedEventArgs>(); this._collectionView.CollectionChanged += (s, e) => actions.Add(e); this._view.Remove(toAddAndRemove); Assert.AreEqual<int>(originalCount, this._view.Count, "The count should decrement by one after removing the city"); Assert.IsFalse(this._view.Contains(toAddAndRemove), "The removed city should no longer be in the view"); Assert.AreEqual<int>(1, actions.Count, "There should have been one CollectionChanged event removing the city"); Assert.AreEqual<NotifyCollectionChangedAction>(NotifyCollectionChangedAction.Remove, actions.Single().Action, "The single CollectionChanged event action should have been a Remove"); Assert.AreEqual<int>(1, actions.Single().OldItems.Count, "There should have been one element in OldItems"); Assert.AreEqual<City>(toAddAndRemove, actions.Single().OldItems.Cast<City>().Single(), "The OldItems item should have been our city that was removed"); }); EnqueueTestComplete(); }
public string Process_EntitiesAndSimpleParams(Zip zip, City city, string otherParam) { return string.Format("{0}_{1}_{2}", zip.Code.ToString(), city.Name, otherParam); }
public void GroupingAddToNewGroupWithinExistingGroup() { this.LoadCitiesGroupedByStateThenCounty(); EnqueueCallback(() => { // Find an existing state that has more than 1 county so that we can insert into the middle IEnumerable<City> cities = this._view.Cast<City>(); string existingStateName = (from city in cities let state = city.StateName let counties = cities.Where(c => c.StateName == state).Distinct().Count() where counties > 1 orderby counties descending select state).FirstOrDefault(); if (existingStateName == null) { Assert.Inconclusive("This test relies on a state with more than 1 county"); } // Force two of the existing elements to have county names such that we can insert in between them // This will test to ensure the new group isn't just put at the beginning or end, but rather // sorted correctly within the first-level group. IEnumerable<City> citiesInState = cities.Where(c => c.StateName == existingStateName); City first = citiesInState.ElementAt(0); this._editableCollectionView.EditItem(first); first.CountyName = "AAAAA"; this._editableCollectionView.CommitEdit(); City second = citiesInState.ElementAt(1); this._editableCollectionView.EditItem(second); second.CountyName = "ZZZZZ"; this._editableCollectionView.CommitEdit(); this.AssertStateCountyCitySorting("After splitting elements 0 and 1 apart"); City toAdd = new City { Name = "Added City", StateName = existingStateName, CountyName = "MMMMM" }; int originalCount = this._view.Count; this._view.Add(toAdd); Assert.AreEqual<int>(originalCount + 1, this._view.Count, "The count should increment by one after adding the city"); Assert.IsTrue(this._view.Contains(toAdd), "The added city should be in the view"); Assert.AreEqual<int>(this._view.IndexOf(toAdd), this._view.CurrentPosition, "CurrentPosition should match the index of the item added"); this.AssertStateCountyCitySorting("After Add"); }); EnqueueTestComplete(); }
public void Approve(City city, string param1, string param2) { }
public void Approve(City city) { }