Beispiel #1
0
        public async void Get_Exists()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiStudioServerResponseModel()));
            StudioController controller = new StudioController(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.Get(default(int));

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var record = (response as OkObjectResult).Value as ApiStudioServerResponseModel;

            record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #2
0
        public async void All_Not_Exists()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult <List <ApiStudioServerResponseModel> >(new List <ApiStudioServerResponseModel>()));
            StudioController controller = new StudioController(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, string.Empty);

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

            items.Should().BeEmpty();
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Beispiel #3
0
        public async void Update_NotFound()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiStudioServerResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiStudioServerRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiStudioServerResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiStudioServerResponseModel>(null));
            StudioController controller = new StudioController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiStudioServerModelMapper());

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

            IActionResult response = await controller.Update(default(int), new ApiStudioServerRequestModel());

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #4
0
        public async void Patch_Record_Not_Found()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiStudioServerResponseModel>(null));
            StudioController controller = new StudioController(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 <ApiStudioServerRequestModel>();

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

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

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #5
0
        public async void Create_Errors()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiStudioServerResponseModel> >(null as ApiStudioServerResponseModel);
            var mockRecord   = new ApiStudioServerResponseModel();

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStudioServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStudioServerResponseModel> >(mockResponse.Object));
            StudioController controller = new StudioController(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 ApiStudioServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStudioServerRequestModel>()));
        }
Beispiel #6
0
        public async void Create_No_Errors()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiStudioServerResponseModel> .CreateResponse(null as ApiStudioServerResponseModel);

            mockResponse.SetRecord(new ApiStudioServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStudioServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStudioServerResponseModel> >(mockResponse));
            StudioController controller = new StudioController(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 ApiStudioServerRequestModel());

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

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