public void Convert()
        {
            // Arrange: create a world model.
            var world = new World();

            var spitfire = new Fighter { Name = "Spitfire", PositionX = 100, PositionY = 200, Rotation = 45 };
            var stuka = new Fighter { Name = "Stuka", PositionX = 300, PositionY = 400, Rotation = 90, Target = spitfire };

            world.Fighters.Add(spitfire);
            world.Fighters.Add(stuka);

            // Act: convert to view model.
            var mainContext = new MainContext(null);
            var worldContext = new WorldContext(mainContext, world);

            // Assert: verify view model
            Assert.IsNotNull(worldContext.Fighters);
            Assert.AreEqual(2, worldContext.Fighters.Count);

            FighterContext spitfireContext = worldContext.Fighters.FirstOrDefault(f => f.Name == "Spitfire");
            Assert.IsNotNull(spitfireContext);
            Assert.AreEqual("Spitfire", spitfireContext.Name);
            Assert.AreEqual(100.0, spitfireContext.Position.X);
            Assert.AreEqual(200.0, spitfireContext.Position.Y);
            Assert.AreEqual(45.0, spitfireContext.Rotation);
            Assert.AreEqual(null, spitfireContext.Target);

            FighterContext stukaContext = worldContext.Fighters.FirstOrDefault(f => f.Name == "Stuka");
            Assert.IsNotNull(stukaContext);
            Assert.AreEqual("Stuka", stukaContext.Name);
            Assert.AreEqual(300.0, stukaContext.Position.X);
            Assert.AreEqual(400.0, stukaContext.Position.Y);
            Assert.AreEqual(90.0, stukaContext.Rotation);
            Assert.AreEqual(spitfireContext, stukaContext.Target);

            // Act: convert back to model.
            world = worldContext.CreateModel();

            // Assert: correctness of created model.
            Assert.IsNotNull(world.Fighters);
            Assert.AreEqual(2, world.Fighters.Count);

            spitfire = world.Fighters.FirstOrDefault(f => f.Name == "Spitfire");
            Assert.IsNotNull(spitfire);
            Assert.AreEqual("Spitfire", spitfire.Name);
            Assert.AreEqual(100, spitfire.PositionX);
            Assert.AreEqual(200, spitfire.PositionY);
            Assert.AreEqual(45, spitfire.Rotation);
            Assert.AreEqual(null, spitfire.Target);

            stuka = world.Fighters.FirstOrDefault(f => f.Name == "Stuka");
            Assert.IsNotNull(stuka);
            Assert.AreEqual("Stuka", stuka.Name);
            Assert.AreEqual(300, stuka.PositionX);
            Assert.AreEqual(400, stuka.PositionY);
            Assert.AreEqual(90, stuka.Rotation);
            Assert.AreEqual(spitfire, stuka.Target);
        }
 protected void New(WorldContext world)
 {
     ClearHistory();
     SelectedFighter = null;
     World = world;
 }
        public void Open(FilePathProvider filePathProvider)
        {
            string newFilePath = filePathProvider(FilePath);

            if (newFilePath != null)
            {
                using (var stream = File.OpenRead(newFilePath))
                {
                    World worldModel = DogFight.World.LoadFrom(stream);
                    var worldContext = new WorldContext(this, worldModel);
                    New(worldContext);

                    FilePath = newFilePath;
                }
            }
        }
 public FighterContext(WorldContext world)
 {
     World = world;
     ClearTargetCommand = CommandFactory.Create(ClearTarget, CanClearTarget, this, TargetProperty);
 }