public void set_up()
        {
            //setting connection options for dbcontext
            var mockOptions = new Mock <IOptions <ConnectionSettings> >();
            //runtime DB connection strings
            var settings = new ConnectionSettings
            {
                ConnectionString = Environment.GetEnvironmentVariable("MONGO_CONN_STRING") ??
                                   @"mongodb://localhost:1433/",
                CollectionName = "process-data",
                Database       = "mat-processes"
            };

            //make options mock return the object with settings
            mockOptions.SetupGet(x => x.Value).Returns(settings);

            //setting up dbcontext
            _dbcontext = new MatDbContext(mockOptions.Object);
            var processDataGateway   = new ProcessDataGateway(_dbcontext);
            var processDataUsecase   = new ProcessDataUseCase(processDataGateway);
            var postInitDocValidator = new PostInitialProcessDocumentRequestValidator();
            var updateDocValidator   = new UpdateProcessDocumentRequestValidator();
            var getDocValidator      = new GetProcessDocumentRequestValidator();
            Mock <ILogger <ProcessDataController> > logger = new Mock <ILogger <ProcessDataController> >();

            _processDataController = new ProcessDataController(processDataUsecase, logger.Object, postInitDocValidator, updateDocValidator, getDocValidator);
        }
        public void postInitialProcessDocument_controller_method_end_to_end_test_with_a_invalid_request() //testing, when validation fails
        {
            //arrange
            PostInitialProcessDocumentRequest requestObject = MatProcessDataHelper.CreatePostInitialProcessDocumentRequestObject();
            string nonsenseGuid = _faker.Random.Word().ToString(); // invalid Guid (not even a guid) - this should trip the validation.

            requestObject.processRef = nonsenseGuid;

            var postValidator  = new PostInitialProcessDocumentRequestValidator();
            var isRequestValid = postValidator.Validate(requestObject);
            var errors         = isRequestValid.Errors;

            var expectedResponse = new BadRequestObjectResult(errors);

            //act
            var controllerResponse = _processDataController.PostInitialProcessDocument(requestObject);
            var actualResult       = (ObjectResult)controllerResponse;
            var actualContents     = (IList <ValidationFailure>)actualResult.Value;

            //assert
            Assert.NotNull(controllerResponse);
            Assert.IsInstanceOf <BadRequestObjectResult>(actualResult); // should be bad request, since validation fails.
            Assert.NotNull(actualResult);
            Assert.IsInstanceOf <IList <ValidationFailure> >(actualContents);
            Assert.NotNull(actualContents);

            Assert.AreEqual(1, actualContents.Count);      // there should be 1 validation failure coming from the invalid guid
            Assert.AreEqual(400, actualResult.StatusCode); // expecting bad request result

            //the following simply proves that validation errors get wraped up properly.
            Assert.AreEqual(((IList <ValidationFailure>)expectedResponse.Value)[0].ErrorMessage, actualContents[0].ErrorMessage);
        }
示例#3
0
 public void SetUp()
 {
     _postInitProcessDocValidator = new PostInitialProcessDocumentRequestValidator();
     randomGuid = _faker.Random.Guid().ToString();
 }