public void ShouldGetWebPartCategoriesFromParentCategoryWithoutRecurse() { // Setup web part category var webPartCategoryMock1 = new Mock <IWebPartCategory>(); webPartCategoryMock1 .Setup(x => x.CategoryID) .Returns(15); var webPartCategoryMock2 = new Mock <IWebPartCategory>(); webPartCategoryMock2 .Setup(x => x.CategoryID) .Returns(16); var webPartCategoryMock3 = new Mock <IWebPartCategory>(); webPartCategoryMock3 .Setup(x => x.CategoryID) .Returns(17); webPartCategoryMock3 .Setup(x => x.CategoryParentID) .Returns(16); // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.GetWebPartCategory(It.IsAny <int>())) .Returns <IWebPartCategory>(null); webPartServiceMock .Setup(x => x.GetWebPartCategory(15)) .Returns(webPartCategoryMock1.Object); webPartServiceMock .Setup(x => x.GetWebPartCategory(16)) .Returns(webPartCategoryMock2.Object); webPartServiceMock .Setup(x => x.GetWebPartCategory(17)) .Returns(webPartCategoryMock3.Object); webPartServiceMock .Setup(x => x.GetWebPartCategories(webPartCategoryMock2.Object)) .Returns(new IWebPartCategory[] { webPartCategoryMock3.Object }); // Setup business layer var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, }; // Test business layer var results = businessLayer.GetWebPartCategories(webPartCategoryMock2.Object, false); results .Should() .NotBeNullOrEmpty(); results .Should() .Contain(new IWebPartCategory[] { webPartCategoryMock3.Object }); results .Should() .NotContainNulls(); }
public void ShouldGetWebPartCategoryFromWebPart() { // Setup web part var webPartMock = new Mock <IWebPart>(); webPartMock .Setup(x => x.WebPartCategoryID) .Returns(15); // Setup web part category var webPartCategoryMock1 = new Mock <IWebPartCategory>(); webPartCategoryMock1 .Setup(x => x.CategoryID) .Returns(15); var webPartCategoryMock2 = new Mock <IWebPartCategory>(); webPartCategoryMock2 .Setup(x => x.CategoryID) .Returns(16); var webPartCategoryMock3 = new Mock <IWebPartCategory>(); webPartCategoryMock3 .Setup(x => x.CategoryID) .Returns(17); var webPartCategoryMock4 = new Mock <IWebPartCategory>(); webPartCategoryMock4 .Setup(x => x.CategoryID) .Returns(18); // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.WebPartCategories) .Returns(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object, webPartCategoryMock3.Object, }); // Setup business layer var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, WriteDebug = Assert.NotNull, WriteVerbose = Assert.NotNull, }; // Test business layer var results = businessLayer.GetWebPartCategory(webPartMock.Object); results .Should() .NotBeNull(); results .Should().BeEquivalentTo(webPartCategoryMock1.Object); }
public void ShouldGetWebPartCategoriesFromIDsWithRecurse() { // Setup web part category var webPartCategoryMock1 = new Mock <IWebPartCategory>(); webPartCategoryMock1 .Setup(x => x.CategoryID) .Returns(15); var webPartCategoryMock2 = new Mock <IWebPartCategory>(); webPartCategoryMock2 .Setup(x => x.CategoryID) .Returns(16); var webPartCategoryMock3 = new Mock <IWebPartCategory>(); webPartCategoryMock3 .Setup(x => x.CategoryID) .Returns(17); webPartCategoryMock3 .Setup(x => x.CategoryParentID) .Returns(16); // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.GetWebPartCategory(It.IsAny <int>())) .Returns <IWebPartCategory>(null); webPartServiceMock .Setup(x => x.GetWebPartCategory(15)) .Returns(webPartCategoryMock1.Object); webPartServiceMock .Setup(x => x.GetWebPartCategory(16)) .Returns(webPartCategoryMock2.Object); webPartServiceMock .Setup(x => x.GetWebPartCategory(17)) .Returns(webPartCategoryMock3.Object); webPartServiceMock .Setup(x => x.GetWebPartCategories(webPartCategoryMock2.Object)) .Returns(new IWebPartCategory[] { webPartCategoryMock3.Object }); var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, WriteDebug = Assert.NotNull, WriteVerbose = Assert.NotNull, }; var results = businessLayer.GetWebPartCategories(new int[] { 15, 16, 18 }, true); results .Should() .NotBeNullOrEmpty(); results .Should() .Contain(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object, webPartCategoryMock3.Object }); results .Should() .NotContainNulls(); }
public void ShouldGetWebPartCategories() { // Setup web part category var webPartCategoryMock = new Mock <IWebPartCategory>(); var webPartCategoryObj = webPartCategoryMock.Object; // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.WebPartCategories) .Returns(new IWebPartCategory[] { webPartCategoryObj, }); var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, WriteDebug = Assert.NotNull, WriteVerbose = Assert.NotNull, }; var results = businessLayer.GetWebPartCategories(); results .Should() .NotBeNullOrEmpty(); results .Single() .Should().BeEquivalentTo(webPartCategoryObj); }
public void ShouldGetWebPartCategoriesByPathWithRecurse() { // Setup web part category var webPartCategoryMock1 = new Mock <IWebPartCategory>(); webPartCategoryMock1 .Setup(x => x.CategoryPath) .Returns("/Category1"); var webPartCategoryMock2 = new Mock <IWebPartCategory>(); webPartCategoryMock2 .Setup(x => x.CategoryPath) .Returns("/Category1/Child1"); // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.WebPartCategories) .Returns(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object, }); webPartServiceMock .Setup(x => x.GetWebPartCategories(webPartCategoryMock1.Object)) .Returns(new IWebPartCategory[] { webPartCategoryMock2.Object }); // Setup business layer var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, WriteDebug = Assert.NotNull, WriteVerbose = Assert.NotNull, }; // Test business layer var results = businessLayer.GetWebPartCategories("/Category1", true); results .Should() .NotBeNullOrEmpty(); results .Should() .Contain(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object, }); }
public void ShouldGetWebPartCategoriesFromMatchStringWithoutRegexAndWithoutRecurse() { // Setup web part category var webPartCategoryMock1 = new Mock <IWebPartCategory>(); webPartCategoryMock1 .Setup(x => x.CategoryDisplayName) .Returns("Display Name"); webPartCategoryMock1 .Setup(x => x.CategoryName) .Returns("Category"); var webPartCategoryMock2 = new Mock <IWebPartCategory>(); webPartCategoryMock2 .Setup(x => x.CategoryDisplayName) .Returns("Different"); webPartCategoryMock2 .Setup(x => x.CategoryName) .Returns("Different"); // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.WebPartCategories) .Returns(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object, }); var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, WriteDebug = Assert.NotNull, WriteVerbose = Assert.NotNull, }; // Test Display Name var results = businessLayer.GetWebPartCategories("*spla*", false, false); results .Should() .NotBeNullOrEmpty(); results .Single() .Should().BeEquivalentTo(webPartCategoryMock1.Object); results = businessLayer.GetWebPartCategories("spla*", false, false); results .Should() .BeEmpty(); // Test Name results = businessLayer.GetWebPartCategories("*cate*", false, false); results .Should() .NotBeNullOrEmpty(); results .Single() .Should().BeEquivalentTo(webPartCategoryMock1.Object); results = businessLayer.GetWebPartCategories("*cate", false, false); results .Should() .BeEmpty(); }
public void ShouldGetWebPartCategoriesFromMatchStringWithtRegexAndWithRecurse() { // Setup web part category var webPartCategoryMock1 = new Mock <IWebPartCategory>(); webPartCategoryMock1 .Setup(x => x.CategoryDisplayName) .Returns("Display Name"); webPartCategoryMock1 .Setup(x => x.CategoryName) .Returns("Category"); var webPartCategoryMock2 = new Mock <IWebPartCategory>(); webPartCategoryMock2 .Setup(x => x.CategoryDisplayName) .Returns("Different"); webPartCategoryMock2 .Setup(x => x.CategoryName) .Returns("Different"); // Setup web part service mock var webPartServiceMock = new Mock <IWebPartService>(); webPartServiceMock .Setup(x => x.WebPartCategories) .Returns(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object, }); webPartServiceMock .Setup(x => x.GetWebPartCategories(webPartCategoryMock1.Object)) .Returns(new IWebPartCategory[] { webPartCategoryMock2.Object }); var businessLayer = new GetCMSWebPartCategoryBusiness { WebPartService = webPartServiceMock.Object, WriteDebug = Assert.NotNull, WriteVerbose = Assert.NotNull, }; // Test Display Name var results = businessLayer.GetWebPartCategories("y+ Name$", true, true); results .Should() .NotBeNullOrEmpty(); results .Count() .Should() .Be(2); results .Should() .Contain(webPartCategoryMock1.Object); results .Should() .Contain(webPartCategoryMock2.Object); results = businessLayer.GetWebPartCategories("^y+ Name$", true, true); results .Should() .BeEmpty(); // Test Name results = businessLayer.GetWebPartCategories("^cate+", true, true); results .Should() .NotBeNullOrEmpty(); results .Count() .Should() .Be(2); results .Should() .Contain(webPartCategoryMock1.Object); results .Should() .Contain(webPartCategoryMock2.Object); results = businessLayer.GetWebPartCategories("cate$", true, true); results .Should() .BeEmpty(); }