Esempio n. 1
0
        public void Extensions_Safe_Catch2()
        {
            var ex0    = new Ex("ex");
            var ex1    = new Ex1("ex");
            var ex2    = new Ex2("ex");
            var ex3    = new Ex3("ex");
            var baseEx = new BaseEx("ex");
            var subEx  = new SubEx("ex");

            var err1 = Safe.Try <bool, Ex1, Ex2>(() => { throw ex1; });
            var err2 = Safe.Try <bool, Ex1, Ex2>(() => { throw ex2; });

            Assert.IsFalse(err1.HasValue);
            Assert.IsFalse(err2.HasValue);

            Assert.IsInstanceOfType(err1.Match(x => null, ex => ex), typeof(Ex1));
            Assert.IsInstanceOfType(err2.Match(x => null, ex => ex), typeof(Ex2));

            Assert.AreEqual(err1.Match(x => null, ex => ex), ex1);
            Assert.AreEqual(err2.Match(x => null, ex => ex), ex2);

            CustomAssert.Throws <Ex>(() => Safe.Try <bool, Ex2, Ex3>(() => { throw ex0; }));
            CustomAssert.Throws <Ex1>(() => Safe.Try <bool, Ex2, Ex3>(() => { throw ex1; }));

            Safe.Try <bool, BaseEx, Ex2>(() => { throw subEx; });
            Safe.Try <bool, Ex, Ex2>(() => { throw ex0; });
            Safe.Try <bool, Ex, Ex2>(() => { throw ex1; });

            var success = Safe.Try <bool, Ex1, Ex2>(() => true);

            Assert.IsTrue(success.ValueOr(false));
        }
Esempio n. 2
0
        public void Extensions_Safe_Catch5()
        {
            var ex0    = new Ex("ex");
            var ex1    = new Ex1("ex");
            var ex2    = new Ex2("ex");
            var ex3    = new Ex3("ex");
            var ex4    = new Ex4("ex");
            var ex5    = new Ex5("ex");
            var ex6    = new Ex6("ex");
            var baseEx = new BaseEx("ex");
            var subEx  = new SubEx("ex");

            var err1 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex1; });
            var err2 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex2; });
            var err3 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex3; });
            var err4 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex4; });
            var err5 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex5; });

            Assert.IsFalse(err1.HasValue);
            Assert.IsFalse(err2.HasValue);
            Assert.IsFalse(err3.HasValue);
            Assert.IsFalse(err4.HasValue);
            Assert.IsFalse(err5.HasValue);

            Assert.IsInstanceOf(typeof(Ex1), err1.Match(x => null, ex => ex));
            Assert.IsInstanceOf(typeof(Ex2), err2.Match(x => null, ex => ex));
            Assert.IsInstanceOf(typeof(Ex3), err3.Match(x => null, ex => ex));
            Assert.IsInstanceOf(typeof(Ex4), err4.Match(x => null, ex => ex));
            Assert.IsInstanceOf(typeof(Ex5), err5.Match(x => null, ex => ex));

            Assert.AreEqual(err1.Match(x => null, ex => ex), ex1);
            Assert.AreEqual(err2.Match(x => null, ex => ex), ex2);
            Assert.AreEqual(err3.Match(x => null, ex => ex), ex3);
            Assert.AreEqual(err4.Match(x => null, ex => ex), ex4);
            Assert.AreEqual(err5.Match(x => null, ex => ex), ex5);

            CustomAssert.Throws <Ex>(() => Safe.Try <bool, Ex2, Ex3, Ex4, Ex5, Ex6>(() => { throw ex0; }));
            CustomAssert.Throws <Ex1>(() => Safe.Try <bool, Ex2, Ex3, Ex4, Ex5, Ex6>(() => { throw ex1; }));

            Safe.Try <bool, BaseEx, Ex2, Ex3, Ex4, Ex5>(() => { throw subEx; });
            Safe.Try <bool, Ex, Ex2, Ex3, Ex4, Ex5>(() => { throw ex0; });
            Safe.Try <bool, Ex, Ex2, Ex3, Ex4, Ex5>(() => { throw ex1; });

            var success = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => true);

            Assert.IsTrue(success.ValueOr(false));
        }
Esempio n. 3
0
        public static void Run(TestHelper helper)
        {
            TextWriter output = helper.Output;

            output.Write("testing default values... ");
            output.Flush();

            {
                var v = new Base();
                TestHelper.Assert(!v.BoolFalse);
                TestHelper.Assert(v.BoolTrue);
                TestHelper.Assert(v.B == 1);
                TestHelper.Assert(v.S == 2);
                TestHelper.Assert(v.I == 3);
                TestHelper.Assert(v.L == 4);
                TestHelper.Assert(v.F == 5.1F);
                TestHelper.Assert(v.D == 6.2);
                TestHelper.Assert(v.Str.Equals("foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007"));
                TestHelper.Assert(v.NoDefault == null);
                TestHelper.Assert(v.ZeroI == 0);
                TestHelper.Assert(v.ZeroL == 0);
                TestHelper.Assert(v.ZeroF == 0);
                TestHelper.Assert(v.ZeroDotF == 0);
                TestHelper.Assert(v.ZeroD == 0);
                TestHelper.Assert(v.ZeroDotD == 0);
            }

            {
                var v = new Derived();
                TestHelper.Assert(!v.BoolFalse);
                TestHelper.Assert(v.BoolTrue);
                TestHelper.Assert(v.B == 1);
                TestHelper.Assert(v.S == 2);
                TestHelper.Assert(v.I == 3);
                TestHelper.Assert(v.L == 4);
                TestHelper.Assert(v.F == 5.1F);
                TestHelper.Assert(v.D == 6.2);
                TestHelper.Assert(v.Str.Equals("foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007"));
                TestHelper.Assert(v.C1 == Color.red);
                TestHelper.Assert(v.C2 == Color.green);
                TestHelper.Assert(v.C3 == Color.blue);
                TestHelper.Assert(v.Nc1 == Nested.Color.red);
                TestHelper.Assert(v.Nc2 == Nested.Color.green);
                TestHelper.Assert(v.Nc3 == Nested.Color.blue);
                TestHelper.Assert(v.NoDefault == null);
                TestHelper.Assert(v.ZeroI == 0);
                TestHelper.Assert(v.ZeroL == 0);
                TestHelper.Assert(v.ZeroF == 0);
                TestHelper.Assert(v.ZeroDotF == 0);
                TestHelper.Assert(v.ZeroD == 0);
                TestHelper.Assert(v.ZeroDotD == 0);
            }

            {
                var v = new BaseEx();
                TestHelper.Assert(!v.BoolFalse);
                TestHelper.Assert(v.BoolTrue);
                TestHelper.Assert(v.B == 1);
                TestHelper.Assert(v.S == 2);
                TestHelper.Assert(v.I == 3);
                TestHelper.Assert(v.L == 4);
                TestHelper.Assert(v.F == 5.1F);
                TestHelper.Assert(v.D == 6.2);
                TestHelper.Assert(v.Str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007");
                TestHelper.Assert(v.NoDefault == null);
                TestHelper.Assert(v.ZeroI == 0);
                TestHelper.Assert(v.ZeroL == 0);
                TestHelper.Assert(v.ZeroF == 0);
                TestHelper.Assert(v.ZeroDotF == 0);
                TestHelper.Assert(v.ZeroD == 0);
                TestHelper.Assert(v.ZeroDotD == 0);
            }

            {
                var v = new DerivedEx();
                TestHelper.Assert(!v.BoolFalse);
                TestHelper.Assert(v.BoolTrue);
                TestHelper.Assert(v.B == 1);
                TestHelper.Assert(v.S == 2);
                TestHelper.Assert(v.I == 3);
                TestHelper.Assert(v.L == 4);
                TestHelper.Assert(v.F == 5.1F);
                TestHelper.Assert(v.D == 6.2);
                TestHelper.Assert(v.Str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007");
                TestHelper.Assert(v.NoDefault == null);
                TestHelper.Assert(v.C1 == Color.red);
                TestHelper.Assert(v.C2 == Color.green);
                TestHelper.Assert(v.C3 == Color.blue);
                TestHelper.Assert(v.Nc1 == Nested.Color.red);
                TestHelper.Assert(v.Nc2 == Nested.Color.green);
                TestHelper.Assert(v.Nc3 == Nested.Color.blue);
                TestHelper.Assert(v.ZeroI == 0);
                TestHelper.Assert(v.ZeroL == 0);
                TestHelper.Assert(v.ZeroF == 0);
                TestHelper.Assert(v.ZeroDotF == 0);
                TestHelper.Assert(v.ZeroD == 0);
                TestHelper.Assert(v.ZeroDotD == 0);
            }

            {
                var v = new ClassProperty();
                TestHelper.Assert(!v.BoolFalse);
                TestHelper.Assert(v.BoolTrue);
                TestHelper.Assert(v.B == 1);
                TestHelper.Assert(v.S == 2);
                TestHelper.Assert(v.I == 3);
                TestHelper.Assert(v.L == 4);
                TestHelper.Assert(v.F == 5.1F);
                TestHelper.Assert(v.D == 6.2);
                TestHelper.Assert(v.Str.Equals("foo bar"));
                TestHelper.Assert(v.NoDefault == null);
                TestHelper.Assert(v.ZeroI == 0);
                TestHelper.Assert(v.ZeroL == 0);
                TestHelper.Assert(v.ZeroF == 0);
                TestHelper.Assert(v.ZeroDotF == 0);
                TestHelper.Assert(v.ZeroD == 0);
                TestHelper.Assert(v.ZeroDotD == 0);
            }

            {
                var v = new ExceptionProperty();
                TestHelper.Assert(!v.BoolFalse);
                TestHelper.Assert(v.BoolTrue);
                TestHelper.Assert(v.B == 1);
                TestHelper.Assert(v.S == 2);
                TestHelper.Assert(v.I == 3);
                TestHelper.Assert(v.L == 4);
                TestHelper.Assert(v.F == 5.1F);
                TestHelper.Assert(v.D == 6.2);
                TestHelper.Assert(v.Str.Equals("foo bar"));
                TestHelper.Assert(v.NoDefault == null);
                TestHelper.Assert(v.ZeroI == 0);
                TestHelper.Assert(v.ZeroL == 0);
                TestHelper.Assert(v.ZeroF == 0);
                TestHelper.Assert(v.ZeroDotF == 0);
                TestHelper.Assert(v.ZeroD == 0);
                TestHelper.Assert(v.ZeroDotD == 0);
            }

            output.WriteLine("ok");
        }
Esempio n. 4
0
        /// <summary>
        /// This method submits the transaction
        /// to the PayPal Payment Gateway.
        /// The response is obtained from the gateway
        /// and response object is populated with the
        /// response values along with the sdk specific
        /// errors in context, if any.
        /// </summary>
        /// <returns>Returns response object for Strong assembly transactions</returns>
        /// <example>
        /// <code lang="C#" escaped="false">
        ///		............
        ///		//Trans is the transaction object.
        ///		............
        ///
        ///		//Submit the transaction.
        ///		Trans.SubmitTransaction();
        ///
        ///		// Get the Response.
        ///		Response Resp = Trans.Response;
        ///		if (Resp != null)
        ///		{
        ///			// Get the Transaction Response parameters.
        ///			TransactionResponse TrxnResponse =  Resp.TransactionResponse;
        ///			if (TrxnResponse != null)
        ///			{
        ///				Console.WriteLine("RESULT = " + TrxnResponse.Result);
        ///				Console.WriteLine("PNREF = " + TrxnResponse.Pnref);
        ///				Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg);
        ///				Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode);
        ///				Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr);
        ///				Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip);
        ///				Console.WriteLine("IAVS = " + TrxnResponse.IAVS);
        ///			}
        ///			// Get the Fraud Response parameters.
        ///			FraudResponse FraudResp =  Resp.FraudResponse;
        ///			if (FraudResp != null)
        ///			{
        ///				Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg);
        ///				Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg);
        ///			}
        ///		}
        ///		// Get the Context and check for any contained SDK specific errors.
        ///		Context Ctx = Resp.TransactionContext;
        ///		if (Ctx != null &amp;&amp; Ctx.getErrorCount() > 0)
        ///		{
        ///			Console.WriteLine(Environment.NewLine + "Errors = " + Ctx.ToString());
        ///		}
        ///</code>
        /// <code lang="Visual Basic" escaped="false">
        ///		............
        ///		'Trans is the transaction object.
        ///		............
        ///		' Submit the transaction.
        ///		Trans.SubmitTransaction()
        ///
        ///		' Get the Response.
        ///		Dim Resp As Response = Trans.Response
        ///
        ///		If Not Resp Is Nothing Then
        ///		' Get the Transaction Response parameters.
        ///
        ///			Dim TrxnResponse As TransactionResponse = Resp.TransactionResponse
        ///
        ///			If Not TrxnResponse Is Nothing Then
        ///				Console.WriteLine("RESULT = " + TrxnResponse.Result)
        ///				Console.WriteLine("PNREF = " + TrxnResponse.Pnref)
        ///				Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg)
        ///				Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode)
        ///				Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr)
        ///				Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip)
        ///				Console.WriteLine("IAVS = " + TrxnResponse.IAVS)
        ///			End If
        ///
        ///			' Get the Fraud Response parameters.
        ///			Dim FraudResp As FraudResponse = Resp.FraudResponse
        ///			If Not FraudResp Is Nothing Then
        ///				Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg)
        ///				Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg)
        ///			End If
        ///		End If
        ///
        ///		' Get the Context and check for any contained SDK specific errors.
        ///		Dim Ctx As Context = Resp.TransactionContext
        ///
        ///		If Not Ctx Is Nothing AndAlso Ctx.getErrorCount() > 0 Then
        ///			Console.WriteLine(Constants.vbLf + "Errors = " + Ctx.ToString())
        ///		End If
        /// </code>
        /// </example>
        public virtual Response SubmitTransaction()
        {
            PayflowNETAPI PfProNetApi   = null;
            String        ResponseValue = null;
            bool          Fatal         = false;

            Logger.Instance.Log("##### BEGIN TRANSACTION ##### -- " + mRequestId, PayflowConstants.SEVERITY_INFO);
            Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Entered", PayflowConstants.SEVERITY_DEBUG);
            try
            {
                if (mClientInfo == null)
                {
                    mClientInfo = new ClientInfo();
                }
                //Check for the errors in the context now.
                ArrayList Errors = PayflowUtility.AlignContext(mContext, false);
                mContext.LoadLoggerErrs = false;
                mContext.ClearErrors();
                mContext.AddErrors(Errors);

                if (mContext.HighestErrorLvl
                    == PayflowConstants.SEVERITY_FATAL)
                {
                    Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SEVERITY_DEBUG);
                    Fatal = true;
                }
                if (!Fatal)
                {
                    GenerateRequest();

                    mRequest = RequestBuffer.ToString();


                    //Remove the trailing PayflowConstants.DELIMITER_NVP;
                    int ParmListLen = mRequest.Length;
                    if (ParmListLen > 0 && mRequest[ParmListLen - 1] == '&')
                    {
                        mRequest = mRequest.Substring(0, ParmListLen - 1);
                    }


                    //Call the api from here and submit transaction

                    if (mPayflowConnectionData != null)
                    {
                        PfProNetApi = new PayflowNETAPI(mPayflowConnectionData.HostAddress,
                                                        mPayflowConnectionData.HostPort,
                                                        mPayflowConnectionData.TimeOut,
                                                        mPayflowConnectionData.ProxyAddress,
                                                        mPayflowConnectionData.ProxyPort,
                                                        mPayflowConnectionData.ProxyLogon,
                                                        mPayflowConnectionData.ProxyPassword);
                    }
                    else
                    {
                        PfProNetApi = new PayflowNETAPI();
                    }

                    PfProNetApi.IsStrongAssemblyTransaction = true;
                    PfProNetApi.ClientInfo = mClientInfo;
                    ResponseValue          = PfProNetApi.SubmitTransaction(mRequest, mRequestId);

                    Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SEVERITY_DEBUG);
                    Logger.Instance.Log("##### END TRANSACTION ##### -- " + mRequestId, PayflowConstants.SEVERITY_INFO);
                }
            }
            catch (BaseException BaseEx)
            {
                ErrorObject Error = BaseEx.GetFirstErrorInExceptionContext();
                //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_FATAL,false, null);
                mContext.AddError(Error);
            }
            catch (Exception Ex)
            {
                TransactionException TransEx = new TransactionException(Ex);
                ErrorObject          Error   = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, TransEx, PayflowConstants.SEVERITY_FATAL, false, null);
                mContext.AddError(Error);
            }
            finally
            {
                if (PfProNetApi != null)
                {
                    mRequest = PfProNetApi.TransactionRequest;
                    mContext.AddErrors(PfProNetApi.TransactionContext.GetErrors());
                    mRequestId  = PfProNetApi.RequestId;
                    mClientInfo = PfProNetApi.ClientInfo;
                }
                else
                {
                    //There is some error due to which the return
                    //is called even before pfpronetapi object is
                    //created.
                    //Check the first fatal error in context and
                    //put its response value to string.
                    if (mRequest != null && mRequest.Length > 0)
                    {
                        mRequest = PayflowUtility.MaskSensitiveFields(mRequest);
                    }
                    ArrayList   ErrorList       = mContext.GetErrors(PayflowConstants.SEVERITY_FATAL);
                    ErrorObject FirstFatalError = (ErrorObject)ErrorList[0];
                    ResponseValue = FirstFatalError.ToString();
                }

                mResponse = new Response(mRequestId, mContext);
                mResponse.setRequestString(mRequest);
                mResponse.SetParams(ResponseValue);


                //Log the context
                if (mContext.IsErrorContained())
                {
                    mContext.LogErrors();
                }
                PfProNetApi = null;
            }
            return(mResponse);
        }
Esempio n. 5
0
        public static void allTests(TestHelper helper)
        {
            TextWriter output = helper.GetWriter();

            output.Write("testing default values... ");
            output.Flush();

            {
                var v = new Base();
                TestHelper.Assert(!v.boolFalse);
                TestHelper.Assert(v.boolTrue);
                TestHelper.Assert(v.b == 1);
                TestHelper.Assert(v.s == 2);
                TestHelper.Assert(v.i == 3);
                TestHelper.Assert(v.l == 4);
                TestHelper.Assert(v.f == 5.1F);
                TestHelper.Assert(v.d == 6.2);
                TestHelper.Assert(v.str.Equals("foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007"));
                TestHelper.Assert(v.noDefault == null);
                TestHelper.Assert(v.zeroI == 0);
                TestHelper.Assert(v.zeroL == 0);
                TestHelper.Assert(v.zeroF == 0);
                TestHelper.Assert(v.zeroDotF == 0);
                TestHelper.Assert(v.zeroD == 0);
                TestHelper.Assert(v.zeroDotD == 0);
            }

            {
                var v = new Derived();
                TestHelper.Assert(!v.boolFalse);
                TestHelper.Assert(v.boolTrue);
                TestHelper.Assert(v.b == 1);
                TestHelper.Assert(v.s == 2);
                TestHelper.Assert(v.i == 3);
                TestHelper.Assert(v.l == 4);
                TestHelper.Assert(v.f == 5.1F);
                TestHelper.Assert(v.d == 6.2);
                TestHelper.Assert(v.str.Equals("foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007"));
                TestHelper.Assert(v.c1 == Color.red);
                TestHelper.Assert(v.c2 == Color.green);
                TestHelper.Assert(v.c3 == Color.blue);
                TestHelper.Assert(v.nc1 == Nested.Color.red);
                TestHelper.Assert(v.nc2 == Nested.Color.green);
                TestHelper.Assert(v.nc3 == Nested.Color.blue);
                TestHelper.Assert(v.noDefault == null);
                TestHelper.Assert(v.zeroI == 0);
                TestHelper.Assert(v.zeroL == 0);
                TestHelper.Assert(v.zeroF == 0);
                TestHelper.Assert(v.zeroDotF == 0);
                TestHelper.Assert(v.zeroD == 0);
                TestHelper.Assert(v.zeroDotD == 0);
            }

            {
                var v = new BaseEx();
                TestHelper.Assert(!v.boolFalse);
                TestHelper.Assert(v.boolTrue);
                TestHelper.Assert(v.b == 1);
                TestHelper.Assert(v.s == 2);
                TestHelper.Assert(v.i == 3);
                TestHelper.Assert(v.l == 4);
                TestHelper.Assert(v.f == 5.1F);
                TestHelper.Assert(v.d == 6.2);
                TestHelper.Assert(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007");
                TestHelper.Assert(v.noDefault == null);
                TestHelper.Assert(v.zeroI == 0);
                TestHelper.Assert(v.zeroL == 0);
                TestHelper.Assert(v.zeroF == 0);
                TestHelper.Assert(v.zeroDotF == 0);
                TestHelper.Assert(v.zeroD == 0);
                TestHelper.Assert(v.zeroDotD == 0);
            }

            {
                var v = new DerivedEx();
                TestHelper.Assert(!v.boolFalse);
                TestHelper.Assert(v.boolTrue);
                TestHelper.Assert(v.b == 1);
                TestHelper.Assert(v.s == 2);
                TestHelper.Assert(v.i == 3);
                TestHelper.Assert(v.l == 4);
                TestHelper.Assert(v.f == 5.1F);
                TestHelper.Assert(v.d == 6.2);
                TestHelper.Assert(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b? \u0007 \u0007");
                TestHelper.Assert(v.noDefault == null);
                TestHelper.Assert(v.c1 == Color.red);
                TestHelper.Assert(v.c2 == Color.green);
                TestHelper.Assert(v.c3 == Color.blue);
                TestHelper.Assert(v.nc1 == Nested.Color.red);
                TestHelper.Assert(v.nc2 == Nested.Color.green);
                TestHelper.Assert(v.nc3 == Nested.Color.blue);
                TestHelper.Assert(v.zeroI == 0);
                TestHelper.Assert(v.zeroL == 0);
                TestHelper.Assert(v.zeroF == 0);
                TestHelper.Assert(v.zeroDotF == 0);
                TestHelper.Assert(v.zeroD == 0);
                TestHelper.Assert(v.zeroDotD == 0);
            }

            {
                var v = new ClassProperty();
                TestHelper.Assert(!v.boolFalse);
                TestHelper.Assert(v.boolTrue);
                TestHelper.Assert(v.b == 1);
                TestHelper.Assert(v.s == 2);
                TestHelper.Assert(v.i == 3);
                TestHelper.Assert(v.l == 4);
                TestHelper.Assert(v.f == 5.1F);
                TestHelper.Assert(v.d == 6.2);
                TestHelper.Assert(v.str.Equals("foo bar"));
                TestHelper.Assert(v.noDefault == null);
                TestHelper.Assert(v.zeroI == 0);
                TestHelper.Assert(v.zeroL == 0);
                TestHelper.Assert(v.zeroF == 0);
                TestHelper.Assert(v.zeroDotF == 0);
                TestHelper.Assert(v.zeroD == 0);
                TestHelper.Assert(v.zeroDotD == 0);
            }

            {
                var v = new ExceptionProperty();
                TestHelper.Assert(!v.boolFalse);
                TestHelper.Assert(v.boolTrue);
                TestHelper.Assert(v.b == 1);
                TestHelper.Assert(v.s == 2);
                TestHelper.Assert(v.i == 3);
                TestHelper.Assert(v.l == 4);
                TestHelper.Assert(v.f == 5.1F);
                TestHelper.Assert(v.d == 6.2);
                TestHelper.Assert(v.str.Equals("foo bar"));
                TestHelper.Assert(v.noDefault == null);
                TestHelper.Assert(v.zeroI == 0);
                TestHelper.Assert(v.zeroL == 0);
                TestHelper.Assert(v.zeroF == 0);
                TestHelper.Assert(v.zeroDotF == 0);
                TestHelper.Assert(v.zeroD == 0);
                TestHelper.Assert(v.zeroDotD == 0);
            }

            output.WriteLine("ok");
        }
Esempio n. 6
0
 /// <summary>
 /// Sets the response params
 /// </summary>
 /// <param name="Response">Response string</param>
 internal void SetParams(String Response)
 {
     try
     {
         mResponseString = Response;
         if (Response != null)
         {
             int ResultIndex = Response.IndexOf(PayflowConstants.PARAM_RESULT);
             if (ResultIndex >= 0)
             {
                 if (ResultIndex > 0)
                 {
                     Response = Response.Substring(ResultIndex);
                 }
                 ParseResponse(Response);
                 SetResultParams(ref mResponseHashTable);
                 SetFraudResultParams(ref mResponseHashTable);
                 SetBuyerAuthResultParams(ref mResponseHashTable);
                 String TrxType = PayflowUtility.LocateValueForName(RequestString,
                                                                    PayflowConstants.PARAM_TRXTYPE, false);
                 if (String.Equals(TrxType, PayflowConstants.TRXTYPE_RECURRING))
                 {
                     SetRecurringResultParams(ref mResponseHashTable);
                 }
                 else
                 {
                     SetExpressCheckoutDOResultParams(ref mResponseHashTable);
                     SetExpressCheckoutGETResultParams(ref mResponseHashTable);
                     SetExpressCheckoutSETResultParams(ref mResponseHashTable);
                     SetExpressCheckoutUPDATEResultParams(ref mResponseHashTable);
                 }
                 mResponseHashTable.Remove(PayflowConstants.INTL_PARAM_FULLRESPONSE);
                 SetExtDataList();
                 mResponseHashTable = null;
             }
             else
             {
                 //Append the RESULT and RESPMSG for error code
                 //E_UNKNOWN_STATE and create a message.
                 //Call SetParams again on it.
                 String ResponseValue = PayflowConstants.PARAM_RESULT
                                        + PayflowConstants.SEPARATOR_NVP
                                        + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_UNKNOWN_STATE]
                                        + PayflowConstants.DELIMITER_NVP
                                        + PayflowConstants.PARAM_RESPMSG
                                        + PayflowConstants.SEPARATOR_NVP
                                        + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_UNKNOWN_STATE]
                                        + ", " + mResponseString;
                 this.SetParams(ResponseValue);
             }
         }
         else
         {
             String      AddlMessage = "Empty response";
             ErrorObject Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_EMPTY_PARAM_LIST, null, PayflowConstants.SEVERITY_WARN, false, AddlMessage);
             mContext.AddError(Err);
             Err = mContext.GetError(mContext.getErrorCount() - 1);
             String ResponseValue = Err.ToString();
             this.SetParams(ResponseValue);
         }
     }
     catch (BaseException BaseEx)
     {
         //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_ERROR,false, null);
         ErrorObject Error = BaseEx.GetFirstErrorInExceptionContext();
         mContext.AddError(Error);
         String ResponseValue = Error.ToString();
         this.SetParams(ResponseValue);
     }
     catch (Exception Ex)
     {
         DataObjectException DEx   = new DataObjectException(Ex);
         ErrorObject         Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, DEx, PayflowConstants.SEVERITY_ERROR, false, null);
         mContext.AddError(Error);
         String ResponseValue = Error.ToString();
         this.SetParams(ResponseValue);
     }
     //catch
     //{
     //    ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,null,PayflowConstants.SEVERITY_ERROR,false,null);
     //    mContext.AddError(Error);
     //    String ResponseValue = Error.ToString();
     //    this.SetParams(ResponseValue);
     //}
 }