public void Setup()
		{
			IOC.UnitTest();
			_requestParameters = new NameValueCollection();
			_basketRequestHandler = new BasketRequestHandler();

			IOC.OrderUpdatingService.Mock(out _mock);
		}
		protected void Page_Load(object sender, EventArgs e)
		{
			//try
			//{	
				var redirectAfterHandle = new BasketRequestHandler().HandleBasketRequest(Request.Form, HttpContext.Current.Request.Url);
				if (redirectAfterHandle == null || !redirectAfterHandle.Any())
				{
					return;
				}

				string redirectUrl;
				var url = redirectAfterHandle.Last().Url;
				if (url == HttpContext.Current.Request.Url)
				{
					redirectUrl = HttpContext.Current.Request.RawUrl;
				}
				else
				{
					redirectUrl = url.AbsoluteUri;	
				}
				
				if ((Request.Form.AllKeys.Any() && (Request.Form.AllKeys.Any(x => x == "disableReload") || Request.Form.AllKeys.Any(x => x == "disableRedirect"))))
				{
					return;
				}

				var validateOrderReffererKey = Request.Form.AllKeys.FirstOrDefault(x => x.ToLower() == "backtoreferreronerror");
				if (validateOrderReffererKey != null && redirectAfterHandle.Any(x => x.Validated == false))
				{
					var validateOrderRefferer = Request.Form[validateOrderReffererKey];

					if ((validateOrderRefferer.ToLower() == "true" || validateOrderRefferer.ToLower() == "backtoreferreronerror" || validateOrderRefferer.ToLower() == "on" || validateOrderRefferer == "1") && HttpContext.Current.Request.UrlReferrer != null)
					{
						redirectUrl = redirectUrl.Replace(HttpContext.Current.Request.Url.AbsolutePath, HttpContext.Current.Request.UrlReferrer.AbsolutePath);
					}
				}

				Response.Redirect(redirectUrl, false);
				
			//}
			//catch (ThreadAbortException)
			//{
			//}
			////catch (Exception ex)
			//{
			//	//throw;
			//	//Log.Instance.LogError(ex, "Unhandled exception during execution of uWebshop basket handler");
			//}
		}
		public ActionResult Handle()
		{
			var refferer = HttpContext.Request.UrlReferrer;

			var redirectAfterHandle = new BasketRequestHandler().HandleBasketRequest(Request.Form, refferer);

			if (Request.UrlReferrer == null)
			{
				return CurrentUmbracoPage();
			}

			foreach (var result in redirectAfterHandle)
			{
				Log.Instance.LogDebug("Handle Result: " + result.Action + "result.Success: " + result.Success + "result.Validated: " + result.Validated + "result.PostConfirmUrl: " + result.PostConfirmUrl);
			}
			
			var redirectUrl = HttpContext.Request.RawUrl;

			var postConfirmUrlHandler = redirectAfterHandle.LastOrDefault(x => x.PostConfirmUrl != null);

			if (postConfirmUrlHandler != null)
			{
				var postConfirmUrl = postConfirmUrlHandler.PostConfirmUrl;

				if (postConfirmUrl != null)
				{
					redirectUrl = postConfirmUrl.AbsoluteUri;
				}
			}

			var validateOrderReffererKey = Request.Form.AllKeys.FirstOrDefault(x => x.ToLower() == "backtoreferreronerror");
			if (validateOrderReffererKey != null && redirectAfterHandle.Any(x => x.Validated == false))
			{
				var validateOrderRefferer = Request.Form[validateOrderReffererKey];

				if ((validateOrderRefferer.ToLower() == "true" || validateOrderRefferer.ToLower() == "backtoreferreronerror" || validateOrderRefferer.ToLower() == "on" || validateOrderRefferer == "1") && HttpContext.Request.UrlReferrer != null)
				{
					redirectUrl = HttpContext.Request.UrlReferrer.AbsolutePath;
				}
			}

			Log.Instance.LogDebug("Handle Result redirectUrl: " + redirectUrl);

			return Redirect(redirectUrl);

		}
		public static void Handle()
		{
			var successFailed = new Dictionary<string, object>();

			try
			{
				

				var qs = HttpContext.Current.Request.QueryString[0];

				var dictionaryList = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(qs);

				var nameValue = new NameValueCollection();

				foreach (var item in dictionaryList)
				{
					nameValue.Add(item.First().Value, item.Last().Value);
				}

				var redirectAfterHandle = new BasketRequestHandler().HandleBasketRequest(nameValue, HttpContext.Current.Request.UrlReferrer);

				var lastItem = redirectAfterHandle.Last();

				if (!successFailed.ContainsKey(lastItem.Action))
				{
					successFailed.Add("success", redirectAfterHandle.All(x => x.Success));
					successFailed.Add("validated", redirectAfterHandle.All(x => x.Validated));

					var messageDictionary = new Dictionary<string, string>();

					foreach (var message in redirectAfterHandle.SelectMany(handleItem => handleItem.Messages.Where(message => !messageDictionary.ContainsKey(message.Key))))
					{
						messageDictionary.Add(message.Key, message.Value);
					}

					successFailed.Add("messages", messageDictionary);
					successFailed.Add("url", lastItem.Url);
					successFailed.Add("item", lastItem.Item);
				}
			}
			catch (Exception ex)
			{
				successFailed = new Dictionary<string, object>();

				var messages = new Dictionary<string, string> {{"exception", ex.ToString()}};
				
				successFailed.Add("success", false);
				successFailed.Add("validated", false);
				successFailed.Add("url", string.Empty);
				successFailed.Add("error", "something went wrong with the Handle method: ");
				successFailed.Add("messages", messages);
			}

			var serializeSettings = new JsonSerializerSettings()
									{
										ReferenceLoopHandling = ReferenceLoopHandling.Ignore, 
										Formatting = GlobalSettings.DebugMode ? Formatting.Indented : Formatting.None
									};

			var json = JsonConvert.SerializeObject(successFailed, Formatting.Indented, serializeSettings);
			HttpContext.Current.Response.ContentType = "application/json";
			HttpContext.Current.Response.Write(json);
		}