public override object ValueAs(Type type, IXmlNamespaceResolver nsResolver) { XmlValueConverter valueConverter = _xmlType.ValueConverter; if (type == typeof(XPathItem) || type == typeof(XmlAtomicValue)) { return(this); } if (_objVal == null) { switch (_clrType) { case TypeCode.Boolean: return(valueConverter.ChangeType(_unionVal.boolVal, type)); case TypeCode.Int32: return(valueConverter.ChangeType(_unionVal.i32Val, type)); case TypeCode.Int64: return(valueConverter.ChangeType(_unionVal.i64Val, type)); case TypeCode.Double: return(valueConverter.ChangeType(_unionVal.dblVal, type)); case TypeCode.DateTime: return(valueConverter.ChangeType(_unionVal.dtVal, type)); default: Debug.Assert(false, "Should never get here"); break; } } return(valueConverter.ChangeType(_objVal, type, nsResolver)); }
public async Task Get_ShouldUseConfiguredValueConverter() { var dto = Fixtures.Dto.SimpleDataContract(); var converter = new XmlValueConverter(); var expected = converter.Write(dto); using (var http = new HttpTest()) { http.RespondWithJson(Fixtures.Key.UpsertResponse(Fixtures.Key.Path, expected)); var client = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri()); client.Configure(x => x.ValueConverter = converter); var response = await client .GetKey(Fixtures.Key.Path); http.Should() .HaveCalled( Fixtures.EtcdUrl .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path) ) .WithVerb(HttpMethod.Get) .Times(1); response.Should().NotBeNull(); response.Data.Should().NotBeNull(); response.Data.RawValue.Should().NotBeNullOrWhiteSpace(); response.Data.RawValue.Should().Be(expected); SimpleDataContractDto responseDto = null; Action getValue = () => responseDto = response.Data.GetValue<SimpleDataContractDto>(); getValue.ShouldNotThrow(); responseDto.Should().NotBeNull(); responseDto.Id.Should().Be(dto.Id); responseDto.Name.Should().Be(dto.Name); } }
public async Task Upsert_ShouldUsedPassedValueConverter() { var dto = Fixtures.Dto.SimpleDataContract(); var converter = new XmlValueConverter(); var expected = converter.Write(dto); using (var http = new HttpTest()) { http.RespondWithJson(Fixtures.Key.DefaultResponse); await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri()) .UpsertKey(Fixtures.Key.Path) .WithValue(dto, converter); http.Should() .HaveCalled( Fixtures.EtcdUrl .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path) ) .WithVerb(HttpMethod.Put) .WithRequestBody(Fixtures.Key.DefaultRequest(expected)) .Times(1); } }