Beispiel #1
0
        public void GetValue_Should_Be_Case_Insensitive()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name", "value");
            string value = settings.GetValue("NaME");

            // Assert
            Assert.That(value, Is.EqualTo("value"));
        }
Beispiel #2
0
        public void getvalue_should_return_known_value()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name1", "value1");
            settings.SetValue("name2", "value2");
            string value = settings.GetValue("name1");

            // Assert
            Assert.That(value, Is.EqualTo("value1"));
        }
        public PluginSettings GetTextPluginSettings(Guid databaseId)
        {
            PluginSettings          pluginSettings = null;
            SiteConfigurationEntity entity         = UnitOfWork.Find <SiteConfigurationEntity>()
                                                     .FirstOrDefault(x => x.Id == databaseId);

            if (entity != null)
            {
                pluginSettings = PluginSettings.LoadFromJson(entity.Content);
            }

            return(pluginSettings);
        }
Beispiel #4
0
        public void GetValue_Should_Return_Known_Value()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name1", "value1");
            settings.SetValue("name2", "value2");
            string value = settings.GetValue("name1");

            // Assert
            Assert.That(value, Is.EqualTo("value1"));
        }
Beispiel #5
0
		public void setvalue_should_be_case_insensitive_when_updating_existing_value()
		{
			// Arrange
			PluginSettings settings = new PluginSettings("mockplugin", "1.0");

			// Act
			settings.SetValue("name", "value");
			settings.SetValue("NaME", "new value");

			// Assert
			List<SettingValue> valueList = new List<SettingValue>(settings.Values);
			Assert.That(valueList.Count, Is.EqualTo(1));
			Assert.That(valueList[0].Value, Is.EqualTo("new value"));
		}
Beispiel #6
0
		public void setvalue_should_add_new_value()
		{
			// Arrange
			PluginSettings settings = new PluginSettings("mockplugin","1.0");

			// Act
			settings.SetValue("name", "value");

			// Assert
			List<SettingValue> valueList = new List<SettingValue>(settings.Values);
			Assert.That(valueList.Count, Is.EqualTo(1));
			Assert.That(valueList[0].Name, Is.EqualTo("name"));
			Assert.That(valueList[0].Value, Is.EqualTo("value"));
		}
Beispiel #7
0
        public void Settings_Should_Throw_Exception_If_Id_Is_Not_Set()
        {
            // Arrange
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            var settingsRepositoryMock          = new SettingsRepositoryMock();

            TextPluginStub plugin = new TextPluginStub("", "", "", "");

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = settingsRepositoryMock;

            // Act + Assert
            PluginSettings actualPluginSettings = plugin.Settings;
        }
Beispiel #8
0
        public void SetValue_Should_Update_Existing_Value()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name", "value");
            settings.SetValue("name", "new value");

            // Assert
            List<SettingValue> valueList = new List<SettingValue>(settings.Values);
            Assert.That(valueList.Count, Is.EqualTo(1));
            Assert.That(valueList[0].Value, Is.EqualTo("new value"));
        }
Beispiel #9
0
        public void setvalue_should_be_case_insensitive_when_updating_existing_value()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name", "value");
            settings.SetValue("NaME", "new value");

            // Assert
            List <SettingValue> valueList = new List <SettingValue>(settings.Values);

            Assert.That(valueList.Count, Is.EqualTo(1));
            Assert.That(valueList[0].Value, Is.EqualTo("new value"));
        }
Beispiel #10
0
        public void setvalue_should_add_new_value()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name", "value");

            // Assert
            List <SettingValue> valueList = new List <SettingValue>(settings.Values);

            Assert.That(valueList.Count, Is.EqualTo(1));
            Assert.That(valueList[0].Name, Is.EqualTo("name"));
            Assert.That(valueList[0].Value, Is.EqualTo("value"));
        }
Beispiel #11
0
        public void SetValue_Should_Be_Case_Insensitive_When_Updating_Existing_Value()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act
            settings.SetValue("name", "value");
            settings.SetValue("NaME", "new value");

            // Assert
            List <SettingValue> valueList = new List <SettingValue>(settings.Values);

            Assert.That(valueList.Count, Is.EqualTo(1));
            Assert.That(valueList[0].Value, Is.EqualTo("new value"));
        }
        public void Settings_Should_Throw_Exception_If_Id_Is_Not_Set()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            TextPluginStub plugin = new TextPluginStub("", "", "", "");

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act + Assert
            PluginSettings actualPluginSettings = plugin.Settings;
        }
Beispiel #13
0
        public void settings_should_default_version_to_1_if_version_is_empty()
        {
            // Arrange
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            var settingsRepositoryMock          = new SettingsRepositoryMock();

            TextPluginStub plugin = new TextPluginStub("id", "name", "desc", "");

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = settingsRepositoryMock;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings.Version, Is.EqualTo("1.0"));
        }
Beispiel #14
0
        public void settings_should_create_instance_when_repository_has_no_settings()
        {
            // Arrange
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            var settingsRepositoryMock          = new SettingsRepositoryMock();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = settingsRepositoryMock;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.Values.Count(), Is.EqualTo(0));
        }
        public void Settings_Should_Default_Version_To_1_If_Version_Is_Empty()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            TextPluginStub plugin = new TextPluginStub("id", "name", "desc", "");

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings.Version, Is.EqualTo("1.0"));
        }
Beispiel #16
0
        public void settings_should_call_oninitializesettings_when_repository_has_no_settings()
        {
            // Arrange
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            var settingsRepositoryMock          = new SettingsRepositoryMock();

            Mock <TextPluginStub> pluginMock = new Mock <TextPluginStub>();

            pluginMock.Setup(x => x.Id).Returns("SomeId");
            pluginMock.Object.PluginCache = pluginCacheMock.Object;
            pluginMock.Object.Repository  = settingsRepositoryMock;

            // Act
            PluginSettings actualPluginSettings = pluginMock.Object.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            pluginMock.Verify(x => x.OnInitializeSettings(It.IsAny <PluginSettings>()), Times.Once);
        }
Beispiel #17
0
        public void settings_should_save_to_repository_when_repository_has_no_settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            var settingsRepositoryMock          = new SettingsRepositoryMock();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = settingsRepositoryMock;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(settingsRepositoryMock.TextPlugins.Count, Is.EqualTo(1));
            Assert.That(settingsRepositoryMock.TextPlugins.FirstOrDefault(), Is.EqualTo(plugin));
        }
        public void Settings_Should_Create_Instance_When_Repository_Has_No_Settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.Values.Count(), Is.EqualTo(0));
        }
        public void Settings_Should_Save_To_Repository_When_Repository_Has_No_Settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(repository.TextPlugins.Count, Is.EqualTo(1));
            Assert.That(repository.TextPlugins.FirstOrDefault(), Is.EqualTo(plugin));
        }
Beispiel #20
0
        public void settings_should_load_from_cache_when_settings_exist_in_cache()
        {
            // Arrange
            Mock <IPluginCache> pluginCacheMock        = new Mock <IPluginCache>();
            PluginSettings      expectedPluginSettings = new PluginSettings("mockplugin", "1.0");

            expectedPluginSettings.SetValue("cache", "test");

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;

            pluginCacheMock.Setup(x => x.GetPluginSettings(plugin)).Returns(expectedPluginSettings);

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.GetValue("cache"), Is.EqualTo("test"));
        }
        public void Settings_Should_Call_OnInitializeSettings_When_Repository_Has_No_Settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            Mock <TextPluginStub> pluginMock = new Mock <TextPluginStub>();

            pluginMock.Setup(x => x.Id).Returns("SomeId");
            pluginMock.Object.PluginCache = pluginCacheMock.Object;
            pluginMock.Object.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = pluginMock.Object.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            pluginMock.Verify(x => x.OnInitializeSettings(It.IsAny <PluginSettings>()), Times.Once);
        }
        public void Settings_Should_Load_From_Cache_When_Settings_Exist_In_Cache()
        {
            // Arrange
            CacheMock           cache                  = new CacheMock();
            ApplicationSettings appSettings            = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock        = new Mock <IPluginCache>();
            PluginSettings      expectedPluginSettings = new PluginSettings("mockplugin", "1.0");

            expectedPluginSettings.SetValue("cache", "test");

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;

            pluginCacheMock.Setup(x => x.GetPluginSettings(plugin)).Returns(expectedPluginSettings);

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.GetValue("cache"), Is.EqualTo("test"));
        }
Beispiel #23
0
        public void settings_should_load_from_repository_when_cache_is_not_set()
        {
            // Arrange
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();

            PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");

            expectedPluginSettings.SetValue("repository", "test");
            var settingsRepositoryMock = new SettingsRepositoryMock();

            settingsRepositoryMock.PluginSettings = expectedPluginSettings;

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = settingsRepositoryMock;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.GetValue("repository"), Is.EqualTo("test"));
        }
Beispiel #24
0
        public void settings_should_return_member_instance_on_second_call_and_not_load_from_cache_or_repository()
        {
            // Arrange
            CacheMock                  cache           = new CacheMock();
            Mock <IPluginCache>        pluginCacheMock = new Mock <IPluginCache>();
            Mock <ISettingsRepository> mockRepository  = new Mock <ISettingsRepository>();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = mockRepository.Object;

            // Act
            PluginSettings settings = plugin.Settings;

            settings = plugin.Settings;

            // Assert
            Assert.That(settings, Is.Not.Null);
            pluginCacheMock.Verify(x => x.GetPluginSettings(plugin), Times.Once);             // 1st time only
            pluginCacheMock.Verify(x => x.UpdatePluginSettings(plugin), Times.Once);
            mockRepository.Verify(x => x.GetTextPluginSettings(plugin.DatabaseId), Times.Once);
            mockRepository.Verify(x => x.SaveTextPluginSettings(plugin), Times.Once);
        }
Beispiel #25
0
 public override void OnInitializeSettings(PluginSettings settings)
 {
 }
Beispiel #26
0
		public void settings_should_load_from_cache_when_settings_exist_in_cache()
		{
			// Arrange
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");
			expectedPluginSettings.SetValue("cache", "test");

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;

			pluginCacheMock.Setup(x => x.GetPluginSettings(plugin)).Returns(expectedPluginSettings);

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(actualPluginSettings.GetValue("cache"), Is.EqualTo("test"));
		}
Beispiel #27
0
        public void Should_Contain_Empty_Values_List()
        {
            // Arrange
            PluginSettings settings = new PluginSettings("mockplugin", "1.0");

            // Act + Assert
            Assert.That(settings.Values, Is.Not.Null);
            Assert.That(settings.Values.Count(), Is.EqualTo(0));
        }
Beispiel #28
0
		public override void OnInitializeSettings(PluginSettings settings)
		{
			
		}
Beispiel #29
0
		public void settings_should_load_from_repository_when_cache_is_not_set()
		{
			// Arrange
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();

			PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");
			expectedPluginSettings.SetValue("repository", "test");
			var settingsRepositoryMock = new SettingsRepositoryMock();
			settingsRepositoryMock.PluginSettings = expectedPluginSettings;

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = settingsRepositoryMock;

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(actualPluginSettings.GetValue("repository"), Is.EqualTo("test"));
		}
Beispiel #30
0
		private void EnsureSettings()
		{
			if (_settings == null)
			{
				// Guard for null SiteCache
				if (PluginCache == null)
				{
					throw new PluginException(null, "The PluginCache property is null for {0} when it should be injected by the DI container. " +
											  "If you're unit testing, set the PluginCache and Repository properties with stubs before calling the Settings properties.", GetType().FullName);
				}

				_settings = PluginCache.GetPluginSettings(this);
				if (_settings == null)
				{
					// Guard for null Repository
					if (Repository == null)
					{
						throw new PluginException(null, "The Repository property is null for {0} and it wasn't found in the cache - it should be injected by the DI container. " +
											  "If you're unit testing, set the PluginCache and Repository properties with stubs before calling the Settings properties.", GetType().FullName);
					}

					// Load from the database
					_settings = Repository.GetTextPluginSettings(this.DatabaseId);

					// If this is the first time the plugin has been used, new up the settings
					if (_settings == null)
					{
						EnsureIdIsValid();
						string version = EnsureValidVersion();
						_settings = new Settings(Id, version);

						// Allow derived classes to add custom setting values
						OnInitializeSettings(_settings);

						// Update the repository
						Repository.SaveTextPluginSettings(this);
					}

					// Cache the settings
					PluginCache.UpdatePluginSettings(this);
				}
			}
		}
Beispiel #31
0
		/// <summary>
		/// Called when settings are first initialized by the <see cref="Settings"/> property. When overriden this 
		/// method allows you add settings and their defaults that the plugin requires.
		/// </summary>
		/// <param name="settings">The plugin settings.</param>
		public virtual void OnInitializeSettings(Settings settings)
		{
		}
Beispiel #32
0
		public void Settings_Should_Load_From_Repository_When_Cache_Is_Not_Set()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();

			PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");
			expectedPluginSettings.SetValue("repository", "test");
			RepositoryMock repository = new RepositoryMock();
			repository.PluginSettings = expectedPluginSettings;

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = repository;

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(actualPluginSettings.GetValue("repository"), Is.EqualTo("test"));
		}
Beispiel #33
0
		public void Settings_Should_Load_From_Cache_When_Settings_Exist_In_Cache()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");
			expectedPluginSettings.SetValue("cache", "test");

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;

			pluginCacheMock.Setup(x => x.GetPluginSettings(plugin)).Returns(expectedPluginSettings);

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(actualPluginSettings.GetValue("cache"), Is.EqualTo("test"));
		}
Beispiel #34
0
 public override void OnInitializeSettings(Settings settings)
 {
     settings.SetValue("FileExtensions", "mp4,ogg,webm");
     base.OnInitializeSettings(settings);
 }