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


C# FakeConnection类代码示例

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


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

示例1: TestInitialConnectionPromptsAfterEachWrite

        public void TestInitialConnectionPromptsAfterEachWrite()
        {
            string endl = Environment.NewLine;
            var connection = new FakeConnection();
            var session = new Session(connection);

            // Send a prompt through the connection. (This should be asking which character to login, or to create a new one.)
            var prompt = session.State.BuildPrompt();
            Verify.IsTrue(prompt.Length > 0);
            Verify.AreEqual(1, connection.FakeMessagesSent.Count);

            connection.Reset();

            session.Write("test 1", true);
            Verify.AreEqual(1, connection.FakeMessagesSent.Count);
            Verify.AreEqual("test 1" + endl + prompt, connection.FakeMessagesSent[0]);

            connection.Reset();

            session.Write("test 2", false);
            Verify.AreEqual(1, connection.FakeMessagesSent.Count);
            Verify.AreEqual(endl + "test 2", connection.FakeMessagesSent[0]);

            connection.Reset();

            session.Write("test 3a");
            session.Write("test 3b");
            Verify.AreEqual(2, connection.FakeMessagesSent.Count);
            Verify.AreEqual("test 3a" + endl + prompt, connection.FakeMessagesSent[0]);
            Verify.AreEqual(endl + "test 3b" + endl + prompt, connection.FakeMessagesSent[1]);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:31,代码来源:TestSession.cs

示例2: Main

        static void Main(string[] args)
        {
            ConsoleColor old = Console.ForegroundColor;
            try{
                var props = new ConnectionProperties();
                using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom))
                {
                    var result = frm.ShowDialog();
                    if (result != System.Windows.Forms.DialogResult.OK)
                        return;
                }

                var cxi = new FakeConnection();
                new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props);

                var driver = new MongoDynamicDataContextDriver();

                List<Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList();
                var code = driver.GetStaticCodeFiles()
                    .Concat(new string[] {driver.GenerateDynamicCode(props, assemblies, "", "driver")});
                if(props.InitializationQuery != null)
                    code = code.Concat(new string[]{driver.GenerateCustomInitQuery(props.InitializationQuery, "driver")});

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("------------------------------------------------");
                foreach (string s in code)
                {
                    Console.WriteLine(s);
                    Console.WriteLine("------------------------------------------------");
                }
                Console.ForegroundColor = old;

                using (var frm = new SaveFileDialog())
                {
                    var result = frm.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        using (StreamWriter writer = new StreamWriter(frm.OpenFile()))
                        {
                            foreach (string s in code)
                            {
                                writer.WriteLine(s);
                                writer.WriteLine("---------------------------------------------------");
                            }

                            writer.Flush();
                        }

                    }
                }

            }catch(Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
            }
            finally{
                Console.ForegroundColor = old;
            }
        }
开发者ID:gburgett,项目名称:LinqPad-mongo-driver,代码行数:60,代码来源:Program.cs

示例3: GivenDb_WhenOnPrepareIsConfigured__AndExecuteIsCalled_CommandIsPrepared

 public void GivenDb_WhenOnPrepareIsConfigured__AndExecuteIsCalled_CommandIsPrepared()
 {
     var fakeConnection = new FakeConnection();
     var db = new Db(fakeConnection, new DbConfig(c => ((FakeCommand)c).Comment = "PREPARED", MappingConvention.OracleStyle, string.Empty));
     db.Execute("");
     Assert.AreEqual("PREPARED", fakeConnection.Commands.Single().Comment);
 }
开发者ID:jhgbrt,项目名称:yadal,代码行数:7,代码来源:DbConfigurationBuilderTests.cs

示例4: StartCreatesAndOpensWebSocket

        public async Task StartCreatesAndOpensWebSocket()
        {
            var fakeWebSocketTransport = new FakeWebSocketTransport();

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

            var fakeConnection = new FakeConnection
            {
                TransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100),
                TotalTransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100),
                Url = "http://fake.url",
                Protocol = new Version(1, 42),
                ConnectionToken = "MyConnToken",
                MessageId = "MsgId"
            };

            // connect timeout unblocks this call hence the expected exception
            await Assert.ThrowsAsync<TimeoutException>(
                async () => await fakeWebSocketTransport.Start(fakeConnection, "test", CancellationToken.None));

            Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
            Assert.Equal(1, fakeConnection.GetInvocations("PrepareRequest").Count());

            var openWebSocketInvocations = fakeWebSocketTransport.GetInvocations("OpenWebSocket").ToArray();
            Assert.Equal(1, openWebSocketInvocations.Length);
            Assert.StartsWith(
                "ws://fake.urlconnect/?clientProtocol=1.42&transport=webSockets&connectionData=test&connectionToken=MyConnToken&messageId=MsgId",
                ((Uri)openWebSocketInvocations[0][1]).AbsoluteUri);
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:34,代码来源:WebSocketTransportFacts.cs

示例5: MigrationTaskRunnerTests

 public MigrationTaskRunnerTests()
 {
     _db = new FakeConnection();
     //_db.Setup(d => d.BeginTransaction()).Returns(new FakeTransaction());
     LogHelper.Register(new ConsoleLogger(), "Default");
     _sb = new StringBuilder();
    _runner = new MigrationTaskRunner(_db, LogHelper.DefaultLogger);
 }
开发者ID:eugman,项目名称:SqlFu,代码行数:8,代码来源:MigrationTaskRunnerTests.cs

示例6: TestInitialConnectionStateIsNotDefaultState

        public void TestInitialConnectionStateIsNotDefaultState()
        {
            string endl = Environment.NewLine;
            var connection = new FakeConnection();
            var session = new Session(connection);

            Verify.IsTrue(session.State is SessionState);
            Verify.IsTrue(!(session.State is DefaultState), "The default session state should have been ConnectedState.");
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:9,代码来源:TestSession.cs

示例7: CreateModel_CreatesANewModel

        public void CreateModel_CreatesANewModel()
        {
            // Arrange
            var connection = new FakeConnection(new RabbitServer());

            // Act
            var result = connection.CreateModel();

            // Assert
            Assert.That(connection.Models,Has.Count.EqualTo(1));
            Assert.That(connection.Models,Is.EquivalentTo(new[]{result}));
        }
开发者ID:paulmccallick,项目名称:RabbitMQ.Fakes,代码行数:12,代码来源:FakeConnectionTests.cs

示例8: When_Key_Is_Found_GetAsync_Returns_True

        public async void When_Key_Is_Found_GetAsync_Returns_True()
        {
            var connection = new FakeConnection();
            connection.SetResponse(ResponsePackets.GET_OPAQUE_5_SUCCESS);
            _connectionPool.AddConnection(connection);

            var bucket = GetBucketForKey("key1");
            var result = await bucket.GetAsync<int>("key1");

            Assert.IsTrue(result.Success);
            Assert.AreEqual(ResponseStatus.Success, result.Status);
        }
开发者ID:hyah,项目名称:couchbase-net-client,代码行数:12,代码来源:MemcachedBucket_Async_Tests.cs

示例9: 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

示例10: Close_TimeoutArguments_ClosesTheConnection

        public void Close_TimeoutArguments_ClosesTheConnection()
        {
            // Arrange
            var connection = new FakeConnection(new RabbitServer());

            // Act
            connection.Close(timeout:2);

            // Assert
            Assert.That(connection.IsOpen, Is.False);
            Assert.That(connection.CloseReason, Is.Not.Null);
        }
开发者ID:paulmccallick,项目名称:RabbitMQ.Fakes,代码行数:12,代码来源:FakeConnectionTests.cs

示例11: When_Add_Succeeds_InsertAsync_Returns_Success

        public async Task When_Add_Succeeds_InsertAsync_Returns_Success()
        {
            var connection = new FakeConnection();
            connection.SetResponse(ResponsePackets.ADD_SUCCESS);
            _connectionPool.AddConnection(connection);

            var bucket = GetBucketForKey("key1");
            var result = await bucket.InsertAsync("key1", "NA");

            Assert.IsTrue(result.Success);
            Assert.AreEqual(ResponseStatus.Success, result.Status);
        }
开发者ID:brantburnett,项目名称:couchbase-net-client,代码行数:12,代码来源:CouchbaseBucket_Async_Tests.cs

示例12: CreateModel_MultipleTimes_CreatesManyModels

        public void CreateModel_MultipleTimes_CreatesManyModels()
        {
            // Arrange
            var connection = new FakeConnection(new RabbitServer());

            // Act
            var result1 = connection.CreateModel();
            var result2 = connection.CreateModel();

            // Assert
            Assert.That(connection.Models, Has.Count.EqualTo(2));
            Assert.That(connection.Models, Is.EquivalentTo(new[] { result1, result2 }));
        }
开发者ID:paulmccallick,项目名称:RabbitMQ.Fakes,代码行数:13,代码来源:FakeConnectionTests.cs

示例13: Close_AllArguments_ClosesTheConnection

        public void Close_AllArguments_ClosesTheConnection()
        {
            // Arrange
            var connection = new FakeConnection(new RabbitServer());

            // Act
            connection.Close(reasonCode: 3, reasonText: "foo",timeout:4);

            // Assert
            Assert.That(connection.IsOpen, Is.False);
            Assert.That(connection.CloseReason.ReplyCode, Is.EqualTo(3));
            Assert.That(connection.CloseReason.ReplyText, Is.EqualTo("foo"));
        }
开发者ID:paulmccallick,项目名称:RabbitMQ.Fakes,代码行数:13,代码来源:FakeConnectionTests.cs

示例14: Can_create_new_connection_lazily_using_given_connection_string

        public void Can_create_new_connection_lazily_using_given_connection_string()
        {
            using (var connection = new FakeConnection(
                CreateConfiguration(e => e.ConnectionString = "Database=FrodoLives"), new ConnectionStringResolver(null)))
            {
                Assert.Equal(0, connection.CreateCount);

                var dbConnection = connection.DbConnection;

                Assert.Equal(1, connection.CreateCount);
                Assert.Equal("Database=FrodoLives", dbConnection.ConnectionString);
            }
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:13,代码来源:RelationalConnectionTest.cs

示例15: UnderlyingConnection_WithConnection_ReturnsConnection

        public void UnderlyingConnection_WithConnection_ReturnsConnection()
        {
            // Arrange
            var factory = new FakeConnectionFactory();
            var connection = new FakeConnection(new RabbitServer());
            factory.WithConnection(connection);

            // Act
            var result = factory.UnderlyingConnection;

            // Assert
            Assert.That(result, Is.SameAs(connection));
        }
开发者ID:paulmccallick,项目名称:RabbitMQ.Fakes,代码行数:13,代码来源:FakeConnectionFactoryTests.cs


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