Beispiel #1
0
        public void Should_compare_with_null_instance(decimal value)
        {
            var instance = new USD(value);

            Assert.IsFalse(instance.Equals(null), "Equals");
            Assert.AreEqual(1, instance.CompareTo(null), "CompareTo");
        }
Beispiel #2
0
        public void Should_compare_with_another_type_of_instance(decimal value)
        {
            var    instance1 = new USD(value);
            object instance2 = value;

            Assert.IsFalse(instance1.Equals(instance2), "Equals");
            Assert.Throws <ArgumentException>(() => instance1.CompareTo(instance2), "CompareTo");
        }
Beispiel #3
0
        public void Should_compare_with_bigger_value(double baseValue, double biggerValue)
        {
            var baseInstance   = new USD((decimal)baseValue);
            var biggerInstance = new USD((decimal)biggerValue);

            Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object");

            Assert.IsFalse(baseInstance == biggerInstance, "==");
            Assert.IsTrue(baseInstance != biggerInstance, "!=");

            Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo");
            Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object");

            Assert.IsTrue(baseInstance < biggerInstance, "<");
            Assert.IsFalse(baseInstance > biggerInstance, ">");

            Assert.IsTrue(baseInstance <= biggerInstance, "<=");
            Assert.IsFalse(baseInstance >= biggerInstance, ">=");
        }
Beispiel #4
0
        public void Should_compare_with_smaller_value(double baseValue, double smallerValue)
        {
            var baseInstance    = new USD((decimal)baseValue);
            var smallerInstance = new USD((decimal)smallerValue);

            Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object");

            Assert.IsFalse(baseInstance == smallerInstance, "==");
            Assert.IsTrue(baseInstance != smallerInstance, "!=");

            Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo");
            Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < smallerInstance, "<");
            Assert.IsTrue(baseInstance > smallerInstance, ">");

            Assert.IsFalse(baseInstance <= smallerInstance, "<=");
            Assert.IsTrue(baseInstance >= smallerInstance, ">=");
        }
Beispiel #5
0
        public void Should_compare_with_same_value(decimal value)
        {
            var baseInstance  = new USD(value);
            var otherInstance = new USD(value);

            Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals");
            Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object");

            Assert.IsTrue(baseInstance == otherInstance, "==");
            Assert.IsFalse(baseInstance != otherInstance, "!=");

            Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo");
            Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < otherInstance, "<");
            Assert.IsFalse(baseInstance > otherInstance, ">");

            Assert.IsTrue(baseInstance <= otherInstance, "<=");
            Assert.IsTrue(baseInstance >= otherInstance, ">=");
        }
Beispiel #6
0
        public static AttributeSet Parse(string vcsid, NameValueCollection request)
        {
            int       index;
            Hashtable htAttr = new Hashtable();

            foreach (string key in request.AllKeys)
            {
                if (!(key.StartsWith(ATTR + vcsid) ||
                      key.StartsWith(ATTR_D + vcsid) ||
                      key.StartsWith(ATTR_T + vcsid))
                    )
                {
                    continue;
                }

                AttributeTypes type = AttributeTypes.ATTR_ID;

                string val  = request[key];
                string skey = key.Substring(ATTR.Length);
                if (skey.StartsWith(USD))
                {
                    index = skey.LastIndexOf(US);
                    string ekey = skey.Substring(index);
                    skey = skey.Substring(0, index);
                    skey = skey.Substring(USD.Length);
                    if (USC.Equals(ekey))
                    {
                        type = AttributeTypes.ATTR_TEXT;
                    }
                    else if (USD.Equals(ekey))
                    {
                        type = AttributeTypes.ATTR_DATE_D;
                    }
                    else if (USM.Equals(ekey))
                    {
                        type = AttributeTypes.ATTR_DATE_M;
                    }
                    else if (USY.Equals(ekey))
                    {
                        type = AttributeTypes.ATTR_DATE_Y;
                    }
                }
                else if (skey.StartsWith(UST))
                {
                    skey = skey.Substring(UST.Length);
                    type = AttributeTypes.ATTR_TEXT;
                }
                else
                {
                    if (val.IndexOf(SEP) > -1)
                    {
                        type = AttributeTypes.ATTR_IDS;
                    }
                    else
                    {
                        type = AttributeTypes.ATTR_ID;
                    }
                }

                AttrInfo info = new AttrInfo();
                info.typeId = type;

                // Peel of the vcsid
                index       = skey.IndexOf(US);
                info.attrId = skey.Substring(index + 1);
                info.csid   = skey.Substring(0, index);
                info.val    = request[key];
                skey        = info.attrId;

                object obj = htAttr[info.attrId];
                if (obj != null)
                {
                    if (obj is ArrayList)
                    {
                        ((ArrayList)obj).Add(info);
                    }
                    else
                    {
                        ArrayList al = new ArrayList();
                        al.Add(obj);
                        al.Add(info);
                        htAttr.Remove(info.attrId);
                        htAttr.Add(skey, al);
                    }
                }
                else
                {
                    htAttr.Add(info.attrId, info);
                }
            }

            return(Compile(htAttr, vcsid));
        }