public void Index_Should_Return_574_Error()
        {
            //arrange
            FormVM formVm = new FormVM();
            //Task<int> reference = 123;
            int reference = 0;
            //Controller needs a controller context
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var mockServiceProvider      = new Mock <IServiceProvider>();
            var mockLogger               = new Mock <ILogger <CheckYourAnswersController> >();
            var mockSession              = new Mock <ISessionService>();
            var mockSubmissionService    = new Mock <ISubmissionService>();
            var mockConfigurationService = new Mock <IConfiguration>();
            var mockNotificationService  = new Mock <INotificationService>();
            var mockDocumentService      = new Mock <IDocumentService>();

            mockSession.Setup(x => x.GetFormVmFromSession()).Returns(formVm);
            mockSubmissionService.Setup(x => x.GenerateUniqueUserRefAsync()).ReturnsAsync(reference);
            mockServiceProvider.Setup(x => x.GetService(typeof(ILogger <CheckYourAnswersController>))).Returns(mockLogger.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ISessionService))).Returns(mockSession.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ISubmissionService))).Returns(mockSubmissionService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(IConfiguration))).Returns(mockConfigurationService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(INotificationService))).Returns(mockNotificationService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(IDocumentService))).Returns(mockDocumentService.Object);

            var sut = new CheckYourAnswersController(mockServiceProvider.Object);

            sut.ControllerContext = controllerContext;
            //act
            var result = sut.Index(new CheckYourAnswersVm());

            //assert
            var statusResult = result as StatusResult;

            statusResult.StatusCode.Should().Be(574);
        }
Exemplo n.º 2
0
        public void Index_Should_Return_571_Error()
        {
            //arrange
            FormVM formVm = new FormVM();
            //Controller needs a controller context
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            var mockLogger               = new Mock <ILogger <CheckYourAnswersController> >();
            var mockSession              = new Mock <ISessionService>();
            var mockSubmissionService    = new Mock <ISubmissionService>();
            var mockConfigurationService = new Mock <IConfiguration>();
            var mockNotificationService  = new Mock <INotificationService>();
            var mockDocumentService      = new Mock <IDocumentService>();
            var mockPageHelper           = new Mock <IPageHelper>();
            var mockCosmosService        = new Mock <ICosmosService>();
            var mockConfig               = new Mock <IConfiguration>();

            mockSession.Setup(x => x.GetFormVmFromSession()).Returns(formVm);
            mockSession.Setup(x => x.GetUserSession()).Returns(new UserSessionVM {
                LocationName = null
            });

            var sut = new CheckYourAnswersController(mockLogger.Object, mockSubmissionService.Object, mockCosmosService.Object,
                                                     mockNotificationService.Object, mockDocumentService.Object, mockSession.Object,
                                                     mockPageHelper.Object, mockConfig.Object);

            sut.ControllerContext = controllerContext;
            //act
            var result = sut.Index();

            //assert
            var statusResult = result as StatusResult;

            statusResult.StatusCode.Should().Be(571);
        }
Exemplo n.º 3
0
        public void Index_Should_Return_570_Error()
        {
            //arrange
            //Controller needs a controller context
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var mockServiceProvider      = new Mock <IServiceProvider>();
            var mockLogger               = new Mock <ILogger <CheckYourAnswersController> >();
            var mockSession              = new Mock <ISessionService>();
            var mockSubmissionService    = new Mock <ISubmissionService>();
            var mockConfigurationService = new Mock <IConfiguration>();
            var mockNotificationService  = new Mock <INotificationService>();
            var mockDocumentService      = new Mock <IDocumentService>();
            var mockPageHelper           = new Mock <IPageHelper>();

            mockServiceProvider.Setup(x => x.GetService(typeof(IPageHelper))).Returns(mockPageHelper.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ILogger <CheckYourAnswersController>))).Returns(mockLogger.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ISessionService))).Returns(mockSession.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ISubmissionService))).Returns(mockSubmissionService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(IConfiguration))).Returns(mockConfigurationService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(INotificationService))).Returns(mockNotificationService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(IDocumentService))).Returns(mockDocumentService.Object);

            var sut = new CheckYourAnswersController(mockServiceProvider.Object);

            sut.ControllerContext = controllerContext;
            //act
            var result = sut.Index();

            //assert
            var statusResult = result as StatusResult;

            statusResult.StatusCode.Should().Be(570);
        }
Exemplo n.º 4
0
        public void Index_Should_Return_574_Error()
        {
            //arrange
            FormVM formVm = new FormVM
            {
                Version = "123",
                Pages   = new List <PageVM>
                {
                    new PageVM
                    {
                        PageId        = "CheckYourAnswers",
                        PreviousPages = new List <PreviousPageVM>
                        {
                            new PreviousPageVM {
                                PageId = "what-you-want-to-tell-us-about", QuestionId = "", Answer = ""
                            },
                            new PreviousPageVM {
                                PageId = "did-you-hear-about-this-form-from-a-charity", QuestionId = "", Answer = ""
                            },
                            new PreviousPageVM {
                                PageId = "give-your-feedback", QuestionId = "", Answer = ""
                            }
                        }
                    }
                }
            };
            CheckYourAnswersVm cyaVm = new CheckYourAnswersVm
            {
                FormVm       = formVm,
                LocationName = "Test Location"
            };
            SubmissionVM submission = new SubmissionVM
            {
                Id = "abc-123"
            };

            var mockLogger              = new Mock <ILogger <CheckYourAnswersController> >();
            var mockSessionService      = new Mock <ISessionService>();
            var mockCosmosService       = new Mock <ICosmosService>();
            var mockSubmissionService   = new Mock <ISubmissionService>();
            var mockNotificationService = new Mock <INotificationService>();
            var mockDocumentService     = new Mock <IDocumentService>();
            var mockPageHelper          = new Mock <IPageHelper>();

            var fakeConfiguration = new ConfigurationBuilder().Add(configData).Build();

            mockSessionService.Setup(x => x.GetFormVmFromSession()).Returns(formVm);
            mockSessionService.Setup(x => x.GetNavOrder()).Returns(new List <string>());
            mockCosmosService.Setup(x => x.GetDocumentId(It.IsAny <string>())).Returns(0);
            mockSubmissionService.Setup(x => x.CreateAsync(It.IsAny <SubmissionVM>())).ReturnsAsync(new SubmissionVM {
                Id = "123-abc"
            });


            var mockSession = new Mock <ISession>();
            var key         = "userdata";
            var value       = new byte[0];

            mockSession.Setup(x => x.Set(key, It.IsAny <byte[]>())).Callback <string, byte[]>((k, v) => value = v);
            mockSession.Setup(x => x.TryGetValue(key, out value)).Returns(true);


            var mockContext  = new Mock <HttpContext>();
            var mockResponse = new Mock <HttpResponse>();
            var requestMock  = new Mock <HttpRequest>();

            var httpContext = new DefaultHttpContext();

            mockResponse.Setup(x => x.HttpContext).Returns(httpContext);
            mockContext.Setup(s => s.Session).Returns(mockSession.Object);
            mockContext.Setup(s => s.Response).Returns(mockResponse.Object);
            mockContext.SetupGet(x => x.Request).Returns(requestMock.Object);

            var controllerContext = new ControllerContext()
            {
                HttpContext = mockContext.Object
            };


            var sut = new CheckYourAnswersController(mockLogger.Object, mockSubmissionService.Object, mockCosmosService.Object,
                                                     mockNotificationService.Object, mockDocumentService.Object, mockSessionService.Object,
                                                     mockPageHelper.Object, fakeConfiguration);

            sut.ControllerContext = controllerContext;

            //act
            var result = sut.Index(cyaVm);

            //assert
            var statusResult = result as StatusResult;

            statusResult.StatusCode.Should().Be(574);
        }
Exemplo n.º 5
0
        public void Index_Should_Return_575_Error()
        {
            //arrange
            FormVM formVm = new FormVM
            {
                Pages = new List <PageVM>
                {
                    new PageVM
                    {
                        PageId        = "CheckYourAnswers",
                        PreviousPages = new List <PreviousPageVM>
                        {
                            new PreviousPageVM {
                                PageId = "what-you-want-to-tell-us-about", QuestionId = "", Answer = ""
                            },
                            new PreviousPageVM {
                                PageId = "did-you-hear-about-this-form-from-a-charity", QuestionId = "", Answer = ""
                            },
                            new PreviousPageVM {
                                PageId = "give-your-feedback", QuestionId = "", Answer = ""
                            }
                        }
                    }
                }
            };
            //Controller needs a controller context
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            var mockServiceProvider      = new Mock <IServiceProvider>();
            var mockLogger               = new Mock <ILogger <CheckYourAnswersController> >();
            var mockSession              = new Mock <ISessionService>();
            var mockSubmissionService    = new Mock <ISubmissionService>();
            var mockConfigurationService = new Mock <IConfiguration>();
            var mockNotificationService  = new Mock <INotificationService>();
            var mockDocumentService      = new Mock <IDocumentService>();
            var mockPageHelper           = new Mock <IPageHelper>();

            mockServiceProvider.Setup(x => x.GetService(typeof(IPageHelper))).Returns(mockPageHelper.Object);
            mockSession.Setup(x => x.GetFormVmFromSession()).Returns(formVm);
            mockSession.Setup(x => x.GetUserSession()).Returns(new UserSessionVM {
                LocationName = "location"
            });
            mockSession.Setup(x => x.GetNavOrder()).Returns(new List <string>());
            mockServiceProvider.Setup(x => x.GetService(typeof(ILogger <CheckYourAnswersController>))).Returns(mockLogger.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ISessionService))).Returns(mockSession.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(ISubmissionService))).Returns(mockSubmissionService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(IConfiguration))).Returns(mockConfigurationService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(INotificationService))).Returns(mockNotificationService.Object);
            mockServiceProvider.Setup(x => x.GetService(typeof(IDocumentService))).Returns(mockDocumentService.Object);

            var sut = new CheckYourAnswersController(mockServiceProvider.Object);

            sut.ControllerContext = controllerContext;
            //act
            var result = sut.Index();

            //assert
            var statusResult = result as StatusResult;

            statusResult.StatusCode.Should().Be(575);
        }