예제 #1
0
        public void TestThatServiceReturnsAForbiddenStatuscode()
        {
            // Use new IndirectionsContext() instead of ShimsContext.Create().
            using (new IndirectionsContext())
            {
                // Arrange
                // Use the indirection stub which has name starting with "PProxy" against one instance.
                var requestProxy = new PProxyHttpWebRequest();
                // The indirection stubs "PProxy..." have implicit operator same as Fakes, so you can write as follows:
                PWebRequest.CreateString().Body = uri => requestProxy;
                // Unlike Fakes, in Prig, "this" is implicitly passed as first parameter of the instance method.
                requestProxy.GetResponse().Body = this1 =>
                {
                    var responseProxy = new PProxyHttpWebResponse();
                    responseProxy.StatusCodeGet().Body = this2 => HttpStatusCode.Forbidden;
                    return(responseProxy);
                };
                // Unlike Fakes, Prig tries invoking the original method by default.
                // If you want to make stubs be do-nothing, change the default behavior as follows:
                requestProxy.ExcludeGeneric().DefaultBehavior = IndirectionBehaviors.DefaultValue;
                var client         = new WebServiceClient();
                var url            = "testService";
                var expectedResult = false;


                // Act
                bool actualresult = client.CallWebService(url);


                // Assert
                Assert.AreEqual(expectedResult, actualresult);
            }
        }