public void BinarySerialisationRoundTrip() { GlobalDefinition gd = new GlobalDefinition(); gd.RandomCatchments(5, 1, 5); BinaryFormatter formatter = new BinaryFormatter(); GlobalDefinition result; using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, gd); stream.Position = 0; result = (GlobalDefinition)formatter.Deserialize(stream); } List <CellDefinition> rCells = result.GetFlatCellList(); foreach (CatchmentDefinition catchment in result) { Assert.That(catchment.Cells, Is.SubsetOf(rCells)); foreach (CellDefinition cell in catchment.Cells) { Assert.That(cell.CatchmentId, Is.EqualTo(catchment.Id)); } } AssertThatDefinitionsAreEquivalent(result, gd); }
public void XmlSerialisationToFileRoundTrip() { GlobalDefinition gd = new GlobalDefinition(); gd.RandomCatchments(3, 1, 5); var filename = Path.GetTempFileName(); try { gd.XmlSerialize(filename); GlobalDefinition result = SerializationHelper.XmlDeserialize <GlobalDefinition>(new FileInfo(filename)); AssertThatDefinitionsAreEquivalent(result, gd); // test the serialisation of the catchment id foreach (CatchmentDefinition cd in result) { foreach (CellDefinition cell in cd.Cells) { Assert.That(cell.CatchmentId, Is.EqualTo(cd.Id)); } } } finally { if (File.Exists(filename)) { File.Delete(filename); } } }
public void XmlSerialisationRoundTrip() { GlobalDefinition gd = new GlobalDefinition(); gd.RandomCatchments(5, 1, 5); string sgd = gd.XmlSerialize(); GlobalDefinition result = SerializationHelper.XmlDeserialize <GlobalDefinition>(sgd); List <CellDefinition> gdCells = gd.GetFlatCellList(); foreach (CatchmentDefinition catchment in gd) { Assert.That(catchment.Cells, Is.SubsetOf(gdCells)); } List <CellDefinition> rCells = result.GetFlatCellList(); foreach (CatchmentDefinition catchment in result) { Assert.That(catchment.Cells, Is.SubsetOf(rCells)); } foreach (CatchmentDefinition cd in result) { foreach (CellDefinition cell in cd.Cells) { Assert.That(cell.CatchmentId, Is.EqualTo(cd.Id)); } } AssertThatDefinitionsAreEquivalent(result, gd); }
public void CellsHaveCorrectParentCatchmentId() { globalDef.RandomCatchments(3, 1, 5); foreach (CatchmentDefinition cd in globalDef) { foreach (CellDefinition cell in cd.Cells) { Assert.That(cell.CatchmentId, Is.EqualTo(cd.Id)); } } }
public void TestCellLists() { GlobalDefinition gd = new GlobalDefinition(); gd.RandomCatchments(7); List <CellDefinition> gdCells = gd.GetFlatCellList(); foreach (CatchmentDefinition catchment in gd) { Assert.That(catchment.Cells, Is.SubsetOf(gdCells)); } }
private int AddComplexCatchments() { gd.RandomCatchments(22, 2, 2); gd.RandomCatchments(12, 12, 12); gd.RandomCatchments(4, 31, 31); return(gd.GetFlatCellList().Count); }