本文整理汇总了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\"}");
}
}
示例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");
}
}
示例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");
}
}
示例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>");
}
示例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>");
}
示例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.");
}
示例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>");
}
示例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>");
}
示例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);
}
示例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>");
}
示例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.");
}
示例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>");
}
示例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>");
}
示例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);
}
示例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>");
}