public async Task PublishAsync_ArgumentNullOnNullRegion() { // Arrange InfectionReport request = new InfectionReport(); AreaReport areaMatch = new AreaReport { UserMessage = "Test user message" }; areaMatch.Areas.Add(new InfectionArea { BeginTimestamp = 0, EndTimestamp = 1, Location = new Coordinates { Latitude = 10.1234, Longitude = -10.1234 }, RadiusMeters = 100 }); request.AreaReports.Add(areaMatch); request.BluetoothSeeds.Add(new BluetoothSeed { EndTimestamp = 1, BeginTimestamp = 0, Seed = "00000000-0000-0000-0000-000000000000" }); // Act string result = await this._service .PublishAsync(request, null, CancellationToken.None); // Assert // Exception caught by decorator }
/// <inheritdoc/> public async Task PublishAreaAsync(AreaReport areaReport, CancellationToken cancellationToken = default) { // Validate inputs if (areaReport == null) { throw new ArgumentNullException(nameof(areaReport)); } RequestValidationResult validationResult = areaReport.Validate(); if (validationResult.Passed) { // Build an InfectionReport containing the submitted areas InfectionReport message = new InfectionReport(); message.AreaReports.Add(areaReport); // Define a regions for the published message IEnumerable <Region> messageRegions = RegionHelper.GetRegionsCoverage(areaReport.Areas, this.RegionPrecision); // Publish await this._reportRepo.InsertAsync(message, messageRegions, cancellationToken); } else { throw new RequestValidationFailedException(validationResult); } }
public async Task PublishAreaAsync_SucceedsOnValidInputs() { // Arrange AreaReport request = new AreaReport(); request.Areas.Add(new InfectionArea { BeginTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), EndTimestamp = DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeMilliseconds(), Location = new Coordinates { Latitude = 10.1234, Longitude = -10.1234 }, RadiusMeters = 100 }); request.UserMessage = "Test user message!"; string repoResponse = "00000000-0000-0000-0000-0000000000001"; this._repo .Setup(r => r.InsertAsync(It.IsAny <InfectionReport>(), It.IsAny <Region>(), CancellationToken.None)) .Returns(Task.FromResult(repoResponse)); // Act await this._service.PublishAreaAsync(request, CancellationToken.None); // Assert // No exceptions thrown }
public async Task PublishAsync_SucceedsOnValidMessage() { // Arrange string repoResponse = "00000000-0000-0000-0000-000000000002"; Region region = new Region { LatitudePrefix = 10.1234, LongitudePrefix = -10.1234, Precision = 4 }; InfectionReport request = new InfectionReport(); AreaReport areaReport = new AreaReport { UserMessage = "Test user message" }; areaReport.Areas.Add(new InfectionArea { BeginTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), EndTimestamp = DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeMilliseconds(), Location = new Coordinates { Latitude = 10.1234, Longitude = -10.1234 }, RadiusMeters = 100 }); request.AreaReports.Add(areaReport); request.BluetoothSeeds.Add(new BluetoothSeed { BeginTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), EndTimestamp = DateTimeOffset.UtcNow.AddHours(1).ToUnixTimeMilliseconds(), Seed = "00000000-0000-0000-0000-000000000001" }); this._repo .Setup(r => r.InsertAsync(It.IsAny <InfectionReport>(), It.IsAny <Region>(), CancellationToken.None)) .Returns(Task.FromResult(repoResponse)); // Act string result = await this._service .PublishAsync(request, region, CancellationToken.None); // Assert Assert.IsNotNull(result); Assert.AreEqual(repoResponse, result); }
public async Task <ActionResult> PutAsync([Required] AreaMatch request, CancellationToken cancellationToken = default) { try { // Parse AreaMatch to AreaReport type AreaReport report = this._map.Map <AreaReport>(request); // Publish area await this._reportService.PublishAreaAsync(report, cancellationToken); return(Ok()); } catch (RequestValidationFailedException ex) { // Only return validation issues return(BadRequest(ex.ValidationResult)); } catch (ArgumentNullException) { return(BadRequest()); } }