Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async void GetPetsAsync_CountMatchesAndContainsEquivalentObjects()
        {
            //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 fakePetOne = new FakePet {
            }.Generate();
            var fakePetTwo = new FakePet {
            }.Generate();
            var fakePetThree = new FakePet {
            }.Generate();

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

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

                var petRepo = await service.GetPetsAsync(new PetParametersDto());

                //Assert
                petRepo.Should()
                .NotBeEmpty()
                .And.HaveCount(3);

                petRepo.Should().ContainEquivalentOf(fakePetOne);
                petRepo.Should().ContainEquivalentOf(fakePetTwo);
                petRepo.Should().ContainEquivalentOf(fakePetThree);

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

            var fakePetOne = new FakePet {
            }.Generate();
            var fakePetTwo = new FakePet {
            }.Generate();
            var fakePetThree = new FakePet {
            }.Generate();

            // need id's due to default sorting
            fakePetOne.PetId   = Guid.Parse("547ee3d9-5241-4ce3-93f6-a65700bd36ca");
            fakePetTwo.PetId   = Guid.Parse("621fab6d-2487-43f4-aec2-354fa54089da");
            fakePetThree.PetId = Guid.Parse("f9335b96-63dd-412e-935b-102463b9f245");

            //Act
            using (var context = new VetClinicDbContext(dbOptions))
            {
                context.Pets.AddRange(fakePetOne, fakePetTwo, fakePetThree);
                context.SaveChanges();

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

                var petRepo = await service.GetPetsAsync(new PetParametersDto { PageSize = 2 });

                //Assert
                petRepo.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                petRepo.Should().ContainEquivalentOf(fakePetOne);
                petRepo.Should().ContainEquivalentOf(fakePetTwo);

                context.Database.EnsureDeleted();
            }
        }
Ejemplo n.º 4
0
        private List <Pet> GetPets()
        {
            PetRepository petRepository = new PetRepository();

            return(petRepository.GetPetsAsync());
        }