using System.Collections.Generic; using System.Linq; using Deltares.Dam.Data; using Deltares.Dam.Data.Sensors; using Deltares.Standard.Extensions; using NUnit.Framework; namespace Deltares.Dam.Tests.Sensors { [TestFixture] public class GroupTest { #region Setup [TestFixtureSetUp] public void FixtureSetup() { } [TestFixtureTearDown] public void FixtureTearDown() { } [SetUp] public void TestSetup() { } [TearDown] public void TestTearDown() { } #endregion /// /// This test was setup because the xml serializer had an issue with lists of enum types /// At the same time it is also good to test if all the required properties get the same value /// after deserializing the object state /// [Test] public void Deserialization_ValidXmlString_ShouldResturnValidGroupWithoutException() { // setup var sensor1 = new Sensor() {Name = "Sensor1", ID = 1}; var sensor2 = new Sensor {Name = "Sensor2", ID = 2}; var group1 = new Group { ID = 1, SensorArray = new[] { sensor1, sensor2 }, // SensorRelativeLocationsArray = new[] // { // new KeyValuePair(sensor1.ID, 10), // new KeyValuePair(sensor2.ID, 20), // }, }; // call var xml = group1.Serialize(); Group group2 = Group.Deserialize(xml); // assert Assert.AreEqual(group1.ID, group2.ID); //Assert.AreEqual(group2.Selection.Count(), group2.SensorRelativeLocations.Count()); foreach (Sensor sensor in group1.Selection) { Assert.IsTrue(group2.Selection.Any( s => s.Name == sensor.Name && s.ID == sensor.ID && s.Depth.AlmostEquals(sensor.Depth))); //Assert.IsTrue(group2.SensorRelativeLocations.Any(s => s.Key == sensor)); } } } }