public async Task ResolveDiscrepancyNotFound() { // Arrange var input = new DiscrepancyResolutionViewModel { DateFirstOffense = DateTime.UtcNow, EnumDiscrepancyType = DiscrepancyType.GapInData, EnumMetricType = Metrics.CpuLoad, Source = "the-source" }; // Act var result = await _controller.ResolveDiscrepancy(input); // Assert var notFoundResult = Assert.IsType <NotFoundObjectResult>(result); _mockNotificationService .Verify( n => n.ScheduleNotificationAsync( It.Is <string>(s => s.Contains("the-source")), NotificationSeverity.Medium ), Times.Never() ); }
public async Task <IActionResult> ResolveDiscrepancy(DiscrepancyResolutionViewModel model) { if ( await _context .Discrepancies .AnyAsync( d => d.DateFirstOffense == model.DateFirstOffense && d.MetricSource == model.Source && d.MetricType == model.EnumMetricType && d.Type == model.EnumDiscrepancyType ) ) { var discrepancy = await _context .Discrepancies .SingleAsync( d => d.DateFirstOffense == model.DateFirstOffense && d.MetricSource == model.Source && d.MetricType == model.EnumMetricType && d.Type == model.EnumDiscrepancyType ); if (discrepancy.Resolved) { TempData["MessageSeverity"] = "warning"; TempData["MessageContent"] = $"Discrepancy {model.EnumDiscrepancyType} from {model.EnumMetricType} of {model.Source} at {model.DateFirstOffense} (UTC) has been already resolved."; } else { discrepancy.Resolved = true; discrepancy.DateResolved = DateTime.UtcNow; await _notification.ScheduleNotificationAsync( $"Discrepancy \"{discrepancy.ToStringWithTimeZone(_config["ServiceManager:NotificationService:TimeZone"])}\" has been resolved!", NotificationSeverity.Medium ); await _context.SaveChangesAsync(); TempData["MessageSeverity"] = "success"; TempData["MessageContent"] = $"Discrepancy {model.EnumDiscrepancyType} from {model.EnumMetricType} of {model.Source} at {model.DateFirstOffense} (UTC) has been resolved."; } return(RedirectToAction("Index", "Admin")); } else { return(NotFound($"Discrepancy for the following request not found. {model}")); } }
public async Task ResolveDiscrepancyWarning() { // Arrange var now = DateTime.UtcNow; await _context.Discrepancies.AddAsync( new Discrepancy { Type = DiscrepancyType.GapInData, MetricType = Metrics.CpuLoad, MetricSource = "the-source", DateFirstOffense = now, Resolved = true } ); await _context.SaveChangesAsync(); var input = new DiscrepancyResolutionViewModel { DateFirstOffense = now, EnumDiscrepancyType = DiscrepancyType.GapInData, EnumMetricType = Metrics.CpuLoad, Source = "the-source" }; // Act var result = await _controller.ResolveDiscrepancy(input); // Assert var redirectResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectResult.ActionName); Assert.Equal("Admin", redirectResult.ControllerName); _mockNotificationService .Verify( n => n.ScheduleNotificationAsync( It.Is <string>(s => s.Contains("the-source")), NotificationSeverity.Medium ), Times.Never() ); }
public async Task ResolveDiscrepancySuccess() { // Arrange var now = DateTime.UtcNow; await _context.Discrepancies.AddAsync( new Discrepancy { Type = DiscrepancyType.GapInData, MetricType = Metrics.CpuLoad, MetricSource = "the-source", DateFirstOffense = now, Resolved = false } ); await _context.SaveChangesAsync(); var input = new DiscrepancyResolutionViewModel { DateFirstOffense = now, EnumDiscrepancyType = DiscrepancyType.GapInData, EnumMetricType = Metrics.CpuLoad, Source = "the-source" }; // Act var result = await _controller.ResolveDiscrepancy(input); // Assert var redirectResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectResult.ActionName); Assert.Equal("Admin", redirectResult.ControllerName); Assert.True( (await _context .Discrepancies .SingleAsync(d => d.DateFirstOffense == now && d.MetricSource == "the-source" && d.MetricType == Metrics.CpuLoad && d.Type == DiscrepancyType.GapInData ) ).Resolved ); Assert.InRange( (await _context .Discrepancies .SingleAsync(d => d.DateFirstOffense == now && d.MetricSource == "the-source" && d.MetricType == Metrics.CpuLoad && d.Type == DiscrepancyType.GapInData ) ).DateResolved, now, now.AddMinutes(1) ); _mockNotificationService .Verify( n => n.ScheduleNotificationAsync( It.Is <string>(s => s.Contains("the-source")), NotificationSeverity.Medium ) ); _mockConfig.Verify(conf => conf["ServiceManager:NotificationService:TimeZone"]); }