当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.Should方法代码示例

本文整理汇总了C#中System.IO.StreamReader.Should方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.Should方法的具体用法?C# StreamReader.Should怎么用?C# StreamReader.Should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.Should方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequestCalledTwiceWithSameHostShouldWork

        public void ProcessRequestCalledTwiceWithSameHostShouldWork()
        {
            var host = new DataServiceHostSimulator {AbsoluteRequestUri = new Uri("http://example.com/Customers(1)"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { }};
            var svc = new TestService();
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();
            customerResponse.Should().Contain("Customer");
            customerResponse.Should().Contain("Redmond Way");
            customerResponse.Should().Contain("[email protected]");

            host.ResponseStream = new MemoryStream();
            host.AbsoluteRequestUri = new Uri("http://example.com/Customers(1)/Address");
            // re-attach the host before calling ProcessRequest
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var addressResponse = new StreamReader(host.ResponseStream).ReadToEnd();
            addressResponse.Should().Contain("Redmond Way");
            addressResponse.Should().NotContain("[email protected]");
            addressResponse.Should().NotMatch(customerResponse);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:25,代码来源:HostScenarioTests.cs

示例2: ProcessRequestCalledSecondTimeWithoutAttachHostShouldThrow

        public void ProcessRequestCalledSecondTimeWithoutAttachHostShouldThrow()
        {
            var host = new DataServiceHostSimulator {AbsoluteRequestUri = new Uri("http://example.com/Customers(1)"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { }};
            var svc = new TestService();
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();
            customerResponse.Should().Contain("Customer");
            customerResponse.Should().Contain("Redmond Way");
            customerResponse.Should().Contain("[email protected]");

            host.ResponseStream = new MemoryStream();
            host.AbsoluteRequestUri = new Uri("http://example.com/Customers(1)/Address");
            Action secondRequest = () => svc.ProcessRequest();
            secondRequest.ShouldThrow<InvalidOperationException>();
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:18,代码来源:HostScenarioTests.cs

示例3: Limits_Synchronously

        public void Limits_Synchronously()
        {
            // ARRANGE
            var innerStream = new MemoryStream(Encoding.ASCII.GetBytes("foobar"));
            var stream = new LimitedStream(innerStream, 3);

            // ACT
            var actual = new StreamReader(stream, Encoding.ASCII).ReadToEnd();

            // ASSERT
            actual.Should().Be("foo");
        }
开发者ID:tablesmit,项目名称:SocketToMe,代码行数:12,代码来源:LimitedStreamTests.cs

示例4: It_Reads_Synchronously

        public void It_Reads_Synchronously()
        {
            // ARRANGE
            var buffer = Encoding.ASCII.GetBytes("foobarbaz");
            var innerStream = new MemoryStream(Encoding.ASCII.GetBytes("FOOBAR"));
            var stream = new PartiallyBufferedStream(buffer, 3, 3, innerStream);

            // ACT
            var content = new StreamReader(stream, Encoding.ASCII).ReadToEnd();

            // ASSERT
            content.Should().Be("barFOOBAR");
        }
开发者ID:tablesmit,项目名称:SocketToMe,代码行数:13,代码来源:PartiallyBufferedStreamTests.cs

示例5: JsonPaddingEnabledWithRawValueSpecified

        public void JsonPaddingEnabledWithRawValueSpecified()
        {
            var settings = new ODataMessageWriterSettings {JsonPCallback = "functionName", DisableMessageStreamDisposal = true};
            settings.SetContentType(ODataFormat.RawValue);
            IODataResponseMessage message = new InMemoryMessage {StatusCode = 200, Stream = new MemoryStream()};

            using (var writer = new ODataMessageWriter(message, settings))
            {
                writer.WriteValue(123);
            }

            var responseStream = message.GetStream();
            responseStream.Position = 0;
            var responseString = new StreamReader(responseStream).ReadToEnd();
            responseString.Should().Be("functionName(123)");
            message.GetHeader("Content-Type").Should().StartWith("text/javascript");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:17,代码来源:WriterSmokeTests.cs

示例6: JsonPaddingEnabledWithJsonFormatSpecified

        public void JsonPaddingEnabledWithJsonFormatSpecified()
        {
            var settings = new ODataMessageWriterSettings {JsonPCallback = "functionName", DisableMessageStreamDisposal = true};
            settings.SetContentType(ODataFormat.Json);
            settings.SetServiceDocumentUri(new Uri("http://stuff"));
            IODataResponseMessage message = new InMemoryMessage {StatusCode = 200, Stream = new MemoryStream()};
            var property = new ODataProperty {Name = "PropertyName", Value = "value"};
            
            using (var writer = new ODataMessageWriter(message, settings))
            {
                writer.WriteProperty(property);
            }

            var responseStream = message.GetStream();
            responseStream.Position = 0;
            var responseString = new StreamReader(responseStream).ReadToEnd();
            responseString.Should().Be("functionName({\"@odata.context\":\"http://stuff/$metadata#Edm.String\",\"value\":\"value\"})");
            message.GetHeader("Content-Type").Should().StartWith("text/javascript");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:19,代码来源:WriterSmokeTests.cs

示例7: StreamEncodingRemainsInvariant

        public void StreamEncodingRemainsInvariant()
        {
            var settings = new ODataMessageWriterSettings { JsonPCallback = "functionName", DisableMessageStreamDisposal = true };
            settings.SetServiceDocumentUri(new Uri("http://stuff"));
            StreamWriter streamWriter = new StreamWriter(new MemoryStream(), Encoding.GetEncoding("iso-8859-1"));
            IODataResponseMessage message = new InMemoryMessage { StatusCode = 200, Stream = streamWriter.BaseStream};
            message.SetHeader("Content-Type", "application/json");
            var property = new ODataProperty { Name = "PropertyName", Value = "value" };

            using (var writer = new ODataMessageWriter(message, settings))
            {
                writer.WriteProperty(property);
            }

            var responseStream = message.GetStream();
            responseStream.Position = 0;
            var responseString = new StreamReader(responseStream, Encoding.GetEncoding("iso-8859-1")).ReadToEnd();       
            responseString.Should().Be("functionName({\"@odata.context\":\"http://stuff/$metadata#Edm.String\",\"value\":\"value\"})");
            message.GetHeader("Content-Type").Should().StartWith("text/javascript");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:20,代码来源:WriterSmokeTests.cs

示例8: ResponseStatusCodeIsNotSetOnHostAfterProcessRequestWith404Error

 public void ResponseStatusCodeIsNotSetOnHostAfterProcessRequestWith404Error()
 {
     HandleExceptionArgs exceptionArgs = null;
     var host = new DataServiceHostSimulator { AbsoluteRequestUri = new Uri("http://example.com/invalid"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { exceptionArgs = args; } };
     var svc = new TestService();
     svc.AttachHost(host);
     svc.ProcessRequest();
     //// Astoria Server fails to set IDSH.ResponseStatusCode for custom hosts in an error scenario
     //// The behavior has been this way from V2 of WCF Data Services and on, when this is changed
     //// it will be a breaking change
     host.ResponseStatusCode.Should().Be(0);
     host.ResponseStream.Position = 0;
     var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();
     customerResponse.Should().Contain("Resource not found for the segment 'invalid'.");
     exceptionArgs.ResponseStatusCode.Should().Be(404);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:HostScenarioTests.cs


注:本文中的System.IO.StreamReader.Should方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。