Exemplo n.º 1
0
 public HomeModule()
 {
     Get["/"] = _ => {
     return View["index.cshtml"];
       };
       Get["/animals/{orderingParameter}"] = parameters => {
     List<Animal> AllAnimals = Animal.GetAll(parameters.orderingParameter);
     return View["animals.cshtml", AllAnimals];
       };
       Get["/types"] = _ => {
     List<Type> AllTypes = Type.GetAll();
     return View["types.cshtml", AllTypes];
       };
       Get["/types/new"] = _ => {
     return View["types_form.cshtml"];
       };
       Post["/types/new"] = _ => {
     Type newType = new Type(Request.Form["animal_type"]);
     newType.Save();
     return View["success.cshtml"];
       };
       Get["/animals/new"] = _ => {
     List<Type> AllTypes = Type.GetAll();
     return View["animals_form.cshtml", AllTypes];
       };
       Post["/animals/new"] = _ => {
     Animal newAnimal = new Animal(Request.Form["animal-name"], Request.Form["animal-gender"], Request.Form["animal-breed"],  Request.Form["animal-admittance-date"], Request.Form["type-id"]);
     newAnimal.Save();
     return View["success.cshtml"];
       };
       Post["/animals/delete"] = _ => {
     Animal.DeleteAll();
     return View["cleared.cshtml"];
       };
       Get["/types/{id}"] = parameters => {
     Dictionary<string, object> model = new Dictionary<string, object>();
     var SelectedType = Type.Find(parameters.id);
     var TypeAnimals = Animal.GetAll("id");
     model.Add("types", SelectedType);
     model.Add("animals", TypeAnimals);
     return View["type.cshtml", model];
       };
       Get["/type/edit/{id}"] = parameters => {
     Type SelectedType = Type.Find(parameters.id);
     System.Console.WriteLine(SelectedType.GetType());
     return View["edit.cshtml", SelectedType];
       };
     Patch["type/edit/{id}"] = parameters => {
     Type SelectedType = Type.Find(parameters.id);
     SelectedType.Update(Request.Form["type-name"]);
     return View["success.cshtml"];
       };
 }
Exemplo n.º 2
0
        public void Test_Find_FindsAnimalInDatabase()
        {
            //Arrange
              DateTime sampleDate = new DateTime(1990,09,05);
              Animal testAnimal = new Animal("Fluffy", "Female", "Persian", sampleDate, 1);
              testAnimal.Save();

              //Act
              Animal foundAnimal = Animal.Find(testAnimal.GetId());

              //Assert
              Assert.Equal(testAnimal, foundAnimal);
        }
Exemplo n.º 3
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
              DateTime sampleDate = new DateTime(1990,09,05);
              Animal testAnimal = new Animal("Fluffy", "Female", "Persian", sampleDate, 1);

              //Act
              testAnimal.Save();
              Animal savedAnimal = Animal.GetAll("id")[0];

              int result = savedAnimal.GetId();
              int testId = testAnimal.GetId();

              //Assert
              Assert.Equal(testId, result);
        }
Exemplo n.º 4
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
              DateTime sampleDate = new DateTime(1990,09,05);
              Animal testAnimal = new Animal("Fluffy", "Female", "Persian", sampleDate, 1);

              //Act
              testAnimal.Save();
              List<Animal> result = Animal.GetAll("id");
              List<Animal> testList = new List<Animal>{testAnimal};

              //Assert
              Assert.Equal(testList, result);
        }