public void handshake_should_create_request_to_paypal() { var url = "https://www.paypal.com/cgi-bin/webscr"; //mock the paypal response var mockPaypalResponse = new Mock<WebResponse>(); mockPaypalResponse.Expect(r => r.GetResponseStream()) .Returns(new MemoryStream()); //mock the request to paypal var mockPaypalRequest = new Mock<WebRequest>(); mockPaypalRequest.Expect(r => r.GetRequestStream()) .Returns(new MemoryStream()); mockPaypalRequest.Expect(r => r.GetResponse()) .Returns(mockPaypalResponse.Object); //mock the service helper var mockHelper = new Mock<IPayPalServiceHelper>(); mockHelper.Expect(h => h.CreateRequest(url)) .Returns(mockPaypalRequest.Object); var requestcontent = "five"; MyMocks.Request .Expect(r => r.ContentLength).Returns(requestcontent.Length); MyMocks.Request .Expect(r => r.BinaryRead(requestcontent.Length)) .Returns((new ASCIIEncoding()).GetBytes(requestcontent)); var service = new PayPalService(null, mockHelper.Object); service.PerformHandShake(MyMocks.Request.Object); //verify mocks long length = (requestcontent + "&cmd=_notify-validate").Length; mockPaypalRequest.VerifySet(r => r.Method, "POST"); mockPaypalRequest.VerifySet(r => r.ContentType, "application/x-www-form-urlencoded"); mockPaypalRequest.VerifySet(r => r.ContentLength, length); mockPaypalRequest.VerifyAll(); mockHelper.VerifyAll(); }