public void ConnectionPoolSizeTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     int expected = 234;
     int actual;
     target.ConnectionPoolSize = expected;
     actual = target.ConnectionPoolSize;
     actual.Should().Be(expected);
 }
Пример #2
0
 /// <summary>
 /// Retrieves an <see cref="IServer"/> proxy object bound to the specified host and port
 /// </summary>
 /// <param name="host">The host.</param>
 /// <param name="port">(optional) The port. If unspecified/null, will use the MongoDB default port</param>
 /// <param name="options">The options.</param>
 /// <param name="readOnly">if set to <c>true</c> the binding is read only.</param>
 /// <returns></returns>
 /// <example>
 /// <code>
 /// IServer server = Mongo.GetServer("localhost", 1910);
 /// //Result would be: "mongo://localhost:1910"
 /// </code>
 /// </example>
 public static IServer GetServer(string host, int port, DBConnectionOptions options = null, bool readOnly = false)
 {
     string uri = (port == Mongo.DefaultPort ? string.Format("mongo://{0}", host.Trim()) : string.Format("mongo://{0}:{1}", host.Trim(), port));
     return GetServer(uri, options, readOnly);
 }
Пример #3
0
 /// <summary>
 /// Retrieves an <see cref="IServer"/> proxy object bound to the <see cref="System.Uri"/> parsed from the supplied string
 /// </summary>
 /// This function will construct a new proxy object on every call.
 /// The <c>serverUri</c> should be of the form: <c>"mongo://host:port"</c>
 /// <returns>The server proxy instance</returns>
 /// <example caption="Uri examples">
 /// <code>
 /// IServer loopback = Mongo.GetServer("mongo://localhost");
 /// IServer ipv4loopback = Mongo.GetServer("mongo://127.0.0.1");
 /// IServer ipv6loopback = Mongo.GetServer("mongo://[::1]");
 /// IServer loopbackport = Mongo.GetServer("mongo://localhost:1910");
 /// IServer ipv4loopbackport = Mongo.GetServer("mongo://127.0.0.1:1910");
 /// IServer ipv6loopbackport = Mongo.GetServer("mongo://[::1]:1910");
 /// </code>
 /// </example>
 /// <param name="serverUriString">The server Uri as a string.</param>
 /// <param name="options">The options.</param>
 /// <param name="readOnly">if set to <c>true</c> this server will be readonly and throw <see cref="System.Data.ReadOnlyException" /> on any write/modify attempts.</param>
 public static IServer GetServer(string serverUriString, DBConnectionOptions options = null, bool readOnly = false)
 {
     return GetServer(new Uri(serverUriString, UriKind.Absolute), options, readOnly);
 }
Пример #4
0
 /// <summary>
 /// Retrieves an <see cref="IServer"/> proxy object bound to the supplied <see cref="System.Uri"/>
 /// </summary>
 /// <remarks>
 /// This function will construct a new proxy object on every call.
 /// The <c>serverUri</c> should be of the form: <c>mongo://host:port</c>
 /// </remarks>
 /// <param name="serverUri">The server URI</param>
 /// <param name="options">The connection options.</param>
 /// <param name="readOnly">if set to <c>true</c> this server will be readonly and throw <see cref="System.Data.ReadOnlyException"/> on any write/modify attempts.</param>
 /// <returns>The server proxy instance</returns>
 public static IServer GetServer(Uri serverUri, DBConnectionOptions options = null, bool readOnly = false)
 {
     return GetServer(new ServerBinding(serverUri, readOnly), options);
 }
Пример #5
0
        /// <summary>
        /// Retrieves an <see cref="IDatabase"/> proxy object bound to the specified host, port, and database name
        /// </summary>
        /// <param name="hostName">The host name.</param>
        /// <param name="databaseName">Name of the database.</param>
        /// <param name="port">(optional) The port. If unspecified/null, will use the MongoDB default port</param>
        /// <param name="options">The options.</param>
        /// <param name="readOnly">if set to <c>true</c> the binding is read only.</param>
        /// <returns></returns>
        /// <example>
        /// <code>
        /// IDatabase db = Mongo.GetDatabase("localhost", 1910, "test");
        /// //Result would be equivalent to: "mongo://localhost:1910/test"
        /// </code>
        /// </example>
        public static IDatabase GetDatabase(string hostName, string databaseName, int? port = null, DBConnectionOptions options = null, bool readOnly = false)
        {
            if (!port.HasValue)
                port = Mongo.DefaultPort;

            Condition.Requires(databaseName, "databaseName").IsNotNullOrWhitespace();
            Condition.Requires(hostName, "hostName").IsNotNullOrWhitespace();
            Condition.Requires(port.Value, "port").IsGreaterOrEqual(0);
            string databaseUriString = (port.Value == Mongo.DefaultPort ? string.Format("mongo://{0}/{1}", hostName.Trim(), databaseName) : string.Format("mongo://{0}:{1}/{2}", hostName.Trim(), port.Value, databaseName));
            return GetDatabase(databaseUriString, options, readOnly);
        }
Пример #6
0
 /// <summary>
 /// Retrieves an <see cref="IDatabase"/> proxy object bound to the supplied <see cref="System.Uri"/>
 /// </summary>
 /// <remarks>
 /// This function will construct a new proxy object on every call.
 /// An <see cref="IServer"/> proxy will be implicitly created by this call. You can access that via <c>IDatabase.Server</c>.
 /// The <c>databaseUri</c> should be of the form: <c>mongo://host:port</c>
 /// </remarks>
 /// <param name="databaseUri">The database URI</param>
 /// <param name="options">The connection options.</param>
 /// <param name="readOnly">if set to <c>true</c> this database (and server) will be readonly and throw <see cref="System.Data.ReadOnlyException"/> on any write/modify attempts.</param>
 /// <returns>The database proxy instance</returns>
 public static IDatabase GetDatabase(Uri databaseUri, DBConnectionOptions options = null, bool readOnly = false)
 {
     Condition.Requires(databaseUri, "databaseUri").IsNotNull().Evaluate(databaseUri.IsAbsoluteUri, "the database URI must be absolute and include server details");
     IServer server = GetServer(databaseUri, options, readOnly);
     IDBBinding dbBinding = server.Binding.GetDBBinding(databaseUri);
     return server.GetDatabase(dbBinding);
 }
Пример #7
0
 /// <summary>
 /// Retrieves an <see cref="IDatabase"/> proxy object bound to the <see cref="System.Uri"/> parsed from the supplied string
 /// </summary>
 /// <remarks>
 /// This function will construct a new proxy object on every call.
 /// An <see cref="IServer"/> proxy will be implicitly created by this call. You can access that via <c>IDatabase.Server</c>.
 /// The <c>databaseUri</c> should be of the form: <c>mongo://host:port</c>
 /// </remarks>
 /// <param name="databaseUri">The database URI in string format</param>
 /// <param name="options">The connection options.</param>
 /// <param name="readOnly">if set to <c>true</c> this database (and server) will be readonly and throw <see cref="System.Data.ReadOnlyException"/> on any write/modify attempts.</param>
 /// <returns>The database proxy instance</returns>
 public static IDatabase GetDatabase(string databaseUri, DBConnectionOptions options = null, bool readOnly = false)
 {
     return GetDatabase(new Uri(databaseUri, UriKind.RelativeOrAbsolute), options, readOnly);
 }
 public void ReceiveBufferSizeTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     int expected = 71;
     int actual;
     target.ReceiveBufferSize = expected;
     actual = target.ReceiveBufferSize;
     actual.Should().Be(expected);
 }
 public void FireAndForgetUpdateTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     bool expected = false;
     bool actual;
     target.FireAndForgetUpdate = expected;
     actual = target.FireAndForgetUpdate;
     actual.Should().Be(expected);
 }
 public void DBConnectionOptionsConstructorTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
 }
 public void ConnectionFactoryTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     target.ConnectionFactory = (ep, o) => null;
     target.ConnectionFactory(null, null).Should().BeNull();
 }
 public void SendBufferSizeTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     int expected = 2344;
     int actual;
     target.SendBufferSize = expected;
     actual = target.SendBufferSize;
     actual.Should().Be(expected);
 }
 public void RetryTimeTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     long expected = 80;
     long actual;
     target.RetryTime = expected;
     actual = target.RetryTime;
     actual.Should().Be(expected);
 }
        public void ResetTest()
        {
            DBConnectionOptions def = new DBConnectionOptions();
            DBConnectionOptions target = new DBConnectionOptions();
            target.AutoConnectRetry = !def.AutoConnectRetry;
            target.ConnectionFactory = (a, b) => null;
            target.ConnectionPoolSize++;
            target.FireAndForgetUpdate = !def.FireAndForgetUpdate;
            target.LingerState = new LingerOption(true, 2);
            target.NoDelay = !def.NoDelay;
            target.ReceiveBufferSize++;
            target.ReceiveTimeout++;
            target.RetryTime++;
            target.SendBufferSize++;
            target.SendTimeout++;

            //Verify our assumptions
            target.AutoConnectRetry.Should().Be(!def.AutoConnectRetry);
            target.ConnectionFactory.Should().NotBe(def.ConnectionFactory);
            target.ConnectionPoolSize.Should().NotBe(def.ConnectionPoolSize);
            target.FireAndForgetUpdate.Should().Be(!def.FireAndForgetUpdate);
            target.LingerState.Should().NotBe(def.LingerState);
            target.NoDelay.Should().Be(!def.NoDelay);
            target.ReceiveBufferSize.Should().NotBe(def.ReceiveBufferSize);
            target.ReceiveTimeout.Should().NotBe(def.ReceiveTimeout);
            target.RetryTime.Should().NotBe(def.RetryTime);
            target.SendBufferSize.Should().NotBe(def.SendBufferSize);
            target.SendTimeout.Should().NotBe(def.SendTimeout);

            //Reset
            target.Reset();
            //Verify the result
            target.AutoConnectRetry.Should().Be(def.AutoConnectRetry, "AutoConnectRetry should have been reset");
            target.ConnectionFactory.Should().Be(def.ConnectionFactory, "ConnectionFactory should have been reset");
            target.ConnectionPoolSize.Should().Be(def.ConnectionPoolSize, "ConnectionPoolSize should have been reset");
            target.FireAndForgetUpdate.Should().Be(def.FireAndForgetUpdate, "FireAndForgetUpdate should have been reset");
            target.LingerState.Should().BeNull("LingerState should have been reset");
            target.NoDelay.Should().Be(def.NoDelay, "NoDelay should have been reset");
            target.ReceiveBufferSize.Should().Be(def.ReceiveBufferSize, "ReceiveBufferSize should have been reset");
            target.ReceiveTimeout.Should().Be(def.ReceiveTimeout, "ReceiveTimeout should have been reset");
            target.RetryTime.Should().Be(def.RetryTime, "RetryTime should have been reset");
            target.SendBufferSize.Should().Be(def.SendBufferSize, "SendBufferSize should have been reset");
            target.SendTimeout.Should().Be(def.SendTimeout, "SendTimeout should have been reset");
        }
Пример #15
0
 internal static IServer GetServer(IServerBinding serverBinding, DBConnectionOptions options = null)
 {
     Server s = new Server(serverBinding,options);
     return s;
 }
 public void LingerStateTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     LingerOption expected = new LingerOption(true, 123);
     LingerOption actual;
     target.LingerState = expected;
     actual = target.LingerState;
     actual.Should().Be(expected);
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Server"/> class.
 /// </summary>
 /// <param name="binding">The binding.</param>
 /// <param name="options">The options.</param>
 public Server(IServerBinding binding, DBConnectionOptions options)
 {
     Binding = binding;
     Options = options ?? new DBConnectionOptions();
     Binding.Bind(this); //Initialize the binding
 }
 public void NoDelayTest()
 {
     DBConnectionOptions target = new DBConnectionOptions();
     bool expected = true;
     bool actual;
     target.NoDelay = expected;
     actual = target.NoDelay;
     actual.Should().Be(expected);
 }