Exemplo n.º 1
0
        private static bool Equals(MacroOpBase x, MacroOpBase y)
        {
            if (x == null || y == null)
            {
                return(false);
            }

            if (x.GetType() != y.GetType())
            {
                return(false);
            }

            AutoSerializeBase.CommandPropertySpec info = AutoSerializeBase.GetPropertySpecForType(x.GetType());

            foreach (var prop in info.Properties)
            {
                object xVal = prop.Getter.DynamicInvoke(x);
                object yVal = prop.Getter.DynamicInvoke(y);
                if (Equals(xVal, yVal))
                {
                    continue;
                }

                if (prop.PropInfo.PropertyType == typeof(double) && Math.Abs((double)xVal - (double)yVal) <= 0.001)
                {
                    continue;
                }

                return(false);
            }

            return(true);
        }
        private void TestStartingWithMacroOperationSingle(Type t, int rounds)
        {
            for (int i = 0; i < rounds; i++)
            {
                MacroOpBase raw = (MacroOpBase)RandomPropertyGenerator.Create(t);

                ICommand cmd          = raw.ToCommand();
                bool     nullCommand  = cmd == null;
                bool     shouldBeNull = expectedNullCommand.Contains(t);
                //Assert.Equal(shouldBeNull, nullCommand); // TODO - reenable this once possible
                if (shouldBeNull || nullCommand)
                {
                    continue;
                }

                var serCmd = cmd as SerializableCommandBase; // TODO - this shouldnt be needed once all Commands have appropriate macro stuff set
                Assert.NotNull(serCmd);

                MacroOpBase entry = serCmd.ToMacroOps().Single();
                if (entry == null)
                {
                    throw new Exception("Deserialized not implemented");
                }
                if (!t.GetTypeInfo().IsAssignableFrom(entry.GetType()))
                {
                    throw new Exception("Deserialized operation of wrong type");
                }

                RandomPropertyGenerator.AssertAreTheSame(raw, entry);
            }
        }
Exemplo n.º 3
0
        private static string ToString(MacroOpBase op)
        {
            AutoSerializeBase.CommandPropertySpec info = AutoSerializeBase.GetPropertySpecForType(op.GetType());

            var sb = new StringBuilder();

            sb.Append(op.GetType().Name);
            sb.Append(":\n");

            foreach (var prop in info.Properties)
            {
                sb.AppendFormat("    {0}={1}\n", prop.PropInfo.Name, prop.Getter.DynamicInvoke(op));
            }

            return(sb.ToString());
        }