public void SaveMethod_PetInput_IsSuccessful()
 {
     var sut = new PetRepositoryNHbn();
     var pet = new Pet() {Age = 8, Breed = "pug", Name = "Integration Test Record", Temperament = "cheery", ModifiedBy = "unit test"};
     sut.SavePet(pet);
     pet.Id.ShouldBeGreaterThan(0);
 }
        public void SetUp()
        {
            const int id = 4765;
            const string firstName = "Julie";
            const string lastName = "Li";
            var pet = new Pet {Id = 4987};
            var address = new Address("1234 Happy St", "Winnipeg", "MB", "R3B 2A2");

            _owner = new Owner
            {
                Id = id,
                FirstName = firstName,
                LastName = lastName,
                Address =address
            };

            _owner.AddPet(pet);

            var sameOwnerPlacedIntoSession = new Owner
            {
                Id = id,
                FirstName = firstName,
                LastName = lastName,
                Address = address
            };

            sameOwnerPlacedIntoSession.AddPet(pet);

            var sessionSource = FluentNHibernateMappingTester.GetNHibernateSessionWithWrappedEntity(sameOwnerPlacedIntoSession);
            _persistenceSpecification = new PersistenceSpecification<Owner>(sessionSource, new DomainEntityComparer());
        }
        public void SavePetEvent_Raised_SavesPetWithName()
        {
            _addPetView.SavePet += null;
            var savePetEvent = LastCall.IgnoreArguments().GetEventRaiser();
            const string petName = "Fido";
            const string breed = "pug";
            const int age = 8;
            const string healthHistory = "Has had cysts removed on 3 occasions, risk of diabetes.";
            var id = Guid.NewGuid();

            Expect.Call(_addPetView.Name).Return(petName).Repeat.AtLeastOnce();
            Expect.Call(_addPetView.Breed).Return(breed).Repeat.AtLeastOnce();
            Expect.Call(_addPetView.Age).Return(age).Repeat.AtLeastOnce();
            Expect.Call(_addPetView.HealthHistory).Return(healthHistory).Repeat.AtLeastOnce();
            _addPetView.Message = "";
            var pet = new Pet
                          {
                              Name = "Fido",
                              Breed = "beagle",
                              Age = 3,
                              Temperament = "gentle",
                              HealthHistory = healthHistory
                          };
            _petRepository.SavePet(pet);
            _addPetView.Message = "Saved. (No page redirect yet.)";

            _mockRepository.ReplayAll();

            var sut = new AddPetPresenter(_petRepository, _addPetView);
            savePetEvent.Raise(_addPetView, EventArgs.Empty);
        }
 public void TwoInstances_SetSameId_AreEqual()
 {
     const int idValue = 3527;
     var sut1 = new Pet();
     var sut2 = new Pet();
     sut1.Id = idValue;
     sut2.Id = idValue;
     Assert.IsTrue(sut1.Equals(sut2));
 }
        public void AddPetMethod_PetInput_IncrementsPetsAssociation()
        {
            const string firstName = "Julie";
            const string lastName = "Smith";
            var sut = new Owner { FirstName = firstName, LastName = lastName };

            var pet = new Pet();
            sut.AddPet(pet);

            Assert.AreEqual(1, sut.Pets.Count);
        }
 public void SavePet(Pet pet)
 {
     using (var session = _factoryBuilder.CreateSqlServerSessionFactory().OpenSession())
     {
         using (session.BeginTransaction())
         {
             pet.ModifiedDate = DateTime.Now;
             session.Save(pet);
             session.Transaction.Commit();
         }
     }
 }
 private void SavePetFormDataToRepository(AddPetFormResponse addPetFormResponse)
 {
     var pet = new Pet
                   {
                       Name = addPetFormResponse.Name,
                       Breed = addPetFormResponse.Breed,
                       Age = addPetFormResponse.Age.Value,
                       HealthHistory = addPetFormResponse.HealthHistory,
                       ModifiedBy = "anonymous web user"
                   };
     _petRepository.SavePet(pet);
 }
 void AddPetViewSavePet(object sender, System.EventArgs e)
 {
     if (!AreViewInputsValid()) return;
     var pet = new Pet
     {
         Name = "Fido",
         Breed = "beagle",
         Age = 3,
         Temperament = "gentle",
         HealthHistory = "diabetes risk"
     };
     pet.HealthHistory = _addPetView.HealthHistory;
     _petRepository.SavePet(pet);
     _addPetView.Message = "Saved. (No page redirect yet.)";
 }
 public ViewResult SavePet(AddPetFormResponse addPetFormResponse)
 {
     if (ModelState.IsValid)
     {
         var pet = new Pet
                   {
                       Name = addPetFormResponse.Name,
                       Breed = addPetFormResponse.Breed,
                       Age = addPetFormResponse.Age.Value,
                       HealthHistory = addPetFormResponse.HealthHistory
                   };
         _petRepository.SavePet(pet);
         ViewData.Add("message", "Pet details have been saved.");
     }
     else
     {
         ViewData.Add("message", addPetFormResponse.Error);
     }
     return View();
 }
        public void Constructor_WithObjectInitializers_MatchProperties()
        {
            const string name = "Ira";
            const string breed = "pug";
            const int age = 3;
            const string temperament = "gentle";
            const string healthHistory = "breathing issues";

            var sut = new Pet
                          {
                              Name = name,
                              Breed = breed,
                              Age = age,
                              Temperament = temperament,
                              HealthHistory = healthHistory
                          };

            Assert.AreEqual(name, sut.Name);
            Assert.AreEqual(breed, sut.Breed );
            Assert.AreEqual(age, sut.Age);
            Assert.AreEqual(temperament, sut.Temperament);
            Assert.AreEqual(healthHistory, sut.HealthHistory);
        }
 public void SavePet(Pet pet)
 {
     // call to db or other persitance storage goes here
     throw new NotImplementedException("Next up: Add ORM to save data to database.");
 }
 public void Constructor_NoInput_IsInstanceOfDomainEntity()
 {
     var sut = new Pet();
     Assert.IsInstanceOfType(typeof(DomainEntity), sut);
 }
        public void SavePetMethod_AddPetFormReponseInputsAreValid_SavesToRepository()
        {
            var apfr = new AddPetFormResponse
                                          {Name = "Fido", Breed = "pug", Age = 3, HealthHistory = "breathing problems"};

            var pet = new Pet
            {
                Name = apfr.Name,
                Breed = apfr.Breed,
                Age = apfr.Age.HasValue ? apfr.Age.Value : 0,
                HealthHistory = apfr.HealthHistory,
                ModifiedBy = "unit test"
            };
            _petRepository.SavePet(pet);

            var sut = new PetManagementController(_petRepository);
            var redirectToRouteResult = (RedirectToRouteResult) sut.SavePet(apfr);

            sut.TempData["Message"].ShouldBe(string.Format("{0} has been added to VetAdmin.", apfr.Name));
            redirectToRouteResult.AssertActionRedirect().ToAction("Success");
        }
예제 #14
0
 public virtual void RemovePet(Pet pet)
 {
     Pets.Remove(pet);
 }
예제 #15
0
 public virtual void AddPet(Pet pet)
 {
     Pets.Add(pet);
 }