예제 #1
0
        public void Index_Get_ReturnsHomePageViewModel()
        {
            // Arrange
            const int homePageId = 1;

            var controller = new HomePageController
            {
                ApplicationService = ApplicationServiceMock.Object,
                MapModelService    = new MapModelService()
            };

            var homePage = new HomePage {
                Id = homePageId
            };

            ApplicationServiceMock.Setup(x => x.GetPageModel <HomePage>(DocTypeAliases.HomePage.Alias)).Returns(homePage);

            var homePageViewModel = controller.MapModelService.Map <HomePageViewModel>(homePage);

            // Act
            var result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsAssignableFrom <HomePageViewModel>(result.Model);
            Assert.AreEqual(homePageViewModel.Id, ((HomePageViewModel)result.Model).Id);
        }
        public void GetTransactions_ShouldReturnListOfNewsletters()
        {
            // Arrange
            var controller = new NewsletterApiController
            {
                ApplicationService = ApplicationServiceMock.Object
            };

            var newsletters = new List <Newsletter>
            {
                new Newsletter {
                    Id = 1, Email = "*****@*****.**"
                },
                new Newsletter {
                    Id = 2, Email = "*****@*****.**"
                }
            };

            var newsletterFolder = new NewsletterFolder {
                Newsletters = newsletters
            };

            ApplicationServiceMock.Setup(x => x.GetPageModel <NewsletterFolder>(DocTypeAliases.NewsletterFolder.Alias))
            .Returns(newsletterFolder);

            // Act
            var result = controller.GetNewsletters();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(newsletters, result);
        }
        public void Subscribe_PostEmail_CreatesContentNodeInUmbracoAndRedirectsToCurrentUmbracoPageWithTempData()
        {
            // Arrange
            const string successKey         = "success";
            const int    newsletterFolderId = 1;
            const string submittedEmail     = "*****@*****.**";

            var umbCtx     = RoutingContext.UmbracoContext;
            var controller = new NewsletterSurfaceController(umbCtx, new UmbracoHelper(umbCtx));

            SetupControllerContext(umbCtx, controller);

            var mockNewsletterFolderNode = new Mock <INode>();

            mockNewsletterFolderNode.Setup(x => x.Id).Returns(newsletterFolderId);
            ApplicationServiceMock.Setup(x => x.GetNode(DocTypeAliases.NewsletterFolder.Alias))
            .Returns(mockNewsletterFolderNode.Object);

            var mockContent = new Mock <IContent>();

            ContentServiceMock.Setup(
                x =>
                x.CreateContent(submittedEmail, mockNewsletterFolderNode.Object.Id,
                                DocTypeAliases.Newsletter.Alias, 0)).Returns(mockContent.Object);

            controller.ApplicationService    = ApplicationServiceMock.Object;
            controller.ContentServiceFactory = ContentServiceFactoryMock.Object;

            // Act
            var result = controller.Subscribe(submittedEmail) as RedirectToUmbracoPageResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(controller.TempData[successKey]);
            ContentServiceMock.Verify(
                x =>
                x.CreateContent(submittedEmail, mockNewsletterFolderNode.Object.Id,
                                DocTypeAliases.Newsletter.Alias, 0), Times.Once);
            mockContent.Verify(x => x.SetValue(DocTypeAliases.Newsletter.Properties.Email, submittedEmail), Times.Once);
            ContentServiceMock.Verify(x => x.SaveAndPublishWithStatus(mockContent.Object, 0, true), Times.Once);
        }