public void Update_ModelWithRemovedProfileSameNameOtherType_ProfileRemoved() { // Setup const string profileName = "A"; var soilProfile = new MacroStabilityInwardsSoilProfile1D(profileName, -2, CreateLayers1D()); var expectedRemovedProfile = new MacroStabilityInwardsStochasticSoilProfile(0.2, soilProfile); var newProfile = new MacroStabilityInwardsStochasticSoilProfile( 0.2, new MacroStabilityInwardsSoilProfile2D(profileName, CreateLayers2D(), Enumerable.Empty <MacroStabilityInwardsPreconsolidationStress>())); MacroStabilityInwardsStochasticSoilModel model = CreateValidModel(new[] { expectedRemovedProfile }); MacroStabilityInwardsStochasticSoilModel otherModel = CreateValidModel(new[] { newProfile }); // Call MacroStabilityInwardsStochasticSoilModelProfileDifference difference = model.Update(otherModel); // Assert CollectionAssert.AreEqual(new[] { newProfile }, difference.AddedProfiles); CollectionAssert.IsEmpty(difference.UpdatedProfiles); CollectionAssert.AreEqual(new[] { expectedRemovedProfile }, difference.RemovedProfiles); }
public void Update_ModelWithUpdatedStochasticSoilProfile_ProfileUpdated() { // Setup const string profileName = "A"; var soilProfile = new MacroStabilityInwardsSoilProfile1D(profileName, -2, CreateLayers1D()); var expectedUpdatedProfile = new MacroStabilityInwardsStochasticSoilProfile(0.2, soilProfile); MacroStabilityInwardsStochasticSoilModel model = CreateValidModel(new[] { expectedUpdatedProfile }); MacroStabilityInwardsStochasticSoilModel otherModel = CreateValidModel(new[] { new MacroStabilityInwardsStochasticSoilProfile(0.5, soilProfile) }); // Call MacroStabilityInwardsStochasticSoilModelProfileDifference difference = model.Update(otherModel); // Assert CollectionAssert.IsEmpty(difference.AddedProfiles); CollectionAssert.AreEqual(new[] { expectedUpdatedProfile }, difference.UpdatedProfiles); CollectionAssert.IsEmpty(difference.RemovedProfiles); }
public void Update_ModelWithAddedProfile_ProfileAdded() { // Setup MacroStabilityInwardsStochasticSoilModel model = CreateValidModel(new[] { CreateStochasticSoilProfile() }); var expectedAddedProfile = new MacroStabilityInwardsStochasticSoilProfile(0.2, new TestSoilProfile("Added Profile")); MacroStabilityInwardsStochasticSoilModel otherModel = CreateValidModel(new[] { CreateStochasticSoilProfile(), expectedAddedProfile }); // Call MacroStabilityInwardsStochasticSoilModelProfileDifference difference = model.Update(otherModel); // Assert AssertStochasticSoilModelAreEqual(otherModel, model); CollectionAssert.AreEqual(new[] { expectedAddedProfile }, difference.AddedProfiles); CollectionAssert.IsEmpty(difference.UpdatedProfiles); CollectionAssert.IsEmpty(difference.RemovedProfiles); }
public void Update_ModelWithUpdatedProperties_PropertiesUpdated() { // Setup var model = new MacroStabilityInwardsStochasticSoilModel("name", new[] { new Point2D(1, 2), new Point2D(4, 5) }, new[] { CreateStochasticSoilProfile() }); const string expectedName = "otherName"; var otherModel = new MacroStabilityInwardsStochasticSoilModel(expectedName, new[] { new Point2D(4, 2) }, new[] { CreateStochasticSoilProfile() }); // Call MacroStabilityInwardsStochasticSoilModelProfileDifference difference = model.Update(otherModel); // Assert AssertStochasticSoilModelAreEqual(otherModel, model); CollectionAssert.IsEmpty(difference.AddedProfiles); CollectionAssert.IsEmpty(difference.UpdatedProfiles); CollectionAssert.IsEmpty(difference.RemovedProfiles); }
private IEnumerable <IObservable> UpdateStochasticSoilModel(MacroStabilityInwardsStochasticSoilModel modelToUpdate, MacroStabilityInwardsStochasticSoilModel modelToUpdateFrom) { Dictionary <MacroStabilityInwardsStochasticSoilProfile, IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> > oldProfiles = modelToUpdate .StochasticSoilProfiles .ToDictionary(ssp => ssp, ssp => ssp.SoilProfile, new ReferenceEqualityComparer <MacroStabilityInwardsStochasticSoilProfile>()); MacroStabilityInwardsStochasticSoilModelProfileDifference difference = modelToUpdate.Update(modelToUpdateFrom); var affectedObjects = new List <IObservable>(); foreach (MacroStabilityInwardsStochasticSoilProfile removedProfile in difference.RemovedProfiles) { affectedObjects.AddRange(MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilProfileFromInput(FailureMechanism, removedProfile)); } foreach (MacroStabilityInwardsStochasticSoilProfile updatedProfile in difference.UpdatedProfiles) { if (!oldProfiles[updatedProfile].Equals(updatedProfile.SoilProfile)) { affectedObjects.AddRange(MacroStabilityInwardsDataSynchronizationService.ClearStochasticSoilProfileDependentData(FailureMechanism, updatedProfile)); } affectedObjects.Add(updatedProfile); } return(affectedObjects); }
public void Update_WithOtherModel_PropertiesUpdated() { // Setup const string equalProfileName = "nameA"; var stochasticProfileA = new MacroStabilityInwardsStochasticSoilProfile(0.5, CreateMacroStabilityInwardsSoilProfile(equalProfileName)); var stochasticProfileB = new MacroStabilityInwardsStochasticSoilProfile(0.5, CreateMacroStabilityInwardsSoilProfile("nameB")); MacroStabilityInwardsStochasticSoilModel model = CreateValidModel(new[] { stochasticProfileA, stochasticProfileB }); const string otherName = "other name"; var otherGeometry = new[] { new Point2D(2, 0), new Point2D(3, 0) }; var otherStochasticProfileA = new MacroStabilityInwardsStochasticSoilProfile(0.7, new TestSoilProfile(equalProfileName)); var otherStochasticProfileB = new MacroStabilityInwardsStochasticSoilProfile(0.3, CreateMacroStabilityInwardsSoilProfile("other profile name")); var otherModel = new MacroStabilityInwardsStochasticSoilModel(otherName, otherGeometry, new[] { otherStochasticProfileA, otherStochasticProfileB }); // Call MacroStabilityInwardsStochasticSoilModelProfileDifference difference = model.Update(otherModel); // Assert AssertStochasticSoilModelAreEqual(otherModel, model); Assert.AreSame(otherGeometry, model.Geometry); MacroStabilityInwardsStochasticSoilProfile[] stochasticSoilProfiles = model.StochasticSoilProfiles.ToArray(); Assert.AreEqual(2, stochasticSoilProfiles.Length); Assert.AreSame(stochasticProfileA, stochasticSoilProfiles[0]); Assert.AreSame(otherStochasticProfileA.SoilProfile, stochasticSoilProfiles[0].SoilProfile); Assert.AreNotSame(stochasticProfileB, stochasticSoilProfiles[1]); Assert.AreSame(otherStochasticProfileB.SoilProfile, stochasticSoilProfiles[1].SoilProfile); CollectionAssert.AreEqual(new[] { stochasticProfileA }, difference.UpdatedProfiles); CollectionAssert.AreEqual(new[] { stochasticProfileB }, difference.RemovedProfiles); CollectionAssert.AreEqual(new[] { otherStochasticProfileB }, difference.AddedProfiles); }