public async Task GetCatsByOwnerGender()
        {
            GetPetsModel petDetails = null;
            // Arrange
            PetRepository repository = new PetRepository();
            PetManager    manager    = new PetManager(repository);
            PetController controller = new PetController(manager);

            //
            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // Act
            var response = await controller.GetPetsByOwnerGender(PetType.Cat);

            if (response.IsSuccessStatusCode)
            {
                petDetails = await response.Content.ReadAsAsync <GetPetsModel>();
            }
            // Assert
            Assert.IsNotNull(petDetails);
            //
            Assert.AreEqual(4, petDetails.MaleOwnedCats.Count());
            Assert.AreEqual(3, petDetails.FemaleOwnedCats.Count());
            //
            Assert.AreEqual("Garfield", petDetails.MaleOwnedCats.ElementAt(0).Name);
            Assert.AreEqual("Jim", petDetails.MaleOwnedCats.ElementAt(1).Name);
            Assert.AreEqual("Max", petDetails.MaleOwnedCats.ElementAt(2).Name);
            Assert.AreEqual("Tom", petDetails.MaleOwnedCats.ElementAt(3).Name);
            //
            Assert.AreEqual("Garfield", petDetails.FemaleOwnedCats.ElementAt(0).Name);
            Assert.AreEqual("Simba", petDetails.FemaleOwnedCats.ElementAt(1).Name);
            Assert.AreEqual("Tabby", petDetails.FemaleOwnedCats.ElementAt(2).Name);
        }
Beispiel #2
0
 public HistoryViewModel(PetRepository repository, IEventAggregator events)
 {
     _repository = repository;
     _history    = repository.History;
     events.GetEvent <NewPetEvent>().Subscribe(pet => PetsChanged());
     events.GetEvent <SoldPetEvent>().Subscribe(pet => PetsChanged());
 }
Beispiel #3
0
        public async void TestDegradeMetrics()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 225, Name = "Noel"
            });
            var happinessAtTimeOfCreation = appDbContext.Add(new Cat {
                Id = 125, Name = "Molly", UserId = 225
            })
                                            .Entity.Metrics[MetricType.HAPPINESS].Value;

            appDbContext.SaveChangesAsync().Wait();

            // Act
            await petService.DegradeMetrics();

            var pet = await petService.GetAsync(125);

            // Assert
            Assert.True(pet.Metrics[MetricType.HAPPINESS].Value < happinessAtTimeOfCreation);
        }
Beispiel #4
0
        public static PetRepository GetPetRepository()
        {
            var repository = new PetRepository();

            repository.UnitOfWork = GetUnitOfWork();
            return(repository);
        }
Beispiel #5
0
        public PetControllerTests()
        {
            var context = new PetContext();
            var repo    = new PetRepository(context);

            underTest = new PetController(repo);
        }
Beispiel #6
0
        public async void TestDeletePetAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 210, Name = "Jessica"
            });
            appDbContext.Add(new Cat {
                Id = 110, Name = "Mae", UserId = 210
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var petDeleted = await petService.DeleteAsync(110);

            var findPet = await petService.GetAsync(110);

            // Assert
            Assert.NotNull(petDeleted);
            Assert.Equal("Mae", petDeleted.Name);
            Assert.Null(findPet);
        }
Beispiel #7
0
        public PetProfilesVM()
        {
            Pets = new List <PetProfileViewModel>();
            PetRepository petRepository = new PetRepository();
            var           _pets         = petRepository.GetPetsAsync();

            foreach (var pet in _pets)
            {
                var _pet = new PetProfileViewModel();
                _pet.Id.Value           = pet.Id;
                _pet.Name.Value         = pet.Name;
                _pet.Breed.Value        = pet.Breed;
                _pet.DOB.Value          = pet.DOB;
                _pet.Sex.Value          = pet.Sex;
                _pet.Neutered.Value     = pet.Neutered;
                _pet.Weight.Value       = pet.Weight;
                _pet.ExerciseGoal.Value = pet.ExerciseGoal;
                _pet.PetImagePath.Value = pet.DPPath;
                Pets.Add(_pet);
            }
            var _dummyPet = new PetProfileViewModel();

            _dummyPet.Id.Value           = -999;
            _dummyPet.PetImagePath.Value = "furryfiticon.png";
            Pets.Add(_dummyPet);
        }
Beispiel #8
0
        public static PetRepository GetPetRepository(IUnitOfWork unitOfWork)
        {
            var repository = new PetRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
        public ActionResult Delete(int id)
        {
            var petRepo = new PetRepository();

            petRepo.Delete(id);
            return(RedirectToAction("Index"));
        }
        // GET: Admin/PetManagement
        public ActionResult Index(String searchString, int page = 1, int pagesize = 10)
        {
            var petRepo = new PetRepository();
            var model   = petRepo.ListAllPaging(searchString, page, pagesize);

            return(View(model));
        }
        public PetProfileViewModel(int petId)
        {
            _id              = new ValidatableObject <int>();
            _petName         = new ValidatableObject <string>();
            _petBreed        = new ValidatableObject <string>();
            _petDOB          = new ValidatableObject <DateTime>();
            _petSex          = new ValidatableObject <string>();
            _petNeutered     = new ValidatableObject <string>();
            _petWeight       = new ValidatableObject <int>();
            _petExerciseGoal = new ValidatableObject <int>();
            _petImagePath    = new ValidatableObject <string>();
            _petImageStream  = new ValidatableObject <Stream>();
            _petDOB.Value    = DateTime.Now;
            _petWeight.Value = 0;
            _isBusy          = false;
            pet              = new Pet();
            PetRepository petRepository = new PetRepository();

            pet = petRepository.GetPetWithIdAsync(petId);

            if (pet != null)
            {
                _id.Value              = pet.Id;
                _petName.Value         = pet.Name;
                _petBreed.Value        = pet.Breed;
                _petDOB.Value          = pet.DOB;
                _petSex.Value          = pet.Sex;
                _petNeutered.Value     = pet.Neutered;
                _petWeight.Value       = pet.Weight;
                _petExerciseGoal.Value = pet.Weight;
                _petImagePath.Value    = pet.DPPath;
            }

            AddValidations();
        }
        public void GetPet_ParametersMatchExpectedValues()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PetDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var currentUser = new Mock <ICurrentUserService>();

            currentUser.SetupGet(c => c.UserId).Returns("testuser");
            var currentUserService = currentUser.Object;

            var fakePet = new FakePet {
            }.Generate();

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Pets.AddRange(fakePet);
                context.SaveChanges();

                var service = new PetRepository(context, new SieveProcessor(sieveOptions));

                //Assert
                var petById = service.GetPet(fakePet.PetId);
                petById.PetId.Should().Be(fakePet.PetId);
                petById.Name.Should().Be(fakePet.Name);
                petById.Type.Should().Be(fakePet.Type);
            }
        }
        public async Task GetAllPets_by_client_orders_by_name()
        {
            var id = new Guid("994aa42a-e292-42f1-b5d4-749cd19a4d29");

            var data = new List <Pet>
            {
                new Pet {
                    Name = "BBB", Client = new Client {
                        Id = id
                    }
                },
                new Pet {
                    Name = "ZZZ", Client = new Client {
                        Id = id
                    }
                },
                new Pet {
                    Name = "AAA", Client = new Client {
                        Id = Guid.NewGuid()
                    }
                },
            }.AsQueryable().BuildMockDbSet();

            var mockContext = new Mock <PetShopDbContext>();

            mockContext.Setup(c => c.Pets).Returns(data.Object);

            var repository = new PetRepository(mockContext.Object);
            var pets       = await repository.GetAllByClient(id);

            pets.Count().Should().Be(2);
            pets.ElementAt(0).Name.Should().BeEquivalentTo("BBB");
            pets.ElementAt(1).Name.Should().BeEquivalentTo("ZZZ");
        }
Beispiel #14
0
        public static List <PetData> GetUserPets(int userId)
        {
            PetRepository   petRep   = new PetRepository();
            KindRepository  kindRep  = new KindRepository();
            BreedRepository breedRep = new BreedRepository();

            List <PhotoData> photos = GetPhotos();

            List <PetData> pets = new List <PetData>();

            petRep.GetUserPets(userId).ToList().ForEach(x => pets.Add(new PetData
            {
                Id           = x.Id,
                Nickname     = x.Nickname,
                KindId       = x.KindId,
                BreedId      = x.BreedId,
                Kind         = kindRep.Get(x.KindId).Name,
                Breed        = breedRep.Get(x.BreedId).Name,
                Conditions   = x.Conditions,
                ArrivalDate  = x.ArrivalDate,
                Color        = x.Color,
                HealthStatus = x.HealthStatus,
                Photos       = photos.Where(k => k.PetId == x.Id).ToList()
            }));
            return(pets);
        }
        protected async void Save()
        {
            IsBusy = true;
            try
            {
                if (ValidateObject())
                {
                    await App.Current.MainPage.DisplayAlert("Validation", "All Ok", "OK");

                    PetRepository petRepository = new PetRepository();
                    pet.Name         = Name.Value;
                    pet.Breed        = Breed.Value;
                    pet.DOB          = DOB.Value;
                    pet.Sex          = Sex.Value;
                    pet.Neutered     = Neutered.Value;
                    pet.Weight       = Weight.Value;
                    pet.ExerciseGoal = ExerciseGoal.Value;

                    if (PetImagePath.Value != string.Empty)
                    {
                        CopyDPToApplicationFolder();
                        //pet.DisplayPicture = GetBytesFromImageStream(PetImageStream.Value);
                    }

                    pet.DPPath = PetImagePath.Value;
                    bool result = false;
                    if (Id.Value == null || Id.Value <= 0)
                    {
                        result   = petRepository.AddPetAsync(pet);
                        Id.Value = pet.Id;
                    }
                    else if (Id.Value > 0)
                    {
                        pet.Id = Id.Value;
                        result = petRepository.UpdatePetAsync(pet);
                        //Id.Value = pet.Id;
                    }

                    if (result)
                    {
                        await App.Current.MainPage.DisplayAlert("Data Saved", "All Ok", "OK");
                    }
                }

                else
                {
                    await App.Current.MainPage.DisplayAlert("Validation", "Errors during validation", "OK");
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                throw;
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #16
0
 public BasketModule(IRegionManager regionManager, IEventAggregator events, PetRepository petRepository, AccessoryRepository accessoryRepository, Messenger messenger)
 {
     _regionManager       = regionManager;
     _events              = events;
     _petRepository       = petRepository;
     _accessoryRepository = accessoryRepository;
     _messenger           = messenger;
 }
Beispiel #17
0
 public OwnerController()
 {
     this.ownerRepository       = new OwnerRepository();
     this.groomerRepository     = new GroomerRepository();
     this.serviceRepository     = new ServiceRepository();
     this.petRepository         = new PetRepository();
     this.appointmentRepository = new AppointmentRepository();
 }
 public Master(string family)
 {
     InitializeComponent();
     Family         = family;
     lblFamily.Text = family;
     _petRepo       = new PetRepository();
     GetPets();
 }
Beispiel #19
0
 public void TestLoadPetOwnersJson_WrongUrl()
 {
     AppSettings settings = new AppSettings {
         BasePetUrl = "http://agl-developer-test.azurewebsites.net", PetJsonUrl = "nosuch.json"
     };
     IPetRepository repository = new PetRepository(settings);
     string         result     = repository.LoadPetOwnersJson();
 }
        public ActionResult Edit(int id)
        {
            var petRepo = new PetRepository();
            var pet     = petRepo.GetByID(id);

            SetViewBag(pet.ID_GiongPet);
            return(View(pet));
        }
        public void Constructor_Should_Set_Users_Correctly()
        {
            // Arrange & Act
            var users         = new Mock <IUserRepository>().Object;
            var petRepository = new PetRepository(users);

            // Assert
            Assert.AreEqual(users, petRepository.Users);
        }
        public void Constructor_Should_Return_New_Instance()
        {
            // Arrange & Act
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);

            // Assert
            Assert.IsInstanceOfType(petRepository, typeof(PetRepository));
        }
        public void Costructor_Should_Initialize_PetList()
        {
            // Arrange & Act
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);

            // Assert
            Assert.IsNotNull(petRepository.Pets);
        }
        public void CreatePet_Should_Throw_ArgumentNullException_When_Pet_Is_Null()
        {
            // Arrange
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);

            // Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => petRepository.CreatePet("", null));
        }
Beispiel #25
0
        public static void Main(string[] args)
        {
            IPetRepository petRepo    = new PetRepository();
            IPetService    petService = new PetService(petRepo);
            var            printer    = new Printer(petService);

            PetDatabase.PopulateList();
            printer.ResetStage();
        }
        static void Main(string[] args)
        {
            var client   = new MongoClient("mongodb://localhost:27017");
            var database = client.GetDatabase("vet_clinic");
            var repo     = new PetRepository(database);

            repo.InitCollection();
            repo.GetSortedPetsPages(3);
            repo.GererateReport();
        }
        public void DeletePet_Should_Throw_ArgumentException_When_Pet_Does_Not_Exist()
        {
            // Arrange
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);
            var pet           = new Mock <IPet>();

            // Act & Assert
            Assert.ThrowsException <ArgumentException>(() => petRepository.DeletePet("", pet.Object));
        }
        public void GetPetByID_InvalidID_ReturnsNull()
        {
            //Arrange
            var petRepository = new PetRepository(new BaseRepository());
            //Act
            var noPetFound = petRepository.GetPetById(Guid.Empty);

            //Assert
            Assert.IsNull(noPetFound);
        }
Beispiel #29
0
        public void TestLoadPetOwnersJson()
        {
            AppSettings settings = new AppSettings {
                BasePetUrl = "http://agl-developer-test.azurewebsites.net", PetJsonUrl = "people.json"
            };
            IPetRepository repository = new PetRepository(settings);
            string         result     = repository.LoadPetOwnersJson();

            Assert.IsNotNull(result);
        }
Beispiel #30
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context        = context;
     Pets            = new PetRepository(context);
     Appointments    = new AppointmentRepository(context);
     Attandences     = new AttendanceRepository(context);
     AnimalType      = new TypeRepository(context);
     Doctors         = new DoctorRepository(context);
     Specializations = new SpecializationRepository(context);
     Users           = new ApplicationUserRepository(context);
 }