示例#1
0
 public ExplicitCastVariation(ExplicitCastTestType testType, NodeCreateType nodeCreateType, Type nodeType, object data, Type retType, TestCase testCase, string desc)
 {
     _desc           = desc;
     _data           = data;
     _nodeType       = nodeType;
     _testType       = testType;
     _retType        = retType;
     _nodeCreateType = nodeCreateType;
 }
                protected override void DetermineChildren()
                {
                    base.DetermineChildren();
                    Type type = Params[0] as Type;
                    ExplicitCastTestType testType   = (ExplicitCastTestType)Params[1];
                    NodeCreateType       createType = (NodeCreateType)Params[2];

                    // add normal types
                    foreach (object o in _data)
                    {
                        string desc = o.GetType().ToString() + " : ";
                        // On Arabic locale DateTime and DateTimeOffset types threw on serialization if the date was
                        // too big for the Arabic calendar
                        if (o is DateTime)
                        {
                            desc += ((DateTime)o).ToString(CultureInfo.InvariantCulture);
                        }
                        else if (o is DateTimeOffset)
                        {
                            desc += ((DateTimeOffset)o).ToString(CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            desc += o;
                        }

                        AddChild(new ExplicitCastVariation(testType, createType, type, o, o.GetType(), this, desc));
                    }

                    // add Nullable types check (not applicable for XmlConvert tests)
                    if (testType == ExplicitCastTestType.RoundTrip)
                    {
                        foreach (object o in _data)
                        {
                            string desc = o.GetType().ToString() + " : ";
                            // On Arabic locale DateTime and DateTimeOffset types threw on serialization if the date was
                            // too big for the Arabic calendar
                            if (o is DateTime)
                            {
                                desc += ((DateTime)o).ToString(CultureInfo.InvariantCulture);
                            }
                            else if (o is DateTimeOffset)
                            {
                                desc += ((DateTimeOffset)o).ToString(CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                desc += o;
                            }
                            AddChild(new ExplicitCastVariation(testType, createType, type, o, typeMapper[o.GetType()], this, desc));
                        }
                    }
                }
                //[Variation(Desc = "Conversion to bool overloads (1,True,true)", Params = new object[] { true, new string[] { "1", "True", "true","TRUE", " TRue " } })]
                //[Variation(Desc = "Conversion to bool overloads (0,False,false)", Params = new object[] {  false, new string[] { "0", "False", "false", "FALSE", " FalsE " } })]
                public void ConversionoBool()
                {
                    Type           type           = Params[0] as Type;
                    NodeCreateType nodeCreateType = (NodeCreateType)Params[2];

                    bool expV = (bool)CurrentChild.Params[0];

                    string[] strs = CurrentChild.Params[1] as string[];

                    object node = null;

                    foreach (string data in strs)
                    {
                        switch (nodeCreateType)
                        {
                        case NodeCreateType.Constructor:
                            if (type == typeof(XElement))
                            {
                                node = new XElement(XName.Get("name"), data);
                            }
                            else if (type == typeof(XAttribute))
                            {
                                node = new XAttribute(XName.Get("name"), data);
                            }
                            break;

                        case NodeCreateType.SetValue:
                            if (type == typeof(XElement))
                            {
                                node = new XElement(XName.Get("name"), "");
                                ((XElement)node).SetValue(data);
                            }
                            else if (type == typeof(XAttribute))
                            {
                                node = new XAttribute(XName.Get("name"), "");
                                ((XAttribute)node).SetValue(data);
                            }
                            break;

                        default:
                            TestLog.Compare(false, "test failed: wrong create type");
                            break;
                        }

                        object retData = type == typeof(XElement) ? (bool)(node as XElement) : (bool)(node as XAttribute);
                        TestLog.Compare(retData.Equals(expV), "Data verification for string :: " + data);
                    }
                }
 public ExplicitCastVariation(ExplicitCastTestType testType, NodeCreateType nodeCreateType, Type nodeType, object data, Type retType, TestCase testCase, string desc)
 {
     _desc = desc;
     _data = data;
     _nodeType = nodeType;
     _testType = testType;
     _retType = retType;
     _nodeCreateType = nodeCreateType;
 }