public void Get_Single_Id_Zero_Throws_InvalidOperationException() { int id = 0; var repository = new Mock <IPokemonRepository>(MockBehavior.Strict); var logic = new PokemonLogic(repository.Object); var ex = Assert.ThrowsException <InvalidOperationException>(() => logic.Get(id)); Assert.AreEqual($"Id must be at least 1. Id parameter: {id}.", ex.Message); repository.VerifyAll(); }
public void Get_Single_Id_Repository_Returns_Null_Valid() { int id = 1; var repository = new Mock <IPokemonRepository>(MockBehavior.Strict); repository.Setup(x => x.Get(id)) .Returns((Pokemon)null); var logic = new PokemonLogic(repository.Object); var result = logic.Get(id); Assert.IsNull(result); repository.VerifyAll(); }
public void Get_Single_Id_Valid() { int id = 1; var pokemon = new Pokemon { Id = 1, Name = "Bulbasaur", Types = new List <PokemonType> { PokemonType.Grass, PokemonType.Poison, }, Weaknesses = new List <PokemonType> { PokemonType.Fire, PokemonType.Psychic, PokemonType.Flying, PokemonType.Ice, }, Description = "There is a plant seed on its back right from the day this Pokémon is born. The seed slowly grows larger.", }; var repository = new Mock <IPokemonRepository>(MockBehavior.Strict); repository.Setup(x => x.Get(id)) .Returns(pokemon); var logic = new PokemonLogic(repository.Object); var result = logic.Get(id); Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); Assert.AreEqual(pokemon.Name, result.Name); Assert.AreEqual(pokemon.Types.Count, result.Types.Count); for (int i = 0; i < pokemon.Types.Count; i++) { Assert.AreEqual(pokemon.Types[i], result.Types[i]); } Assert.AreEqual(pokemon.Weaknesses.Count, result.Weaknesses.Count); for (int i = 0; i < pokemon.Weaknesses.Count; i++) { Assert.AreEqual(pokemon.Weaknesses[i], result.Weaknesses[i]); } Assert.AreEqual(pokemon.Description, result.Description); repository.VerifyAll(); }
public void Get_List_Ids_Negative_Throws_InvalidOperationException() { var ids = new List <int> { 1, -1, }; var repository = new Mock <IPokemonRepository>(MockBehavior.Strict); var logic = new PokemonLogic(repository.Object); var ex = Assert.ThrowsException <InvalidOperationException>(() => logic.Get(ids)); Assert.AreEqual("All Ids must be at least 1. One or more Ids were less than 1.", ex.Message); repository.VerifyAll(); }
public void Get_List_Ids_Repository_Returns_Null_Valid() { var ids = new List <int> { 1, 2, }; var repository = new Mock <IPokemonRepository>(MockBehavior.Strict); repository.Setup(x => x.Get(ids)) .Returns((IList <Pokemon>)null); var logic = new PokemonLogic(repository.Object); var resultList = logic.Get(ids); Assert.IsNull(resultList); repository.VerifyAll(); }
public void Get_List_Ids_Valid() { var ids = new List <int> { 1, 2, }; var pokemon1 = new Pokemon { Id = 1, Name = "Bulbasaur", Types = new List <PokemonType> { PokemonType.Grass, PokemonType.Poison, }, Weaknesses = new List <PokemonType> { PokemonType.Fire, PokemonType.Psychic, PokemonType.Flying, PokemonType.Ice, }, Description = "There is a plant seed on its back right from the day this Pokémon is born. The seed slowly grows larger.", }; var pokemon2 = new Pokemon { Id = 2, Name = "Ivysaur", Types = new List <PokemonType> { PokemonType.Grass, PokemonType.Poison, }, Weaknesses = new List <PokemonType> { PokemonType.Fire, PokemonType.Psychic, PokemonType.Flying, PokemonType.Ice, }, Description = "When the bulb on its back grows large, it appears to lose the ability to stand on its hind legs.", }; var pokemonList = new List <Pokemon> { pokemon1, pokemon2, }; var repository = new Mock <IPokemonRepository>(MockBehavior.Strict); repository.Setup(x => x.Get(ids)) .Returns(pokemonList); var logic = new PokemonLogic(repository.Object); var resultList = logic.Get(ids); Assert.IsNotNull(resultList); Assert.AreEqual(pokemonList.Count, resultList.Count); for (int i = 0; i < pokemonList.Count; i++) { var pokemon = pokemonList[i]; var result = resultList[i]; Assert.AreEqual(pokemon.Id, result.Id); Assert.AreEqual(pokemon.Name, result.Name); Assert.AreEqual(pokemon.Types.Count, result.Types.Count); for (int j = 0; j < pokemon.Types.Count; j++) { Assert.AreEqual(pokemon.Types[j], result.Types[j]); } Assert.AreEqual(pokemon.Weaknesses.Count, result.Weaknesses.Count); for (int j = 0; j < pokemon.Weaknesses.Count; j++) { Assert.AreEqual(pokemon.Weaknesses[j], result.Weaknesses[j]); } Assert.AreEqual(pokemon.Description, result.Description); } repository.VerifyAll(); }