예제 #1
0
        public void PokemonReader_ShouldLogDeserializationOfPokemon()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            var reader = new PokemonReader(_dateTimeWrapperMock.Object, _loggerMock.Object);

            // Act
            reader.ReadPokemon(_json);

            // Assert
            _loggerMock.Verify(x => x.Information($"Pokemon deserialized. Id: {_expectedPokemon.Id}, Name: {_expectedPokemon.Name}, Type: {_expectedPokemon.Type}, Timestamp: {_expectedPokemon.Timestamp}"));
        }
예제 #2
0
        public void PokemonReader_ShouldDeserializePokemon()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            var reader = new PokemonReader(_dateTimeWrapperMock.Object, _loggerMock.Object);

            // Act
            var result = reader.ReadPokemon(_json);

            // Assert
            result.Should().BeEquivalentTo(_expectedPokemon);
        }
예제 #3
0
        public void EntityReader_ShouldLogValidationResult()
        {
            // Arrange
            _dateTimeWrapperMock.Setup(x => x.GetNow()).Returns(new DateTime(2010, 1, 1));
            _databaseMock.Setup(x => x.IsValidationEnabled()).Returns(true);
            var reader = new PokemonReader(_dateTimeWrapperMock.Object, _loggerMock.Object, _databaseMock.Object);

            // Act
            reader.ReadPokemon(_json);

            // Assert
            _loggerMock.Verify(x => x.Information($"Validation result: {true}"));
        }
예제 #4
0
        public void PokemonReader_ShouldDeserializePokemon()
        {
            // Arrange
            var expectedPokemon = new Pokemon
            {
                Id   = 1,
                Name = "Charmander",
                Type = PokemonType.Fire
            };
            var reader = new PokemonReader();

            // Act
            var result = reader.ReadPokemon(_json);

            // Assert
            Assert.AreEqual(expectedPokemon.Id, result.Id);
            Assert.AreEqual(expectedPokemon.Name, result.Name);
            Assert.AreEqual(expectedPokemon.Type, result.Type);
        }
        public async Task <ImportingStatus> ImportPokemon(string filePath)
        {
            try
            {
                Console.WriteLine($"Received pokemon to import: {filePath}...");

                var fileContent = File.ReadAllText(filePath);
                var reader      = new PokemonReader();
                var pokemon     = reader.ReadPokemon(fileContent);

                var database = new PokemonStore();
                await database.SavePokemon(pokemon);

                Console.WriteLine($"Pokemon saved. Id: {pokemon.Id}, Name: {pokemon.Name}, Type: {pokemon.Type}, Timestamp: {pokemon.Timestamp}");

                return(ImportingStatus.Success);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error! " + e.Message);
                return(ImportingStatus.Error);
            }
        }