Beispiel #1
0
        public void CreateDriverDocument_should_return_expected_result()
        {
            var result = ClientDocumentHelper.CreateDriverDocument();

            result["name"].AsString.Should().Be("mongo-csharp-driver");
            result["version"].BsonType.Should().Be(BsonType.String);
        }
Beispiel #2
0
        public void RemoveOptionalFieldsUntilDocumentIsLessThan512Bytes_should_return_expected_result(
            [Range(-1, 4)]
            int largeOptionalFieldNameIndex)
        {
            var optionalFieldNames = new[] { "application", "os.version", "os.architecture", "os.name", "platform" };
            var clientDocument     = CreateClientDocument();

            if (largeOptionalFieldNameIndex != -1)
            {
                var largeOptionalFieldName = optionalFieldNames[largeOptionalFieldNameIndex];
                SetField(clientDocument, largeOptionalFieldName, new string('x', 512));
            }

            var result = ClientDocumentHelper.RemoveOptionalFieldsUntilDocumentIsLessThan512Bytes(clientDocument);

            var expectedResult = CreateClientDocument();

            if (largeOptionalFieldNameIndex != -1)
            {
                for (var i = 0; i <= largeOptionalFieldNameIndex; i++)
                {
                    RemoveField(expectedResult, optionalFieldNames[i]);
                }
            }
            result.Should().Be(expectedResult);
        }
Beispiel #3
0
        public void RemoveOneOptionalField_should_return_expected_result(
            [Range(0, 6)]
            int timesCalled)
        {
            var clientDocument = CreateClientDocument();

            var result = clientDocument;

            for (var i = 0; i < timesCalled; i++)
            {
                result = ClientDocumentHelper.RemoveOneOptionalField(result);
            }

            var expectedResult = CreateClientDocument();

            if (timesCalled < 6)
            {
                var optionalFieldNames = new[] { "application", "os.version", "os.architecture", "os.name", "platform" };
                for (var i = 0; i < timesCalled; i++)
                {
                    var dottedFieldName = optionalFieldNames[i];
                    RemoveField(expectedResult, dottedFieldName);
                }
            }
            else
            {
                expectedResult = null;
            }
            result.Should().Be(expectedResult);
        }
Beispiel #4
0
        public void CreateOSDocument_should_return_expected_result()
        {
            var result = ClientDocumentHelper.CreateOSDocument();

            var names = result.Names.ToList();

            names.Should().Contain("type");
        }
Beispiel #5
0
        public void CreateDriverDocument_with_args_should_return_expected_result(
            [Values("2.4.0", "2.4.1")]
            string driverVersion)
        {
            var result = ClientDocumentHelper.CreateDriverDocument(driverVersion);

            result.Should().Be($"{{ name : 'mongo-csharp-driver', version : '{driverVersion}' }}");
        }
 public ConnectionInitializer(
     string applicationName,
     IReadOnlyList <CompressorConfiguration> compressors,
     ServerApi serverApi)
 {
     _clientDocument = ClientDocumentHelper.CreateClientDocument(applicationName);
     _compressors    = Ensure.IsNotNull(compressors, nameof(compressors));
     _serverApi      = serverApi;
 }
Beispiel #7
0
        public void CreateClientDocument_should_return_expected_result()
        {
            var result = ClientDocumentHelper.CreateClientDocument(null);

            var names = result.Names.ToList();

            names.Count.Should().Be(3);
            names[0].Should().Be("driver");
            names[1].Should().Be("os");
            names[2].Should().Be("platform");
        }
Beispiel #8
0
        public void CreateOSDocument_with_args_should_return_expected_result(
            [Values("Windows", "Linux")]
            string osType,
            [Values("Windows 10", "macOS")]
            string osName,
            [Values("x86_32", "x86_64")]
            string architecture,
            [Values("8.1", "10.0")]
            string osVersion)
        {
            var result = ClientDocumentHelper.CreateOSDocument(osType, osName, architecture, osVersion);

            result.Should().Be($"{{ type : '{osType}', name : '{osName}', architecture : '{architecture}', version : '{osVersion}' }}");
        }
Beispiel #9
0
        public void CreateClientDocument_with_args_should_return_expected_result(
            [Values(null, "app1", "app2")]
            string applicationName,
            [Values("{ name : 'mongo-csharp-driver', version : '2.4.0' }", "{ name : 'mongo-csharp-driver', version : '2.4.1' }")]
            string driverDocumentString,
            [Values(
                 "{ type : 'Windows', name : 'Windows 10', architecture : 'x86_64', version : '10.0' }",
                 "{ type : 'Windows', name : 'Windows 10', architecture : 'x86_64', version : '10.1' }")]
            string osDocumentString,
            [Values("net45", "net46")]
            string platformString)
        {
            var driverDocument = BsonDocument.Parse(driverDocumentString);
            var osDocument     = BsonDocument.Parse(osDocumentString);

            var result = ClientDocumentHelper.CreateClientDocument(applicationName, driverDocument, osDocument, platformString);

            var applicationNameElement = applicationName == null ? null : $"application : {{ name : '{applicationName}' }},";
            var expectedResult         = $"{{ {applicationNameElement} driver : {driverDocumentString}, os : {osDocumentString}, platform : '{platformString}' }}";

            result.Should().Be(expectedResult);
        }
Beispiel #10
0
        public void GetPlatformString_should_return_expected_result()
        {
            var result = ClientDocumentHelper.GetPlatformString();

            result.Should().NotBeNull();
        }
Beispiel #11
0
 public ConnectionInitializer(string applicationName)
 {
     _clientDocument = ClientDocumentHelper.CreateClientDocument(applicationName);
 }