Esempio n. 1
0
        public void GetFishThatPreferMySpecies_ReturnsAllFishMatches_FishList()
        {
            //Arrange
            Species newSpecies = new Species("Angler");

            newSpecies.Save();
            Species newSpecies2 = new Species("Shark");

            newSpecies2.Save();
            int id  = newSpecies.GetSpeciesId();
            int id2 = newSpecies2.GetSpeciesId();

            Fish testFish = new Fish("Jim", id, "Jim45", "Password1");

            testFish.Save();
            Fish testFish2 = new Fish("Tom", id2, "Tom45", "Password1");

            testFish2.Save();

            testFish.AddSpecies(newSpecies2);
            testFish2.AddSpecies(newSpecies);

            //Act
            List <Fish> testFishThatPreferMe = testFish.GetFishThatPreferMySpecies();
            List <Fish> savedFish            = new List <Fish> {
                testFish2
            };

            //Assert
            CollectionAssert.AreEqual(testFishThatPreferMe, savedFish);
        }
        public ActionResult CreateFish()
        {
            string userNameActual = Request.Form["userName"];
            int    speciesId      = Int32.Parse(Request.Form["speciesId"]);
            string firstName      = Request.Form["firstName"];
            string lastName       = Request.Form["lastName"];
            string userPassword   = Request.Form["userPassword"];
            Fish   newFish        = new Fish(firstName, lastName, speciesId, userNameActual, userPassword);

            newFish.Save();
            int    newSessionId = Fish.Login(Request.Form["userName"], Request.Form["userPassword"]);
            string fishBio      = Request.Form["bio"];

            newFish.AddBio(fishBio);

            string selectedSpecies = Request.Form["chosenSpecies"];

            if (selectedSpecies != null)
            {
                String[] speciesIds = selectedSpecies.Split(',');
                foreach (var species in speciesIds)
                {
                    int     speciesIdInt = int.Parse(species);
                    Species newSpecies   = Species.Find(speciesIdInt);
                    newFish.AddSpecies(newSpecies);
                }
            }
            return(RedirectToAction("ViewProfile", new { sessionId = newSessionId }));
        }
Esempio n. 3
0
        public void Test_AddSpeciesPreference_AddsSpecies_SpeciesList()
        {
            //Arrange
            Fish testFish = new Fish("Jim", 1, "Jim45", "Password1");

            testFish.Save();

            Species testSpecies1 = new Species("Tom");

            testSpecies1.Save();

            //Act
            testFish.AddSpecies(testSpecies1);
            List <Species> result  = testFish.GetPreferredSpecies();
            int            testId  = result[0].GetSpeciesId();
            int            testId2 = testSpecies1.GetSpeciesId();

            //Assert
            Assert.AreEqual(testId, testId2);
        }