public void AddFighter() { // Arrange: create a main context. var main = new MainContext(null); // Assert: no fighters should be added yet Assert.AreEqual(main.World.Fighters.Count, 0); // Act: create new fighter context var newFighterContext = new NewFighterContext(main); // Assert: context must be invalid (name not yet given) Assert.IsFalse(newFighterContext.IsValid); // Act: set name newFighterContext.Name = "newFighter"; // Assert: context must be valid now Assert.IsTrue(newFighterContext.IsValid); // Assert: we must be able to add the fighter now. Assert.IsTrue(newFighterContext.AddFighterCommand.CanExecute(null)); // Act: Add a new fighter newFighterContext.AddFighterCommand.Execute(null); // Assert: the new fighter must have been added and be the selected one. Assert.AreEqual(main.World.Fighters.Count, 1); Assert.AreEqual(main.SelectedFighter, main.World.Fighters[0]); // Assert: the fighter should have the correct name Assert.AreEqual(main.SelectedFighter.Name, newFighterContext.Name); }
private void HandleAddButtonClick(object sender, RoutedEventArgs e) { var mainContext = (MainContext)DataContext; var newFighterContext = new NewFighterContext(mainContext); var newFighterWindow = new NewFighterWindow { DataContext = newFighterContext, WindowStartupLocation = WindowStartupLocation.CenterOwner, Owner = Application.Current.MainWindow }; newFighterWindow.ShowDialog(); }