public TypeConstraintBuilder WithConstraint(string @namespace, string type, bool isExplicit = false)
        {
            this.constraints.Add(new TypeNameConstraint {
                Value = SimpleType.Create(@namespace, type, isExplicit)
            });

            return(this);
        }
Пример #2
0
        public async Task ReadFromMessagePackAsync_Generic_Test()
        {
            var content = MessagePackContent.Create(SimpleType.Create(), _options);

            var model = await content.ReadFromMessagePackAsync <SimpleType>(_options);

            model.Verify();
        }
Пример #3
0
        public async Task PostAsProtoBufAsync_String_UsesProtoBufContent()
        {
            var response =
                await _client.PostAsProtoBufAsync(_uri, SimpleType.Create(), _typeModel, CancellationToken.None);

            var content = Assert.IsType <ProtoBufContent>(response.RequestMessage.Content);

            Assert.Same(_typeModel, content.TypeModel);
        }
Пример #4
0
        public async Task PostAsProtoBufAsync_Uri_WhenOptionsIsNull_UsesProtoBufContentWithDefaultOptions()
        {
            var response =
                await _client.PostAsProtoBufAsync(new Uri(_uri), SimpleType.Create(), CancellationToken.None);

            var content = Assert.IsType <ProtoBufContent>(response.RequestMessage.Content);

            Assert.Same(ProtoBufDefaults.TypeModel, content.TypeModel);
        }
Пример #5
0
        public async Task GetFromProtoBufAsync_Generic_StringUri_Test()
        {
            _handler.ResponseContent = ProtoBufContent.Create(SimpleType.Create(), _typeModel);

            var result =
                await _client.GetFromProtoBufAsync <SimpleType>(_uri, _typeModel, CancellationToken.None);

            Assert.NotNull(result);
            result.Verify();
        }
        public async Task GetFromMessagePackAsync_Generic_StringUri_Test()
        {
            _handler.ResponseContent = MessagePackContent.Create(SimpleType.Create(), _options);

            var result =
                await _client.GetFromMessagePackAsync <SimpleType>(_uri, _options, CancellationToken.None);

            Assert.NotNull(result);
            result.Verify();
        }
Пример #7
0
        public async Task ReadFromMessagePackAsync_Test()
        {
            var content = MessagePackContent.Create(SimpleType.Create(), _options);

            var model = await content.ReadFromMessagePackAsync(typeof(SimpleType), _options);

            var simpleType = Assert.IsType <SimpleType>(model);

            simpleType.Verify();
        }
        public void Create_InputValueInvalidType_ThrowsException()
        {
            var exception = Assert.Throws <ArgumentException>(() =>
                                                              ProtoBufContent.Create(typeof(int),
                                                                                     SimpleType.Create(), RuntimeTypeModel.Default, ProtoBufDefaults.MediaTypeHeader));

            Assert.Contains(
                $"An object of type '{nameof(SimpleType)}' cannot be used with a type parameter of '{nameof(Int32)}'.",
                exception.Message);
        }
Пример #9
0
        public async Task ReadFromProtoBufAsync_Generic_Test()
        {
            var content = new StreamProtoBufHttpContent();

            content.WriteObject(SimpleType.Create(), _typeModel);

            var model = await content.ReadFromProtoBufAsync <SimpleType>(_typeModel);

            model.Verify();
        }
Пример #10
0
        public void Create_Generic_DefaultPropertyValues_Test()
        {
            var inputValue = SimpleType.Create();

            var content = MessagePackContent.Create(inputValue);

            Assert.Same(inputValue, content.Value);
            Assert.Same(typeof(SimpleType), content.ObjectType);
            Assert.Same(MessagePackDefaults.MediaTypeHeader, content.Headers.ContentType);
            Assert.Same(MessagePackDefaults.SerializerOptions, content.SerializerOptions);
        }
Пример #11
0
        public void Create_Generic_Test()
        {
            var inputValue = SimpleType.Create();

            var content = MessagePackContent.Create(inputValue, _options, _mediaType);

            Assert.Same(inputValue, content.Value);
            Assert.Same(typeof(SimpleType), content.ObjectType);
            Assert.Same(_mediaType, content.Headers.ContentType);
            Assert.Same(_options, content.SerializerOptions);
        }
Пример #12
0
        public async Task ReadAsStreamArrayAsync_Test()
        {
            var inputValue = SimpleType.Create();
            var content    = MessagePackContent.Create(inputValue, _options, _mediaType);

            await using var stream = await content.ReadAsStreamAsync();

            var model = await MessagePackSerializer.DeserializeAsync <SimpleType>(stream, _options);

            model.Verify();
        }
        public void Create_Generic_DefaultPropertyValues_Test()
        {
            var inputValue = SimpleType.Create();

            var content = ProtoBufContent.Create(inputValue);

            Assert.Same(inputValue, content.Value);
            Assert.Same(typeof(SimpleType), content.ObjectType);
            Assert.Equal(ProtoBufDefaults.MediaTypeHeader, content.Headers.ContentType);
            Assert.Same(ProtoBufDefaults.TypeModel, content.TypeModel);
        }
        public void Create_Generic_Test()
        {
            var inputValue = SimpleType.Create();

            var content = ProtoBufContent.Create(inputValue, _typeModel, _mediaType);

            Assert.Same(inputValue, content.Value);
            Assert.Same(typeof(SimpleType), content.ObjectType);
            Assert.Equal(_mediaType, content.Headers.ContentType);
            Assert.Same(_typeModel, content.TypeModel);
        }
        public async Task ReadAsStreamArrayAsync_Test()
        {
            var inputValue = SimpleType.Create();
            var content    = ProtoBufContent.Create(inputValue, _typeModel, _mediaType);

            await using var stream = await content.ReadAsStreamAsync();

            var model = _typeModel.Deserialize <SimpleType>(stream);

            model.Verify();
        }
Пример #16
0
        public async Task ReadFromProtoBufAsync_Test()
        {
            var content = new StreamProtoBufHttpContent();

            content.WriteObject(SimpleType.Create(), _typeModel);

            var model = await content.ReadFromProtoBufAsync(typeof(SimpleType), _typeModel);

            var simpleType = Assert.IsType <SimpleType>(model);

            simpleType.Verify();
        }
        public async Task GetFromMessagePackAsync_StringUri_Test()
        {
            _handler.ResponseContent = MessagePackContent.Create(SimpleType.Create(), _options);

            var result =
                await _client.GetFromMessagePackAsync(_uri, typeof(SimpleType), _options, CancellationToken.None);

            Assert.Contains(MessagePackDefaults.MediaTypeHeader, _handler.Request.Headers.Accept);
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
Пример #18
0
        public async Task GetFromProtoBufAsync_Uri_Test()
        {
            _handler.ResponseContent = ProtoBufContent.Create(SimpleType.Create(), _typeModel);

            var result =
                await _client.GetFromProtoBufAsync(new Uri(_uri), typeof(SimpleType), _typeModel,
                                                   CancellationToken.None);

            Assert.Contains(ProtoBufDefaults.MediaTypeHeader, _handler.Request.Headers.Accept);
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
        public async Task WriteToStreamAsync_WritesSimplesType()
        {
            // Arrange
            var input   = SimpleType.Create();
            var content = new StreamMessagePackHttpContent();

            // Act
            await _formatter.WriteToStreamAsync(typeof(SimpleType), input, content.Stream, content, _context);

            // Assert
            var result = await content.ReadObjectAsync <SimpleType>(_serializerOptions);

            result.Verify();
        }
        public async Task PutAsync_SimpleType()
        {
            // Act
            var response = await Client.PutAsync("/json-formatter", SimpleType.Create(), _formatter);

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsAsync <SimpleType>(new[] { _formatter });

            // Assert
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
        public async Task WriteToStreamAsync_WritesSimpleType()
        {
            // Arrange
            var input = SimpleType.Create();

            // Act
            await _formatter.WriteToStreamAsync(typeof(SimpleType), input, _content.Stream, _content, _context);

            // Assert
            var result = await _content.ReadObjectAsync <SimpleType>();

            Assert.NotEqual(0, _content.Headers.ContentLength);
            result.Verify();
        }
        public async Task ReadFromStreamAsync_ReadsSimpleTypes()
        {
            // Arrange
            var content = new StreamMessagePackHttpContent();
            await content.WriteObjectAsync(SimpleType.Create(), _serializerOptions);

            // Act
            var result = await _formatter.ReadFromStreamAsync(typeof(SimpleType), content.Stream, content, _logger);

            // Assert
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
        public async Task CopyToAsync_Test()
        {
            var inputValue = SimpleType.Create();
            var content    = ProtoBufContent.Create(inputValue, _typeModel, _mediaType);

            await using var stream = new MemoryStream();

            await content.CopyToAsync(stream);

            stream.Position = 0;

            var model = _typeModel.Deserialize <SimpleType>(stream);

            model.Verify();
        }
        public async Task ReadFromStreamAsync_ReadsSimpleTypes()
        {
            // Arrange
            var input = SimpleType.Create();
            await _content.WriteObjectAsync(input);

            // Act
            var result = await _formatter.ReadFromStreamAsync(typeof(SimpleType), _content.Stream, _content, _logger);

            // Assert
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
Пример #25
0
        public async Task CopyToAsync_Test()
        {
            var inputValue = SimpleType.Create();
            var content    = MessagePackContent.Create(inputValue, _options, _mediaType);

            await using var stream = new MemoryStream();

            await content.CopyToAsync(stream);

            stream.Position = 0;

            var model = await MessagePackSerializer.DeserializeAsync <SimpleType>(stream, _options);

            model.Verify();
        }
Пример #26
0
        public async Task PutAsProtoBufAsync()
        {
            // Arrange
            var input = SimpleType.Create();

            // Act
            var response = await Client.PutAsProtoBufAsync("/protobuf-formatter", input, _typeModel);

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadFromProtoBufAsync <SimpleType>();

            // Assert
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
        public async Task PutAsMessagePackAsync()
        {
            // Arrange
            var input = SimpleType.Create();

            // Act
            var response = await Client.PutAsMessagePackAsync("/msgpack-formatter", input, _options);

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsAsync <SimpleType>(new[] { _formatter });

            // Assert
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
        public async Task Test()
        {
            // Arrange
            var input = SimpleType.Create();

            // Act
            var content  = new ObjectContent <SimpleType>(input, _formatter);
            var response = await Client.PostAsync("/protobuf-formatter", content);

            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsAsync <SimpleType>(new[] { _formatter });

            // Assert
            Assert.NotNull(result);
            var model = Assert.IsType <SimpleType>(result);

            model.Verify();
        }
Пример #29
0
        public async Task PostAsProtoBufAsync_Uri_WhenUriIsNull_ThrowsException()
        {
            var exception =
                await Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                                     _client.PostAsProtoBufAsync(((Uri)null !), SimpleType.Create(), CancellationToken.None));

            Assert.Equal(
                "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.",
                exception.Message);
        }
Пример #30
0
        public async Task PostAsProtoBufAsync_String_WhenClientIsNull_ThrowsException()
        {
            var exception = await Assert.ThrowsAsync <ArgumentNullException>(() =>
                                                                             ((HttpClient)null !).PostAsProtoBufAsync(_uri, SimpleType.Create(), CancellationToken.None));

            Assert.Equal("client", exception.ParamName);
        }