public void given_a_valid_and_existing_processRef_when_GetProcessData_controller_method_is_called_then_it_returns_a_200_Ok_result() { //arrange int expectedStatusCode = 200; var existingDocument = MatProcessDataHelper.CreateProcessDataObject(); _dbcontext.getCollection().InsertOne(BsonDocument.Parse(JsonConvert.SerializeObject(existingDocument))); // insert expected document, which we expect the gateway to retrieve var request = new GetProcessDataRequest() { processRef = existingDocument.Id }; //valid, and existing //act var contollerResponse = _processDataController.GetProcessData(request); var controllerObjectResult = contollerResponse as ObjectResult; //assert Assert.NotNull(contollerResponse); Assert.IsInstanceOf <OkObjectResult>(controllerObjectResult); Assert.AreEqual(expectedStatusCode, controllerObjectResult.StatusCode); }
public void given_a_processRef_when_getprocessdata_method_is_called_the_controller_returns_correct_json_response() { //arange string processRef = faker.Random.Guid().ToString(); var request = new GetProcessDataRequest() { processRef = processRef }; var response = new GetProcessDataResponse(request, new MatProcessData(), DateTime.Now); _mockUsecase.Setup(x => x.ExecuteGet(It.Is <GetProcessDataRequest>(i => i.processRef == processRef))).Returns(response); //act var actualResponse = _processDataController.GetProcessData(request); var okResult = (OkObjectResult)actualResponse; var resultContent = (GetProcessDataResponse)okResult.Value; //assert Assert.NotNull(actualResponse); Assert.NotNull(okResult); Assert.IsInstanceOf <GetProcessDataResponse>(resultContent); Assert.NotNull(resultContent); Assert.AreEqual(JsonConvert.SerializeObject(response), JsonConvert.SerializeObject(resultContent)); Assert.AreEqual(200, okResult.StatusCode); }