Ejemplo n.º 1
0
        public void it_seeks_its_underlying_stream_to_its_start_when_open_is_invoked()
        {
            var fakeStore = MockRepository.GenerateMock<Stream>();
            var body = new Body(fakeStore);

            body.Open();

            fakeStore.AssertWasCalled(it => it.Seek(0, SeekOrigin.Begin), options => options.
                Repeat.Once().
                Message("Expected it to seek its underlying stream to its beginning")
            );
        }
Ejemplo n.º 2
0
        public void it_closes_its_underlying_stream()
        {
            var fakeStore = MockRepository.GenerateMock<Stream>();
            var body = new Body(fakeStore);

            body.Dispose();

            fakeStore.AssertWasCalled(it => it.Close(), options => options.
                Repeat.Once().
                Message("Expected that when a body is disposed of, it closes its underlying stream")
            );
        }
Ejemplo n.º 3
0
        public Body Format(Payload payload)
        {
            var serializedParams = ToQuery(payload);

            var theBytes = Encoding.UTF8.GetBytes(serializedParams);

            var result = new Body(new MemoryStream()) {
                ContentLength = theBytes.Length,
                ContentType = this.ContentType
            };

            var writer = new BinaryWriter(result.Open());
            writer.Write(theBytes);
            writer.Flush();

            return result;
        }
 private String ToText(Body result)
 {
     using (var rdr = new StreamReader(result.Open())) {
         return rdr.ReadToEnd();
     }
 }
Ejemplo n.º 5
0
 private MultipartFormDataBodyBuilder NewBodyBuilder(Body body)
 {
     return new MultipartFormDataBodyBuilder(Boundary, Encoding.UTF8, body.Open());
 }