Esempio n. 1
0
        public async void GetVetsAsync_FilterHasSpayNeuterListWithExact()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"VetDb{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 fakeVetOne = new FakeVet {
            }.Generate();

            fakeVetOne.HasSpayNeuter = false;

            var fakeVetTwo = new FakeVet {
            }.Generate();

            fakeVetTwo.HasSpayNeuter = true;

            var fakeVetThree = new FakeVet {
            }.Generate();

            fakeVetThree.HasSpayNeuter = false;

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);
                context.SaveChanges();

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

                var vetRepo = await service.GetVetsAsync(new VetParametersDto { Filters = $"HasSpayNeuter == true" });

                //Assert
                vetRepo.Should()
                .HaveCount(1);

                context.Database.EnsureDeleted();
            }
        }
Esempio n. 2
0
        public async void GetVetsAsync_ListOpenDateSortedInDescOrder()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"VetDb{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 fakeVetOne = new FakeVet {
            }.Generate();

            fakeVetOne.OpenDate = DateTime.Now.AddDays(2);

            var fakeVetTwo = new FakeVet {
            }.Generate();

            fakeVetTwo.OpenDate = DateTime.Now.AddDays(1);

            var fakeVetThree = new FakeVet {
            }.Generate();

            fakeVetThree.OpenDate = DateTime.Now.AddDays(3);

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);
                context.SaveChanges();

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

                var vetRepo = await service.GetVetsAsync(new VetParametersDto { SortOrder = "-OpenDate" });

                //Assert
                vetRepo.Should()
                .ContainInOrder(fakeVetThree, fakeVetOne, fakeVetTwo);

                context.Database.EnsureDeleted();
            }
        }
Esempio n. 3
0
        public async void GetVetsAsync_CountMatchesAndContainsEquivalentObjects()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"VetDb{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 fakeVetOne = new FakeVet {
            }.Generate();
            var fakeVetTwo = new FakeVet {
            }.Generate();
            var fakeVetThree = new FakeVet {
            }.Generate();

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);
                context.SaveChanges();

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

                var vetRepo = await service.GetVetsAsync(new VetParametersDto());

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

                vetRepo.Should().ContainEquivalentOf(fakeVetOne);
                vetRepo.Should().ContainEquivalentOf(fakeVetTwo);
                vetRepo.Should().ContainEquivalentOf(fakeVetThree);

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

            var fakeVetOne = new FakeVet {
            }.Generate();
            var fakeVetTwo = new FakeVet {
            }.Generate();
            var fakeVetThree = new FakeVet {
            }.Generate();

            // need id's due to default sorting
            fakeVetOne.VetId   = 1;
            fakeVetTwo.VetId   = 2;
            fakeVetThree.VetId = 3;

            //Act
            using (var context = new VetClinicDbContext(dbOptions))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);
                context.SaveChanges();

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

                var vetRepo = await service.GetVetsAsync(new VetParametersDto { PageSize = 2 });

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

                vetRepo.Should().ContainEquivalentOf(fakeVetOne);
                vetRepo.Should().ContainEquivalentOf(fakeVetTwo);

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

            var fakeVetOne = new FakeVet {
            }.Generate();

            fakeVetOne.OpenDate = DateTime.Now.AddDays(1);

            var fakeVetTwo = new FakeVet {
            }.Generate();

            fakeVetTwo.OpenDate = DateTime.Parse(DateTime.Now.AddDays(2).ToString("MM/dd/yyyy"));

            var fakeVetThree = new FakeVet {
            }.Generate();

            fakeVetThree.OpenDate = DateTime.Now.AddDays(3);

            //Act
            using (var context = new VetClinicDbContext(dbOptions))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);
                context.SaveChanges();

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

                var vetRepo = await service.GetVetsAsync(new VetParametersDto { Filters = $"OpenDate == {fakeVetTwo.OpenDate}" });

                //Assert
                vetRepo.Should()
                .HaveCount(1);

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

            var fakeVetOne = new FakeVet {
            }.Generate();

            fakeVetOne.Capacity = 2;

            var fakeVetTwo = new FakeVet {
            }.Generate();

            fakeVetTwo.Capacity = 1;

            var fakeVetThree = new FakeVet {
            }.Generate();

            fakeVetThree.Capacity = 3;

            //Act
            using (var context = new VetClinicDbContext(dbOptions))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);
                context.SaveChanges();

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

                var vetRepo = await service.GetVetsAsync(new VetParametersDto { SortOrder = "-Capacity" });

                //Assert
                vetRepo.Should()
                .ContainInOrder(fakeVetThree, fakeVetOne, fakeVetTwo);

                context.Database.EnsureDeleted();
            }
        }