public void UnitSerializationTest1() { var data = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Unit u = new Unit { Id = 1, State = States.Stay, Position = new Position { X = 0, Y = 0 }, TargetPosition = new Position { X = 0, Y = 0 }, PositionF = new PositionF { X = 0, Y = 0 } }; var array = u.ToByteArray(); Assert.AreEqual(data.Length, array.Length); Assert.AreEqual(data, array); }
public void UnitDeserializationTest3() { Unit unit1 = new Unit { Id = 1, Position = new Position { X = 10, Y = 150 }, State = States.Stay, TargetPosition = new Position { X = 13, Y = 26 } }; var data = unit1.ToByteArray(); Unit unit2 = new Unit(); unit2.FromBytes(data); Assert.AreEqual(unit1.Id, unit2.Id); Assert.AreEqual(unit1.State, unit2.State); Assert.AreEqual(unit1.Position.X, unit2.Position.X); Assert.AreEqual(unit1.Position.Y, unit2.Position.Y); Assert.NotNull(unit2.TargetPosition); Assert.AreEqual(unit1.TargetPosition.X, unit2.TargetPosition.X); Assert.AreEqual(unit1.TargetPosition.Y, unit2.TargetPosition.Y); }