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); }
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 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(); }
public async Task GetFromProtoBufAsync_StringUri_Test() { _handler.ResponseContent = ProtoBufContent.Create(SimpleType.Create(), _typeModel); var result = await _client.GetFromProtoBufAsync(_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 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(); }
/// <inheritdoc /> public override async Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) { if (type is null) { throw new ArgumentNullException(nameof(type)); } if (writeStream is null) { throw new ArgumentNullException(nameof(writeStream)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } var protoBufContent = content as ProtoBufContent ?? ProtoBufContent.Create(value, type, Model); await protoBufContent.CopyToAsync(writeStream).ConfigureAwait(false); content.Headers.ContentLength = protoBufContent.Headers.ContentLength; }