Example #1
0
        static async Task Main(string[] args)
        {
            var command = new ImportPokemonCommand();

            await command.ImportPokemon(@"App_Data\data.json");

            Console.ReadKey();
        }
Example #2
0
        public async Task ImportPokemonCommand_ShouldReadFile()
        {
            // Arrange
            var command = new ImportPokemonCommand(_loggerMock.Object, _databaseMock.Object, _pokemonReaderMock.Object, _fileSystemWrapperMock.Object);

            // Act
            await command.ImportPokemon(FakeFilePath);

            // Assert
            _fileSystemWrapperMock.Verify(x => x.ReadFile(FakeFilePath));
        }
Example #3
0
        public async Task ImportPokemonCommand_ShouldLogReceivedFile()
        {
            // Arrange
            var command = new ImportPokemonCommand(_loggerMock.Object, _databaseMock.Object, _pokemonReaderMock.Object, _fileSystemWrapperMock.Object);

            // Act
            await command.ImportPokemon(FakeFilePath);

            // Assert
            _loggerMock.Verify(x => x.Information($"Received pokemon to import: {FakeFilePath}..."));
        }
Example #4
0
        public async Task ImportPokemonCommand_ShouldReturnImportingStatusSuccess()
        {
            // Arrange
            var file    = new FileInfo("test.json");
            var command = new ImportPokemonCommand();

            // Act
            var result = await command.ImportPokemon(file.FullName);

            // Assert
            Assert.AreEqual(ImportingStatus.Success, result);
        }
Example #5
0
        public async Task ImportPokemonCommand_ShouldReturnImportingStatusError_WhenMissingFile()
        {
            // Arrange
            var file    = new FileInfo("dummy_file.json");
            var command = new ImportPokemonCommand();

            // Act
            var result = await command.ImportPokemon(file.FullName);

            // Assert
            Assert.AreEqual(ImportingStatus.Error, result);
        }
Example #6
0
        public async Task ImportPokemonCommand_ShouldReturnImportingStatusSuccess()
        {
            // Arrange
            var command = new ImportPokemonCommand(_loggerMock.Object, _databaseMock.Object, _pokemonReaderMock.Object, _fileSystemWrapperMock.Object);

            _fileSystemWrapperMock.Setup(x => x.ReadFile(FakeFilePath)).Returns(_json);
            _pokemonReaderMock.Setup(x => x.ReadPokemon(_json)).Returns(_expectedPokemon);

            // Act
            var result = await command.ImportPokemon(FakeFilePath);

            // Assert
            Assert.AreEqual(ImportingStatus.Success, result);
        }
Example #7
0
        public async Task ImportPokemonCommand_ShouldSaveDatabase()
        {
            // Arrange
            var command = new ImportPokemonCommand(_loggerMock.Object, _databaseMock.Object, _pokemonReaderMock.Object, _fileSystemWrapperMock.Object);

            _fileSystemWrapperMock.Setup(x => x.ReadFile(FakeFilePath)).Returns(_json);
            _pokemonReaderMock.Setup(x => x.ReadPokemon(_json)).Returns(_expectedPokemon);

            // Act
            await command.ImportPokemon(FakeFilePath);

            // Assert
            _databaseMock.Verify(x => x.SavePokemon(_expectedPokemon));
        }
Example #8
0
        static async Task Main(string[] args)
        {
            var command = new ImportPokemonCommand(
                new Logger(),
                new PokemonStore(),
                new PokemonReader(
                    new DateTimeWrapper(),
                    new Logger()),
                new FileSystemWrapper());

            await command.ImportPokemon(@"App_Data\data.json");

            Console.ReadKey();
        }
Example #9
0
        public async Task ImportPokemonCommand_ShouldReturnImportingStatusSuccess()
        {
            // Arrange
            string json = @"{ ""id"": 1, ""name"": ""Charmander"", ""type"": 1 }";

            File.WriteAllText("test.json", json);
            var file    = new FileInfo("test.json");
            var command = new ImportPokemonCommand();

            // Act
            var result = await command.ImportPokemon(file.FullName);

            File.Delete("test.json");

            // Assert
            Assert.AreEqual(ImportingStatus.Success, result);
        }