private void OnCreateNewBoard(object parameter) { if (parameter == null) { this.Minesweeper = MinesweeperFactory.Create(this.Minesweeper); return; } if (parameter is BoardSize) { this.Minesweeper = MinesweeperFactory.Create((BoardSize)parameter); } else if (parameter is string) { var text = (string)parameter; if (text.StartsWith("*")) { var boardSize = new BoardSize(this.Minesweeper.Tiles.Width, this.Minesweeper.Tiles.Height, this.Minesweeper.MineCount); this.Minesweeper = MinesweeperFactory.Create(boardSize); } else { var boardSize = BoardSize.Parse(parameter.ToString()); this.Minesweeper = MinesweeperFactory.Create(boardSize); } } else { throw new ArgumentException("parameter must either be of type String or BoardSize, or be set to null."); } }
public void TestParse(string source, int x, int y) { var prop = (BoardSize)BoardSize.Parse(new List <string>(new[] { source })); Assert.NotNull(prop); Assert.Equal(x, prop.x); Assert.Equal(y, prop.y); if (x == y) { Assert.Equal($"SZ[{x}]", prop.StringValue()); } else { Assert.Equal($"SZ[{source}]", prop.StringValue()); } }