public void SetUp()
        {
            ComponentFactory.Container = new SimpleContainer();
            _cachingProvider           = MockComponentProvider.CreateDataCacheProvider();

            _mockHostController = new Mock <IHostController>();
            _mockHostController.Setup(c => c.GetString(Constants.SearchIndexFolderKey, It.IsAny <string>())).Returns(SearchIndexFolder);
            _mockHostController.Setup(c => c.GetDouble(Constants.SearchReaderRefreshTimeKey, It.IsAny <double>())).Returns(_readerStaleTimeSpan);
            _mockHostController.Setup(c => c.GetInteger(Constants.SearchMinLengthKey, It.IsAny <int>())).Returns(Constants.DefaultMinLen);
            _mockHostController.Setup(c => c.GetInteger(Constants.SearchMaxLengthKey, It.IsAny <int>())).Returns(Constants.DefaultMaxLen);
            _mockHostController.Setup(c => c.GetInteger(Constants.SearchRetryTimesKey, It.IsAny <int>())).Returns(DefaultSearchRetryTimes);
            HostController.RegisterInstance(_mockHostController.Object);

            _mockSearchHelper = new Mock <ISearchHelper>();
            _mockSearchHelper.Setup(c => c.GetSynonyms(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())).Returns <int, string, string>(GetSynonymsCallBack);
            _mockSearchHelper.Setup(c => c.GetSearchStopWords(It.IsAny <int>(), It.IsAny <string>())).Returns(new SearchStopWords());
            _mockSearchHelper.Setup(c => c.GetSearchMinMaxLength()).Returns(new Tuple <int, int>(Constants.DefaultMinLen, Constants.DefaultMaxLen));
            _mockSearchHelper.Setup(x => x.StripTagsNoAttributes(It.IsAny <string>(), It.IsAny <bool>())).Returns((string html, bool retainSpace) => html);
            SearchHelper.SetTestableInstance(_mockSearchHelper.Object);

            _mockSearchQuery = new Mock <SearchQuery>();

            DeleteIndexFolder();
            CreateNewLuceneControllerInstance();
        }
예제 #2
0
        public void LoadPortalSettings_Sets_TimeZone_Property_To_Local_TimeZone()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings()
            {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var hostSettings = PortalSettingsControllerTestFactory.GetHostSettings();

            var mockPortalController = new Mock <IPortalController>();

            mockPortalController
            .Setup(c => c.GetPortalSettings(It.IsAny <int>()))
            .Returns(new Dictionary <string, string>());
            PortalController.SetTestableInstance(mockPortalController.Object);

            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(c => c.GetString(It.IsAny <string>()))
            .Returns((string s) => hostSettings[s]);
            mockHostController.Setup(c => c.GetString(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string s1, string s2) => hostSettings[s1]);
            mockHostController.Setup(c => c.GetBoolean(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns((string s, bool b) => Boolean.Parse(hostSettings[s]));
            mockHostController.Setup(c => c.GetInteger(It.IsAny <string>(), It.IsAny <int>()))
            .Returns((string s, int i) => Int32.Parse(hostSettings[s]));
            HostController.RegisterInstance(mockHostController.Object);

            //Act
            controller.LoadPortalSettings(settings);

            //Assert
            Assert.AreEqual(TimeZoneInfo.Local, settings.TimeZone);
        }
예제 #3
0
        public void SetUp()
        {
            SetupContianer();
            ComponentFactory.Container = new SimpleContainer();
            UnitTestHelper.ClearHttpContext();
            _dataProvider = MockComponentProvider.CreateDataProvider();
            MockComponentProvider.CreateDataCacheProvider();
            MockComponentProvider.CreateEventLogController();
            _clientCapabilityProvider = MockComponentProvider.CreateNew <ClientCapabilityProvider>();
            _mockHostController       = new Mock <IHostController>();
            HostController.RegisterInstance(_mockHostController.Object);

            _redirectionController = new RedirectionController();

            SetupDataProvider();
            SetupClientCapabilityProvider();
            SetupRoleProvider();

            var tabController     = TabController.Instance;
            var dataProviderField = tabController.GetType().GetField("_dataProvider", BindingFlags.NonPublic | BindingFlags.Instance);

            if (dataProviderField != null)
            {
                dataProviderField.SetValue(tabController, _dataProvider.Object);
            }
        }
예제 #4
0
        public void LoadPortalSettings_Loads_Default_Value(Dictionary <string, string> testFields)
        {
            //Arrange
            var propertyName  = testFields["PropertyName"];
            var settingName   = testFields["SettingName"];
            var isHostDefault = Boolean.Parse(testFields["IsHostDefault"]);
            var defaultValue  = testFields["DefaultValue"];
            var controller    = new PortalSettingsController();
            var settings      = new PortalSettings()
            {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var hostSettings = PortalSettingsControllerTestFactory.GetHostSettings();

            var mockPortalController = new Mock <IPortalController>();

            mockPortalController
            .Setup(c => c.GetPortalSettings(It.IsAny <int>()))
            .Returns(new Dictionary <string, string>());
            PortalController.SetTestableInstance(mockPortalController.Object);

            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(c => c.GetString(It.IsAny <string>()))
            .Returns((string s) => hostSettings[s]);
            mockHostController.Setup(c => c.GetString(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string s1, string s2) => hostSettings[s1]);
            mockHostController.Setup(c => c.GetBoolean(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns((string s, bool b) => Boolean.Parse(hostSettings[s]));
            mockHostController.Setup(c => c.GetInteger(It.IsAny <string>(), It.IsAny <int>()))
            .Returns((string s, int i) => Int32.Parse(hostSettings[s]));
            mockHostController.Setup(c => c.GetInteger(It.IsAny <string>()))
            .Returns((string s) => Int32.Parse(hostSettings[s]));
            HostController.RegisterInstance(mockHostController.Object);

            if (isHostDefault)
            {
                defaultValue = hostSettings[settingName];
            }

            //Act
            controller.LoadPortalSettings(settings);


            //Assert
            var property    = settings.GetType().GetProperty(propertyName);
            var actualValue = property.GetValue(settings, null);

            if (actualValue is bool)
            {
                Assert.AreEqual(defaultValue, actualValue.ToString().ToLowerInvariant());
            }
            else
            {
                Assert.AreEqual(defaultValue, actualValue.ToString());
            }
        }
        public void LoadPortalSettings_Loads_Setting_Value(Dictionary <string, string> testFields)
        {
            //Arrange
            var propertyName  = testFields["PropertyName"];
            var settingName   = testFields["SettingName"];
            var settingValue  = testFields["SettingValue"];
            var propertyValue = (testFields.ContainsKey("PropertyValue")) ? testFields["PropertyValue"] : settingValue;
            var controller    = new PortalSettingsController();
            var settings      = new PortalSettings()
            {
                PortalId = ValidPortalId
            };
            var hostSettings = PortalSettingsControllerTestFactory.GetHostSettings();

            var mockPortalController = new Mock <IPortalController>();

            mockPortalController
            .Setup(c => c.GetPortalSettings(It.IsAny <int>()))
            .Returns(new Dictionary <string, string> {
                { settingName, settingValue }
            });
            PortalController.SetTestableInstance(mockPortalController.Object);

            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(c => c.GetString(It.IsAny <string>()))
            .Returns((string s) => hostSettings[s]);
            mockHostController.Setup(c => c.GetString(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string s1, string s2) => hostSettings[s1]);
            mockHostController.Setup(c => c.GetBoolean(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns((string s, bool b) => Boolean.Parse(hostSettings[s]));
            mockHostController.Setup(c => c.GetInteger(It.IsAny <string>(), It.IsAny <int>()))
            .Returns((string s, int i) => Int32.Parse(hostSettings[s]));
            HostController.RegisterInstance(mockHostController.Object);

            //Act
            controller.LoadPortalSettings(settings);

            //Assert
            var property    = settings.GetType().GetProperty(propertyName);
            var actualValue = property.GetValue(settings, null);

            if (actualValue is bool)
            {
                Assert.AreEqual(propertyValue, actualValue.ToString().ToLower());
            }
            else
            {
                Assert.AreEqual(propertyValue, actualValue.ToString());
            }
        }
 private void SetupHostController()
 {
     this._mockHostController.Setup(c => c.GetString(Constants.SearchIndexFolderKey, It.IsAny <string>())).Returns(SearchIndexFolder);
     this._mockHostController.Setup(c => c.GetDouble(Constants.SearchReaderRefreshTimeKey, It.IsAny <double>())).Returns(this._readerStaleTimeSpan);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchTitleBoostSetting, It.IsAny <int>())).Returns(Constants.DefaultSearchTitleBoost);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchTagBoostSetting, It.IsAny <int>())).Returns(Constants.DefaultSearchTagBoost);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchContentBoostSetting, It.IsAny <int>())).Returns(Constants.DefaultSearchKeywordBoost);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchDescriptionBoostSetting, It.IsAny <int>()))
     .Returns(Constants.DefaultSearchDescriptionBoost);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchAuthorBoostSetting, It.IsAny <int>())).Returns(Constants.DefaultSearchAuthorBoost);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchMinLengthKey, It.IsAny <int>())).Returns(Constants.DefaultMinLen);
     this._mockHostController.Setup(c => c.GetInteger(Constants.SearchMaxLengthKey, It.IsAny <int>())).Returns(Constants.DefaultMaxLen);
     HostController.RegisterInstance(this._mockHostController.Object);
 }
예제 #7
0
 public void SetUp()
 {
     _mockCache          = MockComponentProvider.CreateDataCacheProvider();
     _mockHostController = new Mock <IHostController>();
     _portalController   = new Mock <IPortalController>();
     _moduleController   = new Mock <IModuleController>();
     _userController     = new Mock <IUserController>();
     PortalController.SetTestableInstance(_portalController.Object);
     ModuleController.SetTestableInstance(_moduleController.Object);
     UserController.SetTestableInstance(_userController.Object);
     HostController.RegisterInstance(_mockHostController.Object);
     SetupPortalSettings();
     SetupModuleInfo();
     SetupUserInfo();
 }
예제 #8
0
 public void SetUp()
 {
     ComponentFactory.RegisterComponentInstance <TokenProvider>(new CoreTokenProvider());
     this._mockCache          = MockComponentProvider.CreateDataCacheProvider();
     this._mockHostController = new Mock <IHostController>();
     this._portalController   = new Mock <IPortalController>();
     this._moduleController   = new Mock <IModuleController>();
     this._userController     = new Mock <IUserController>();
     PortalController.SetTestableInstance(this._portalController.Object);
     ModuleController.SetTestableInstance(this._moduleController.Object);
     UserController.SetTestableInstance(this._userController.Object);
     HostController.RegisterInstance(this._mockHostController.Object);
     this.SetupPortalSettings();
     this.SetupModuleInfo();
     this.SetupUserInfo();
 }
예제 #9
0
        public void UpdateHostSettingsCallsHostControllerUpdate()
        {
            //Arrange
            var mockHostController = new Mock <IHostController>();

            HostController.RegisterInstance(mockHostController.Object);

            //Act
            var controller = SetupControllerForTests(new SettingsController(), HttpMethod.Post);
            var result     = controller.UpdateHostSetting(new SettingsController.UpdateSettingDTO {
                Key = "key", Value = "value"
            });

            //Assert
            Assert.IsTrue(result.IsSuccessStatusCode);
            mockHostController.Verify(x => x.Update("key", "value"), Times.Once());
        }
예제 #10
0
        public void ConfigureTab_Builds_Breadcrumbs_For_Tab_And_Parent()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId, ParentId = ParentTabId
            };
            var parentTab = new TabInfo {
                TabID = ParentTabId, PortalID = ValidPortalId
            };

            settings.ActiveTab         = validTab;
            settings.ActiveTab.SkinSrc = TabSkin;

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab, parentTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(c => c.GetString("DefaultPortalContainer")).Returns("DefaultPortalContainer");
            HostController.RegisterInstance(mockHostController.Object);

            //Act
            controller.ConfigureActiveTab(settings);

            //Assert
            var actualParent = settings.ActiveTab.BreadCrumbs[0] as TabInfo;
            var actualTab    = settings.ActiveTab.BreadCrumbs[1] as TabInfo;

            Assert.AreEqual(2, settings.ActiveTab.BreadCrumbs.Count);
            Assert.AreEqual(ValidTabId, actualTab.TabID);
            Assert.AreEqual(ParentTabId, actualParent.TabID);
        }
예제 #11
0
        public void HostSettingsRetreivesAllSettings()
        {
            //Arrange
            var expected = new Dictionary <string, string> {
                { "SettingA", "valueA" }, { "SettingB", "valueB" }
            };
            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(x => x.GetSettingsDictionary()).Returns(expected);
            HostController.RegisterInstance(mockHostController.Object);

            //Act
            SettingsController  settingsController = SetupControllerForTests(new SettingsController(), HttpMethod.Get);
            HttpResponseMessage result             = settingsController.HostSettings();

            //Assert
            Assert.IsTrue(result.IsSuccessStatusCode);
            CollectionAssert.AreEquivalent(expected, result.Content.ReadAsAsync <Dictionary <string, string> >().Result);
        }
        public void GetSubscriptionTypes_ShouldCallDataService_WhenNoError()
        {
            // Arrange
            var mockHostController = new Mock <IHostController>();

            mockHostController
            .Setup(c => c.GetString("PerformanceSetting"))
            .Returns("0");
            HostController.RegisterInstance(mockHostController.Object);

            mockDataService
            .Setup(ds => ds.GetSubscriptionTypes())
            .Returns(SubscriptionTypeDataReaderMockHelper.CreateEmptySubscriptionTypeReader())
            .Verifiable();

            //Act
            subscriptionTypeController.GetSubscriptionTypes();

            //Assert
            mockDataService.Verify(ds => ds.GetSubscriptionTypes(), Times.Once());
        }
예제 #13
0
        public void ConfigureTab_Uses_PortalSettings_DefaultContainer_If_ContainerSrc_Not_Set()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, DefaultPortalContainer = DefaultContainer, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId
            };

            settings.ActiveTab         = validTab;
            settings.ActiveTab.SkinSrc = TabSkin;

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(c => c.GetString("DefaultPortalContainer")).Returns("DefaultPortalContainer");
            HostController.RegisterInstance(mockHostController.Object);

            //Act
            controller.ConfigureActiveTab(settings);

            //Assert
            Assert.AreEqual(DefaultContainer, settings.ActiveTab.ContainerSrc);
        }
예제 #14
0
        public virtual void SetUp()
        {
            //Mock Repository and component factory
            MockRepository             = new MockRepository(MockBehavior.Default);
            ComponentFactory.Container = new SimpleContainer();

            // Setup Mock
            MockCache = MockComponentProvider.CreateNew <CachingProvider>();
            HostController.RegisterInstance(MockHostController.Object);

            MockPortalController = MockRepository.Create <IPortalController>();
            PortalController.SetTestableInstance(MockPortalController.Object);
            MockModuleController = MockRepository.Create <IModuleController>();
            ModuleController.SetTestableInstance(MockModuleController.Object);

            // Setup mock cache
            MockCacheCollection = new Hashtable();
            MockHostController.Setup(hc => hc.GetString("PerformanceSetting")).Returns("3");
            MockCache.Setup(c => c.Insert(It.IsAny <string>(), It.IsAny <object>())).Callback((string cacheKey, object itemToCache) => MockCacheCollection[cacheKey] = itemToCache);
            MockCache.Setup(c => c.Insert(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <DNNCacheDependency>(), It.IsAny <DateTime>(), It.IsAny <TimeSpan>(), It.IsAny <CacheItemPriority>(), It.IsAny <CacheItemRemovedCallback>()))
            .Callback((string cacheKey, object itemToCache, DNNCacheDependency dcd, DateTime dt, TimeSpan ts, CacheItemPriority cip, CacheItemRemovedCallback circ) => MockCacheCollection[cacheKey] = itemToCache);
            MockCache.Setup(c => c.GetItem(It.IsAny <string>())).Returns((string cacheKey) => MockCacheCollection[cacheKey]);
        }
예제 #15
0
        public void SetUp()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <IApplicationStatusInfo>(container => Mock.Of <IApplicationStatusInfo>());
            serviceCollection.AddTransient <INavigationManager>(container => Mock.Of <INavigationManager>());
            serviceCollection.AddTransient <IHostSettingsService, HostController>();
            Globals.DependencyProvider = serviceCollection.BuildServiceProvider();

            ComponentFactory.RegisterComponentInstance <TokenProvider>(new CoreTokenProvider());
            this.mockCache          = MockComponentProvider.CreateDataCacheProvider();
            this.mockHostController = new Mock <IHostController>();
            this.portalController   = new Mock <IPortalController>();
            this.moduleController   = new Mock <IModuleController>();
            this.userController     = new Mock <IUserController>();
            PortalController.SetTestableInstance(this.portalController.Object);
            ModuleController.SetTestableInstance(this.moduleController.Object);
            UserController.SetTestableInstance(this.userController.Object);
            HostController.RegisterInstance(this.mockHostController.Object);
            this.SetupPortalSettings();
            this.SetupModuleInfo();
            this.SetupUserInfo();
        }
예제 #16
0
        public void SetUp()
        {
            ComponentFactory.Container = new SimpleContainer();
            _cachingProvider           = MockComponentProvider.CreateDataCacheProvider();
            _dataProvider = MockComponentProvider.CreateDataProvider();

            _mockSearchHelper = new Mock <ISearchHelper>();
            _mockSearchHelper.Setup(c => c.GetSynonymsGroups(It.IsAny <int>(), It.IsAny <string>())).Returns(GetSynonymsGroupsCallBack);
            _mockSearchHelper.Setup(x => x.GetSearchTypeByName(It.IsAny <string>()))
            .Returns((string name) => new SearchType {
                SearchTypeId = 0, SearchTypeName = name
            });
            SearchHelper.SetTestableInstance(_mockSearchHelper.Object);

            _mockHostController = new Mock <IHostController>();
            _mockHostController.Setup(c => c.GetInteger(Constants.SearchTitleBoostSetting,
                                                        Constants.DefaultSearchTitleBoost)).Returns(Constants.StandardLuceneBoost);
            HostController.RegisterInstance(_mockHostController.Object);

            _internalSearchController = new InternalSearchControllerImpl();

            SetupDataProvider();
        }
 private void SetupHostController()
 {
     _mockHostController = new Mock <IHostController>();
     _mockHostController.Setup(c => c.GetString(It.IsRegex("PerformanceSetting"))).Returns(Globals.PerformanceSettings.LightCaching.ToString());
     HostController.RegisterInstance(_mockHostController.Object);
 }