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

            return(this);
        }
Exemplo n.º 2
0
        public async Task ReadFromMessagePackAsync_Generic_Test()
        {
            var content = MessagePackContent.Create(SimpleType.Create(), _options);

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

            model.Verify();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }