public void ShouldMapInspectionResponse() { // assert 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 }); var mapper = new DomainToResponseMapper(); // act var actual = mapper.MapInspectionResponses(new[] { expectedInspection }); // assert var actualInspection = Assert.Single(actual); Assert.NotNull(actualInspection); Assert.Equal(expectedInspection.Date, actualInspection.Date); Assert.Equal(expectedInspection.InspectionStatus.Name, actualInspection.Status); Assert.Equal(expectedInspection.Infractions.Count, actualInspection.Infractions.Count()); }
public async Task ShouldPersistEstablishment() { var options = new DbContextOptionsBuilder <WhereToBiteContext>() .UseInMemoryDatabase("test2") .Options; var whereToBiteContext = new WhereToBiteContext(options); var establishmentRepository = new EstablishmentRepository(whereToBiteContext); var expectedEstablishment = new Establishment(1, "test", "Restaurant", string.Empty, "Pass", Point.Empty); var infraction = new Infraction("M - Minor", "Ticket", DateTime.Now, "", 0m); var inspection = new Inspection("Pass", DateTime.Now); inspection.AddNewInfractions(new[] { infraction }); var inspections = new[] { inspection }; expectedEstablishment.AddNewInspections(inspections); await establishmentRepository.AddIfNotExistsAsync(expectedEstablishment, CancellationToken.None); await establishmentRepository.UnitOfWork.SaveEntitiesAsync(); var actualEstablishment = whereToBiteContext.Establishments.FirstOrDefault(); Assert.NotNull(actualEstablishment); Assert.Equal(expectedEstablishment.DineSafeId, actualEstablishment.DineSafeId); Assert.Equal(expectedEstablishment.Name, actualEstablishment.Name); Assert.Equal(expectedEstablishment.Type, actualEstablishment.Type); Assert.Equal(expectedEstablishment.EstablishmentStatus, actualEstablishment.EstablishmentStatus); Assert.NotEmpty(actualEstablishment.Inspections); var expectedInspection = expectedEstablishment.Inspections.FirstOrDefault(); var actualInspection = actualEstablishment.Inspections.FirstOrDefault(); Assert.NotNull(expectedInspection); Assert.NotNull(actualInspection); Assert.Equal(expectedInspection.InspectionStatus, actualInspection.InspectionStatus); var expectedInfraction = expectedInspection.Infractions.FirstOrDefault(); var actualInfraction = actualInspection.Infractions.FirstOrDefault(); Assert.NotNull(expectedInfraction); Assert.NotNull(actualInfraction); Assert.Equal(expectedInfraction.InfractionAction, actualInfraction.InfractionAction); Assert.Equal(expectedInfraction.Severity, actualInfraction.Severity); Assert.Equal(expectedInfraction.AmountFined, actualInfraction.AmountFined); }
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 void ShouldOnlyAddNewInfractions() { var actual = new Inspection("Pass", DateTime.Now); var infractions = new List <Infraction> { new Infraction("M - Minor", "Ticket", DateTime.Now.AddHours(-2), "", 0m) }; actual.AddNewInfractions(infractions); infractions.Add(new Infraction("M - Minor", "Ticket", DateTime.Now, "", 0m)); actual.AddNewInfractions(infractions); Assert.Equal(2, actual.Infractions.Count); Assert.Equal(infractions, actual.Infractions); }
public async Task ShouldReturnEstablishmentInspections() { 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)); 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(); // act var actual = await establishmentRepository.GetInspectionsAsync(1, CancellationToken.None); Assert.NotNull(actual); var actualInspection = Assert.Single(actual); Assert.NotNull(actualInspection); Assert.Equal(expectedInspection.Date, actualInspection.Date); Assert.Equal(expectedInspection.Id, actualInspection.Id); Assert.Equal(expectedInspection.InspectionStatus, actualInspection.InspectionStatus); Assert.Equal(expectedInspection.Infractions.Count, actualInspection.Infractions.Count); }
public void ShouldAddNewInfraction() { var actual = new Inspection("Pass", DateTime.Now); var infractions = new[] { new Infraction("M - Minor", "Ticket", DateTime.Now, "", 0m) }; actual.AddNewInfractions(infractions); }
public void ShouldMapValuesForOverallAmountFinedAndOverAllInfractions() { // arrange var expectedPoint = new Point(1, 2); var expectedEstablishment = new Establishment( 1, "TestName", "type", "", EstablishmentStatus.Closed.ToString(), expectedPoint); 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 }); var expectedEstablishments = new[] { expectedEstablishment }; var mapper = new DomainToResponseMapper(); // act var actual = mapper.MapEstablishmentResponses(expectedEstablishments); // assert var lastInspectionStatus = expectedEstablishment.GetLastInspection(); var actualMappedEstablishment = Assert.Single(actual); Assert.NotNull(actualMappedEstablishment); Assert.Equal(lastInspectionStatus.InspectionStatus.Name, actualMappedEstablishment.LastInspection.Status); Assert.Equal(expectedPoint.X, actualMappedEstablishment.Longitude); Assert.Equal(expectedPoint.Y, actualMappedEstablishment.Latitude); Assert.Equal(expectedInfraction.AmountFined + expectedInfractionTwo.AmountFined, actualMappedEstablishment.OverallAmountFined); Assert.Equal(expectedInspection.Infractions.Count, actualMappedEstablishment.OverallNumberOfInfractions); }
private static IEnumerable <Inspection> ExtractInspections(DineSafeEstablishment dineSafeEstablishment) { if (dineSafeEstablishment.Inspections == null) { return(Enumerable.Empty <Inspection>()); } var inspections = new List <Inspection>(); foreach (var dineSafeInspection in dineSafeEstablishment.Inspections) { var inspection = new Inspection(dineSafeInspection.Status, dineSafeInspection.Date); inspection.AddNewInfractions(ExtractInfractions(dineSafeInspection)); inspections.Add(inspection); } return(inspections); }