示例#1
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));
        }
示例#2
0
 public Archiver(
     ISettingsChecker settingsChecker,
     IAppSettings settings,
     IMessagesService messageService,
     IDecompressorFactory decompressorFactory,
     ICompressorFactory compressorFactory)
 {
     _settingsChecker     = settingsChecker ?? throw new ArgumentNullException(nameof(settingsChecker));
     _settings            = settings ?? throw new ArgumentNullException(nameof(settings));
     _messageService      = messageService ?? throw new ArgumentNullException(nameof(messageService));
     _decompressorFactory = decompressorFactory ?? throw new ArgumentNullException(nameof(decompressorFactory));
     _compressorFactory   = compressorFactory ?? throw new ArgumentNullException(nameof(compressorFactory));
 }
        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}.");
        }
示例#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));
        }
示例#10
0
 public GameLogic(ISettingsChecker settingsChecker, IGridBuilder gridBuilder, ICoordinateParser coordinateParser)
 {
     _settingsChecker  = settingsChecker;
     _gridBuilder      = gridBuilder;
     _coordinateParser = coordinateParser;
 }