コード例 #1
0
        public void Build_CantFindPlaceForAllShips_ExceptionIsThrown()
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 5
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = 5, Count = 5
                    }
                }
            });
            _gridMock.Setup(x => x.Build(10, 5));
            var ship = new Ship("Battleship", new Coordinate(0, 0), true, 5);

            _shipFactoryMock.Setup(x => x.BuildShip("Battleship"))
            .Returns(ship);
            _gridMock.Setup(x => x.TryPlaceShip(ship))
            .Returns(false);

            Action act = () => _sut.Build();

            act.Should().Throw <ApplicationException>().WithMessage("Can't find any place for new ship.");
        }
コード例 #2
0
ファイル: GameLogic.cs プロジェクト: TomaszChudak/Battleships
        public ResponseEnvelope <GridSize> StartNewGame()
        {
            try
            {
                var validationResult = _settingsChecker.Check();
                if (validationResult?.ErrorMessage != null)
                {
                    return new ResponseEnvelope <GridSize> {
                               Success = false, ErrorDescription = validationResult.ErrorMessage
                    }
                }
                ;

                _grid = _gridBuilder.Build();

                return(new ResponseEnvelope <GridSize> {
                    Success = true, Content = _grid.Size
                });
            }
            catch (Exception e)
            {
                return(new ResponseEnvelope <GridSize> {
                    Success = false, ErrorDescription = e.Message
                });
            }
        }
コード例 #3
0
        public void Build_CantFindPlaceForAllShips_ExceptionIsThrown()
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 5
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "BigShip", Size = 5, Count = 10
                    }
                }
            });

            Action act = () => _sut.Build();

            act.Should().Throw <ApplicationException>().WithMessage("Can't find any place for new ship.");
        }