public void testBasic()
 {
     ScriptBuilder builder = new ScriptBuilder();
     builder.ScriptLanguage = "Groovy";
     builder.ScriptText = "print 'foo'";
     Script s1 = builder.Build();
     Assert.AreEqual("Groovy", s1.ScriptLanguage);
     Assert.AreEqual("print 'foo'", s1.ScriptText);
     builder = new ScriptBuilder();
     builder.ScriptLanguage = "Groovy";
     builder.ScriptText = "print 'foo'";
     Script s2 = builder.Build();
     Assert.AreEqual(s1, s2);
     Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode());
 }
        public void testLanguageNotBlank()
        {
            try
            {
                ScriptBuilder builder = new ScriptBuilder();
                builder.ScriptText = "print 'foo'";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // OK.
            }

            try
            {
                ScriptBuilder builder = new ScriptBuilder();
                builder.ScriptText = "print 'foo'";
                builder.ScriptLanguage = "";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // OK.
            }

            try
            {
                ScriptBuilder builder = new ScriptBuilder();
                builder.ScriptText = "print 'foo'";
                builder.ScriptLanguage = " ";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // OK.
            }
        }
示例#3
0
 public void TestScript()
 {
     ScriptBuilder builder = new ScriptBuilder();
     builder.ScriptLanguage = "language";
     builder.ScriptText = "text";
     Script v1 = builder.Build();
     Script v2 = (Script)CloneObject(v1);
     Assert.AreEqual("language", v2.ScriptLanguage);
     Assert.AreEqual("text", v2.ScriptText);
 }
        public void testTextNotNull()
        {
            ScriptBuilder builder = new ScriptBuilder();
            try
            {
                builder.ScriptLanguage = "Groovy";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                // OK.
            }

            // The text can be empty.
            builder = new ScriptBuilder();
            builder.ScriptLanguage = "Groovy";
            builder.ScriptText = "";
            builder.Build();
        }
        public void TestCreateTestConfiguration()
        {
            IDictionary<string, object> expectedData = new Dictionary<string, object>();
            expectedData["String"] = "retipipiter";
            expectedData["StringArray"] = new [] { "value1", "value2", "value3" };
            expectedData["Long"] = 11L;
            expectedData["LongArray"] = new []{12L, 13L};
            expectedData["LongObject"] = 14L;
            expectedData["LongObjectArray"] = new long?[]{15, null};
            expectedData["Char"] = 'a';
            expectedData["CharArray"] = new []{'b','c'};
            expectedData["Character"] = 'd';
            expectedData["CharacterArray"] = new char?[]{'e','f'};
            expectedData["Double"] = 0D;
            expectedData["DoubleArray"] = new []{0D, 100D};
            expectedData["DoubleObject"] = 0d;
            expectedData["DoubleObjectArray"] = new double?[] { 0D, 100D };
            expectedData["Float"] = 0F;
            expectedData["FloatArray"] = new[] { 0F, 100F };
            expectedData["FloatObject"] = null;
            expectedData["FloatObjectArray"] = new float?[] { 0F, 100F };
            expectedData["Int"] = 0;
            expectedData["IntArray"] = new[] { 0, 100 };
            expectedData["Integer"] = 0;
            expectedData["IntegerArray"] = new int?[] { 0, 100 };
            expectedData["Boolean"] = true;
            expectedData["BooleanArray"] = new[]{true, false};
            expectedData["BooleanObject"] = false;
            expectedData["BooleanObjectArray"] = new bool?[] { true, false };
            expectedData["URI"] = new Uri("http://localhost:8080");            expectedData["URIArray"] = "";
            expectedData["URIArray"] = new[] { new Uri("http://localhost:8080"), new Uri("http://localhost:8443") };
            expectedData["File"] = new FileName("c:\\Users\\Admin");
            expectedData["FileArray"] = new[] {new FileName("c:\\Users\\Admin\\Documents"), new FileName("c:\\Users\\Admin\\Settings")};
            var array = new GuardedByteArray();
            Encoding.UTF8.GetBytes("array").ToList().ForEach(array.AppendByte);
            expectedData["GuardedByteArray"] = array;

            array = new GuardedByteArray();
            Encoding.UTF8.GetBytes("item1").ToList().ForEach(array.AppendByte);
            var array2 = new GuardedByteArray();
            Encoding.UTF8.GetBytes("item2").ToList().ForEach(array2.AppendByte);
            expectedData["GuardedByteArrayArray"] = new []{array, array2};

            var secret = new GuardedString();
            "secret".ToCharArray().ToList().ForEach(secret.AppendChar);
            expectedData["GuardedString"] = secret;

            secret = new GuardedString();
            "secret1".ToCharArray().ToList().ForEach(secret.AppendChar);
            var secret2 = new GuardedString();
            "secret2".ToCharArray().ToList().ForEach(secret2.AppendChar);

            expectedData["GuardedStringArray"] = new[]{secret, secret2};
            expectedData["Script"] = new ScriptBuilder { ScriptLanguage = "PowerShell", ScriptText = "echo 'Hello OpenICF Developer'" }.Build();
            expectedData["ScriptArray"] = new[]{new ScriptBuilder { ScriptLanguage = "Groovy", ScriptText = "println 'Hello'" }.Build(),new ScriptBuilder { ScriptLanguage = "Groovy", ScriptText = "println 'OpenICF Developer'" }.Build()};

            Environment.SetEnvironmentVariable(TestHelpers.TestConfigEVName, "converter");

            FieldInfo info = typeof (TestHelpers).GetField("_propertyBags", BindingFlags.NonPublic | BindingFlags.Static);
            (info.GetValue(null) as Dictionary<string, PropertyBag>).Clear();

            PropertyBag propertyBag =
                TestHelpers.GetProperties(typeof(Org.IdentityConnectors.TestConnector.FakeConnector));
            (info.GetValue(null) as Dictionary<string, PropertyBag>).Clear();

            APIConfiguration testable = TestHelpers.CreateTestConfiguration(SafeType<Connector>.Get<Org.IdentityConnectors.TestConnector.FakeConnector>(), propertyBag, null);

            foreach (KeyValuePair<string, object> entry in expectedData)
            {
                Assert.AreEqual(entry.Value, testable.ConfigurationProperties.GetProperty(entry.Key).Value, "Configuration property: " + entry.Key + " has different value");
            }
        }