public void AnimalEntryArchiveTest() { //-- Arrange AnimalRepository animalRepos = new AnimalRepository(); Animal animal = new Animal() { AnimalType = "Cat", AnimalName = "MyKitty", AnimalAge = 5, AnimalId = "TESTID" }; var expected = true; //-- Act animalRepos.Add(animal, "test.csv"); animalRepos.Archive(animal.AnimalId, "test.csv"); var actual = true; var animalRetrieved = animalRepos.Retrieve(animal.AnimalId, "test.csv"); if (animalRetrieved.InShelterState != AnimalStateOption.Returned) { actual = false; } File.Delete("test.csv"); //-- Assert Assert.AreEqual(expected, actual); }
public void AnimalEntryUpdateTest() { //-- Arrange AnimalRepository animalRepos = new AnimalRepository(); Animal animal = new Animal() { AnimalType = "Cat", AnimalName = "MyKitty", AnimalAge = 5, AnimalId = "TESTID" }; Animal animalUpdated = new Animal() { AnimalType = "Cat", AnimalName = "MyKitty", AnimalAge = float.Parse("5.6"), AnimalId = "TESTID" }; var expected = true; //-- Act animalRepos.Add(animal, "test.csv"); animalRepos.Update(animalUpdated, animal.AnimalId, "test.csv"); var animalRetrieved = animalRepos.Retrieve(animal.AnimalId, "test.csv"); var actual = true; Type type = typeof(Animal); if (animalRetrieved != null) { foreach (System.Reflection.PropertyInfo pi in type.GetProperties()) { var exptValue = type.GetProperty(pi.Name).GetValue(animalUpdated); var actValue = type.GetProperty(pi.Name).GetValue(animalRetrieved); if (exptValue != null && !exptValue.Equals(actValue)) { actual = false; break; } else if (exptValue == null && actValue != null && !actValue.Equals("") && !actValue.Equals("=\"\"")) { actual = false; break; } } } File.Delete("test.csv"); //-- Assert Assert.AreEqual(expected, actual); }