当前位置: 首页>>代码示例>>C#>>正文


C# Mock.SetupSet方法代码示例

本文整理汇总了C#中Mock.SetupSet方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetupSet方法的具体用法?C# Mock.SetupSet怎么用?C# Mock.SetupSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.SetupSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: post_CallsPopulateRequestParameters

        public void post_CallsPopulateRequestParameters()
        {
            // Arrange
            var testBundle = new AddImageRequestTestBundle();
            var mockWebRequest = new Mock<IWebRequest>(MockBehavior.Strict);
            var mockLog = new Mock<ILog>();

            testBundle.MockLogProvider.Setup(x => x.GetLogger(It.IsAny<Type>())).Returns(mockLog.Object);
            testBundle.AddImageRequest.FileBytes = new byte[] {1, 2, 3};
            testBundle.AddImageRequest.FileName = "Test.foo";
            testBundle.AddImageRequest.RequestUrl = "http://google.com/";

            mockWebRequest.SetupSet(x => x.Method = "POST");
            mockWebRequest.SetupSet(x => x.ContentType = "application/x-www-form-urlencoded");
            mockWebRequest.SetupSet(x => x.ContentLength = 30);
            mockWebRequest.SetupGet(x => x.Headers).Returns(new WebHeaderCollection());
            mockWebRequest.Setup(x => x.GetRequestStream()).Returns(new MemoryStream());
            mockWebRequest.Setup(x => x.GetResponse()).Returns(new Mock<IHttpWebResponse>().Object);
            testBundle.MockWebRequestFactory.Setup(x => x.Create(It.IsAny<string>())).Returns(mockWebRequest.Object);
            // WebRequestFactory.AddWebRequestMock(mockWebRequest.Object);

            // Act
            testBundle.AddImageRequest.Post();

            // Assert
            Assert.AreEqual("http://google.com/image", testBundle.AddImageRequest.RequestUrl);
        }
开发者ID:MadDonkeySoftware,项目名称:DonkeySuite,代码行数:27,代码来源:AddImageRequestTest.cs

示例2: ExecuteResult

        public void ExecuteResult()
        {
            // Arrange
            string content = "Some content.";
            string contentType = "Some content type.";
            Encoding contentEncoding = Encoding.UTF8;

            // Arrange expectations
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
            mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentType = contentType).Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentEncoding = contentEncoding).Verifiable();
            mockControllerContext.Setup(c => c.HttpContext.Response.Write(content)).Verifiable();

            ContentResult result = new ContentResult
            {
                Content = content,
                ContentType = contentType,
                ContentEncoding = contentEncoding
            };

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:26,代码来源:ContentResultTest.cs

示例3: op_ExecuteResult_ControllerContext

        public void op_ExecuteResult_ControllerContext()
        {
            var response = new Mock<HttpResponseBase>(MockBehavior.Strict);
            response
                .SetupSet(x => x.ContentEncoding = Encoding.UTF8)
                .Verifiable();
            response
                .SetupSet(x => x.ContentType = "application/xml")
                .Verifiable();
            response
                .Setup(x => x.Write(It.IsAny<string>()))
                .Verifiable();

            var context = new Mock<HttpContextBase>(MockBehavior.Strict);
            context
                .SetupGet(x => x.Response)
                .Returns(response.Object)
                .Verifiable();

            new XmlSerializationResult(123).ExecuteResult(new ControllerContext
                                                              {
                                                                  HttpContext = context.Object
                                                              });

            response.VerifyAll();
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:26,代码来源:XmlSerializationResult.Facts.cs

示例4: Should_be_able_prepare_a_query

        public void Should_be_able_prepare_a_query()
        {
            const string sql = "select @Id";

            var guid = Guid.NewGuid();
            var mc = new MappedColumn<Guid>("Id", DbType.Guid);
            var query = new RawQuery(sql).AddParameterValue(mc, guid);
            var dataParameterCollection = new Mock<IDataParameterCollection>();
            var dataParameterFactory = new Mock<IDbDataParameterFactory>();

            dataParameterFactory.Setup(m => m.Create("@Id", DbType.Guid, guid));

            var dataSource = new DataSource("data-source", dataParameterFactory.Object);

            var command = new Mock<IDbCommand>();

            dataParameterCollection.Setup(m => m.Add(It.IsAny<IDbDataParameter>())).Verifiable();

            command.SetupGet(m => m.Parameters).Returns(dataParameterCollection.Object);
            command.SetupSet(m => m.CommandText = sql).Verifiable();
            command.SetupSet(m => m.CommandType = CommandType.Text).Verifiable();

            query.Prepare(dataSource, command.Object);

            command.VerifyAll();
            dataParameterFactory.VerifyAll();
        }
开发者ID:ltvan,项目名称:shuttle-core-data,代码行数:27,代码来源:RawQueryTests.cs

示例5: op_ExecuteResult_ControllerContext

        public void op_ExecuteResult_ControllerContext()
        {
            var response = new Mock<HttpResponseBase>(MockBehavior.Strict);
            response
                .SetupSet(x => x.ContentEncoding = Encoding.UTF8)
                .Verifiable();
            response
                .SetupSet(x => x.ContentType = "text/plain")
                .Verifiable();
            response
                .Setup(x => x.Write(It.IsAny<string>()))
                .Verifiable();

            var context = new Mock<HttpContextBase>(MockBehavior.Strict);
            context
                .Setup(x => x.Response)
                .Returns(response.Object)
                .Verifiable();

            new TextResult("test").ExecuteResult(new ControllerContext
                                                     {
                                                         HttpContext = context.Object
                                                     });

            context.VerifyAll();
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:26,代码来源:TextResult.Facts.cs

示例6: op_OnActionExecuting_FilterExecutedContext

        public void op_OnActionExecuting_FilterExecutedContext()
        {
            var context = new Mock<HttpContextBase>(MockBehavior.Strict);
            context
                .SetupSet(x => x.Response.BufferOutput = true)
                .Verifiable();
            context
                .SetupSet(x => x.Response.Filter = It.IsAny<WrappedStream>())
                .Verifiable();

            using (var stream = new MemoryStream())
            {
                context
                    .SetupGet(x => x.Response.Filter)
                    .Returns(stream)
                    .Verifiable();

                new ContentMD5Attribute().OnActionExecuting(new ActionExecutingContext
                                                                {
                                                                    HttpContext = context.Object
                                                                });
            }

            context.VerifyAll();
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:25,代码来源:ContentMD5Attribute.Facts.cs

示例7: ExecuteResult

        public void ExecuteResult()
        {
            // Arrange
            object data = _jsonData;
            string contentType = "Some content type.";
            Encoding contentEncoding = Encoding.UTF8;

            // Arrange expectations
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
            mockControllerContext.SetupGet(c => c.HttpContext.Request.HttpMethod).Returns("POST").Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentType = contentType).Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentEncoding = contentEncoding).Verifiable();
            mockControllerContext.Setup(c => c.HttpContext.Response.Write(_jsonSerializedData)).Verifiable();

            JsonResult result = new JsonResult
            {
                Data = data,
                ContentType = contentType,
                ContentEncoding = contentEncoding
            };

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:27,代码来源:JsonResultTest.cs

示例8: ExecuteResultWithDescription

        public void ExecuteResultWithDescription() {
            // Arrange
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = 666).Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusDescription = "Foo Bar").Verifiable();
            HttpStatusCodeResult result = new HttpStatusCodeResult(666, "Foo Bar");

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:13,代码来源:HttpStatusCodeResultTest.cs

示例9: GetMockClient

        protected Mock<IRestClient> GetMockClient(string content)
        {
            var response = new Mock<IRestResponse>(MockBehavior.Strict);
            response.SetupGet(x => x.Content).Returns(content);
            response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com"));
            response.SetupGet(x => x.StatusDescription).Returns("");
            response.SetupGet(x => x.StatusCode).Returns(HttpStatusCode.OK);

            var client = new Mock<IRestClient>(MockBehavior.Strict);
            client.SetupSet(x => x.BaseUrl = It.IsAny<Uri>());
            client.SetupSet(x => x.Authenticator = It.IsAny<IAuthenticator>());
            client.Setup(x => x.Execute(It.IsAny<IRestRequest>())).Returns(response.Object);
            return client;
        }
开发者ID:maccca,项目名称:promisepay-dotnet,代码行数:14,代码来源:AbstractTest.cs

示例10: ExecuteResult

        public void ExecuteResult() {
            // Arrange
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = 401).Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusDescription = "Some description").Verifiable();

            HttpUnauthorizedResult result = new HttpUnauthorizedResult("Some description");

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:14,代码来源:HttpUnauthorizedResultTest.cs

示例11: AddingExceptionShouldStoreExceptionInLoggingEvent

        public void AddingExceptionShouldStoreExceptionInLoggingEvent()
        {
            var loggingEventMock = new Mock<LoggingEvent>();
            loggingEventMock.Object.Tags = new List<string>();

            var loggingEventBuilder = new LoggingEventBuilder(loggingEventMock.Object);

            loggingEventMock.SetupSet(x => x.Text = It.Is<string>(v => v == "exceptionmessage"));
            loggingEventMock.Setup(x => x.Tags.Add(It.Is<string>(v => v == "error")));
            loggingEventMock.SetupSet(x => x.Data["MS_Exception"] = It.IsAny<ExceptionInformation>());

            loggingEventBuilder.AddException(new Exception("exceptionmessage"));

            loggingEventMock.VerifyAll();
        }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:15,代码来源:LoggingEventBuilderTests.cs

示例12: SafeResetKeyBindings2

 public void SafeResetKeyBindings2()
 {
     var mock = new Mock<Command>(MockBehavior.Strict);
     mock.SetupSet(x => x.Bindings = It.IsAny<object>()).Throws(new COMException()).Verifiable();
     mock.Object.SafeResetBindings();
     mock.Verify();
 }
开发者ID:honeyhoneywell,项目名称:VsVim,代码行数:7,代码来源:ExtensionsTest.cs

示例13: GetRecommendations_PerformsCorrectRequest

        public void GetRecommendations_PerformsCorrectRequest()
        {
            //Setup
            UserReqStub request = new UserReqStub("ExternalID", "DevKey", "api.careerbuilder.com", "", "");

            //Mock crap
            RestResponse<List<RecommendJobResult>> response = new RestResponse<List<RecommendJobResult>>();
            response.Data = new List<RecommendJobResult>();
            
            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("ExternalID", "ExternalID"));
            restReq.SetupSet(x => x.RootElement = "RecommendJobResults");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/recommendations/foruser");
            restClient.Setup(x => x.Execute<List<RecommendJobResult>>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assert//
            List<RecommendJobResult> resp = request.GetRecommendations();
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:stevenwu2012,项目名称:Careerbuilder.com-API-for-.Net,代码行数:26,代码来源:UserRecommendationsRequestTest.cs

示例14: TestWritingResponse

        public void TestWritingResponse()
        {
            TokenResponse response = new TokenResponse
            {
                Body = "body",
                HttpStatusCode = 200
            };

            Mock<HttpResponseBase> mckResponse = new Mock<HttpResponseBase>();
            mckResponse.SetupSet(x => x.ContentType = "application/json");
            mckResponse.SetupSet(x => x.StatusCode = 200);
            mckResponse.Setup(x => x.Write("body"));
            TokenResponseWriter writer = new TokenResponseWriter(mckResponse.Object);
            writer.WriteResponse(response);
            mckResponse.VerifyAll();
        }
开发者ID:nicklv,项目名称:SharpOAuth2,代码行数:16,代码来源:TokenResponseWriterTests.cs

示例15: Search_PerformsCorrectRequest

        public void Search_PerformsCorrectRequest()
        {
            //Setup
            JobSearchStub request = new JobSearchStub("DevKey", "api.careerbuilder.com","","");
            
            //Mock crap
            RestResponse<ResponseJobSearch> response = new RestResponse<ResponseJobSearch>();
            response.Data = new ResponseJobSearch();
                        
            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("CountryCode", "NL"));
            restReq.SetupSet(x => x.RootElement = "ResponseJobSearch");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/jobsearch");
            restClient.Setup(x => x.Execute<ResponseJobSearch>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;
            
            //Assert
            ResponseJobSearch resp = request.WhereCountryCode(CountryCode.NL).Search();
            restReq.Verify();
            restClient.VerifyAll();
        }
开发者ID:stevenwu2012,项目名称:Careerbuilder.com-API-for-.Net,代码行数:26,代码来源:JobSearchRequestTest.cs


注:本文中的Mock.SetupSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。