public async Task ShouldGetEstablishmentsWithinRadius() { var options = new DbContextOptionsBuilder <WhereToBiteContext>() .UseInMemoryDatabase("test4") .Options; var whereToBiteContext = new WhereToBiteContext(options); var establishmentRepository = new EstablishmentRepository(whereToBiteContext); var expectedEstablishment = new Establishment( 1, "test", "Restaurant", string.Empty, "Pass", new Point(-79.45886, 43.65493)); var expectedInspection = new Inspection(InspectionStatus.Pass.ToString(), DateTime.Today.AddDays(-10)); var expectedInfraction = new Infraction( "C - Crucial", "Ticket", expectedInspection.Date, "Fine", 10000.00m); var expectedInfractionTwo = new Infraction( "M - Minor", "Ticket", expectedInspection.Date, "Fine", 10.00m); expectedInspection.AddNewInfractions(new [] { expectedInfraction, expectedInfractionTwo }); expectedEstablishment.AddNewInspections(new [] { expectedInspection }); await whereToBiteContext.Establishments.AddAsync(expectedEstablishment); await whereToBiteContext.SaveChangesAsync(); var actual = await establishmentRepository.GetAllWithinRadiusAsync( 1000, new Point(-79.46377746577373, 43.655427942971166), CancellationToken.None); var actualEstablishment = Assert.Single(actual); Assert.NotNull(actualEstablishment); Assert.Equal(expectedEstablishment.Address, actualEstablishment.Address); Assert.Equal(expectedEstablishment.Name, actualEstablishment.Name); Assert.Equal(expectedEstablishment.Type, actualEstablishment.Type); Assert.Equal(expectedEstablishment.EstablishmentStatus, actualEstablishment.EstablishmentStatus); Assert.Equal( expectedInfraction.AmountFined + expectedInfractionTwo.AmountFined, actualEstablishment.Inspections.Select(x => x.Infractions.Sum(infraction => infraction.AmountFined)).Sum()); }
public async Task ShouldThrowIfCenterIsNull() { var options = new DbContextOptionsBuilder <WhereToBiteContext>() .UseInMemoryDatabase("test5") .Options; var whereToBiteContext = new WhereToBiteContext(options); var establishmentRepository = new EstablishmentRepository(whereToBiteContext); var expectedEstablishment = new Establishment(1, "test", "Restaurant", string.Empty, "Pass", new Point(-79.45886, 43.65493)); await whereToBiteContext.Establishments.AddAsync(expectedEstablishment); await whereToBiteContext.SaveChangesAsync(); await Assert.ThrowsAsync <ArgumentNullException>(() => establishmentRepository.GetAllWithinRadiusAsync(1000, null !, CancellationToken.None)); }