Example #1
0
        public static UnitTest Load(string serialized)
        {
            var     lookup  = TraitPair.ParseAll(serialized).ToDictionary(pair => pair.Name);
            Factory factory = Factory.Load(lookup[nameof(Factory)].Value);
            string  name    = lookup[nameof(Name)].Value;
            var     method  = factory.ReturnType.GetMethod(name, Type.EmptyTypes);

            return(new UnitTest(factory, method));
        }
Example #2
0
            //  Used via reflection.
#pragma warning disable IDE0051 // Remove unused private members
            private static NamedCtorFactory Load(Fixture fixture, string subclassData)
#pragma warning restore IDE0051 // Remove unused private members
            {
                var pairs = TraitPair.ParseAll(subclassData).ToDictionary(pair => pair.Name);

                string returnTypeName = pairs[nameof(ReturnType)].Value;
                Type   returnType     = Type.GetType(returnTypeName);

                string methodName = pairs[nameof(method)].Value;
                var    methodInfo = returnType.GetMethod(methodName, Type.EmptyTypes);

                return(new NamedCtorFactory(fixture, methodInfo));
            }
Example #3
0
        public static Factory Load(string serializedFactory)
        {
            var lookup = TraitPair.ParseAll(serializedFactory)
                         .ToDictionary(pair => pair.Name);

            Fixture fixture      = Fixture.Load(lookup[nameof(Fixture)].Value);
            string  subclassData = lookup["SubclassData"].Value;
            Type    subclassType = Type.GetType(lookup[nameof(Type)].Value);

            Debug.Assert(typeof(Factory).IsAssignableFrom(subclassType));

            var loadMethod = subclassType.GetMethod(
                "Load", BindingFlags.Static | BindingFlags.Public |
                BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            return((Factory)loadMethod.Invoke(null, new object[] { fixture, subclassData }));
        }
Example #4
0
        public static Fixture Load(string serializedFixture)
        {
            var lookup = TraitPair.ParseAll(serializedFixture)
                         .ToDictionary(pair => pair.Name);

            string getOrThrow(string name)
            {
                if (!lookup.TryGetValue(name, out TraitPair pair))
                {
                    throw new FormatException($"Missing {name} property when loading {nameof(Fixture)} from {serializedFixture}.");
                }
                return(pair.Value);
            }

            Assembly assembly = Assembly.LoadFrom(getOrThrow(nameof(Assembly)));
            Type     type     = assembly.GetType(getOrThrow(nameof(Type)));

            return(new Fixture(type));
        }