public void ConvertCollectionBytesToReadOnlyByteArray()
        {
            var context = new TestConverterContext("output", typeof(ReadOnlyMemory <byte>[]), _sourceMemoryEnumerable);

            Assert.True(_converter.TryConvert(context, out object target));
            TestUtility.AssertIsTypeAndConvert <ReadOnlyMemory <byte>[]>(target);
        }
        public void ConvertCollectionDoubleToDoubleArray()
        {
            var context = new TestConverterContext("output", typeof(double[]), _sourceDoubleEnumerable);

            Assert.True(_converter.TryConvert(context, out object target));
            TestUtility.AssertIsTypeAndConvert <double[]>(target);
        }
        public void ConvertCollectionSint64ToLongArray()
        {
            var context = new TestConverterContext("output", typeof(long[]), _sourceLongEnumerable);

            Assert.True(_converter.TryConvert(context, out object target));
            TestUtility.AssertIsTypeAndConvert <long[]>(target);
        }
        public void ExactMatch()
        {
            string source  = "abc";
            var    context = new TestConverterContext("input", typeof(string), source);

            Assert.True(_paramConverterManager.TryConvert(context, out object target));
            Assert.Equal(source, target);
        }
        public async Task ConvertCollectionBytesToReadOnlyByteArray()
        {
            var context = new TestConverterContext(typeof(ReadOnlyMemory <byte>[]), _sourceMemoryEnumerable);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);
            TestUtility.AssertIsTypeAndConvert <ReadOnlyMemory <byte>[]>(conversionResult.Value);
        }
        public async Task ConvertCollectionDoubleToDoubleArray()
        {
            var context = new TestConverterContext(typeof(double[]), _sourceDoubleEnumerable);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);
            TestUtility.AssertIsTypeAndConvert <double[]>(conversionResult.Value);
        }
        public void SourceIsNotValidJsonString_ReturnsNull()
        {
            string source  = "invalid string";
            var    context = new TestConverterContext("input", typeof(Book), source);

            Assert.False(_jsonPocoConverter.TryConvert(context, out object target));

            Assert.Null(target);
        }
        public async Task ConversionFailedForInvalidParameterType(object source, Type parameterType)
        {
            var context = new TestConverterContext(parameterType, source);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Unhandled, conversionResult.Status);
            Assert.Null(conversionResult.Value);
        }
        public async Task ConversionFailedForInvalidSourceValue(object source)
        {
            var context = new TestConverterContext(typeof(Guid), source);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Unhandled, conversionResult.Status);
            Assert.Null(conversionResult.Value);
        }
        public void ConvertToString()
        {
            var context = new TestConverterContext("output", typeof(string), _sourceMemory);

            Assert.True(_converter.TryConvert(context, out object target));

            var convertedString = TestUtility.AssertIsTypeAndConvert <string>(target);

            Assert.Equal(_sourceString, convertedString);
        }
        public void ConvertToByteArray()
        {
            var context = new TestConverterContext("output", typeof(byte[]), _sourceMemory);

            Assert.True(_converter.TryConvert(context, out object target));

            var bytes = TestUtility.AssertIsTypeAndConvert <byte[]>(target);

            Assert.Equal(_sourceBytes, bytes);
        }
Example #12
0
        public async Task SourceIsNotValidJsonString_ReturnsNull()
        {
            string source  = "invalid string";
            var    context = new TestConverterContext(typeof(Book), source);

            var conversionResult = await _jsonPocoConverter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Failed, conversionResult.Status);
            Assert.Null(conversionResult.Value);
            Assert.NotNull(conversionResult.Error);
        }
        public async Task ConversionSuccessfulForValidSourceValueAsync(object source, Type parameterType)
        {
            var context = new TestConverterContext(parameterType, source);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);
            var convertedGuid = TestUtility.AssertIsTypeAndConvert <Guid>(conversionResult.Value);

            Assert.Equal(Guid.Parse(source.ToString()), convertedGuid);
        }
        public async Task ConvertToString()
        {
            var context = new TestConverterContext(typeof(string), _sourceMemory);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);
            var convertedString = TestUtility.AssertIsTypeAndConvert <string>(conversionResult.Value);

            Assert.Equal(_sourceString, convertedString);
        }
        public async Task ConvertToByteArray()
        {
            var context = new TestConverterContext(typeof(byte[]), _sourceMemory);

            var conversionResult = await _converter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);
            var bytes = TestUtility.AssertIsTypeAndConvert <byte[]>(conversionResult.Value);

            Assert.Equal(_sourceBytes, bytes);
        }
Example #16
0
        public void SuccessfulConversion()
        {
            string source  = "{ \"Title\": \"a\", \"Author\": \"b\" }";
            var    context = new TestConverterContext("input", typeof(Book), source);

            Assert.True(_jsonPocoConverter.TryConvert(context, out object bookObj));

            var book = TestUtility.AssertIsTypeAndConvert <Book>(bookObj);

            Assert.Equal("a", book.Title);
            Assert.Equal("b", book.Author);
        }
        public void SuccessfulConversion()
        {
            string source  = "{ \"Title\": \"a\", \"Author\": \"b\" }";
            var    context = new TestConverterContext("input", typeof(Book), source);

            Assert.True(_jsonPocoConverter.TryConvert(context, out object bookObj));

            Book book = bookObj as Book;

            Assert.NotNull(book);
            Assert.Equal("a", book.Title);
            Assert.Equal("b", book.Author);
        }
Example #18
0
        public void ConvertMemory()
        {
            string source       = "{ \"Title\": \"a\", \"Author\": \"b\" }";
            var    sourceMemory = new ReadOnlyMemory <byte>(Encoding.UTF8.GetBytes(source));
            var    context      = new TestConverterContext("input", typeof(Book), sourceMemory);

            Assert.True(_jsonPocoConverter.TryConvert(context, out object bookObj));

            var book = TestUtility.AssertIsTypeAndConvert <Book>(bookObj);

            Assert.Equal("a", book.Title);
            Assert.Equal("b", book.Author);
        }
        public void ConvertJsonStringArrayToIEnumerableOfT()
        {
            var source  = "[ \"a\", \"b\", \"c\" ]";
            var context = new TestConverterContext("input", typeof(IEnumerable <string>), source);

            Assert.True(_jsonPocoConverter.TryConvert(context, out object target));

            var targetEnum = TestUtility.AssertIsTypeAndConvert <IEnumerable <string> >(target);

            Assert.Collection(targetEnum,
                              p => Assert.True(p == "a"),
                              p => Assert.True(p == "b"),
                              p => Assert.True(p == "c"));
        }
Example #20
0
        public async Task SuccessfulConversion()
        {
            string source  = "{ \"Title\": \"a\", \"Author\": \"b\" }";
            var    context = new TestConverterContext(typeof(Book), source);

            var conversionResult = await _jsonPocoConverter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);

            var book = TestUtility.AssertIsTypeAndConvert <Book>(conversionResult.Value);

            Assert.Equal("a", book.Title);
            Assert.Equal("b", book.Author);
        }
Example #21
0
        public async Task ConvertMemory()
        {
            string source       = "{ \"Title\": \"a\", \"Author\": \"b\" }";
            var    sourceMemory = new ReadOnlyMemory <byte>(Encoding.UTF8.GetBytes(source));
            var    context      = new TestConverterContext(typeof(Book), sourceMemory);

            var conversionResult = await _jsonPocoConverter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);

            var book = TestUtility.AssertIsTypeAndConvert <Book>(conversionResult.Value);

            Assert.Equal("a", book.Title);
            Assert.Equal("b", book.Author);
        }
Example #22
0
        public void UpdatesExecutionContext()
        {
            var converter = new OutputBindingConverter();

            var context = new TestConverterContext("output", typeof(OutputBinding <string>), null);

            Assert.True(converter.TryConvert(context, out object target));

            var outputBinding = TestUtility.AssertIsTypeAndConvert <OutputBinding <string> >(target);

            outputBinding.SetValue("abc");

            var outputs = context.ExecutionContext.OutputBindings;

            Assert.Equal("abc", outputs["output"]);
        }
Example #23
0
        public async Task ConvertJsonStringArrayToIEnumerableOfT()
        {
            var source  = "[ \"a\", \"b\", \"c\" ]";
            var context = new TestConverterContext(typeof(IEnumerable <string>), source);

            var conversionResult = await _jsonPocoConverter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);

            var targetEnum = TestUtility.AssertIsTypeAndConvert <IEnumerable <string> >(conversionResult.Value);

            Assert.Collection(targetEnum,
                              p => Assert.True(p == "a"),
                              p => Assert.True(p == "b"),
                              p => Assert.True(p == "c"));
        }
Example #24
0
        public void Newtonsoft()
        {
            var options = new WorkerOptions
            {
                Serializer = new NewtonsoftJsonObjectSerializer()
            };

            var wrapper           = new OptionsWrapper <WorkerOptions>(options);
            var jsonPocoConverter = new JsonPocoConverter(wrapper);

            string source  = "{ \"title\": \"a\", \"Author\": \"b\" }";
            var    context = new TestConverterContext("input", typeof(NewtonsoftBook), source);

            Assert.True(jsonPocoConverter.TryConvert(context, out object bookObj));

            var book = TestUtility.AssertIsTypeAndConvert <NewtonsoftBook>(bookObj);

            Assert.Equal("a", book.BookTitle);
            Assert.Equal("b", book.BookAuthor);
        }
        public void JsonArrayToIReadOnlyListOfT()
        {
            // Simulate Cosmos for POCO with case insensitive json
            var source =
                @"[
                    { ""id"": ""1"", ""author"": ""a"", ""title"": ""b"" },
                    { ""id"": ""2"", ""author"": ""c"", ""title"": ""d"" },
                    { ""id"": ""3"", ""author"": ""e"", ""title"": ""f"" }
                  ]";

            var context = new TestConverterContext("input", typeof(IReadOnlyList <Book>), source);

            Assert.True(_paramConverterManager.TryConvert(context, out object target));

            var targetEnum = TestUtility.AssertIsTypeAndConvert <IReadOnlyList <Book> >(target);

            Assert.Collection(targetEnum,
                              p => Assert.True(p.Id == "1" && p.Author == "a"),
                              p => Assert.True(p.Id == "2" && p.Author == "c"),
                              p => Assert.True(p.Id == "3" && p.Author == "e"));
        }
Example #26
0
        public async Task Newtonsoft()
        {
            var options = new WorkerOptions
            {
                Serializer = new NewtonsoftJsonObjectSerializer()
            };

            var wrapper           = new OptionsWrapper <WorkerOptions>(options);
            var jsonPocoConverter = new JsonPocoConverter(wrapper);

            string source  = "{ \"title\": \"a\", \"Author\": \"b\" }";
            var    context = new TestConverterContext(typeof(NewtonsoftBook), source);

            var conversionResult = await jsonPocoConverter.ConvertAsync(context);

            Assert.Equal(ConversionStatus.Succeeded, conversionResult.Status);

            var book = TestUtility.AssertIsTypeAndConvert <NewtonsoftBook>(conversionResult.Value);

            Assert.Equal("a", book.BookTitle);
            Assert.Equal("b", book.BookAuthor);
        }