public void WriteCreatesDeterministicWriterWithCorrectEncoding()
        {
            const string funnyCharacters = "úĀąü";
            ISparkRenderer renderer = new StubSparkRendererThatWritesStuff(funnyCharacters);
            SparkCodec sparkCodec = new SparkCodecBuilder().With(renderer).Build();
            var httpEntity = MockRepository.GenerateStub<IHttpEntity>();
            var stream = new MemoryStream();
            Assert.That(stream.CanRead, Is.True);
            httpEntity.Stub(x => x.Stream).Return(stream);

            sparkCodec.WriteTo(null, httpEntity, new[] { "a", "b" });

            stream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(stream, new UTF8Encoding());
            Assert.That(reader.ReadToEnd(), Is.EqualTo(funnyCharacters));
        }
        public void WriteWritesToStreamIfHttpEntityDoesNotSupportTextWriter()
        {
            const string expectedContents = "abcdefg";
            var          renderer         = new StubSparkRendererThatWritesStuff(expectedContents);
            SparkCodec   sparkCodec       = new SparkCodecBuilder().With(renderer).Build();

            var httpEntity = MockRepository.GenerateStub <IHttpEntity>();
            var stream     = new MemoryStream();

            httpEntity.Stub(x => x.Stream).Return(stream);

            sparkCodec.WriteTo(null, httpEntity, new[] { "a", "b" });

            stream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(stream);

            Assert.That(reader.ReadToEnd(), Is.EqualTo(expectedContents));
        }
        public void WriteCreatesDeterministicWriterWithCorrectEncoding()
        {
            const string   funnyCharacters = "úĀąü";
            ISparkRenderer renderer        = new StubSparkRendererThatWritesStuff(funnyCharacters);
            SparkCodec     sparkCodec      = new SparkCodecBuilder().With(renderer).Build();
            var            httpEntity      = MockRepository.GenerateStub <IHttpEntity>();
            var            stream          = new MemoryStream();

            Assert.That(stream.CanRead, Is.True);
            httpEntity.Stub(x => x.Stream).Return(stream);

            sparkCodec.WriteTo(null, httpEntity, new[] { "a", "b" });

            stream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(stream, new UTF8Encoding());

            Assert.That(reader.ReadToEnd(), Is.EqualTo(funnyCharacters));
        }
        public void WriteWritesToStreamIfHttpEntityDoesNotSupportTextWriter()
        {
            const string expectedContents = "abcdefg";
            var renderer = new StubSparkRendererThatWritesStuff(expectedContents);
            SparkCodec sparkCodec = new SparkCodecBuilder().With(renderer).Build();

            var httpEntity = MockRepository.GenerateStub<IHttpEntity>();
            var stream = new MemoryStream();
            httpEntity.Stub(x => x.Stream).Return(stream);

            sparkCodec.WriteTo(null, httpEntity, new[]{"a", "b"});

            stream.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(stream);
            Assert.That(reader.ReadToEnd(), Is.EqualTo(expectedContents));
        }