public void CannotRemoveSectionTypesThatAreUsedByCrossSections() { //setup a network with a crossection and a sectiontype that is used var channel = new Channel(); var network = new HydroNetwork(); var crossSectionZW = new CrossSectionDefinitionZW(); var crossSectionSectionType = new CrossSectionSectionType(); crossSectionZW.Sections.Add(new CrossSectionSection { SectionType = crossSectionSectionType }); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionZW, 0.0); network.CrossSectionSectionTypes.Add(crossSectionSectionType); network.Branches.Add(channel); //action! remove the sectiontype network.CrossSectionSectionTypes.Remove(crossSectionSectionType); //still have 2. one plus a 'default'? Assert.AreEqual(2, network.CrossSectionSectionTypes.Count); Assert.IsTrue(network.CrossSectionSectionTypes.Contains(crossSectionSectionType)); }
private HydroNetwork GetNetwork() { var network = new HydroNetwork(); var crossSectionSectionType = new CrossSectionSectionType { Name = "Jan" }; network.CrossSectionSectionTypes.Add(crossSectionSectionType); crossSectionSectionType.Id = 666;//debug easy by idd var from = new HydroNode(); var to = new HydroNode(); network.Nodes.Add(from); network.Nodes.Add(to); var channel = new Channel { Source = from, Target = to }; network.Branches.Add(channel); var crossSectionXYZ = new CrossSectionDefinitionXYZ { Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) }) }; crossSectionXYZ.Sections.Add(new CrossSectionSection { SectionType = crossSectionSectionType }); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0); return(network); }
public void UnsubscribeOldSectionType() { var section = new CrossSectionSection(); var old = new CrossSectionSectionType { Name = "old" }; section.SectionType = old; var newType = new CrossSectionSectionType { Name = "new" }; section.SectionType = newType; ((INotifyPropertyChange)section).PropertyChanging += (s, e) => Assert.Fail("FAAAAAAAAAAAAAAIL!"); old.Name = "hoi"; }
public void CopyFrom() { var type = new CrossSectionSectionType { Name = "Main" }; var sourceDefinition = new CrossSectionDefinitionYZ(); sourceDefinition.Sections.Add(new CrossSectionSection { MinY = 0, MaxY = 10, SectionType = type }); var sourceCrossSection = new CrossSection(sourceDefinition); var targetDefinition = new CrossSectionDefinitionYZ(); var targetCrossSection = new CrossSection(targetDefinition); targetCrossSection.CopyFrom(sourceCrossSection); Assert.AreEqual("Main", targetCrossSection.Definition.Sections[0].SectionType.Name); }
public void CloneHydroNetworkWithCrossSectionSectionTypes() { var network = new HydroNetwork(); var crossSectionSectionType = new CrossSectionSectionType { Name = "Jan" }; network.CrossSectionSectionTypes.Add(crossSectionSectionType); crossSectionSectionType.Id = 666;//debug easy by idd var from = new HydroNode(); var to = new HydroNode(); network.Nodes.Add(from); network.Nodes.Add(to); var channel = new Channel { Source = from, Target = to }; network.Branches.Add(channel); var crossSectionXYZ = new CrossSectionDefinitionXYZ { Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) }) }; crossSectionXYZ.Sections.Add(new CrossSectionSection { SectionType = crossSectionSectionType }); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0); var clonedHydroNetwork = (IHydroNetwork)network.Clone(); clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1); var cloneCrossSection = clonedHydroNetwork.CrossSections.FirstOrDefault(); var clonedType = clonedHydroNetwork.CrossSectionSectionTypes.FirstOrDefault(t => t.Name == "Jan"); //the type should be cloned Assert.AreNotEqual(clonedType, crossSectionSectionType); //the crosssection reference should be updated to use the cloned type Assert.AreEqual(clonedType, cloneCrossSection.Definition.Sections[0].SectionType); }
public void RemoveInvalidSections() { var mainType = new CrossSectionSectionType { Name = "Main" }; var crossSection = new CrossSectionDefinitionZW(); crossSection.Sections.Add(new CrossSectionSection { SectionType = mainType }); Assert.AreEqual(1, crossSection.Sections.Count); //now rename the type and call mainType.Name = "newName"; crossSection.RemoveInvalidSections(); Assert.AreEqual(0, crossSection.Sections.Count); }
public void Clone() { var crossSection = new TestCrossSectionDefinition("Test", 0) { Thalweg = 3.0, }; var type = new CrossSectionSectionType(); crossSection.Sections.Add(new CrossSectionSection { MinY = 0, MaxY = 10, SectionType = type }); var clone = (TestCrossSectionDefinition)crossSection.Clone(); Assert.AreEqual(crossSection.Thalweg, clone.Thalweg); Assert.AreEqual(crossSection.Sections.Count, clone.Sections.Count); Assert.AreNotSame(crossSection.Sections[0], clone.Sections[0]); Assert.AreEqual(crossSection.Sections[0].MinY, clone.Sections[0].MinY); Assert.AreEqual(crossSection.Sections[0].MaxY, clone.Sections[0].MaxY); Assert.AreSame(crossSection.Sections[0].SectionType, clone.Sections[0].SectionType); }