Ejemplo n.º 1
0
        private int HandleInput()
        {
            int  ret     = 0;
            bool success = false;

            while (success == false)
            {
                var result = Console.ReadLine();
                ValidResponse.ForEach(x =>
                {
                    if (x == result)
                    {
                        ret     = Convert.ToInt16(x);
                        success = true;
                    }
                    ;
                });
                if (!success)
                {
                    Console.Clear();
                    Console.WriteLine("Invalid Entry.  Please try again.");
                    ScreeensController.Redo();
                    Display();
                }
            }
            return(ret);
        }
Ejemplo n.º 2
0
        public void ShouldRunFirstValidInput()
        {
            //Arrange
            FakeRegexBookEnd fakeRegexBookEnd = new FakeRegexBookEnd.Builder().IsMatch(Bool.True).Build();
            FakeWriter       fakeWriter       = new FakeWriter();
            FakeReader       fakeReader       = new FakeReader("A", "B", "C");
            FakeValidInputResponseAction <string> fakeValidInputResponseAction = new FakeValidInputResponseAction <string> .Builder().Response("A").Build();

            ValidResponse <string> subject = new ValidResponse <string>(fakeRegexBookEnd, new[] { "", "", "" }, fakeValidInputResponseAction, fakeWriter, fakeReader);

            //Act
            string input = subject.Response();

            //Assert
            fakeRegexBookEnd.AssertIsMatchInvokedCountMatches(1);
            fakeValidInputResponseAction.AssertResponseInvokedWith("A");
        }
Ejemplo n.º 3
0
        public async override Task <WeiXinResponse> ExecuteAsync()
        {
            ValidResponse response = new ValidResponse(WeiXin);
            await Task.Run(() =>
            {
                ValidRequest request = new ValidRequest(WeiXin);
                List <string> list   = new List <string>()
                {
                    _weixinSettings.ValidToken, request.Timestamp, request.Nonce
                };
                list.Sort();

                string validCode = string.Join("", list.ToArray()).SHA1Encrypt();
                if (validCode == request.Signature)
                {
                    response.EchoStr = request.EchoStr;
                }
            });

            return(response);
        }
Ejemplo n.º 4
0
        public static bool PayPalProcess(PaymentLibrary.PayPal.PayPalResponse paypalResponse)
        {
            ExcellentMarketResearchEntities db = new ExcellentMarketResearchEntities();

            if (paypalResponse != null && (!string.IsNullOrEmpty(paypalResponse.PAYERID) || !string.IsNullOrEmpty(paypalResponse.guid)))
            {
                BuyingInfo b = new BuyingInfo();

                if (string.IsNullOrEmpty(paypalResponse.PAYERID))
                {
                    log4net.LogManager.GetLogger("Error").Error("PayerID not found OR Response is null OR guid is not found.\nData - " + Newtonsoft.Json.JsonConvert.SerializeObject(paypalResponse));
                }

                //TODO: Get buyer from table using guid

                var buyer = GetBuyerByGuId(paypalResponse.guid);

                //bool IsBuyerExist= buyer.Count(x=>x.GuId==paypalResponse.guid)>0?true:false;
                bool IsBuyerExist = buyer != null ? true : false;

                //TODO: Check buyer if exist or not
                if (IsBuyerExist == null)
                {
                    // log4net.logmanager.getlogger("error").error("buyer not found.\ndata - " + newtonsoft.json.jsonconvert.serializeobject(paypalresponse));
                    return(false);
                }


                ValidResponse vResponse = PaymentLibrary.PayPal.PayPal.IsPaymentValid(paypalResponse,
                                                                                      PayPalConfig.GetConfiguration(HttpContext.Current.Server.MapPath("/paypalconfig/paypal.config"), false), false);

                if (vResponse.IsValid)
                {
                    //TODO: update status of payment transaction to success

                    var updatestatus = db.BuyingInfoes.Where(x => x.GuId == paypalResponse.guid).FirstOrDefault();
                    b.PaymentTransaction            = true;
                    updatestatus.PaymentTransaction = b.PaymentTransaction;
                    db.Entry(updatestatus).State    = EntityState.Modified;
                    db.SaveChanges();
                    return(true);
                }
                Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                Stream     s = new MemoryStream();
                TextWriter t = new StreamWriter(s);

                serializer.Serialize(t, paypalResponse);
                TextReader r = new StreamReader(s);

                //TODO: Save error to db

                //_saveStatus(, 'f', vResponse.Reason + "|ErrorCode - " + vResponse.ErrorCode + "|PaypalResponse - " + r.ReadToEnd());

                var saveError = db.BuyingInfoes.Where(x => x.GuId == paypalResponse.guid).FirstOrDefault();
                b.PaymentTransaction         = false;
                saveError.PaymentTransaction = b.PaymentTransaction;
                saveError.ErrorReason        = vResponse.Reason;
                saveError.ErrorCode          = vResponse.ErrorCode;
                db.Entry(saveError).State    = EntityState.Modified;
                db.SaveChanges();

                return(false);
            }
            return(false);
        }