예제 #1
0
        public void SessionHelper_Transact_AllowsNestedCalls()
        {
            var stubWebpage = new StubWebpage();

            this.Invoking(tests => Session.Transact(session => session.Transact(iSession => iSession.Save(stubWebpage))))
            .ShouldNotThrow();
        }
예제 #2
0
        public void FormAdminService_ClearFormData_ShouldDeleteFormPosting()
        {
            var webpage = new StubWebpage();
            var posting = new FormPosting
            {
                IsDeleted  = false,
                Webpage    = webpage,
                FormValues = new List <FormValue>
                {
                    new FormValue
                    {
                        IsDeleted = false,
                        IsFile    = false,
                        Key       = "Name",
                        Value     = "MrCMS"
                    }
                }
            };

            webpage.FormPostings = new List <FormPosting> {
                posting
            };

            Session.Transact(session => session.Save(posting));

            _formAdminService.ClearFormData(webpage);

            Session.QueryOver <FormPosting>().RowCount().Should().Be(0);
        }
예제 #3
0
        private ExcelPackage GetSpreadsheet()
        {
            DateTime currentTime = DateTime.Parse("2013-07-19 15:18:20");
            var      document    = new StubWebpage
            {
                UrlSegment         = "test-url",
                Name               = "Test Document",
                BodyContent        = "Test Body Content",
                MetaDescription    = "Test SEO Description",
                MetaKeywords       = "Test, Thought",
                MetaTitle          = "Test SEO Title",
                DisplayOrder       = 2,
                RevealInNavigation = true,
                RequiresSSL        = false,
                PublishOn          = currentTime
            };

            document.Tags.Add(new Tag {
                Id = 1, Name = "Test"
            });
            document.Urls.Add(new UrlHistory {
                UrlSegment = "test-url-old"
            });
            var items = new List <Webpage> {
                document
            };

            ExcelPackage exportExcelPackage = new ExportDocumentsService().GetExportExcelPackage(items);

            return(exportExcelPackage);
        }
        public void DocumentTagsAdminService_SetTags_ShouldRemoveTheDocumentFromTags()
        {
            var textPage = new StubWebpage();
            var tag1     = new Tag {
                Name = "test 1"
            };
            var tag2 = new Tag {
                Name = "test 2"
            };

            textPage.Tags.Add(tag1);
            textPage.Tags.Add(tag2);
            tag1.Documents.Add(textPage);
            tag2.Documents.Add(textPage);

            Session.Transact(session =>
            {
                session.SaveOrUpdate(textPage);
                session.SaveOrUpdate(tag1);
                session.SaveOrUpdate(tag2);
            });

            _documentTagsAdminService.SetTags("test 1", textPage);

            tag1.Documents.Should().HaveCount(1);
            tag2.Documents.Should().HaveCount(0);
        }
예제 #5
0
        public void FormAdminService_ExportFormData_ShouldReturnByteArray()
        {
            var webpage = new StubWebpage();
            var posting = new FormPosting
            {
                IsDeleted  = false,
                Webpage    = webpage,
                FormValues = new List <FormValue>
                {
                    new FormValue
                    {
                        IsDeleted = false,
                        IsFile    = false,
                        Key       = "Name",
                        Value     = "MrCMS"
                    }
                }
            };

            webpage.FormPostings = new List <FormPosting> {
                posting
            };

            byte[] result = _formAdminService.ExportFormData(webpage);

            result.Should().BeOfType <byte[]>();
        }
예제 #6
0
        public void DefaultFormRenderer_GetDefault_ShouldCallRenderLabelThenRenderElementForEachProperty()
        {
            var textBox1 = new TextBox {
                Name = "test-1"
            };
            var textBox2 = new TextBox {
                Name = "test-2"
            };

            var stubWebpage = new StubWebpage
            {
                FormProperties = new List <FormProperty> {
                    textBox1, textBox2
                }
            };
            var formElementRenderer = A.Fake <IFormElementRenderer>();

            A.CallTo(() => formElementRenderer.AppendElement(textBox1, _existingValue, _siteSettings.FormRendererType)).Returns(new TagBuilder("input"));
            A.CallTo(() => formElementRenderer.AppendElement(textBox2, _existingValue, _siteSettings.FormRendererType)).Returns(new TagBuilder("input"));
            A.CallTo(() => _elementRendererManager.GetElementRenderer <FormProperty>(textBox1))
            .Returns(formElementRenderer);
            A.CallTo(() => _elementRendererManager.GetElementRenderer <FormProperty>(textBox2))
            .Returns(formElementRenderer);
            A.CallTo(() => _htmlHelper.Action("Render", "Form", A <object> ._)).Throws <Exception>();

            _defaultFormRenderer.GetDefault(_htmlHelper, stubWebpage, new FormSubmittedStatus(false, null, _formCollection));

            List <ICompletedFakeObjectCall> elementRendererCalls = Fake.GetCalls(formElementRenderer).ToList();
            List <ICompletedFakeObjectCall> labelRendererCalls   = Fake.GetCalls(_labelRenderer).ToList();

            labelRendererCalls.Where(x => x.Method.Name == "AppendLabel").Should().HaveCount(2);
            elementRendererCalls.Where(x => x.Method.Name == "AppendElement").Should().HaveCount(2);
        }
        public void DocumentTagsAdminService_SetTags_ShouldTrimTagNames()
        {
            var textPage = new StubWebpage();

            _documentTagsAdminService.SetTags("test 1, test 2", textPage);

            textPage.Tags.ElementAt(1).Name.Should().Be("test 2");
        }
예제 #8
0
        public void DocumentTagsAdminService_SetTags_ShouldNotCreateTagsWithEmptyNamesForTrailingComma()
        {
            var textPage = new StubWebpage();

            _sut.SetTags("test 1, test 2, ", textPage);

            textPage.Tags.Should().HaveCount(2);
        }
예제 #9
0
        public void FormController_ExportFormData_ShouldCallExportFormData()
        {
            var stubWebpage = new StubWebpage();

            _formController.ExportFormData(stubWebpage);

            A.CallTo(() => _formAdminService.ExportFormData(stubWebpage)).MustHaveHappened();
        }
예제 #10
0
        public void DocumentTagsAdminService_SetTags_ShouldAddTagsToDocument()
        {
            var textPage = new StubWebpage();

            _sut.SetTags("test 1, test 2", textPage);

            textPage.Tags.Should().HaveCount(2);
        }
예제 #11
0
        public void FormController_ExportFormData_ShouldReturnFileResult()
        {
            var stubWebpage = new StubWebpage();

            var result = _formController.ExportFormData(stubWebpage);

            result.Should().BeOfType <FileContentResult>();
        }
예제 #12
0
        public void DocumentTagsAdminService_SetTags_IfTagsHasTwoCommaSeparatedTagsTheTagListShouldHave2Tags()
        {
            var textPage = new StubWebpage();

            _sut.SetTags("test 1, test 2", textPage);

            textPage.Tags.Should().HaveCount(2);
        }
예제 #13
0
        public void FormController_ClearFormDataPOST_ShouldReturnRedirectToRouteResult()
        {
            var stubWebpage = new StubWebpage();

            var result = _formController.ClearFormData_POST(stubWebpage);

            result.Should().BeOfType <RedirectToRouteResult>();
        }
예제 #14
0
        public void FormController_ClearFormDataPOST_ShouldCallClearFormData()
        {
            var stubWebpage = new StubWebpage();

            _formController.ClearFormData_POST(stubWebpage);

            A.CallTo(() => _formAdminService.ClearFormData(stubWebpage)).MustHaveHappened();
        }
        public void DocumentTagsAdminService_SetTags_ShouldNotCreateTagsWithEmptyNames()
        {
            var textPage = new StubWebpage();

            _documentTagsAdminService.SetTags("test 1,,test 2", textPage);

            textPage.Tags.Should().HaveCount(2);
        }
예제 #16
0
        public void DefaultFormRenderer_GetDefault_ShouldReturnAnEmptyStringIfThereAreNoProperties()
        {
            var stubWebpage = new StubWebpage();

            var @default = _defaultFormRenderer.GetDefault(_htmlHelper, stubWebpage, new FormSubmittedStatus(false, null, null));

            @default.Should().Be(String.Empty);
        }
예제 #17
0
        public void WebpageController_Delete_ReturnsRedirectToIndex()
        {
            var stubWebpage = new StubWebpage();

            _webpageController.Delete(stubWebpage).Should().BeOfType <RedirectToRouteResult>();
            _webpageController.Delete(stubWebpage).As <RedirectToRouteResult>().RouteValues["action"].Should()
            .Be("Index");
        }
        public void WebpageWidgetController_Show_CallsDocumentServiceShowWithPassedArguments()
        {
            var stubWebpage = new StubWebpage();

            _webpageWidgetController.Show(stubWebpage, 2, 3);

            A.CallTo(() => _webpageWidgetAdminService.Show(stubWebpage, 2)).MustHaveHappened();
        }
예제 #19
0
        public void FormController_ClearFormData_ShouldReturnPartialViewResult()
        {
            var stubWebpage = new StubWebpage();

            var result = _formController.ClearFormData(stubWebpage);

            result.Should().BeOfType <PartialViewResult>();
        }
예제 #20
0
        public void DocumentTagsAdminService_SetTags_IfTagsIsNullForANewDocumentTheTagListShouldBeEmpty()
        {
            var textPage = new StubWebpage();

            _sut.SetTags((string)null, textPage);

            textPage.Tags.Should().HaveCount(0);
        }
예제 #21
0
        public void FormController_ClearFormDataPOST_ShouldRedirectToEditWebpage()
        {
            var stubWebpage = new StubWebpage();

            var result = _formController.ClearFormData_POST(stubWebpage);

            result.RouteValues["action"].Should().Be("Edit");
        }
예제 #22
0
        public void DocumentTagsAdminService_SetTags_IfTagsHasOneStringTheTagListShouldHave1Tag()
        {
            var textPage = new StubWebpage();

            _sut.SetTags("test tag", textPage);

            textPage.Tags.Should().HaveCount(1);
        }
예제 #23
0
        public void FormController_Save_SetsTempDataFormSubmittedToTrue()
        {
            var stubWebpage = new StubWebpage();

            A.CallTo(() => _documentService.GetDocument <Webpage>(1)).Returns(stubWebpage);
            ActionResult result = _formController.Save(1);

            _formController.TempData["form-submitted"].Should().Be(true);
        }
예제 #24
0
        public void FormController_Save_CallsFormServiceSaveFormDataWithPassedObjects()
        {
            var stubWebpage = new StubWebpage();

            A.CallTo(() => _documentService.GetDocument <Webpage>(1)).Returns(stubWebpage);
            ActionResult result = _formController.Save(1);

            A.CallTo(() => _formPostingHandler.SaveFormData(stubWebpage, _formController.Request)).MustHaveHappened();
        }
예제 #25
0
        public void DocumentTagsAdminService_SetTags_ShouldTrimTagNamesOnNewTags()
        {
            var textPage = new StubWebpage();

            A.CallTo(() => _getExistingTag.GetTag(A <string> .Ignored)).Returns(null);

            _sut.SetTags("test 1, test 2", textPage);

            textPage.Tags.ElementAt(1).Name.Should().Be("test 2");
        }
예제 #26
0
        public void FormController_Save_ReturnsRedirectToTheReferrer()
        {
            var stubWebpage = new StubWebpage();

            A.CallTo(() => _documentService.GetDocument <Webpage>(1)).Returns(stubWebpage);
            ActionResult result = _formController.Save(1);

            result.Should().BeOfType <RedirectResult>();
            result.As <RedirectResult>().Url.Should().Be("http://www.example.com/test-redirect");
        }
예제 #27
0
        public void FormController_Save_SetsTempDataFormSubmittedToTrue()
        {
            var stubWebpage = new StubWebpage();

            A.CallTo(() => _formPostingHandler.GetWebpage(123)).Returns(stubWebpage);

            ActionResult result = _formController.Save(123);

            _formController.TempData["form-submitted"].Should().Be(true);
        }
예제 #28
0
        public void FormRenderer_RenderForm_WhenFormDesignIsEmptyReturnsResultOfIDefaultFormRenderer()
        {
            var stubWebpage         = new StubWebpage();
            var formSubmittedStatus = new FormSubmittedStatus(false, null, null);

            A.CallTo(() => _defaultFormRenderer.GetDefault(stubWebpage, formSubmittedStatus)).Returns("test-default");

            var renderForm = _formRenderingManager.RenderForm(stubWebpage, formSubmittedStatus);

            renderForm.Should().Be("test-default");
        }
        public void WebpageWidgetController_Show_SetsRouteValuesForIdAndLayoutAreaId()
        {
            var stubWebpage = new StubWebpage {
                Id = 1
            };

            var redirectToRouteResult = _webpageWidgetController.Show(stubWebpage, 2, 3).As <RedirectToRouteResult>();

            redirectToRouteResult.RouteValues["action"].Should().Be("Edit");
            redirectToRouteResult.RouteValues["id"].Should().Be(stubWebpage.Id);
            redirectToRouteResult.RouteValues["layoutAreaId"].Should().Be(3);
        }
예제 #30
0
        public void DocumentTagsAdminService_SetTags_ShouldAssignDocumentToTag()
        {
            var textPage = new StubWebpage();

            _documentRepository.Add(textPage);

            _sut.SetTags("test 1", textPage);

            var tags = textPage.Tags;

            tags.Should().HaveCount(1);
            tags.First().Documents.Should().HaveCount(1);
        }