Esempio n. 1
0
        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
                });
            }
        }
Esempio n. 2
0
        public void Check_ShipTypeSizeWrong_ValidataionResultWithError(int size)
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 10
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = size, Count = 1
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            var result = _sut.Check();

            result.Should().NotBe(ValidationResult.Success);
            result.ErrorMessage.Should()
            .Be(
                $"An issue with settings in {SettingsRules.SettingFileName} file has been found. ShipTypes -> Size of 'Battleship' should be between {SettingsRules.MinimalShipTypeSize} and {SettingsRules.MaximalShipTypeSize}.");

            _configMock.Verify(x => x.Value, Times.AtLeast(1));
        }
        public void Check_NoAppSettingFile_ValidataionResultWithError()
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid      = null,
                ShipTypes = null
            });
            _sut = new SettingsChecker(_configMock.Object);

            var result = _sut.Check();

            result.Should().NotBe(ValidationResult.Success);
            result.ErrorMessage.Should().Be($"An issue with settings in {SettingsRules.SettingFileName} file has been found. All elements of setting file are missing or no {SettingsRules.SettingFileName} file has been found.");
        }
        public void Check_ShipCountOk_NoExceptionIsThrown(int count)
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 10
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = 5, Count = count
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            _sut.Check();
        }
        public void Check_IssueWithGrid_ValidataionResultWithError()
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = 5, Count = 1
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            var result = _sut.Check();

            result.Should().NotBe(ValidationResult.Success);
            result.ErrorMessage.Should().Be($"An issue with settings in {SettingsRules.SettingFileName} file has been found. Lack of Grid setting.");
        }
        public void Check_ShipTypeSizeOk_NoExceptionIsThrown(int size)
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 10
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = size, Count = 1
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            var result = _sut.Check();

            result.Should().Be(ValidationResult.Success);
        }
        public void Check_ShipTypeNameAndShipCountNameAreTheSame_NoExceptionIsThrown()
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 10
                },
                ShipTypes = new List <ShipTypeSettings>
                {
                    new ShipTypeSettings {
                        Name = "Destroyer", Size = 4, Count = 2
                    }, new ShipTypeSettings {
                        Name = "Battleship", Size = 5, Count = 1
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            _sut.Check();
        }
        public void Check_GridRowCountWrong_ValidataionResultWithError(int rowCount)
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = rowCount
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = 4, Count = 5
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            var result = _sut.Check();

            result.Should().NotBe(ValidationResult.Success);
            result.ErrorMessage.Should().Be($"An issue with settings in {SettingsRules.SettingFileName} file has been found. Grid -> RowCount should be between {SettingsRules.MinimalGridRowCount} and {SettingsRules.MaximalGridRowCount}.");
        }
Esempio n. 9
0
        public void Check_IssueWithShipCount_ValidataionResultWithError()
        {
            _configMock.Setup(x => x.Value)
            .Returns(new AppSettings
            {
                Grid = new GridSettings {
                    ColumnCount = 10, RowCount = 10
                },
                ShipTypes = new List <ShipTypeSettings> {
                    new ShipTypeSettings {
                        Name = "Battleship", Size = 5
                    }
                }
            });
            _sut = new SettingsChecker(_configMock.Object);

            var result = _sut.Check();

            result.Should().NotBe(ValidationResult.Success);
            result.ErrorMessage.Should().Be($"An issue with settings in {SettingsRules.SettingFileName} file has been found. Lack of ShipTypes -> Count of 'Battleship' setting.");

            _configMock.Verify(x => x.Value, Times.AtLeast(1));
        }