public static List<Animal> SearchAnd(IEnumerable<Animal> animalList, Animal seachAnimal) { if (!string.IsNullOrEmpty(seachAnimal.Name)) { animalList = animalList.Where(x => x.Name == seachAnimal.Name); } if (seachAnimal.NumberOfLegs != null) { animalList = animalList.Where(x => x.NumberOfLegs == seachAnimal.NumberOfLegs); } if (seachAnimal.NumberOfWings != null) { animalList = animalList.Where(x => x.NumberOfWings == seachAnimal.NumberOfWings); } if (seachAnimal.CanFly != null) { animalList = animalList.Where(x => x.CanFly == seachAnimal.CanFly); } if (seachAnimal.CanGoUnderwater != null) { animalList = animalList.Where(x => x.CanGoUnderwater == seachAnimal.CanGoUnderwater); } if (!string.IsNullOrEmpty(seachAnimal.Voice)) { animalList = animalList.Where(x => x.Voice == seachAnimal.Voice); } return animalList.ToList(); }
public static List<Animal> SearchOr(List<Animal> animalList, Animal seachAnimal) { var resultsAnimals = from animal in animalList where ((animal.Name != null && seachAnimal.Name != null && seachAnimal.Name != string.Empty) && animal.Name.Contains(seachAnimal.Name)) || ((animal.NumberOfLegs != null && seachAnimal.NumberOfLegs != null) && animal.NumberOfLegs == seachAnimal.NumberOfLegs) || ((animal.NumberOfWings != null && seachAnimal.NumberOfWings != null) && animal.NumberOfWings == seachAnimal.NumberOfWings) || (seachAnimal.CanFly != null && animal.CanFly != null && animal.CanFly == seachAnimal.CanFly) || (seachAnimal.CanGoUnderwater != null && animal.CanGoUnderwater != null && animal.CanGoUnderwater == seachAnimal.CanGoUnderwater) || ((animal.Voice != null && seachAnimal.Voice != null && seachAnimal.Voice != string.Empty) && animal.Voice.Contains(seachAnimal.Voice)) select animal; return resultsAnimals.ToList(); }
public void GetByNumberOfLegsOfLegsNull() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { NumberOfLegs = null }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 0); }
public void GetCanFlyIsFalse() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { CanFly = false }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 3); }
public static string Talk(Animal animal) { return animal.Voice; }
public void GetNumberOfWingsIsZero() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { NumberOfWings = 0 }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 3); }
public void GetVoiceWoof() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Voice = "Woof" }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 1); }
public void GetDogByName() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Name = "Dog" }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals[0].Name, "Dog"); }
public void GetFourLeggedCatThatMeows() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Name = "Cat", Voice = "Meow", NumberOfLegs = 4 }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 2); //Might seem odd buts its a or seach }
public void GetCountNoneWhereNameNull() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Name = null }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 0); }
public void GetCatThatMeowsEveyThingElseNull() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Name = "Cat", CanFly = null, CanGoUnderwater = null, NumberOfLegs = null, NumberOfWings = null, Voice = null }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 1); }
public void GetCatThatMeows() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Name = "Cat", Voice = "Meow" }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 1); }
public void GetCanGoUnderwaterIsTrue() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { CanGoUnderwater = true }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchOr(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 1); }
public void GetVoiceStringEmpty() { //Arrange var animalList = FourAnimalFactory.GetAnimals(); var searchAnimal = new Animal() { Voice = string.Empty }; //Act List<Animal> resultsAnimals = AnimalSearchTableDriven.SearchAnd(animalList, searchAnimal); //Assert Assert.AreEqual(resultsAnimals.Count, 4); }