public void Test_GetValue_DottedAspect_NullMidResult() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            Munger munger = new Munger("This.NullProperty.ToUpperInvariant");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.IsNull(value);
        }
        public void Test_GetValue_VirtualProperty_CalledOnBaseClass() {
            // Arrange
            TestBaseClass instance = new TestSubClass();
            string testValue = "some test value";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("VirtualTestProperty");

            // Act
            string value = munger.GetValue(instance) as string;

            // Assert
            Assert.AreEqual(testValue, value);
        }
        public void Test_GetValue_DottedAspect_Success() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            string testValue = "1234567890";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.ToUpperInvariant.Length");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.AreEqual(testValue.Length, value);
        }
        public void Test_GetValue_DottedAspect_UnknownAspect() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            string testValue = "1234567890";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.UnknownProperty.Length");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            string errorMsg = "'UnknownProperty' is not a parameter-less method, property or field of type 'System.String'";
            Assert.AreEqual(errorMsg, value);
        }
 public void Initialize()
 {
     _munger = new Munger();
 }
 public void Cleanup()
 {
     _munger = null;
 }
        public void Test_PutValue_NonVirtualProperty_CalledOnBaseClass() {
            // Arrange
            TestBaseClass instance = new TestSubClass();
            string testValue = "some test value";
            Munger munger = new Munger("NonVirtualTestProperty");

            // Act
            munger.PutValue(instance, testValue);

            // Munger acts on the runtime type of the instance, so it (correctly)
            // calls the subclass' version of this property. The compiler
            // uses the declared type of the instance, so instance.NonVirtualTestProperty
            // returns null, which is correct but perhaps unexpected.

            // Assert
            Assert.AreEqual(null, instance.NonVirtualTestProperty);
            Assert.AreEqual(testValue, (instance as TestSubClass).NonVirtualTestProperty);
            Assert.IsTrue((instance as TestSubClass).subClassPropertyModified);
        }
        public void Test_PutValue_NonVirtualProperty_CalledOnSubClass() {
            // Arrange
            TestSubClass instance = new TestSubClass();
            string testValue = "some test value";
            Munger munger = new Munger("NonVirtualTestProperty");

            // Act
            munger.PutValue(instance, testValue);

            // Assert
            Assert.AreEqual(testValue, instance.NonVirtualTestProperty);
            Assert.IsTrue(instance.subClassPropertyModified);
        }
        public void Test_PutValue_DottedAspect_CantModifyReadOnlyProperty() {
            // Arrange
            TestSubClass instance = new TestSubClass();
            string testValue = "some test value";
            string testValue2 = "some test value2";
            Munger munger = new Munger("This.This.ReadOnlyProperty");
            instance.SetReadOnlyProperty(testValue);
            Assert.AreEqual(testValue, instance.ReadOnlyProperty);

            // Act
            munger.PutValue(instance, testValue2);

            // Assert
            Assert.AreEqual(testValue, instance.ReadOnlyProperty);
        }
        public void Test_PutValue_DottedAspect_UnknownAspect() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            string testValue = "1234567890";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.UnknownProperty");

            // Act
            munger.PutValue(instance, testValue);

            // Assert
            Assert.AreEqual(testValue, instance.VirtualTestProperty);
        }
        public void Test_PutValue_DottedAspect_Success() {
            // Arrange
            TestSubClass instance = new TestSubClass();
            string testValue = "some test value";
            Munger munger = new Munger("This.This.VirtualTestProperty");

            // Act
            munger.PutValue(instance, testValue);

            // Assert
            Assert.AreEqual(testValue, instance.VirtualTestProperty);
        }
Exemple #12
0
    private void ProcessFile(ModifyFileType file, HandlerStartInfo startInfo)
    {
        bool createIfMissing = config.CreateSettingIfNotFound;

        if (file.CreateSettingIfNotFound.HasValue)
        {
            createIfMissing = file.CreateSettingIfNotFound.Value;
        }

        bool overwrite = config.OverwriteExisting;

        if (file.OverwriteExisting.HasValue)
        {
            overwrite = file.OverwriteExisting.Value;
        }

        ConfigType modifyType = config.Type;

        if (file.Type != ConfigType.None)
        {
            modifyType = file.Type;
        }

        if (config.BackupSource)
        {
            try
            {
                ZephyrFile sourceFile = Utilities.GetZephyrFile(file.Source, clients);
                ZephyrFile backupFile = Utilities.GetZephyrFile($"{file.Source}_{DateTime.Now.ToString("yyyyMMddHHmmss")}", clients);
                sourceFile.CopyTo(backupFile);
            }
            catch (Exception e)
            {
                OnLogMessage("BackupSource", $"Error When Backing Up Source File [{file.Source}].", config.StopOnError ? LogLevel.Error : LogLevel.Warn, e);
                if (config.StopOnError)
                {
                    throw;
                }
            }
        }

        try
        {
            Stream settingsFileStream = GetSettingsFileStream(modifyType, file.SettingsFile, startInfo.Crypto);

            switch (modifyType)
            {
            case ConfigType.KeyValue:
                Munger.KeyValue(PropertyFile.Type.Java, file.Source, file.Destination, settingsFileStream, file.SettingsKvp, createIfMissing, overwrite, clients);
                break;

            case ConfigType.INI:
                Munger.KeyValue(PropertyFile.Type.Ini, file.Source, file.Destination, settingsFileStream, file.SettingsKvp, createIfMissing, overwrite, clients);
                break;

            case ConfigType.Regex:
                Munger.RegexMatch(file.Source, file.Destination, settingsFileStream, file.SettingsKvp, overwrite, clients);
                break;

            case ConfigType.XmlTransform:
                Munger.XMLTransform(file.Source, file.Destination, settingsFileStream, overwrite, clients);
                break;

            case ConfigType.XPath:
                Munger.XPath(file.Source, file.Destination, settingsFileStream, file.SettingsKvp, overwrite, clients);
                break;

            default:
                String message = "Unknown File Type [" + modifyType + "] Received.";
                OnLogMessage("ProcessFile", message);
                throw new Exception(message);
            }

            if (String.IsNullOrWhiteSpace(file.Destination))
            {
                OnLogMessage("ModifyFileHandler", String.Format(@"Config Type [{0}], Modified [{1}].", modifyType, file.Source));
            }
            else
            {
                OnLogMessage("ModifyFileHandler", String.Format(@"Config Type [{0}], Modified [{1}] to [{2}].", modifyType, file.Source, file.Destination));
            }
        }
        catch (Exception e)
        {
            OnLogMessage(config.Type.ToString(), $"Error Modifying File [{file.Source}].", (config.StopOnError == true) ? LogLevel.Error : LogLevel.Warn, e);
            if (config.StopOnError)
            {
                throw;
            }
        }
    }