コード例 #1
0
        public async void Patch_Record_Not_Found()
        {
            ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiApiKeyResponseModel>(null));
            ApiKeyController controller = new ApiKeyController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiApiKeyRequestModel>();

            patch.Replace(x => x.ApiKeyHashed, "A");

            IActionResult response = await controller.Patch(default(string), patch);

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <string>()));
        }
コード例 #2
0
        public async void Create_Errors()
        {
            ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiApiKeyResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiApiKeyResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiApiKeyRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiApiKeyResponseModel> >(mockResponse.Object));
            ApiKeyController controller = new ApiKeyController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiApiKeyRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiApiKeyRequestModel>()));
        }
コード例 #3
0
        public async void All_Exists()
        {
            ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade();
            var record  = new ApiApiKeyResponseModel();
            var records = new List <ApiApiKeyResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            ApiKeyController controller = new ApiKeyController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiApiKeyResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
コード例 #4
0
        public async void Create_No_Errors()
        {
            ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade();

            var mockResponse = new CreateResponse <ApiApiKeyResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiApiKeyResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiApiKeyRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiApiKeyResponseModel> >(mockResponse));
            ApiKeyController controller = new ApiKeyController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiApiKeyRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiApiKeyResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiApiKeyRequestModel>()));
        }