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


C# MemoryStream.ShouldEqual方法代码示例

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


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

示例1: Should_return_a_valid_model_in_json_format

 public void Should_return_a_valid_model_in_json_format()
 {
     using (var stream = new MemoryStream())
     {
         response.Contents(stream);
         stream.ShouldEqual("{\"FirstName\":\"Andy\",\"LastName\":\"Pike\"}");
     }
 }
开发者ID:nathanpalmer,项目名称:Nancy,代码行数:8,代码来源:JsonFormatterExtensionsFixtures.cs

示例2: Should_return_a_valid_model_in_csv_format

 public void Should_return_a_valid_model_in_csv_format()
 {
     using (var stream = new MemoryStream())
     {
         response.Contents(stream);
         stream.ShouldEqual("FirstName,LastName\r\nEmmanuel,Morales");
     }
 }
开发者ID:emmanuelmorales,项目名称:Nancy,代码行数:8,代码来源:CsvFormatterExtensionsFixtures.cs

示例3: Should_return_null_in_json_format

 public void Should_return_null_in_json_format()
 {
     var nullResponse = formatter.AsJson<Person>(null);
     using (var stream = new MemoryStream())
     {
         nullResponse.Contents(stream);
         stream.ShouldEqual("null");
     }
 }
开发者ID:nathanpalmer,项目名称:Nancy,代码行数:9,代码来源:JsonFormatterExtensionsFixtures.cs

示例4: GetCompiledView_should_render_to_stream

        public void GetCompiledView_should_render_to_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                "django",
                new StringReader(@"{% ifequal a a %}<h1>Hello Mr. test</h1>{% endifequal %}")
            );

            var stream = new MemoryStream();

            // When
            var action = engine.RenderView(location, null);
            action.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:patrik-hagne,项目名称:Nancy,代码行数:18,代码来源:NDjangoViewCompilerFixture.cs

示例5: GetCompiledView_should_render_to_stream

        public void GetCompiledView_should_render_to_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                "cshtml",
                new StringReader(@"@{var x = ""test"";}<h1>Hello Mr. @x</h1>")
            );

            var stream = new MemoryStream();

            // When
            var action = this.engine.RenderView(location, null);
            action.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:Ang3lFir3,项目名称:Nancy,代码行数:18,代码来源:RazorViewCompilerFixture.cs

示例6: Include_should_look_for_a_partial

        public void Include_should_look_for_a_partial()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "liquid",
                () => new StringReader(@"<h1>Including a partial</h1>{% include 'partial' %}")
            );

            var stream = new MemoryStream();

            // When
            var response = this.engine.RenderView(location, null, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Including a partial</h1>Some template.");
        }
开发者ID:nicolasgarfinkiel,项目名称:Nancy,代码行数:19,代码来源:DotLiquidViewEngineFixture.cs

示例7: GetCompiledView_should_render_to_stream

        public void GetCompiledView_should_render_to_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "django",
                () => new StringReader(@"{% ifequal a a %}<h1>Hello Mr. test</h1>{% endifequal %}")
            );
            A.CallTo(() => this.renderContext.LocateView(".django", null)).Returns(location);

            var stream = new MemoryStream();

            // When
            var action = engine.RenderView(location, null, this.renderContext);
            action.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:nathanpalmer,项目名称:Nancy,代码行数:20,代码来源:NDjangoViewEngineFixture.cs

示例8: RenderView_should_accept_a_model_and_read_from_it_into_the_stream

        public void RenderView_should_accept_a_model_and_read_from_it_into_the_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "liquid",
                () => new StringReader(@"<h1>Hello Mr. {{ Model.name }}</h1>")
            );

            var currentStartupContext =
                CreateContext(new[] { location });

            this.engine.Initialize(currentStartupContext);
            var stream = new MemoryStream();

            // When
            var response = this.engine.RenderView(location, new { name = "test" }, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:piccoloaiutante,项目名称:Nancy,代码行数:23,代码来源:DotLiquidViewEngineFixture.cs

示例9: RenderView_csharp_should_be_able_to_use_a_using_statement

        public void RenderView_csharp_should_be_able_to_use_a_using_statement()
        {
            // Given
            var view = new StringBuilder()
                .AppendLine("@model Nancy.ViewEngines.Razor.Tests.Models.Person")
                .AppendLine("@using Nancy.ViewEngines.Razor.Tests.Models")
                .AppendLine(@"@{ var hobby = new Hobby { Name = ""Music"" }; }")
                .Append("<h1>Mr. @Model.Name likes @hobby.Name!</h1>");

            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "cshtml",
                () => new StringReader(view.ToString())
            );

            var stream = new MemoryStream();

            var model = new Person { Name = "Jeff" };

            // When
            var response = this.engine.RenderView(location, model, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Mr. Jeff likes Music!</h1>", true);
        }
开发者ID:l3m,项目名称:Nancy,代码行数:27,代码来源:RazorViewEngineFixture.cs

示例10: RenderView_csharp_should_be_able_to_use_a_model_from_another_assembly

        public void RenderView_csharp_should_be_able_to_use_a_model_from_another_assembly()
        {
            // Given
            var view = new StringBuilder()
                .AppendLine("@model Nancy.ViewEngines.Razor.Tests.Models.Person")
                .Append("<h1>Hello Mr. @Model.Name</h1>");

            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "cshtml",
                () => new StringReader(view.ToString())
            );

            var stream = new MemoryStream();

            var model = new Person { Name = "Jeff" };

            // When
            var response = this.engine.RenderView(location, model, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. Jeff</h1>");
        }
开发者ID:l3m,项目名称:Nancy,代码行数:25,代码来源:RazorViewEngineFixture.cs

示例11: Include_should_work_with_double_quotes

        public void Include_should_work_with_double_quotes()
        {
            // Set up the view startup context
            string partialPath = Path.Combine(Environment.CurrentDirectory, @"TestViews\_partial.liquid");

            // Set up a ViewLocationResult that the test can use
            var testLocation = new ViewLocationResult(
                Environment.CurrentDirectory,
                "test",
                "liquid",
                () => new StringReader(@"<h1>Including a partial</h1>{% include ""partial"" %}")
            );

            var partialLocation = new ViewLocationResult(
                partialPath,
                "partial",
                "liquid",
                () => new StringReader(File.ReadAllText(partialPath))
            );

            var currentStartupContext = CreateContext(new [] {testLocation, partialLocation});

            this.engine = new DotLiquidViewEngine(new LiquidNancyFileSystem(currentStartupContext));

            // Given
            var stream = new MemoryStream();

            // When
            var response = this.engine.RenderView(testLocation, null, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Including a partial</h1>Some template.");
        }
开发者ID:JohanObrink,项目名称:Nancy,代码行数:34,代码来源:DotLiquidViewEngineFixture.cs

示例12: RenderView_should_accept_a_model_with_a_list_and_iterate_over_it

        public void RenderView_should_accept_a_model_with_a_list_and_iterate_over_it()
        {
            // TODO - Fixup on Mono
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "liquid",
                () => new StringReader(@"<ul>{% for item in model.Widgets %}<li>{{ item.name }}</li>{% endfor %}</ul>")
            );

            var currentStartupContext = CreateContext(new [] {location});
            this.engine = new DotLiquidViewEngine(new LiquidNancyFileSystem(currentStartupContext));
            var stream = new MemoryStream();

            // When
            var widgets = new List<object> { new { name = "Widget 1" }, new { name = "Widget 2" }, new { name = "Widget 3" }, new { name = "Widget 4" } };
            var response = this.engine.RenderView(location, new { Widgets = widgets }, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<ul><li>Widget 1</li><li>Widget 2</li><li>Widget 3</li><li>Widget 4</li></ul>");
        }
开发者ID:JohanObrink,项目名称:Nancy,代码行数:23,代码来源:DotLiquidViewEngineFixture.cs

示例13: RenderView_should_accept_a_model_and_read_from_it_into_the_stream

        public void RenderView_should_accept_a_model_and_read_from_it_into_the_stream()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "liquid",
                () => new StringReader(@"<h1>Hello Mr. {{ model.name }}</h1>")
            );

            var stream = new MemoryStream();

            // When
            var action = this.engine.RenderView(location, new { name = "test" }, this.renderContext);
            action.Invoke(stream);

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:nathanpalmer,项目名称:Nancy,代码行数:19,代码来源:DotLiquidViewEngineFixture.cs

示例14: should_serialize_to_stream

 public void should_serialize_to_stream(Action<Stream> serialize, Stream output)
 {
     var stream = new MemoryStream();
     serialize(stream);
     stream.Seek(0, SeekOrigin.Begin);
     stream.ShouldEqual(output);
 }
开发者ID:mikeobrien,项目名称:Bender,代码行数:7,代码来源:SaveTests.cs

示例15: should_work_on_multiple_threads

        public void should_work_on_multiple_threads()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "cshtml",
                () =>
                {
                    Thread.Sleep(500);
                    return new StringReader(@"@{var x = ""test"";}<h1>Hello Mr. @x</h1>");
                });

            var wait = new ManualResetEvent(false);

            var stream = new MemoryStream();

            // When
            ThreadPool.QueueUserWorkItem(_ =>
                {
                    var response2 = this.engine.RenderView(location, null, this.renderContext);
                    response2.Contents.Invoke(new MemoryStream());
                    wait.Set();
                });
            var response = this.engine.RenderView(location, null, this.renderContext);
            response.Contents.Invoke(stream);

            wait.WaitOne(1000).ShouldBeTrue();

            // Then
            stream.ShouldEqual("<h1>Hello Mr. test</h1>");
        }
开发者ID:l3m,项目名称:Nancy,代码行数:32,代码来源:RazorViewEngineFixture.cs


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