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


C# Mock.ExpectGet方法代码示例

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


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

示例1: Should_Show_Next_Unless_Offset_Plus_Limit_Gte_Count

 public void Should_Show_Next_Unless_Offset_Plus_Limit_Gte_Count()
 {
     var result = new Mock<IViewResult>();
     result.ExpectGet(x => x.OffSet).Returns(5);
     var options = new ViewOptions();
     options.Limit = 5;
     result.ExpectGet(x => x.TotalRows).Returns(10);
     var model = new PageableModel();
     model.UpdatePaging(options, result.Object);
     Assert.IsFalse(model.ShowNext);
 }
开发者ID:soitgoes,项目名称:LoveSeat,代码行数:11,代码来源:PagingHelperTest.cs

示例2: AuthHeaderWithMalformedHeader

        public void AuthHeaderWithMalformedHeader()
        {
            // given
            given_pipeline_contributor<AuthenticationContributor>();

            var mockScheme = new Mock<IAuthenticationScheme>();

            mockScheme.ExpectGet(s => s.Name).Returns("BASIC");

            mockScheme
                .Expect(s => s.Authenticate(It.IsAny<IRequest>()))
                .Returns(new AuthenticationResult.MalformedCredentials());

            given_dependency(mockScheme.Object);

            Context.Request.Headers.Add("Authorization", "BASIC anythinghere");

            // when
            var result = when_sending_notification<KnownStages.IHandlerSelection>();

            // then
            Context.Response.Headers["Warning"].ShouldBe("Malformed credentials");
            Context.OperationResult.ShouldBeOfType<OperationResult.BadRequest>();
            result.ShouldBe(PipelineContinuation.RenderNow);
        }
开发者ID:rokite,项目名称:openrasta-stable,代码行数:25,代码来源:Authentication_Specification.cs

示例3: ShouldAddClaimSet

        public void ShouldAddClaimSet()
        {
            var principal = new GenericPrincipal(new GenericIdentity("foo"), null);
            var httpContext = new HttpContext(
                new HttpRequest("foo", "http://foo", ""),
                new HttpResponse(Console.Out));
            HttpContext.Current = httpContext;
            httpContext.User = principal;

            object state = null;
            HttpContextIdentityPolicy policy = new HttpContextIdentityPolicy();

            var evaluationContextMock = new Mock<EvaluationContext>();

            var properties = new Dictionary<string, object>();

            evaluationContextMock
                .ExpectGet(ec => ec.Properties)
                .Returns(properties);

            evaluationContextMock.Expect(ec => ec.AddClaimSet(policy, It.IsAny<ClaimSet>())).Verifiable();

            policy.Evaluate(evaluationContextMock.Object, ref state);

            evaluationContextMock.Verify();
        }
开发者ID:thaneswarreddy,项目名称:netfx,代码行数:26,代码来源:HttpContextIdentityPolicyFixture.cs

示例4: 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.ExpectGet(c => c.HttpContext.Request.HttpMethod).Returns("POST").Verifiable();
            mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, contentType).Verifiable();
            mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentEncoding, contentEncoding).Verifiable();
            mockControllerContext.Expect(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:pruiz,项目名称:AspMvc2,代码行数:25,代码来源:JsonResultTest.cs

示例5: Should_Show_Previous_If_OffSet_Not_Equal_Zero

 public void Should_Show_Previous_If_OffSet_Not_Equal_Zero()
 {
     var result = new Mock<IViewResult>();
     result.ExpectGet(x => x.OffSet).Returns(1);
     var options = new ViewOptions();
     var model = new PageableModel();
     model.UpdatePaging(options, result.Object);
      Assert.IsTrue(model.ShowPrev);
 }
开发者ID:soitgoes,项目名称:LoveSeat,代码行数:9,代码来源:PagingHelperTest.cs

示例6: Should_Skip_1_On_Next_Url_When_Offset_is_Not_Zero

 public void Should_Skip_1_On_Next_Url_When_Offset_is_Not_Zero()
 {
     var result = new Mock<IViewResult>();
     result.ExpectGet(x => x.OffSet).Returns(1);
     var options = new ViewOptions();
     var model = new PageableModel();
     model.UpdatePaging(options, result.Object);
     Assert.IsTrue(model.PrevUrlParameters.Contains("skip=1"));
     Assert.IsTrue(model.PrevUrlParameters.Contains("descending=true"));
 }
开发者ID:ahazelwood,项目名称:LoveSeat,代码行数:10,代码来源:PagingHelperTest.cs

示例7: SetUp

        public void SetUp() {
            var requestMock = new Mock<HttpRequestBase>();
            requestMock.ExpectGet(r => r.Path).Returns("basePath");
            
            var contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectGet(c => c.Request).Returns(requestMock.Object);

            gi = new TestGeneratedImage(contextMock.Object) {
                ImageHandlerUrl = "Handler.ashx"
            };
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:11,代码来源:GeneratedImageTest.cs

示例8: SetUp

        public void SetUp() {
            _imageStoreMock = new Mock<StubImageStore>();

            _now = DateTime.Now;
            _imageHandlerMock = new Mock<StubImageHandler>(_imageStoreMock.Object, _now);
            _imageHandler = _imageHandlerMock.Object;

            var requestMock = new Mock<HttpRequestBase>();
            requestMock.ExpectGet(r => r.QueryString).Returns(new NameValueCollection());

            _cachePolicyMock = new Mock<HttpCachePolicyBase>();

            _responseMock = new Mock<HttpResponseBase>();
            _responseMock.ExpectGet(r => r.Cache).Returns(_cachePolicyMock.Object);
            _responseMock.ExpectGet(r => r.OutputStream).Returns(new MemoryStream());

            _contextMock = new Mock<HttpContextBase>();
            _contextMock.ExpectGet(c => c.Request).Returns(requestMock.Object);
            _contextMock.ExpectGet(c => c.Response).Returns(_responseMock.Object);
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:20,代码来源:ImageHandlerTest.cs

示例9: CreateInterfaceMockTest

        public void CreateInterfaceMockTest()
        {
            var mock = new Mock<IMocked>();

            mock.ExpectCall(m => m.Method(2)).Returns("2").Once();
            mock.ExpectGet(m => m.Property).Gets(2).Never();
            mock.ExpectSet(m => m.Property).Sets(2).Never();

            var value = mock.Object.Method(2);

            mock.Verify();

            Assert.That(value, Is.EqualTo("2"));
        }
开发者ID:mtamme,项目名称:NFake,代码行数:14,代码来源:MockTestFixture.cs

示例10: BindModelReturnsEmptyResultIfEmptyFileInputElementInPost

        public void BindModelReturnsEmptyResultIfEmptyFileInputElementInPost() {
            // Arrange
            Mock<HttpPostedFileBase> mockFile = new Mock<HttpPostedFileBase>();
            mockFile.Expect(f => f.ContentLength).Returns(0);
            mockFile.Expect(f => f.FileName).Returns(String.Empty);
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.ExpectGet(c => c.HttpContext.Request.Files["fileName"]).Returns(mockFile.Object);

            HttpPostedFileBaseModelBinder binder = new HttpPostedFileBaseModelBinder();
            ModelBindingContext bindingContext = new ModelBindingContext() { ModelName = "fileName" };

            // Act
            object result = binder.BindModel(mockControllerContext.Object, bindingContext);

            // Assert
            Assert.IsNull(result);
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:17,代码来源:HttpPostedFileBaseModelBinderTest.cs

示例11: BindModelReturnsResultIfFileFound

        public void BindModelReturnsResultIfFileFound() {
            // Arrange
            Mock<HttpPostedFileBase> mockFile = new Mock<HttpPostedFileBase>();
            mockFile.Expect(f => f.ContentLength).Returns(1234);
            mockFile.Expect(f => f.FileName).Returns("somefile");
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.ExpectGet(c => c.HttpContext.Request.Files["fileName"]).Returns(mockFile.Object);

            HttpPostedFileBaseModelBinder binder = new HttpPostedFileBaseModelBinder();
            ModelBindingContext bindingContext = new ModelBindingContext() { ModelName = "fileName" };

            // Act
            object result = binder.BindModel(mockControllerContext.Object, bindingContext);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreSame(mockFile.Object, result, "Returned file did not match mock file.");
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:18,代码来源:HttpPostedFileBaseModelBinderTest.cs

示例12: CanQueryBySpecification

        public void CanQueryBySpecification()
        {
            const string DATA = "One";

            var moqSpecs = new Mock<SpecificationBase<FakeEntity>>();
            moqSpecs.ExpectGet(x => x.Predicate)
                .Returns(x => x.Data == DATA);

            SpecificationBase<FakeEntity> specs = moqSpecs.Object;

            IQueryable<FakeEntity> entities = FakeEntity.CreateFakeEntities();

            IQueryable<FakeEntity> entitiesWithDataOne = specs.Query(entities);

            Assert.GreaterThan(entitiesWithDataOne.Count(), 0);

            foreach (FakeEntity entity in entitiesWithDataOne)
            {
                Assert.AreEqual(DATA, entity.Data);
            }
        }
开发者ID:splotter,项目名称:Splotter-Common,代码行数:21,代码来源:SpecificationTest.cs

示例13: PrepareRequestTo

    public static void PrepareRequestTo(string controller, string action)
    {
      var routeHandler = new AsyncMvcRouteHandler();
      var httpContextBase = new Mock<HttpContextBase>();
      var sessionState = new Mock<HttpSessionStateBase>();
      var writer = new StringWriter();
      var controllerFactory = new Mock<IControllerFactory>();
      var request = new Mock<HttpRequestBase>();

      var routeData = new RouteData();
      routeData.Values["controller"] = controller;
      routeData.Values["action"] = action;

      httpContextBase.ExpectGet(x => x.Session).Returns(sessionState);
      httpContextBase.ExpectGet(x => x.Request).Returns(request);

      controllerFactory.Expect(x => x.CreateController(Arg.IsAny<RequestContext>(), controller)).Returns(new TestController());

      ControllerBuilder.Current.SetControllerFactory(controllerFactory.Object);

      httpContext = new HttpContext(new HttpRequest("foo", "http://foo", "foo"), new HttpResponse(writer));
      CallContext.HostContext = httpContext;

      var requestContext = new RequestContext(httpContextBase, routeData);

      httpHandler = (IHttpAsyncHandler)routeHandler.GetHttpHandler(requestContext);
    }
开发者ID:benlovell,项目名称:machine,代码行数:27,代码来源:AsyncControllerSpecs.cs

示例14: AuthHeaderWithValidCredentials

        public void AuthHeaderWithValidCredentials()
        {
            // given
            given_pipeline_contributor<AuthenticationContributor>();

            var mockScheme = new Mock<IAuthenticationScheme>();

            mockScheme.ExpectGet(s => s.Name).Returns("BASIC");

            var username = "someUsername";
            var roles = new[] { "role1", "role2" };

            mockScheme
                .Expect(s => s.Authenticate(It.IsAny<IRequest>()))
                .Returns(new AuthenticationResult.Success(username, roles));

            given_dependency(mockScheme.Object);

            Context.Request.Headers.Add("Authorization", "BASIC anythinghere");

            // when
            var result = when_sending_notification<KnownStages.IHandlerSelection>();

            // then
            result.ShouldBe(PipelineContinuation.Continue);

            Context.User.Identity.Name.ShouldBe(username);
            Context.User.IsInRole(roles[0]);
            Context.User.IsInRole(roles[1]);
        }
开发者ID:endjin,项目名称:openrasta-stable,代码行数:30,代码来源:Authentication_Specification.cs

示例15: ShouldSetIdentityProperty

        public void ShouldSetIdentityProperty()
        {
            var evaluationContextMock = new Mock<EvaluationContext>();

            var properties = new Dictionary<string, object>();

            evaluationContextMock
                .ExpectGet(ec => ec.Properties)
                .Returns(properties);

            var principal = new GenericPrincipal(new GenericIdentity("foo"), null);
            var httpContext = new HttpContext(
                new HttpRequest("foo", "http://foo", ""),
                new HttpResponse(Console.Out));
            HttpContext.Current = httpContext;
            httpContext.User = principal;

            object state = null;
            HttpContextIdentityPolicy policy = new HttpContextIdentityPolicy();

            policy.Evaluate(evaluationContextMock.Object, ref state);

            Assert.IsTrue(properties.ContainsKey("Identities"));
            Assert.IsTrue(properties["Identities"] is List<IIdentity>);
            Assert.AreSame(principal.Identity, ((List<IIdentity>)properties["Identities"])[0]);
        }
开发者ID:thaneswarreddy,项目名称:netfx,代码行数:26,代码来源:HttpContextIdentityPolicyFixture.cs


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