Ejemplo n.º 1
0
        public string Save()
        {
            var factoryPair = new TraitPair(nameof(Factory), Factory.Save());
            var namePair    = new TraitPair(nameof(Name), Name);

            return(TraitPair.SaveAll(factoryPair, namePair));
        }
Ejemplo n.º 2
0
        public string Save()
        {
            var assemblyPair = new TraitPair(nameof(Assembly), Assembly.Location);
            var typePair     = new TraitPair(nameof(Type), Type.FullName);

            return(TraitPair.SaveAll(assemblyPair, typePair));
        }
Ejemplo n.º 3
0
#pragma warning restore IDE0060 // Remove unused parameter
            protected private override string SaveSubclassData()
            {
                var ourTypePair = new TraitPair(nameof(Type), GetType().FullName);
                var fixturePair = new TraitPair(nameof(Fixture), Fixture.Save());

                return(TraitPair.SaveAll(ourTypePair, fixturePair));
            }
Ejemplo n.º 4
0
        public string Save()
        {
            var ourTypePair      = new TraitPair(nameof(Type), GetType().FullName);
            var fixturePair      = new TraitPair(nameof(Fixture), Fixture.Save());
            var subclassDataPair = new TraitPair("SubclassData", SaveSubclassData());

            return(TraitPair.SaveAll(ourTypePair, fixturePair, subclassDataPair));
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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));
            }
Ejemplo n.º 7
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 }));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
 protected private override string SaveSubclassData()
 {
     return(TraitPair.SaveAll(
                new TraitPair(nameof(method), method.Name),
                new TraitPair(nameof(ReturnType), ReturnType.AssemblyQualifiedName)));
 }