diff --git a/src/api/Features/Geocoding/UspsDeliveryPointLocation.cs b/src/api/Features/Geocoding/UspsDeliveryPointLocation.cs index 27bd12a6..360bd463 100644 --- a/src/api/Features/Geocoding/UspsDeliveryPointLocation.cs +++ b/src/api/Features/Geocoding/UspsDeliveryPointLocation.cs @@ -25,7 +25,7 @@ public class Handler(IStaticCache staticCache, ILogger log) : IComputationHandle _staticCache.UspsDeliveryPoints.TryGetValue(request._address.Zip5.Value.ToString(), out var items); - if (items?.Count != 0) { + if ((items?.Count ?? 0) == 0) { _log?.ForContext("zip", request._address.Zip5.Value) .Debug("Delivery Point: cache miss"); diff --git a/src/api/Middleware/AuthorizeApiKey.cs b/src/api/Middleware/AuthorizeApiKey.cs index c6612683..0d75ba6f 100644 --- a/src/api/Middleware/AuthorizeApiKey.cs +++ b/src/api/Middleware/AuthorizeApiKey.cs @@ -25,7 +25,9 @@ public class AuthorizeApiKeyFilter(ILogger log, IBrowserKeyProvider browserProvi } var apiKey = await _repo.GetKey(key); - await _db.StringIncrementAsync(key, flags: CommandFlags.FireAndForget); + try { + await _db.StringIncrementAsync(key, flags: CommandFlags.FireAndForget); + } catch { } // key hasn't been created if (apiKey == null) { diff --git a/src/data-migration/Program.cs b/src/data-migration/Program.cs index 84e780e6..0734015d 100644 --- a/src/data-migration/Program.cs +++ b/src/data-migration/Program.cs @@ -6,7 +6,7 @@ Console.WriteLine("Migrating RavenDB to firestore..."); var store = new DocumentStore() { - Urls = new[] { "http://localhost:3000" }, + Urls = ["http://localhost:3000"], Database = "export" }.Initialize(); diff --git a/test/api.unit.tests/Features/Geocoding/DeliveryPointTests.cs b/test/api.unit.tests/Features/Geocoding/DeliveryPointTests.cs index 7c8e9819..f99e776f 100644 --- a/test/api.unit.tests/Features/Geocoding/DeliveryPointTests.cs +++ b/test/api.unit.tests/Features/Geocoding/DeliveryPointTests.cs @@ -24,9 +24,7 @@ public async Task Should_return_candidate_from_cache() { const int pobox = -1; const int zip = 84114; - var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip, - new[] { new ZipGridLink(84114, "grid", 0) } - ); + var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip, [new ZipGridLink(84114, "grid", 0)]); var geocodeOptions = new SingleGeocodeRequestOptionsContract { PoBox = true, diff --git a/test/api.unit.tests/Features/Geocoding/DoubleAveExceptionTests.cs b/test/api.unit.tests/Features/Geocoding/DoubleAveExceptionTests.cs index d015631c..32423373 100644 --- a/test/api.unit.tests/Features/Geocoding/DoubleAveExceptionTests.cs +++ b/test/api.unit.tests/Features/Geocoding/DoubleAveExceptionTests.cs @@ -17,13 +17,13 @@ public DoubleAveExceptionTests() { mediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((AddressSystemFromPlace.Computation g, CancellationToken _) => { if (g?._cityKey == "slc") { - return new[] { new PlaceGridLink("slc", "salt lake city", 1) }; + return [new PlaceGridLink("slc", "salt lake city", 1)]; } - return Array.Empty(); + return []; }); mediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) - .ReturnsAsync(Array.Empty()); + .ReturnsAsync([]); var regexCache = new RegexCache(new Abbreviations()); _computationHandler = new ZoneParsing.Handler(regexCache, mediator.Object, mockLogger.Object); diff --git a/test/api.unit.tests/Features/Geocoding/GeocodeQueryTests.cs b/test/api.unit.tests/Features/Geocoding/GeocodeQueryTests.cs index 965300fe..f06a8bee 100644 --- a/test/api.unit.tests/Features/Geocoding/GeocodeQueryTests.cs +++ b/test/api.unit.tests/Features/Geocoding/GeocodeQueryTests.cs @@ -19,21 +19,21 @@ public async Task Should_run_through_main_process() { var computeMediator = new Mock(); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((AddressParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => null); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((GeocodePlan.Computation __, CancellationToken _) => - new[] { new LocatorProperties("http://geocoding.plan", "test", 0) } + [new LocatorProperties("http://geocoding.plan", "test", 0)] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((Geocode.Computation __, CancellationToken _) => - new[] { new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0) } + [new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) => @@ -63,11 +63,11 @@ public async Task Should_return_404_when_there_is_no_geocode_plan() { var computeMediator = new Mock(); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((AddressParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => null); @@ -77,7 +77,7 @@ public async Task Should_return_404_when_there_is_no_geocode_plan() { ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((Geocode.Computation __, CancellationToken _) => - Array.Empty() + [] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) => @@ -107,21 +107,21 @@ public async Task Should_return_404_when_there_is_no_candidate_above_match_score var computeMediator = new Mock(); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((AddressParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => null); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((GeocodePlan.Computation __, CancellationToken _) => - new[] { new LocatorProperties("http://geocoding.plan", "test", 0) } + [new LocatorProperties("http://geocoding.plan", "test", 0)] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((Geocode.Computation __, CancellationToken _) => - new[] { new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0) } + [new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) => null); @@ -142,11 +142,11 @@ public async Task Should_return_early_with_delivery_point() { var computeMediator = new Mock(); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((AddressParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) => - new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false) + new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false) ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => @@ -154,11 +154,11 @@ public async Task Should_return_early_with_delivery_point() { ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((GeocodePlan.Computation __, CancellationToken _) => - new[] { new LocatorProperties("http://geocoding.plan", "test", 0) } + [new LocatorProperties("http://geocoding.plan", "test", 0)] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((Geocode.Computation __, CancellationToken _) => - new[] { new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0) } + [new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)] ); computeMediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) => diff --git a/test/api.unit.tests/Features/Geocoding/PoBoxTests.cs b/test/api.unit.tests/Features/Geocoding/PoBoxTests.cs index e89799f5..44cc05ce 100644 --- a/test/api.unit.tests/Features/Geocoding/PoBoxTests.cs +++ b/test/api.unit.tests/Features/Geocoding/PoBoxTests.cs @@ -7,7 +7,7 @@ public class PoBoxTests { public PoBoxTests() { _poBoxes.Add(84114, new PoBoxAddress(84114, 1, 1)); _exclusions.Add(841140001, new PoBoxAddressCorrection(84114, 841140001, 2, 2)); - IReadOnlyCollection zipExclusions = new[] { 84114 }; + IReadOnlyCollection zipExclusions = [84114]; var mockCache = new Mock(); mockCache.Setup(x => x.PoBoxes).Returns(_poBoxes); @@ -32,7 +32,7 @@ public async Task Should_return_candidate_from_exclusions() { const int zip = 84114; var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip, - new[] { new ZipGridLink(84114, "grid", 0) } + [new ZipGridLink(84114, "grid", 0)] ); var geocodeOptions = new SingleGeocodeRequestOptionsContract { @@ -56,7 +56,7 @@ public async Task Should_return_candidate_from_poboxes() { const int zip = 84114; var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip, - new[] { new ZipGridLink(84114, "grid", 0) } + [new ZipGridLink(84114, "grid", 0)] ); var geocodeOptions = new SingleGeocodeRequestOptionsContract { diff --git a/test/api.unit.tests/Features/Geocoding/ReverseGeocodeQueryTests.cs b/test/api.unit.tests/Features/Geocoding/ReverseGeocodeQueryTests.cs index a5489ee7..a138e9d5 100644 --- a/test/api.unit.tests/Features/Geocoding/ReverseGeocodeQueryTests.cs +++ b/test/api.unit.tests/Features/Geocoding/ReverseGeocodeQueryTests.cs @@ -16,7 +16,7 @@ public async Task Should_return_404_when_no_plan_is_created() { var mediator = new Mock(); mediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) .ReturnsAsync((ReverseGeocodePlan.Computation __, CancellationToken _) => - Array.Empty() + [] ); var handler = new ReverseGeocodeQuery.Handler(mediator.Object, _logger); diff --git a/test/api.unit.tests/Features/Geocoding/SingleGeocodeResponseContractTests.cs b/test/api.unit.tests/Features/Geocoding/SingleGeocodeResponseContractTests.cs index 52d84efc..a58f2662 100644 --- a/test/api.unit.tests/Features/Geocoding/SingleGeocodeResponseContractTests.cs +++ b/test/api.unit.tests/Features/Geocoding/SingleGeocodeResponseContractTests.cs @@ -72,7 +72,7 @@ public void Should_return_graphic_for_esri_json() { point.Y.ShouldBe(2); } - feature.Attributes.Keys.ShouldBe(new[] { "Location", "Score", "Locator", "MatchAddress", "InputAddress", "StandardizedAddress", "AddressGrid", "ScoreDifference", "Wkid", "Candidates" }); + feature.Attributes.Keys.ToList().ShouldBe(["Location", "Score", "Locator", "MatchAddress", "InputAddress", "StandardizedAddress", "AddressGrid", "ScoreDifference", "Wkid", "Candidates"]); feature.Attributes["Location"].ShouldNotBeNull(); feature.Attributes["Score"].ShouldBe(score); feature.Attributes["Locator"].ShouldBe(locatorType.ToString()); diff --git a/test/api.unit.tests/Features/Geocoding/ZoneParsingTests.cs b/test/api.unit.tests/Features/Geocoding/ZoneParsingTests.cs index 7e87b553..6d41a997 100644 --- a/test/api.unit.tests/Features/Geocoding/ZoneParsingTests.cs +++ b/test/api.unit.tests/Features/Geocoding/ZoneParsingTests.cs @@ -13,10 +13,10 @@ public ZoneParsingTests() { It.IsAny())) .ReturnsAsync((AddressSystemFromPlace.Computation g, CancellationToken _) => { if (g._cityKey == "alta") { - return new[] { new PlaceGridLink("alta", "grid", 1) }; + return [new PlaceGridLink("alta", "grid", 1)]; } - return Array.Empty(); + return []; }); var mock = new Mock() { DefaultValue = DefaultValue.Mock }; diff --git a/test/api.unit.tests/Features/Milepost/DominantRouteResolverTests.cs b/test/api.unit.tests/Features/Milepost/DominantRouteResolverTests.cs index 3450c51d..bc0691a2 100644 --- a/test/api.unit.tests/Features/Milepost/DominantRouteResolverTests.cs +++ b/test/api.unit.tests/Features/Milepost/DominantRouteResolverTests.cs @@ -25,8 +25,8 @@ public async Task Should_build_route_map_for_every_location() { new Concurrencies.ResponseLocations([ new Concurrencies.ConcurrencyLocations(true,"1", -1, 1) ], "1", -1, 1), - new Concurrencies.ResponseLocations(Array.Empty(), "2", -1, 1), - new Concurrencies.ResponseLocations(Array.Empty(), "3", -1, 1) + new Concurrencies.ResponseLocations([], "2", -1, 1), + new Concurrencies.ResponseLocations([], "3", -1, 1) ], null); var computation = new DominantRouteResolver.Computation(locations, null, 0); diff --git a/test/api.unit.tests/Features/Searching/AttributeTableKeyFormattingTests.cs b/test/api.unit.tests/Features/Searching/AttributeTableKeyFormattingTests.cs index ecee53f7..755e010f 100644 --- a/test/api.unit.tests/Features/Searching/AttributeTableKeyFormattingTests.cs +++ b/test/api.unit.tests/Features/Searching/AttributeTableKeyFormattingTests.cs @@ -23,7 +23,7 @@ public AttributeTableKeyFormattingTests() { var mediator = new Mock(); mediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) - .ReturnsAsync(Array.Empty()); + .ReturnsAsync([]); var dbOptions = Options.Create(new SearchProviderConfiguration()); diff --git a/test/api.unit.tests/Features/Searching/SearchQueryTests.cs b/test/api.unit.tests/Features/Searching/SearchQueryTests.cs index 8f8683de..61b3d4e4 100644 --- a/test/api.unit.tests/Features/Searching/SearchQueryTests.cs +++ b/test/api.unit.tests/Features/Searching/SearchQueryTests.cs @@ -16,7 +16,7 @@ public async Task Should_return_results() { var mediator = new Mock(); mediator.Setup(x => x.Handle(It.IsAny(), It.IsAny())) - .ReturnsAsync(new[] { + .ReturnsAsync([ new SearchResponseContract { Geometry = new SerializableGraphic( new Graphic( @@ -27,7 +27,7 @@ public async Task Should_return_results() { { "key", "value"} } } - }); + ]); var handler = new SearchQuery.Handler(mediator.Object, _logger); var result = await handler.Handle(query, CancellationToken.None) as IApiResponse>; diff --git a/test/api.unit.tests/Filters/AuthorizeApiKeyTests.cs b/test/api.unit.tests/Filters/AuthorizeApiKeyTests.cs index 8a226eda..af1efec8 100644 --- a/test/api.unit.tests/Filters/AuthorizeApiKeyTests.cs +++ b/test/api.unit.tests/Filters/AuthorizeApiKeyTests.cs @@ -58,6 +58,8 @@ public AuthorizeApiKeyTests() { [InlineData(@"^htt(p|ps)://168\.177\.222\.22\/app\/.*", "http://168.177.222.22/app/whatever", null)] public async Task Should_validate_production_browser_key(string pattern, string url, object responseCode) { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -74,7 +76,7 @@ public async Task Should_validate_production_browser_key(string pattern, string var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Referrer"] = url; - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -134,6 +136,8 @@ public async Task Should_validate_production_browser_key(string pattern, string public async Task Should_validate_production_browser_key_with_cors_header( string pattern, string url, object responseCode) { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -149,9 +153,9 @@ public async Task Should_validate_production_browser_key_with_cors_header( var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Referrer"] = url; - httpContext.Request.Headers["Origin"] = url; + httpContext.Request.Headers.Origin = url; - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -172,6 +176,8 @@ public async Task Should_validate_production_browser_key_with_cors_header( [InlineData("^htt(p|ps)://machine-name", "http://machine-name/index.html", null)] public async Task Should_validate_dev_key(string pattern, string url, object responseCode) { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -188,7 +194,7 @@ public async Task Should_validate_dev_key(string pattern, string url, object res var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Referrer"] = url; - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -208,6 +214,8 @@ public async Task Should_validate_dev_key(string pattern, string url, object res [InlineData(null)] public async Task Should_404_empty_key(string key) { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -219,7 +227,7 @@ public async Task Should_404_empty_key(string key) { var httpContext = new DefaultHttpContext(); - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -238,6 +246,8 @@ public async Task Should_404_empty_key(string key) { [InlineData(false, false)] public async Task Should_404_disabled_or_deleted_keys(bool deleted, bool disabled) { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -253,7 +263,7 @@ public async Task Should_404_disabled_or_deleted_keys(bool deleted, bool disable var httpContext = new DefaultHttpContext(); - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -272,6 +282,9 @@ public async Task Should_404_disabled_or_deleted_keys(bool deleted, bool disable [InlineData("1.1.1.1", "0.0.0.1", 400)] public async Task Should_validate_ip_based_keys(string ip, string keyIp, object responseCode) { var keyProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); + keyProvider.Setup(x => x.Get(It.IsAny())) .Returns("key"); @@ -289,7 +302,7 @@ public async Task Should_validate_ip_based_keys(string ip, string keyIp, object var httpContext = new DefaultHttpContext(); - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -306,6 +319,8 @@ public async Task Should_validate_ip_based_keys(string ip, string keyIp, object [Fact] public async Task Should_404_no_key() { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -317,7 +332,7 @@ public async Task Should_404_no_key() { var httpContext = new DefaultHttpContext(); - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); @@ -334,6 +349,8 @@ public async Task Should_404_no_key() { [Fact] public async Task Should_pass_elevated_keys() { var ipProvider = new Mock(); + var mockMultiplexer = new Mock(); + var redisProvider = new Lazy(() => mockMultiplexer.Object); var keyProvider = new Mock(); keyProvider.Setup(x => x.Get(It.IsAny())) @@ -349,7 +366,7 @@ public async Task Should_pass_elevated_keys() { var httpContext = new DefaultHttpContext(); - var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object); + var filter = new AuthorizeApiKeyFilter(_log, keyProvider.Object, ipProvider.Object, apiRepo.Object, redisProvider); var contextMock = new Mock(); contextMock.Setup(x => x.HttpContext).Returns(httpContext); diff --git a/test/api.unit.tests/Models/ArcGis/MeasureToGeometryTests.cs b/test/api.unit.tests/Models/ArcGis/MeasureToGeometryTests.cs index 0cd1b09a..d318f01f 100644 --- a/test/api.unit.tests/Models/ArcGis/MeasureToGeometryTests.cs +++ b/test/api.unit.tests/Models/ArcGis/MeasureToGeometryTests.cs @@ -48,7 +48,7 @@ public void Should_create_valid_json_for_request_location() { } [Fact] public void Should_strip_leading_zeros_and_trailing_m() { - var model = new MeasureToGeometry.ResponseLocation(MeasureToGeometry.Status.esriLocatingOK, Array.Empty(), "0001PM", GeometryType.esriGeometryPoint, null); + var model = new MeasureToGeometry.ResponseLocation(MeasureToGeometry.Status.esriLocatingOK, [], "0001PM", GeometryType.esriGeometryPoint, null); model.RouteId.ShouldBe("1P"); }