public async Task<IActionResult> PostAuthorise([FromBody] AuthorisationArgs args, [FromServices] HttpPostAuthoriseCommand command) { if (command == null) throw new ArgumentNullException(nameof(command)); _Logger.LogInformation("POST lab confirmation triggered."); return await command.Execute(args); }
public async Task PostLabConfirmation_ReturnsUnauthorized_When_NotAuthorized() { // Arrange var args = new AuthorisationArgs { LabConfirmationId = "222222", DateOfSymptomsOnset = DateTime.Today }; var client = _Factory.CreateClient(); var source = new CancellationTokenSource(); var token = source.Token; var content = new StringContent(JsonSerializer.Serialize(args)) { Headers = { ContentType = new MediaTypeHeaderValue("application/json") } }; // Act var result = await client.PostAsync($"{EndPointNames.CaregiversPortalApi.LabConfirmation}", content, token); // Assert Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode); }
public async Task <IActionResult> PostAuthorise([FromBody] AuthorisationArgs args, [FromServices] HttpPostAuthoriseCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } _Logger.WriteLabStart(); return(await command.ExecuteAsync(args)); }
public void Valid(string labConfirmationId) { // Assemble var dtp = new StandardUtcDateTimeProvider(); var validator = new AuthorisationArgsValidator(new LabConfirmationIdService(new StandardRandomNumberGenerator()), dtp); var args = new AuthorisationArgs { LabConfirmationId = labConfirmationId, DateOfSymptomsOnset = dtp.Snapshot }; // Act var result = validator.Validate(args); // Assert Assert.Empty(result); }
public async Task <IActionResult> PostAuthorise([FromBody] AuthorisationArgs args) { if (_RestApiClient == null) { throw new ArgumentNullException(nameof(_RestApiClient)); } var source = new CancellationTokenSource(); var token = source.Token; _Logger.WriteLabStart(); var result = await _RestApiClient.PostAsync(args, $"{EndPointNames.CaregiversPortalApi.LabConfirmation}", token); return(Ok()); }
public async Task PostAuthorise_ReturnsBadRequestResult_When_ConfirmationId_IsNotValid() { // Arrange var args = new AuthorisationArgs { LabConfirmationId = "111111", DateOfSymptomsOnset = DateTime.Today }; var client = _Factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { var sp = services.BuildServiceProvider(); using (var scope = sp.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <WorkflowDbContext>(); db.Database.EnsureCreated(); db.KeyReleaseWorkflowStates.Add(new TekReleaseWorkflowStateEntity { LabConfirmationId = args.LabConfirmationId, DateOfSymptomsOnset = args.DateOfSymptomsOnset }); db.SaveChanges(); } }); }) .CreateClient(); var source = new CancellationTokenSource(); var token = source.Token; var content = new StringContent(JsonSerializer.Serialize(args)) { Headers = { ContentType = new MediaTypeHeaderValue("application/json") } }; // Act var result = await client.PostAsync($"{EndPointNames.CaregiversPortalApi.LabConfirmation}", content, token); // Assert Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); }
public async Task <ActionResult <AuthorisationResponse> > PostAuthorise([FromBody] AuthorisationArgs args, [FromServices] HttpPostAuthoriseLabConfirmationIdCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } _Logger.WriteLabStart(); var result = await command.ExecuteAsync(args); if (result == null) { return(new BadRequestResult()); } return(Ok()); }
public async Task PostAuthorise_ReturnsOkResult_When_ConfirmationId_IsNotValid() { // Arrange var args = new AuthorisationArgs { LabConfirmationId = "111111", DateOfSymptomsOnset = DateTime.Today }; var client = _Factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { var descriptor = services.SingleOrDefault(d => d.ServiceType.Name == nameof(RestApiClient)); services.Remove(descriptor); services.AddHttpClient <IRestApiClient, FakeRestApiClient>(); services.AddSingleton <IPolicyEvaluator, FakePolicyEvaluator>(); }); }) .CreateClient(); var source = new CancellationTokenSource(); var token = source.Token; var content = new StringContent(JsonSerializer.Serialize(args)) { Headers = { ContentType = new MediaTypeHeaderValue("application/json") } }; // Act var result = await client.PostAsync($"{EndPointNames.CaregiversPortalApi.LabConfirmation}", content, token); // Assert Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
public async Task <IActionResult> PostAuthorise([FromBody] AuthorisationArgs args, [FromServices] HttpPostAuthorise command) { return(await command.Execute(args)); }