コード例 #1
0
        public async Task BuilderResponseWhenRepositoryReturnsValidResponse()
        {
            var pharmacyInputModelMock = new PharmacyInputModel
            {
                Latitude  = 23.4,
                Longitude = -3.43
            };

            var pharmacyDataModelMock = new PharmacyDataModel
            {
                Name     = "Store1",
                Address  = "Address1",
                Distance = 23M
            };

            var pharmacyModelMock = new PharmacyModel
            {
                Name     = "Store1",
                Address  = "Address1",
                Distance = 23M
            };

            _pharmacyRepositoryMock.Setup(x => x.FindClosestPharmacyAsync(pharmacyInputModelMock.Latitude, pharmacyInputModelMock.Longitude)).ReturnsAsync(pharmacyDataModelMock);
            var pharmacyBuilder = new PharmacyBuilder(_pharmacyRepositoryMock.Object, _loggerMock.Object);

            Assert.True(pharmacyModelMock.Equals(await pharmacyBuilder.FindClosestAsync(pharmacyInputModelMock)));
        }
コード例 #2
0
        public async Task GetClosestPharmacyWhenValid()
        {
            var testResponse = new PharmacyDataModel
            {
                Name     = "CVS PHARMACY",
                Address  = "5001 WEST 135 ST",
                Distance = 65.98M
            };

            var pharmacyRepository = new PharmacyRepository(_dbProvider, _loggerMock.Object);
            var result             = await pharmacyRepository.FindClosestPharmacyAsync(37.926752574631, -94.66152902993963);

            Assert.Equal(testResponse, result);
        }
コード例 #3
0
        public async Task <PharmacyDataModel> FindClosestPharmacyAsync(double latitude, double longitude)
        {
            _logger.LogDebug("Invoked Repository FindClosestPharmacyAsync");
            using (var conn = _dbProvider.Get())
            {
                const string query = @"
Declare @geo geography = geography::Point(@latitude, @longitude, @srid);
Select Top 1 
    Cast(pl.Location.STDistance(@geo)/1609.344 as dec(8,2)) Distance, 
    p.Name, 
    p.Address
From dbo.Pharmacy p
Inner Join dbo.PharmacyLocation pl
on p.Id = pl.PharmacyId
Where pl.Location.STDistance(@geo) is not null
Order By pl.Location.STDistance(@geo);
";
                var          data  = await conn.QueryFirstOrDefaultAsync <dynamic>(query, new { latitude, longitude, srid = 4326 });

                if (data == null)
                {
                    _logger.LogDebug("Repository FindClosestPharmacyAsync null successful");
                    return(null);
                }

                var result = new PharmacyDataModel
                {
                    Name     = data.Name,
                    Address  = data.Address,
                    Distance = data.Distance
                };
                _logger.LogDebug("Repository FindClosestPharmacyAsync successful");

                return(result);
            }
        }