예제 #1
0
        public void ShouldAddInspection()
        {
            var inspections = new[] { new Inspection("Pass", DateTime.Now) };

            _establishment.AddNewInspections(inspections);

            Assert.Equal(inspections, _establishment.Inspections);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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 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);
        }