Exemple #1
0
        public async Task PostTest()
        {
            var actual = await controller.Create(new Video()
            {
                Name = "CreateVideo", UserId = "1"
            });

            Assert.IsType <CreatedResult>(actual);
            CreatedResult result = actual as CreatedResult;
            var           item   = result.Value as Video;

            Assert.Equal("CreateVideo", item.Name);
        }
Exemple #2
0
        public async void Create_Errors()
        {
            VideoControllerMockFacade mock = new VideoControllerMockFacade();

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

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

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

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

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

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

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

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