Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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());
            }
        }