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 void GetCity_ParametersMatchExpectedValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>() .UseInMemoryDatabase(databaseName: $"CityDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeCity = new FakeCity { }.Generate(); //Act using (var context = new VetClinicDbContext(dbOptions)) { context.Cities.AddRange(fakeCity); context.SaveChanges(); var service = new CityRepository(context, new SieveProcessor(sieveOptions)); //Assert var cityById = service.GetCity(fakeCity.CityId); cityById.CityId.Should().Be(fakeCity.CityId); cityById.Name.Should().Be(fakeCity.Name); } }
public void GetVet_ParametersMatchExpectedValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>() .UseInMemoryDatabase(databaseName: $"VetDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeVet = new FakeVet { }.Generate(); //Act using (var context = new VetClinicDbContext(dbOptions)) { context.Vets.AddRange(fakeVet); context.SaveChanges(); var service = new VetRepository(context, new SieveProcessor(sieveOptions)); //Assert var vetById = service.GetVet(fakeVet.VetId); vetById.VetId.Should().Be(fakeVet.VetId); vetById.Name.Should().Be(fakeVet.Name); vetById.Capacity.Should().Be(fakeVet.Capacity); vetById.OpenDate.Should().Be(fakeVet.OpenDate); vetById.HasSpayNeuter.Should().Be(fakeVet.HasSpayNeuter); } }
public VetRepository(VetClinicDbContext context, SieveProcessor sieveProcessor) { _context = context ?? throw new ArgumentNullException(nameof(context)); _sieveProcessor = sieveProcessor ?? throw new ArgumentNullException(nameof(sieveProcessor)); }
public static void SeedSampleVetData(VetClinicDbContext context) { if (!context.Vets.Any()) { context.Vets.Add(new AutoFaker <Vet>()); context.Vets.Add(new AutoFaker <Vet>()); context.Vets.Add(new AutoFaker <Vet>()); context.SaveChanges(); } }
public static void SeedSampleCityData(VetClinicDbContext context) { if (!context.Cities.Any()) { context.Cities.Add(new AutoFaker <City>()); context.Cities.Add(new AutoFaker <City>()); context.Cities.Add(new AutoFaker <City>()); context.SaveChanges(); } }
public async void GetCitiesAsync_FilterCityIdListWithExact() { //Arrange var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>() .UseInMemoryDatabase(databaseName: $"CityDb{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 fakeCityOne = new FakeCity { }.Generate(); fakeCityOne.CityId = 1; var fakeCityTwo = new FakeCity { }.Generate(); fakeCityTwo.CityId = 2; var fakeCityThree = new FakeCity { }.Generate(); fakeCityThree.CityId = 3; //Act using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService())) { context.Cities.AddRange(fakeCityOne, fakeCityTwo, fakeCityThree); context.SaveChanges(); var service = new CityRepository(context, new SieveProcessor(sieveOptions)); var cityRepo = await service.GetCitiesAsync(new CityParametersDto { Filters = $"CityId == 2" }); //Assert cityRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
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(); } }
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(); } }
public void DeleteCity_ReturnsProperCount() { //Arrange var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>() .UseInMemoryDatabase(databaseName: $"CityDb{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 fakeCityOne = new FakeCity { }.Generate(); var fakeCityTwo = new FakeCity { }.Generate(); var fakeCityThree = new FakeCity { }.Generate(); //Act using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService())) { context.Cities.AddRange(fakeCityOne, fakeCityTwo, fakeCityThree); var service = new CityRepository(context, new SieveProcessor(sieveOptions)); service.DeleteCity(fakeCityTwo); context.SaveChanges(); //Assert var cityList = context.Cities.ToList(); cityList.Should() .NotBeEmpty() .And.HaveCount(2); cityList.Should().ContainEquivalentOf(fakeCityOne); cityList.Should().ContainEquivalentOf(fakeCityThree); Assert.DoesNotContain(cityList, c => c == fakeCityTwo); context.Database.EnsureDeleted(); } }
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 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(); } }
public async void GetCitiesAsync_ReturnExpectedPageSize() { //Arrange var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>() .UseInMemoryDatabase(databaseName: $"CityDb{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 fakeCityOne = new FakeCity { }.Generate(); var fakeCityTwo = new FakeCity { }.Generate(); var fakeCityThree = new FakeCity { }.Generate(); //Act using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService())) { context.Cities.AddRange(fakeCityOne, fakeCityTwo, fakeCityThree); context.SaveChanges(); var service = new CityRepository(context, new SieveProcessor(sieveOptions)); var cityRepo = await service.GetCitiesAsync(new CityParametersDto { PageSize = 2 }); //Assert cityRepo.Should() .NotBeEmpty() .And.HaveCount(2); cityRepo.Should().ContainEquivalentOf(fakeCityOne); cityRepo.Should().ContainEquivalentOf(fakeCityTwo); 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(); } }
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(); } }
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(); } }
public void DeleteVet_ReturnsProperCount() { //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(); //Act using (var context = new VetClinicDbContext(dbOptions)) { context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree); var service = new VetRepository(context, new SieveProcessor(sieveOptions)); service.DeleteVet(fakeVetTwo); context.SaveChanges(); //Assert var vetList = context.Vets.ToList(); vetList.Should() .NotBeEmpty() .And.HaveCount(2); vetList.Should().ContainEquivalentOf(fakeVetOne); vetList.Should().ContainEquivalentOf(fakeVetThree); Assert.DoesNotContain(vetList, v => v == fakeVetTwo); context.Database.EnsureDeleted(); } }
public async void GetVetsAsync_CountMatchesAndContainsEquivalentObjects() { //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(); //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()); //Assert vetRepo.Should() .NotBeEmpty() .And.HaveCount(3); vetRepo.Should().ContainEquivalentOf(fakeVetOne); vetRepo.Should().ContainEquivalentOf(fakeVetTwo); vetRepo.Should().ContainEquivalentOf(fakeVetThree); context.Database.EnsureDeleted(); } }
public AdminServiceDB(VetClinicDbContext context) { this.context = context; }
public BackupServiceDB(VetClinicDbContext context) { this.context = context; }
public ClientImitationServiceDB(VetClinicDbContext context) { this.context = context; }
public DrugServiceDB(VetClinicDbContext context) { this.context = context; }
public ReportServiceDB(VetClinicDbContext context) { this.context = context; }