/// <summary>
        /// Create an instance of <see cref="ArangoDBClient"/> from an existing
        /// <see cref="HttpClient"/> instance, using the default JSON serialization.
        /// </summary>
        /// <param name="client"></param>
        public ArangoDBClient(HttpClient client)
        {
            _transport = new HttpApiTransport(client, HttpContentType.Json);

            var serialization = new JsonNetApiClientSerialization();

            InitializeApis(_transport, serialization);
        }
        /// <summary>
        /// Create an instance of <see cref="ArangoDBClient"/>
        /// using the provided transport layer and the default JSON serialization.
        /// </summary>
        /// <param name="transport">The ArangoDB transport layer implementation.</param>
        public ArangoDBClient(IApiClientTransport transport)
        {
            _transport = transport;

            var serialization = new JsonNetApiClientSerialization();

            InitializeApis(_transport, serialization);
        }
Beispiel #3
0
        /// <summary>
        /// Create an instance of <see cref="ArangoDBClient"/>
        /// using the provided transport layer and the default JSON serialization.
        /// </summary>
        /// <param name="transport">The ArangoDB transport layer implementation.</param>
        public ArangoDBClient(IApiClientTransport transport)
        {
            _transport = transport;

            var serialization = new JsonNetApiClientSerialization();

            Auth        = new AuthApiClient(_transport, serialization);
            Cursor      = new CursorApiClient(_transport, serialization);
            Database    = new DatabaseApiClient(_transport, serialization);
            Document    = new DocumentApiClient(_transport, serialization);
            Collection  = new CollectionApiClient(_transport, serialization);
            Transaction = new TransactionApiClient(_transport, serialization);
            Graph       = new GraphApiClient(_transport, serialization);
        }
        public void DeserializeFromStream_ShouldSucceed()
        {
            // Deserializing should match both "camelCase" and "CamelCase"

            byte[] jsonBytes = Encoding.UTF8.GetBytes(
                "{\"propertyToCamelCase\":\"myvalue\",\"NullPropertyToIgnore\":\"something\"}");

            var stream = new MemoryStream(jsonBytes);

            var serialization = new JsonNetApiClientSerialization();

            TestModel model = serialization.DeserializeFromStream <TestModel>(stream);

            Assert.Equal("myvalue", model.PropertyToCamelCase);
            Assert.Equal("something", model.NullPropertyToIgnore);
        }
        public void Serialize_ShouldSucceed()
        {
            var model = new TestModel
            {
                NullPropertyToIgnore = null,
                PropertyToCamelCase  = "myvalue"
            };

            var serialization = new JsonNetApiClientSerialization();

            byte[] jsonBytes = serialization.Serialize(model, true, true);

            string jsonString = Encoding.UTF8.GetString(jsonBytes);

            Assert.Contains("propertyToCamelCase", jsonString);
            Assert.DoesNotContain("nullPropertyToIgnore", jsonString);
        }
        public void Serialize_ShouldNotIgnoreNull_WhenSerializingPostCursorBody()
        {
            var body = new PostCursorBody
            {
                BindVars = new Dictionary <string, object>
                {
                    ["DontCamelCaseKey"] = null
                }
            };
            var serialization = new JsonNetApiClientSerialization();

            byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(true, true));

            string jsonString = Encoding.UTF8.GetString(jsonBytes);

            Assert.Contains("DontCamelCaseKey", jsonString);
        }
        public void Serialize_ShouldSucceed()
        {
            var model = new TestModel()
            {
                NullPropertyToIgnore  = null,
                PropertyToCamelCase   = "myvalue",
                EnumToConvertToString = TestModel.Number.Two
            };

            var serialization = new JsonNetApiClientSerialization();

            // Perform serialize with camel case option
            byte[] jsonBytesWithCamelCase = serialization.Serialize(model,
                                                                    new ApiClientSerializationOptions(true, true, true));
            string jsonStringWithCamelCase = Encoding.UTF8.GetString(jsonBytesWithCamelCase);

            // Perform serialize without camel case option
            byte[] jsonBytesWithoutCamelCase = serialization.Serialize(model,
                                                                       new ApiClientSerializationOptions(false, true, true));
            string jsonStringWithoutCamelCase = Encoding.UTF8.GetString(jsonBytesWithoutCamelCase);

            // standard property with and without camelCase
            Assert.Contains("propertyToCamelCase", jsonStringWithCamelCase);
            Assert.Contains("PropertyToCamelCase", jsonStringWithoutCamelCase);

            // Null property should be ignored in both cases
            // (ignore case is important to make sure we don't miss the string
            // if it is using different casing than we checked for)
            Assert.DoesNotContain(
                "nullPropertyToIgnore",
                jsonStringWithCamelCase,
                System.StringComparison.OrdinalIgnoreCase);

            Assert.DoesNotContain("nullPropertyToIgnore",
                                  jsonStringWithoutCamelCase,
                                  System.StringComparison.OrdinalIgnoreCase);

            // We expect enum conversion to string, as well as camelCase
            Assert.Contains("enumToConvertToString", jsonStringWithCamelCase);

            // We expect enum conversion to string, but not camelCase
            Assert.Contains("EnumToConvertToString", jsonStringWithoutCamelCase);
        }
Beispiel #8
0
        public void Serialize_ShouldNotCamelCaseBindVars_WhenSerializingPostCursorBody()
        {
            var body = new PostCursorBody
            {
                BindVars = new Dictionary <string, object>
                {
                    ["DontCamelCaseKey"] = new { DontCamelCaseMe = true }
                }
            };
            var serialization = new JsonNetApiClientSerialization();

            byte[] jsonBytes = serialization.Serialize(body, true, true);

            string jsonString = Encoding.UTF8.GetString(jsonBytes);

            Assert.Contains("DontCamelCaseMe", jsonString);
            Assert.Contains("DontCamelCaseKey", jsonString);
            Assert.DoesNotContain("dontCamelCaseMe", jsonString);
            Assert.DoesNotContain("dontCamelCaseKey", jsonString);
        }
        public void Serialize_ShouldSucceed_WhenUsingDefaultOptions()
        {
            var model = new TestModel()
            {
                NullPropertyToIgnore  = null,
                PropertyToCamelCase   = "myvalue",
                EnumToConvertToString = TestModel.Number.Two
            };
            var serialization = new JsonNetApiClientSerialization();

            // Perform serialize with default options
            // i.e. camelCase: false, ignoreNull: true, stringEnum: false
            byte[] jsonBytes  = serialization.Serialize(model, null);
            string jsonString = Encoding.UTF8.GetString(jsonBytes);

            Assert.Contains("PropertyToCamelCase", jsonString);
            Assert.DoesNotContain(
                "NullPropetyToIgnore",
                jsonString,
                System.StringComparison.OrdinalIgnoreCase);
            Assert.Contains("EnumToConvertToString", jsonString);
        }