Ejemplo n.º 1
0
        public void Enum_GetName_MultipleMatches()
        {
            // In the case of multiple matches, GetName returns one of them (which one is an implementation detail.)
            string s = Enum2.GetName(typeof(SimpleEnum), 3);

            Assert.IsTrue(s == "Green" || s == "Green_a" || s == "Green_b", "got '{0}'", s);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Executes the request and returns a response, authenticating if needed
        /// </summary>
        /// <param name="request">Request to be executed</param>
        /// <returns>RestResponse</returns>
        public virtual IRestResponse Execute(IRestRequest request)
        {
            var method = Enum2.GetName(typeof(Method), request.Method);

            switch (request.Method)
            {
            case Method.COPY:
                return(Execute(request, method, DoExecuteAsPost));

            case Method.POST:
                return(Execute(request, method, DoExecuteAsPost));

            case Method.PUT:
                return(Execute(request, method, DoExecuteAsPost));

            case Method.PATCH:
                return(Execute(request, method, DoExecuteAsPost));

            case Method.MERGE:
                return(Execute(request, method, DoExecuteAsPost));

            default:
                return(Execute(request, method, DoExecuteAsGet));
            }
            ;
        }
        /// <summary>
        ///     Executes the request and callback asynchronously, authenticating if needed
        /// </summary>
        /// <param name="request">Request to be executed</param>
        /// <param name="callback">Callback function to be executed upon completion providing access to the async handle.</param>
        /// <param name="httpMethod">HTTP call method (GET, PUT, etc)</param>
        public virtual RestRequestAsyncHandle ExecuteAsync(
            IRestRequest request,
            Action <IRestResponse, RestRequestAsyncHandle> callback, Method httpMethod
            )
        {
            var method = Enum2.GetName(typeof(Method), httpMethod);

            switch (httpMethod)
            {
            case Method.COPY:
                return(ExecuteAsync(request, callback, method, DoAsPostAsync));

            case Method.MERGE:
                return(ExecuteAsync(request, callback, method, DoAsPostAsync));

            case Method.PATCH:
                return(ExecuteAsync(request, callback, method, DoAsPostAsync));

            case Method.POST:
                return(ExecuteAsync(request, callback, method, DoAsPostAsync));

            case Method.PUT:
                return(ExecuteAsync(request, callback, method, DoAsPostAsync));

            default:
                return(ExecuteAsync(request, callback, method, DoAsGetAsync));
            }
        }
Ejemplo n.º 4
0
        public void Enum_GetName_Invalid()
        {
            Type t = typeof(SimpleEnum);

            AssertExtensions.Throws <ArgumentNullException>("enumType", () => Enum2.GetName(null, 1)); // Enum type is null
            AssertExtensions.Throws <ArgumentNullException>("value", () => Enum2.GetName(t, null));    // Value is null

            //AssertExtensions.Throws<ArgumentException>(null, () => Enum2.GetName(typeof(object), 1)); // Enum type is not an enum
            AssertExtensions.Throws <ArgumentException>("enumType", () => Enum2.GetName(typeof(object), 1)); // Enum type is not an enum
            AssertExtensions.Throws <ArgumentException>("value", () => Enum2.GetName(t, "Red"));             // Value is not the type of the enum's raw data
            AssertExtensions.Throws <ArgumentException>("value", () => Enum2.GetName(t, (IntPtr)0));         // Value is out of range
        }
Ejemplo n.º 5
0
        private static void Enum_GetName(Type enumType, object value, string expected)
        {
            Assert.AreEqual(expected, Enum2.GetName(enumType, value),
                            "Invalid name for {0} of type {1}", value, enumType.Name);

            // The format "G" should return the name of the enum case
            if (value.GetType() == enumType)
            {
                ToString_Format((Enum)value, "G", expected);
            }
            else
            {
                Format(enumType, value, "G", expected ?? value.ToString());
            }
        }
Ejemplo n.º 6
0
        private void EnumGetName(Type enumType, object[] values, string[] names)
        {
            Assert.IsNotNull(values);
            Assert.IsNotNull(names);
            Assert.AreEqual(values.Length, names.Length);

            if (values.Length < 1)
            {
                Assert.Fail("Values cannot be empty");
            }

            for (int i = 0; i < values.Length; i++)
            {
                string name = Enum2.GetName(enumType, values[i]);
                Assert.AreEqual(names[i], name);
            }
        }