Beispiel #1
0
        public void ShouldCreateReleaseWithPrePatEmail()
        {
            //given
            var releaseRepository = new Mock <IReleaseRepository>();
            var releaseController = new ReleaseController(releaseRepository.Object);

            //We'll need mocks (fake) of Context, Request and a fake PostedFile
            var postedfile = new Mock <HttpPostedFileBase>();
            var release    = new Release();

            //Someone is going to ask for Request.File and we'll need a mock (fake) of that.
            string expectedFileName          = "Enzo Pre-PAT release 19122011 ref REL11125.0.00";
            string expectedFileTypeExtension = ".msg";
            string savedFileName             = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                            String.Concat(expectedFileName, expectedFileTypeExtension));

            postedfile.Setup(f => f.ContentLength).Returns(8192);
            postedfile.Setup(f => f.FileName).Returns(String.Concat(expectedFileName, expectedFileTypeExtension));

            releaseRepository.Setup(m => m.SaveReleaseDetails(It.IsAny <Release>()));

            //when
            releaseController.Create(release, postedfile.Object);

            //Then
            releaseRepository.Verify(x => x.SaveReleaseDetails(It.IsAny <Release>()), Times.Once());
            postedfile.Verify(x => x.SaveAs(savedFileName), Times.Once());


            Assert.That(release.PrePatEmailFile.Name, Is.EqualTo(savedFileName));
            Assert.That(release.PrePatEmailFile.Length, Is.EqualTo(8192));
        }
Beispiel #2
0
        public void ShouldBeAbleToCreateRelease()
        {
            //given
            var releaseRepository = new Mock <IReleaseRepository>();
            var releaseController = new ReleaseController(releaseRepository.Object);

            //when
            var redirectToRouteResult = (RedirectToRouteResult)releaseController.Create(new Release(), null);

            //then
            Assert.That(redirectToRouteResult.RouteValues["Controller"], Is.EqualTo("Release"));
            Assert.That(redirectToRouteResult.RouteValues["Action"], Is.EqualTo("Index"));
        }
        public void ShouldBeAbleToCreateRelease()
        {
            //given
            var releaseRepository = new Mock <IReleaseRepository>();
            var releaseController = new ReleaseController(releaseRepository.Object);

            //when
            var release = new Release();
            var redirectToRouteResult = (RedirectToRouteResult)releaseController.Create(release, null);

            //then
            releaseRepository.Verify(x => x.SaveReleaseDetails(release), Times.Once());
            Assert.That(redirectToRouteResult.RouteValues["Controller"], Is.EqualTo("Release"));
            Assert.That(redirectToRouteResult.RouteValues["Action"], Is.EqualTo("Index"));
        }
Beispiel #4
0
        public async void Create_Errors()
        {
            ReleaseControllerMockFacade mock = new ReleaseControllerMockFacade();

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

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

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

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

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

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

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

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiReleaseRequestModel>()));
        }
        public void ShouldCreateReleaseWithoutPrePatEmail()
        {
            //given


            var releaseRepository = new Mock <IReleaseRepository>();
            var releaseController = new ReleaseController(releaseRepository.Object);

            var releaseDetailsModel = new Release()
            {
                ReleaseNumber         = "REL1216",
                ReleaseFiInstructions = "FI as Normal",
                TeamName             = "ENZO",
                ServiceNowTicketLink = "www.google.co.uk"
            };

            //when
            releaseController.Create(releaseDetailsModel, null);

            //then
            releaseRepository.Verify(x => x.SaveReleaseDetails(releaseDetailsModel));
        }