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


C# MockContext.Arrange方法代码示例

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


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

示例1: Arrange_CallBackFourArguments_InvokesCallback

        public void Arrange_CallBackFourArguments_InvokesCallback()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);
            int firstResult = 0;
            int secondResult = 0;
            int thirdResult = 0;
            int fourthResult = 0;
            mockContext.Arrange(
                f => f.Execute(The<int>.IsAnyValue, The<int>.IsAnyValue, The<int>.IsAnyValue, The<int>.IsAnyValue))
                .Callback<int, int, int, int>(
                    (i1, i2, i3, i4) =>
                    {
                        firstResult = i1;
                        secondResult = i2;
                        thirdResult = i3;
                        fourthResult = i4;
                    });

            fooMock.Execute(1, 2, 3, 4);

            Assert.AreEqual(1, firstResult);
            Assert.AreEqual(2, secondResult);
            Assert.AreEqual(3, thirdResult);
            Assert.AreEqual(4, fourthResult);
        }
开发者ID:gazzyt,项目名称:LightMock,代码行数:26,代码来源:ArrangementTests.cs

示例2: Arrange_CallBackOneArgument_InvokesCallback

 public void Arrange_CallBackOneArgument_InvokesCallback()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     int callBackResult = 0;
     mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue)).Callback<int>(s => callBackResult = s);
     fooMock.Execute(1);
     Assert.AreEqual(1, callBackResult);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:9,代码来源:ArrangementTests.cs

示例3: Arrange_CallBackNoArguments_InvokesCallback

 public void Arrange_CallBackNoArguments_InvokesCallback()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     bool isCalled = false;
     mockContext.Arrange(f => f.Execute()).Callback(() => isCalled = true);
     fooMock.Execute();
     Assert.IsTrue(isCalled);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:9,代码来源:ArrangementTests.cs

示例4: Cloud_auth_object_returns_project_id

        public void Cloud_auth_object_returns_project_id()
        {
            var mockContext = new MockContext<CloudAuthenticator>();
            mockContext.Arrange(f => f.GetProjectId()).Returns("ProjectId");

            var cloudAuthMock = new CloudAuthenticatorMock(mockContext);
            var result = cloudAuthMock.GetProjectId();

            mockContext.Assert(f => f.GetProjectId(), Invoked.Once);
            Assert.Equal("ProjectId", result);
        }
开发者ID:neil-119,项目名称:GAE-NET,代码行数:11,代码来源:AuthTests.cs

示例5: Cloud_auth_object_returns_initializer

        public void Cloud_auth_object_returns_initializer()
        {
            var initializer = new BaseClientService.Initializer();
            var mockContext = new MockContext<CloudAuthenticator>();
            mockContext.Arrange(f => f.GetInitializer()).Returns(initializer);

            var cloudAuthMock = new CloudAuthenticatorMock(mockContext);
            var result = cloudAuthMock.GetInitializer();

            mockContext.Assert(f => f.GetInitializer(), Invoked.Once);
            Assert.Equal(initializer, result);
        }
开发者ID:neil-119,项目名称:GAE-NET,代码行数:12,代码来源:AuthTests.cs

示例6: MessageControllerTest

 public MessageControllerTest(ITestOutputHelper output)
 {
     this.output = output;
     lookupRepo = new FakeLookupRepository();
     logger = new DivineLogger<FakeDataStore>(new FakeDataStore());
     cache = new MemoryCache(new MemoryCacheOptions());
     msgService = new FakeCommunicationService();
     var mockContext = new MockContext<IRepository<Member>>();
     membersRepo = new FakeMemberRepository(mockContext);
     var repositories = new DivineRepositories(attendanceRepo, lookupRepo, membersRepo, msgRepo);
     //divineBot = new TextDivineBot(repositories, msgService);
     mockContext.Arrange(x => (x.GetAllAsync())).Returns(Task.FromResult(membersList.AsQueryable()));
     messageCtrl = new MessageController(repositories, msgService, cache, logger, null);
 }
开发者ID:mgolois,项目名称:DivineChMS,代码行数:14,代码来源:MessageControllerTest.cs

示例7: Arrange_CallBackTwoArguments_InvokesCallback

 public void Arrange_CallBackTwoArguments_InvokesCallback()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     int firstResult = 0;
     int secondResult = 0;
     mockContext.Arrange(f => f.Execute(The<int>.IsAnyValue, The<int>.IsAnyValue)).Callback<int, int>(
         (i, i1) =>
         {
             firstResult = i;
             secondResult = i1;
         });
     fooMock.Execute(1, 2);
     Assert.AreEqual(1, firstResult);
     Assert.AreEqual(2, secondResult);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:16,代码来源:ArrangementTests.cs

示例8: Get_ReturnsBadRequest

        public async Task Get_ReturnsBadRequest()
        {
            //Arrange
            var mockContext = new MockContext<IRepository<Member>>();
            membersRepo = new FakeMemberRepository(mockContext);
            var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null), logger, null, null);
            mockContext.Arrange(x => (x.GetAllAsync())).Throws(() => new NullReferenceException("null Data"));

            //Act
            var result = await controller.Get();

            //Assert
            Assert.NotNull(result);
            Assert.Equal(result.StatusCode , (int) HttpStatusCode.BadRequest);
            Assert.IsType<string>(result.Value);
            Assert.Contains("error",result.Value.ToString(),  StringComparison.OrdinalIgnoreCase);
        }
开发者ID:mgolois,项目名称:DivineChMS,代码行数:17,代码来源:MembersControllerTests.cs

示例9: Get_ReturnsNoException

        public async Task Get_ReturnsNoException()
        {
            //Arrange
            var mockContext = new MockContext<IRepository<Member>>();
            membersRepo = new FakeMemberRepository(mockContext);
            var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null),logger, null, null);
            var data = new List<Member> { new Member { Id = 1 } }.AsQueryable();
            mockContext.Arrange(x => (x.GetAllAsync())).Returns(Task.FromResult(data));

            //ACT
            var result = await controller.Get();

            //Assert
            Assert.NotNull(result);
            Assert.IsType<List<Member>>(result.Value);
            Assert.Equal(data.Count(), ((List<Member>)result.Value).Count());


        }
开发者ID:mgolois,项目名称:DivineChMS,代码行数:19,代码来源:MembersControllerTests.cs

示例10: Execute_ArrangedReturnValue_ReturnsValueUsingLambda

        public void Execute_ArrangedReturnValue_ReturnsValueUsingLambda()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);
            var outerVariable = " works";
            mockContext.Arrange(f => f.Execute(The<string>.IsAnyValue)).Returns<string>(
                a =>
                {
                    var r = a + outerVariable + "!";
                    return r;
                });

            var result = fooMock.Execute("It");

            Assert.AreEqual("It works!", result);
        }
开发者ID:gazzyt,项目名称:LightMock,代码行数:16,代码来源:MockContextTests.cs

示例11: Arrange_ReturnsWithFourArguments_InvokesGetResult

        public void Arrange_ReturnsWithFourArguments_InvokesGetResult()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);
            mockContext.Arrange(
                f =>
                    f.Execute(
                        The<string>.IsAnyValue,
                        The<string>.IsAnyValue,
                        The<string>.IsAnyValue,
                        The<string>.IsAnyValue))
                .Returns<string, string, string, string>((a, b, c, d) => "This" + a + b + c + d);
            fooMock.Execute(1, 2, 3, 4);

            var result = fooMock.Execute(" is", " really", " cool", "!");
            Assert.AreEqual("This is really cool!", result);
        }
开发者ID:gazzyt,项目名称:LightMock,代码行数:17,代码来源:ArrangementTests.cs

示例12: Arrange_ReturnsWithNoArguments_InvokesGetResult

        public void Arrange_ReturnsWithNoArguments_InvokesGetResult()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);

            mockContext.Arrange(f => f.Execute()).Returns(() => "This");
            var result = fooMock.Execute();
            Assert.AreEqual("This", result);
        }
开发者ID:gazzyt,项目名称:LightMock,代码行数:9,代码来源:ArrangementTests.cs

示例13: Arrange_ReturnsWithOneArgument_InvokesGetResult

 public void Arrange_ReturnsWithOneArgument_InvokesGetResult()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     mockContext.Arrange(f => f.Execute(The<string>.IsAnyValue)).Returns<string>(a => "This" + a);
     var result = fooMock.Execute(" is");
     Assert.AreEqual("This is", result);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:8,代码来源:ArrangementTests.cs

示例14: Execute_ArrangedRuturnValue_ArrayElementContraintSupport

 public void Execute_ArrangedRuturnValue_ArrayElementContraintSupport()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     var inputData = new byte[] {1, 2, 3, 4, 5 };
     mockContext.Arrange(
         f => f.Execute(The<byte[]>.Is(a => a[4] == 5)))
         .Returns<byte[]>(a => a);
     var result = fooMock.Execute(inputData);
     Assert.AreEqual(inputData, result);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:11,代码来源:MockContextTests.cs

示例15: PropertySupport_ArrangeGetterReturnValue_IsVerified

        public void PropertySupport_ArrangeGetterReturnValue_IsVerified()
        {
            var mockContext = new MockContext<IProp>();
            var propMock = new PropMock(mockContext);
            mockContext.Arrange(x => x.ReadOnlyProperty).Returns(() => "result");

            var propertyValue = propMock.ReadOnlyProperty;
            Assert.AreEqual("result", propertyValue);
        }
开发者ID:gazzyt,项目名称:LightMock,代码行数:9,代码来源:MockContextTests.cs


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