public void ActivateAllCanonicalTypesTest()
        {
            var failed     = false;
            var failedList = new List <string>();

            foreach (var canonName in ECTypeNameMap.Keys)
            {
                string typeName;
                if (!ECTypeNameMap.TryGetTypeName(canonName, out typeName) || String.IsNullOrEmpty(typeName))
                {
                    context.WriteLine("Could not get the type name for '{0}'", canonName);
                    failed = true;
                    failedList.Add(canonName);
                    continue;
                }
                try
                {
                    object o;
                    Type   t = null;
                    if (!ECTypeMap.TryGetType(canonName, out t))
                    {
                        context.WriteLine("Could not get the type for '{0}' from ECTypeMap.TryGetType(<canonName>)", canonName);
                        failed = true;
                        failedList.Add(canonName);
                        continue;
                    }
                    if (!t.IsAbstract && !t.IsInterface)
                    {
                        var ctor = t.GetConstructor(new Type[] {});
                        if (ctor == null)
                        {
                            context.WriteLine("No default constructor for : {0}", t.Name);
                            continue;
                        }
                        o = Activator.CreateInstance(t);

                        context.WriteLine("Success for type '{0}'", o.GetType().FullName);
                    }
                    else
                    {
                        context.WriteLine("Type is not createable (Abstract or Interfact): {0}", t.Name);
                    }
                }
                catch (Exception)
                {
                    failed = true;
                    failedList.Add(canonName);
                }
            }
            if (failedList.Count > 0)
            {
                context.WriteLine("CreateInstance failed for the following canonical names:");
            }
            foreach (var name in failedList)
            {
                context.WriteLine(name);
            }
            Assert.IsFalse(failed, "At least one type could not be created.");
        }
Exemple #2
0
        public void ECTypeMapGetsAllMappedTypesFromKey()
        {
            // For all keys...
            // Take name from     ECModelTypeMap     (in the Model namespace)
            // Get the type from  ECModelTypeMap
            // Get the type from  ECModelTypeNameMap (in the Configuration namespace).
            // Compare the two for equality...

            var failed = false;

            foreach (var name in ECTypeMap.Keys)
            {
                string typeName;
                var    found = ECTypeNameMap.TryGetTypeName(name, out typeName);
                if (!found)
                {
                    failed = true;
                    TestContext.WriteLine("TypeName for '{0}' could not be mapped to a type name.");
                    continue;
                }

                // we have to use the assembly qualified name here because we are outside the model assembly
                typeName += ", BraneCloud.Evolution.EC"; // Assembly qualified name required.
                Type typeFromMap;
                found = ECTypeMap.TryGetType(name, out typeFromMap);
                if (!found)
                {
                    failed = true;
                    TestContext.WriteLine("Type for '{0}' could not be obtained using ECTypeMap.TryGetType().");
                    continue;
                }
                var typeFromString = Type.GetType(typeName);
                if (typeFromString != null)
                {
                    TestContext.WriteLine("TypeFromString.FullName = {0}", typeFromString.FullName);
                }
                else
                {
                    failed = true;
                    TestContext.WriteLine("ERROR! Could not get type = {0}", typeName);
                }
                Assert.IsFalse(failed);
            }
        }
Exemple #3
0
        public void ECTypeMapGetsAllMappedTypesFromModelAssembly()
        {
            // For all keys...
            // Take name from     ECModelTypeMap     (in the Model namespace)
            // Get the type from  ECModelTypeMap
            // Get the type from  ECModelTypeNameMap (in the Configuration namespace).
            // Compare the two for equality...
            foreach (var name in ECTypeMap.Keys)
            {
                string typeName;
                var    found = ECTypeNameMap.TryGetTypeName(name, out typeName);
                if (!found)
                {
                    TestContext.WriteLine("TypeName for '{0}' could not be mapped to a type name.");
                }

                // we have to use the assembly qualified name here because we are outside the model assembly
                typeName += ", BraneCloud.Evolution.EC"; // Assembly qualified name required.
                var typeFromString = Type.GetType(typeName);
                if (typeFromString != null)
                {
                    TestContext.WriteLine("TypeFromString.FullName = {0}", typeFromString.FullName);
                }
                else
                {
                    TestContext.WriteLine("ERROR! Could not get type = {0}", typeName);
                }
                //Assert.IsNotNull(typeFromString);
                //var typeFromMap = BraneCloud.Evolution.EC.ECModelTypeMap.TryGetType(name);
                //if (typeFromString == null)
                // {
                //    //Assert.IsNotNull(typeFromMap);
                //    TestContext.WriteLine("TypeFromMap.FullName    = {0}", typeFromMap.FullName);
                //    Assert.AreEqual(typeFromMap, typeFromString);
                //}
            }
        }