public IActionResult GetPerson([FromQuery] GetPersonRequest request) { if (request.AuditingEnabled && !string.IsNullOrEmpty(request.UserId)) { var auditRequest = new CreateRequestAuditRequest() { ActionName = "view_resident", UserName = request.UserId, Metadata = new Dictionary <string, object>() { { "residentId", request.Id } } }; _createRequestAuditUseCase.Execute(auditRequest); } var response = _residentUseCase.GetResident(request); if (response == null) { return(NotFound()); } return(StatusCode(200, response)); }
public void GetPersonByIdCallsTheCreateRequestAuditUseCaseWithCorrectValuesWhenAuditingIsEnabledIsTrueAndUserIdIsProvided() { var getPersonRequest = new GetPersonRequest() { AuditingEnabled = true, UserId = _faker.Person.Email, Id = 1 }; var request = new CreateRequestAuditRequest() { ActionName = "view_resident", UserName = getPersonRequest.UserId, Metadata = new Dictionary <string, object>() { { "residentId", getPersonRequest.Id } } }; _mockCreateRequestAuditUseCase.Setup(x => x.Execute(request)).Verifiable(); _residentController.GetPerson(getPersonRequest); _mockCreateRequestAuditUseCase.Verify(x => x.Execute(It.Is <CreateRequestAuditRequest>( y => y.ActionName == request.ActionName && y.UserName == request.UserName && JsonConvert.SerializeObject(y.Metadata) == JsonConvert.SerializeObject(request.Metadata) )), Times.Once); }
public void GetCaseByRecordIdCallsTheCreateRequestAuditUseCaseWithCorrectValuesWhenAuditingIsEnabled() { var getCaseNotesRequest = new GetCaseNotesRequest() { AuditingEnabled = true, UserId = _faker.Person.Email, Id = "tyut67t89t876t", ResidentId = "4" }; var auditRequest = new CreateRequestAuditRequest() { ActionName = "view_case_note", UserName = getCaseNotesRequest.UserId, Metadata = new Dictionary <string, object>() { { "residentId", getCaseNotesRequest.ResidentId }, { "casenoteId", getCaseNotesRequest.Id } } }; _mockCreateRequestAuditUseCase.Setup(x => x.Execute(auditRequest)).Verifiable(); _caseController.GetCaseByRecordId(getCaseNotesRequest); _mockCreateRequestAuditUseCase.Verify(x => x.Execute(It.Is <CreateRequestAuditRequest>( x => x.ActionName == auditRequest.ActionName && x.UserName == auditRequest.UserName && JsonConvert.SerializeObject(x.Metadata) == JsonConvert.SerializeObject(auditRequest.Metadata) )), Times.Once); }
public IActionResult GetCaseByRecordId([FromQuery] GetCaseNotesRequest request) { if (request.AuditingEnabled && !string.IsNullOrEmpty(request.UserId) && !string.IsNullOrEmpty(request.ResidentId)) { var auditRequest = new CreateRequestAuditRequest() { ActionName = "view_case_note", UserName = request.UserId, Metadata = new Dictionary <string, object>() { { "residentId", request.ResidentId }, { "casenoteId", request.Id } } }; _createRequestAuditUseCase.Execute(auditRequest); } var caseRecord = _caseRecordsUseCase.Execute(request.Id); if (caseRecord == null) { return(NotFound("Document Not Found")); } return(Ok(caseRecord)); }
public void DoesNotThrowAnExceptionWhenDatabaseGatewayThrowsAnException() { var request = new CreateRequestAuditRequest(); _mockDatabaseGateway.Setup(x => x.CreateRequestAudit(request)).Throws(new Exception()); _createRequestUseCase.Invoking(x => x.Execute(request)).Should().NotThrow <Exception>(); }
public void CallsDatabaseGateway() { var request = new CreateRequestAuditRequest(); _createRequestUseCase.Execute(request); _mockDatabaseGateway.Verify(x => x.CreateRequestAudit(request)); }
public void Execute(CreateRequestAuditRequest request) { try { _databaseGateway.CreateRequestAudit(request); } catch (Exception) { } }
public void CreateRequestAudit(CreateRequestAuditRequest request) { var requestAudit = (new RequestAudit() { ActionName = request.ActionName, UserName = request.UserName, Metadata = request.Metadata, Timestamp = DateTime.Now }); _databaseContext.RequestAudits.Add(requestAudit); _databaseContext.SaveChanges(); }
public void CreatesRequestAudit() { var metadata = new Dictionary <string, object>() { { "residentId", 333 }, { "caseNoteId", 555 } }; CreateRequestAuditRequest requestAuditRequest = new CreateRequestAuditRequest() { ActionName = "view_resident", UserName = _faker.Person.Email, Metadata = metadata }; _databaseGateway.CreateRequestAudit(requestAuditRequest); var requestAudit = DatabaseContext.RequestAudits.FirstOrDefault(); requestAudit?.ActionName.Should().Be(requestAuditRequest.ActionName); requestAudit?.UserName.Should().Be(requestAuditRequest.UserName); requestAudit?.Timestamp.Should().BeCloseTo(DateTime.Now, precision: 1000); requestAudit?.Metadata.Should().BeEquivalentTo(requestAuditRequest.Metadata); }