Exemple #1
0
        public void TestValidListOfObjectLiterals()
        {
            var resolvers = new ObjectLiteral[]
            {
                CreateObject("kind", "SourceResolver"),
                CreateObject("kind", "SourceResolver")
            };

            // lazy because in case there is a _bug_ in the converter, we don't want this auxiliary conversion
            // to fail first, before the actual unit test (inside the for loop)
            var myConvertedResolversArrayLazy = Lazy.Create(() =>
                                                            resolvers.Select(r => ConfigurationConverter.Convert <IResolverSettings>(m_context, r)).ToArray());

            foreach (var resolversList in GetDifferentListRepresenations(resolvers))
            {
                IConfiguration conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                    m_context,
                    CreateObject("resolvers", resolversList));

                XAssert.IsNotNull(conf);
                AssertAlmostEqualToDefaultConfigurationObject(conf, "Resolvers");
                var confResolversArray = conf.Resolvers.ToArray();

                XAssert.IsTrue(MyEqual(myConvertedResolversArrayLazy.Value, confResolversArray));
            }
        }
Exemple #2
0
        public void TestMapConversion()
        {
            var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject(
                    "resolvers",
                    CreateArray(
                        CreateObject(
                            "kind", "MsBuild",
                            "root", AbsolutePath.Invalid,
                            "environment", CreateMap(new KeyValuePair <object, object>[] {
                new KeyValuePair <object, object>("1", "hi"),
                new KeyValuePair <object, object>("2", "bye")
            }
                                                     )
                            )
                        )
                    )
                );
            var resolver        = conf.Resolvers.Single();
            var msBuildResolver = resolver as MsBuildResolverSettings;

            XAssert.IsNotNull(msBuildResolver);

            XAssert.AreEqual("hi", msBuildResolver.Environment["1"]);
            XAssert.AreEqual("bye", msBuildResolver.Environment["2"]);
        }
Exemple #3
0
        public void TestValidLessSimple()
        {
            var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject(
                    "cache", CreateObject(
                        "cacheGraph", true,
                        "cacheSpecs", SpecCachingOption.Enabled),
                    "schedule", CreateObject("stopOnFirstError", false),
                    "sandbox", CreateObject("defaultTimeout", 1000)));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "Cache", "Schedule", "Engine", "Sandbox");
            AssertAlmostEqual(
                new CacheConfiguration
            {
                CacheGraph = true,
                CacheSpecs = SpecCachingOption.Enabled
            },
                conf.Cache,
                "CacheGraph", "CacheSpec");
            AssertAlmostEqual(
                new ScheduleConfiguration
            {
                StopOnFirstError = false,
            },
                conf.Schedule,
                "DefaultTimeout");
            XAssert.IsTrue(conf.Cache.CacheGraph);
            XAssert.AreEqual(SpecCachingOption.Enabled, conf.Cache.CacheSpecs);
            XAssert.IsFalse(conf.Schedule.StopOnFirstError);
            XAssert.AreEqual(1000, conf.Sandbox.DefaultTimeout);
        }
Exemple #4
0
 public void TestArrayLiteralDoesNotConvertToObjectLiteral()
 {
     Assert.Throws <ConversionException>(() =>
                                         ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                                             m_context,
                                             CreateObject(
                                                 "mounts",
                                                 CreateArray("1", "2", "3"))));
 }
Exemple #5
0
 public void TestInvalidMapOfStringToIValue()
 {
     Assert.Throws <ConversionException>(() =>
                                         ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                                             m_context,
                                             CreateObject(
                                                 "mounts", CreateObject(
                                                     "mount1", "str1",
                                                     "mount2", "str2"))));
 }
Exemple #6
0
        public void TestValidNullListOfObjectLiterals()
        {
            var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject("resolvers", null));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "Resolvers");
            XAssert.AreEqual(null, conf.Resolvers);
        }
Exemple #7
0
        public void TestValidEmptyListOfStrings()
        {
            var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject("allowedEnvironmentVariables", new ObjectLiteral[0]));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "AllowedEnvironmentVariables");
            XAssert.IsNotNull(conf.AllowedEnvironmentVariables);
            XAssert.AreEqual(0, conf.AllowedEnvironmentVariables.Count);
        }
Exemple #8
0
 public void TestInvalidPathAsString()
 {
     Assert.Throws <ConversionException>(() =>
     {
         const string PathStr = "test";
         ConfigurationConverter.ConvertObjectLiteralToConfiguration(
             m_context,
             CreateObject(
                 "cache", CreateObject(
                     "cacheLogFilePath", PathStr)));
     });
 }
Exemple #9
0
        public void TestInvalidMapOfPaths()
        {
            var    Path0 = AbsolutePath.Create(m_context.PathTable, A("x", "temp", "file1.txt"));
            string Path1 = "file2.txt";

            Assert.Throws <ConversionException>(() =>
                                                ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                                                    m_context,
                                                    CreateObject(
                                                        "engine", CreateObject(
                                                            "rootMap", CreateObject("path0", Path0,
                                                                                    "path1", Path1)))));
        }
Exemple #10
0
        public void TestValidEnum()
        {
            var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject("logging", CreateObject("diagnostic", DiagnosticLevels.Engine)));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "Logging");
            AssertAlmostEqual(
                new LoggingConfiguration(),
                conf.Logging,
                "Diagnostic");
            XAssert.AreEqual(DiagnosticLevels.Engine, conf.Logging.Diagnostic);
        }
Exemple #11
0
        public void TestValidListOfStrings()
        {
            var envVarStrings = new[] { "var1", "var2" };

            foreach (var envVarList in GetDifferentListRepresenations(envVarStrings))
            {
                IConfiguration conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                    m_context,
                    CreateObject("allowedEnvironmentVariables", envVarList));

                XAssert.IsNotNull(conf);
                AssertAlmostEqualToDefaultConfigurationObject(conf, "AllowedEnvironmentVariables");
                XAssert.IsTrue(MyEqual(envVarStrings, conf.AllowedEnvironmentVariables.ToArray()));
            }
        }
Exemple #12
0
        public void TestValidSimple()
        {
            var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject(
                    "sandbox",
                    CreateObject("breakOnUnexpectedFileAccess", true)));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "Sandbox");
            AssertAlmostEqual(
                new SandboxConfiguration(),
                conf.Sandbox,
                "BreakOnUnexpectedFileAccess");
            XAssert.IsTrue(conf.Sandbox.BreakOnUnexpectedFileAccess);
        }
Exemple #13
0
        public void TestValidMapOfPaths()
        {
            var Path0 = AbsolutePath.Create(m_context.PathTable, A("x", "temp", "file1.txt"));
            var Path1 = AbsolutePath.Create(m_context.PathTable, A("x", "temp", "file2.txt"));
            var conf  = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject(
                    "engine", CreateObject(
                        "rootMap", CreateObject("path0", Path0,
                                                "path1", Path1))));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "Engine");
            XAssert.AreEqual(2, conf.Engine.RootMap.Count);
            XAssert.AreEqual(Path0, conf.Engine.RootMap["path0"]);
            XAssert.AreEqual(Path1, conf.Engine.RootMap["path1"]);
        }
Exemple #14
0
        public void TestValidPathAsString()
        {
            string PathStr = A("x", "temp");
            var    conf    = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                m_context,
                CreateObject(
                    "cache", CreateObject(
                        "cacheLogFilePath", PathStr)));

            XAssert.IsNotNull(conf);
            AssertAlmostEqualToDefaultConfigurationObject(conf, "Cache");
            AssertAlmostEqual(
                new CacheConfiguration(),
                conf.Cache,
                "CacheLogFilePath");
            XAssert.AreEqual(PathStr, conf.Cache.CacheLogFilePath.ToString(m_context.PathTable));
        }
Exemple #15
0
        public void TestValidListOfInts()
        {
            var noLogInts = new[] { 1, 2 };

            foreach (var noLogList in GetDifferentListRepresenations(noLogInts))
            {
                var conf = ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                    m_context,
                    CreateObject("logging", CreateObject("noLog", noLogList)));

                XAssert.IsNotNull(conf);
                AssertAlmostEqualToDefaultConfigurationObject(conf, "Logging");

                XAssert.AreEqual(noLogInts.Length, conf.Logging.NoLog.Count);
                XAssert.AreEqual(noLogInts[0], conf.Logging.NoLog[0]);
                XAssert.AreEqual(noLogInts[1], conf.Logging.NoLog[1]);
            }
        }
Exemple #16
0
        public void TestValidListOfObjectLiteralsButInvalidResolvers()
        {
            var resolvers = new ObjectLiteral[] { CreateObject("priority", 2, "kind", "UnknownResolver") };

            foreach (var resolversList in GetDifferentListRepresenations(resolvers))
            {
                try
                {
                    ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                        m_context,
                        CreateObject("resolvers", resolversList));
                    XAssert.Fail("Expected to fail with ConversionException when trying to set string[] to List<IResolver>");
                }
                catch (ConversionException)
                {
                    // OK, as expected
                }
            }
        }
Exemple #17
0
        public void TestInvalidListOfStrings()
        {
            var resolvers = new ObjectLiteral[] { CreateObject("priority", 1), CreateObject("type", "1") };

            foreach (var resolversList in GetDifferentListRepresenations(resolvers))
            {
                try
                {
                    ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                        m_context,
                        CreateObject("allowedEnvironmentVariables", resolversList));
                    XAssert.Fail("Expected to fail with ConversionException when trying to set ObjectLiteral[] to List<string>");
                }
                catch (ConversionException)
                {
                    // OK, as expected
                }
            }
        }
Exemple #18
0
        public void TestInvalidListOfPaths()
        {
            string PathStr0 = A("x", "temp", "file1.txt");
            string PathStr1 = "file2.txt";

            foreach (var configImportsList in GetDifferentListRepresenations(new[] { PathStr0, PathStr1 }))
            {
                try
                {
                    ConfigurationConverter.ConvertObjectLiteralToConfiguration(
                        m_context,
                        CreateObject(
                            "startup",
                            CreateObject("additionalConfigFiles", configImportsList)));
                    XAssert.Fail("Expected to fail with ConversionException when trying to set string[] containing invalid path strings to List<Path>");
                }
                catch (ConversionException)
                {
                    // OK, as expected
                }
            }
        }
Exemple #19
0
 public void TestInvalidArgObjectLiteral()
 {
     Assert.ThrowsAny <Exception>(() =>
                                  ConfigurationConverter.ConvertObjectLiteralToConfiguration(m_context, null));
 }
Exemple #20
0
 public void TestInvalidArgTable()
 {
     Assert.ThrowsAny <Exception>(() =>
                                  ConfigurationConverter.ConvertObjectLiteralToConfiguration(null, s_emptyObjectLiteral));
 }