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


C# FakeConnection.Setup方法代码示例

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


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

示例1: SpecificCommand

        public void SpecificCommand()
        {
            var connection = new FakeConnection();
            var cmdToReturn = new FakeCommand(new ScalarCommandResult("SELECT count(*) FROM users", null){Result = 201});
            connection.Setup(cmdToReturn);

            var cmd = connection.CreateCommand();
            cmd.CommandText = "SELECT count(*) FROM users";
            var result = cmd.ExecuteScalar();

           Assert.Equal(201, result);
        }
开发者ID:jmptrader,项目名称:Griffin.AdoNetFakes,代码行数:12,代码来源:ConnectionTests.cs

示例2: AutomaticResult

        public void AutomaticResult()
        {
            var table = new FakeTable(new[]
                {
                    new object[] {1, "jonas"},
                    new object[] {2, "arne"},
                });
            var connection = new FakeConnection();
            connection.Setup(new FakeCommand(table));

            var cmd = connection.CreateCommand();
            cmd.CommandText = "SELECT Id, UserName FROM users";
            var result = cmd.ExecuteReader();
            
            Assert.True(result.Read());
            Assert.Equal(1, (int)result[0]);
            Assert.Equal("jonas", result[1]);
        }
开发者ID:jmptrader,项目名称:Griffin.AdoNetFakes,代码行数:18,代码来源:ConnectionTests.cs

示例3: ReconnectStopsReconnectingIfStartingWebSocketCancelled

        public async Task ReconnectStopsReconnectingIfStartingWebSocketCancelled()
        {
            var fakeConnection = new FakeConnection
            {
                LastActiveAt = DateTime.UtcNow,
                ReconnectWindow = new TimeSpan(0, 0, 15),
                Url = "http://fakeserver/"
            };

            fakeConnection.Setup("ChangeState",
                () =>
                {
                    fakeConnection.State = ConnectionState.Reconnecting;
                    return true;
                });

            var fakeWebSocketTransport = new FakeWebSocketTransport
            {
                ReconnectDelay = new TimeSpan(0, 0, 0, 1)
            };

            fakeWebSocketTransport.Setup<Task>("OpenWebSocket", () =>
            {
                var tcs = new TaskCompletionSource<object>();
                tcs.SetCanceled();
                return tcs.Task;
            });

            await fakeWebSocketTransport.Reconnect(fakeConnection, null);

            Assert.Equal(1, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
            Assert.Equal(0, fakeConnection.GetInvocations("Stop").Count());
            Assert.Equal(0, fakeConnection.GetInvocations("OnError").Count());
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:34,代码来源:WebSocketTransportFacts.cs

示例4: ReconnectRetriesReconnectingIfStartingWebSocketThrows

        public async Task ReconnectRetriesReconnectingIfStartingWebSocketThrows()
        {
            var fakeConnection = new FakeConnection
            {
                LastActiveAt = DateTime.UtcNow,
                ReconnectWindow = new TimeSpan(0, 0, 15),
                Url = "http://fakeserver/"
            };

            fakeConnection.Setup("ChangeState",
                () =>
                {
                    fakeConnection.State = ConnectionState.Reconnecting;
                    return true;
                });

            var fakeWebSocketTransport = new FakeWebSocketTransport
            {
                ReconnectDelay = new TimeSpan(0, 0, 0, 1)
            };

            var openWebSocketInvoked = false;
            var exception = new Exception();
            fakeWebSocketTransport.Setup<Task>("OpenWebSocket", () =>
            {
                if (!openWebSocketInvoked)
                {
                    openWebSocketInvoked = true;
                    throw exception;
                }

                var tcs = new TaskCompletionSource<object>();
                tcs.TrySetResult(null);
                return tcs.Task;
            });

            await fakeWebSocketTransport.Reconnect(fakeConnection, null);

            Assert.Equal(2, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
            var onErrorInvocations = fakeConnection.GetInvocations("OnError").ToArray();
            Assert.Equal(1, onErrorInvocations.Length);
            Assert.Same(exception, onErrorInvocations[0][0]);
            Assert.Equal(1, fakeConnection.GetInvocations("OnReconnected").Count());
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:44,代码来源:WebSocketTransportFacts.cs

示例5: ReconnectDoesNotStartNewWebSocketIfClientWasNotInConnectState

        public async Task ReconnectDoesNotStartNewWebSocketIfClientWasNotInConnectState()
        {
            var fakeConnection = new FakeConnection
            {
                LastActiveAt = DateTime.UtcNow,
                ReconnectWindow = new TimeSpan(0, 0, 15),
                Url = "http://fakeserver/"
            };

            fakeConnection.Setup("ChangeState",
                () =>
                {
                    fakeConnection.State = ConnectionState.Disconnected;
                    return false;
                });

            var fakeWebSocketTransport = new FakeWebSocketTransport();

            await fakeWebSocketTransport.Reconnect(fakeConnection, null);

            Assert.Equal(0, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
            Assert.Equal(0, fakeConnection.GetInvocations("Stop").Count());
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:23,代码来源:WebSocketTransportFacts.cs

示例6: ReconnectStopsConnectionAndDoesNotStartNewWebSocketIfReconnectWindowExceeded

        public async Task ReconnectStopsConnectionAndDoesNotStartNewWebSocketIfReconnectWindowExceeded()
        {
            var fakeConnection = new FakeConnection
            {
                LastActiveAt = DateTime.UtcNow.AddSeconds(-10),
                ReconnectWindow = new TimeSpan(0, 0, 5),
                Url = "http://fakeserver/"
            };

            fakeConnection.Setup("ChangeState",
                () =>
                {
                    fakeConnection.State = ConnectionState.Reconnecting;
                    return true;
                });

            var fakeWebSocketTransport = new FakeWebSocketTransport();

            await fakeWebSocketTransport.Reconnect(fakeConnection, null);

            Assert.Equal(0, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
            var stopInvocations = fakeConnection.GetInvocations("Stop").ToArray();
            Assert.Equal(1, stopInvocations.Length);
            Assert.IsType(typeof(TimeoutException), stopInvocations[0][0]);
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:25,代码来源:WebSocketTransportFacts.cs

示例7: ReconnectStartsNewWebSocket

        public async Task ReconnectStartsNewWebSocket()
        {
            var fakeConnection = new FakeConnection
            {
                LastActiveAt = DateTime.Now.AddDays(1),
                ReconnectWindow = new TimeSpan(0, 0, 0),
                Url = "http://fakeserver/"
            };

            fakeConnection.Setup("ChangeState",
                () =>
                {
                    fakeConnection.State = ConnectionState.Reconnecting;
                    return true;
                });

            var fakeWebSocketTransport = new FakeWebSocketTransport();
            fakeWebSocketTransport.Setup<Task>("OpenWebSocket", () =>
            {
                var tcs = new TaskCompletionSource<object>();
                tcs.TrySetResult(null);
                return tcs.Task;
            });

            await fakeWebSocketTransport.Reconnect(fakeConnection, "abc");

            var openWebSocketInvocations = fakeWebSocketTransport.GetInvocations("OpenWebSocket").ToArray();
            Assert.Equal(1, openWebSocketInvocations.Length);
            Assert.StartsWith("ws://fakeserver/reconnect?", ((Uri)openWebSocketInvocations[0][1]).AbsoluteUri);
            Assert.Contains("&connectionData=abc", ((Uri)openWebSocketInvocations[0][1]).AbsoluteUri);
            Assert.Equal(1, fakeConnection.GetInvocations("OnReconnected").Count());
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:32,代码来源:WebSocketTransportFacts.cs


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