Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            }
        }