本文整理汇总了C#中StubViewData类的典型用法代码示例。如果您正苦于以下问题:C# StubViewData类的具体用法?C# StubViewData怎么用?C# StubViewData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StubViewData类属于命名空间,在下文中一共展示了StubViewData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddViewDataDifferentTypes
public void AddViewDataDifferentTypes()
{
mocks.ReplayAll();
var viewData = new StubViewData { { "comment", new Comment { Text = "Hello world" } } };
var viewContext = MakeViewContext("addviewdatadifferenttypes", null, viewData);
Assert.That(() => factory.RenderView(viewContext), Throws.TypeOf<CompilerException>());
mocks.VerifyAll();
}
示例2: AddViewDataDifferentTypes
public void AddViewDataDifferentTypes()
{
mocks.ReplayAll();
var viewData = new StubViewData { { "comment", new Comment { Text = "Hello world" } } };
var viewContext = MakeViewContext("addviewdatadifferenttypes", null, viewData);
factory.RenderView(viewContext);
mocks.VerifyAll();
}
示例3: ExecuteView
private string ExecuteView(StubViewData viewData)
{
var view = (StubSparkView)Activator.CreateInstance(_compiler.CompiledType);
_languageFactory.InstanceCreated(_compiler, view);
view.ViewData = viewData;
var contents = new StringWriter();
view.RenderView(contents);
_languageFactory.InstanceReleased(_compiler, view);
return contents.ToString();
}
示例4: AddViewDataMoreThanOnce
public void AddViewDataMoreThanOnce()
{
mocks.ReplayAll();
var viewData = new StubViewData { { "comment", new Comment { Text = "Hello world" } } };
var viewContext = MakeViewContext("addviewdatamorethanonce", null, viewData);
factory.RenderView(viewContext);
mocks.VerifyAll();
string content = sb.ToString();
Assert.That(content, Contains.InOrder(
"<div>Hello world</div>",
"<div>\r\n Again: Hello world\r\n</div>"));
}
示例5: AlternateViewdataSyntax
public void AlternateViewdataSyntax()
{
mocks.ReplayAll();
var viewData = new StubViewData<IList<string>> { { "my-data", "alpha" } };
viewData.Model = new[] { "beta", "gamma", "delta" };
var viewContext = MakeViewContext("alternate-viewdata-syntax", null, viewData);
factory.RenderView(viewContext);
mocks.VerifyAll();
string content = sb.ToString();
Assert.That(content, Contains.InOrder(
"<p>", "alpha", "</p>",
"<p>", "beta", "</p>",
"<p>", "gamma", "</p>",
"<p>", "delta", "</p>"
));
}
示例6: CacheExpiresTakesOutContentAfterTime
public void CacheExpiresTakesOutContentAfterTime()
{
_viewFolder.Add("home\\index.spark", @"
<viewdata model=""System.Func<string>""/>
<for each='var x in new[]{1,2,3,1,2,3}'>
<cache key='x' expires='System.TimeSpan.FromSeconds(30)'>
<p>${x}:${ViewData.Model()}</p>
</cache>
</for>
<p cache.expires='40'>last:${ViewData.Model()}</p>
");
var calls = 0;
var data = new StubViewData<Func<string>>
{
Model = () => (++calls).ToString()
};
var contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1:1</p>",
"<p>2:2</p>",
"<p>3:3</p>",
"<p>1:1</p>",
"<p>2:2</p>",
"<p>3:3</p>",
"<p>last:4</p>"));
_cacheService.UtcNow = _cacheService.UtcNow.AddSeconds(25);
contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1:1</p>",
"<p>2:2</p>",
"<p>3:3</p>",
"<p>1:1</p>",
"<p>2:2</p>",
"<p>3:3</p>",
"<p>last:4</p>"));
_cacheService.UtcNow = _cacheService.UtcNow.AddSeconds(10);
contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1:5</p>",
"<p>2:6</p>",
"<p>3:7</p>",
"<p>1:5</p>",
"<p>2:6</p>",
"<p>3:7</p>",
"<p>last:4</p>"));
_cacheService.UtcNow = _cacheService.UtcNow.AddSeconds(10);
contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1:5</p>",
"<p>2:6</p>",
"<p>3:7</p>",
"<p>1:5</p>",
"<p>2:6</p>",
"<p>3:7</p>",
"<p>last:8</p>"));
}
示例7: LateBoundEvalResolvesViewData
public void LateBoundEvalResolvesViewData()
{
mocks.ReplayAll();
var viewData = new StubViewData()
{
{"alpha", "<strong>hi</strong>"},
{"beta", "yadda"}
};
var viewContext = MakeViewContext("LateBoundEvalResolvesViewData", null, viewData);
factory.RenderView(viewContext);
mocks.VerifyAll();
string content = sb.ToString();
Assert.That(content, Contains.InOrder(
"<p><strong>hi</strong></p>",
"<p><strong>hi</strong></p>",
"yadda",
"<p>42</p>"));
}
示例8: CommaCreatesMultiPartKey
public void CommaCreatesMultiPartKey()
{
_viewFolder.Add("home\\index.spark",
@"
<viewdata model=""System.Func<string>""/>
<for each='var x in new[]{1,2,3,1,2,3}'>
<p cache='x,xIndex'>${x}:${ViewData.Model()}</p>
</for>");
var calls = 0;
var data = new StubViewData<Func<string>>
{
Model = () => (++calls).ToString()
};
var contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1:1</p>",
"<p>2:2</p>",
"<p>3:3</p>",
"<p>1:4</p>",
"<p>2:5</p>",
"<p>3:6</p>"));
Assert.That(_cacheService.AllKeys.Count(x => x.Substring(32) == "1\u001f0"), Is.EqualTo(1));
Assert.That(_cacheService.AllKeys.Count(x => x.Substring(32) == "2\u001f1"), Is.EqualTo(1));
Assert.That(_cacheService.AllKeys.Count(x => x.Substring(32) == "3\u001f2"), Is.EqualTo(1));
Assert.That(_cacheService.AllKeys.Count(x => x.Substring(32) == "1\u001f3"), Is.EqualTo(1));
Assert.That(_cacheService.AllKeys.Count(x => x.Substring(32) == "2\u001f4"), Is.EqualTo(1));
Assert.That(_cacheService.AllKeys.Count(x => x.Substring(32) == "3\u001f5"), Is.EqualTo(1));
}
示例9: DefaultValuesStandInForNullViewData
public void DefaultValuesStandInForNullViewData()
{
mocks.ReplayAll();
var viewData = new StubViewData();
var viewContext = MakeViewContext("DefaultValuesStandInForNullViewData", null, viewData);
factory.RenderView(viewContext);
mocks.VerifyAll();
string content = sb.ToString();
Assert.IsFalse(content.Contains("default"));
Assert.That(content, Contains.InOrder("ok1", "ok2"));
Assert.IsFalse(content.Contains("fail"));
}
示例10: MakeViewContext
StubViewContext MakeViewContext(string viewName, string masterName, StubViewData data)
{
return new StubViewContext { ControllerName = "Home", ViewName = viewName, MasterName = masterName, Output = sb, Data = data };
}
示例11: MultipleCachesShouldActAsDifferentSite
public void MultipleCachesShouldActAsDifferentSite()
{
_viewFolder.Add("home\\index.spark", @"
<viewdata model=""System.Func<string>""/>
<div>
<cache>
<p>${ViewData.Model()}</p>
</cache>
<cache>
<p>${ViewData.Model()}</p>
</cache>
</div>");
var calls = 0;
var data = new StubViewData<Func<string>>
{
Model = () => (++calls).ToString()
};
var contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>1</p>
<p>2</p>
</div>"));
Assert.That(calls, Is.EqualTo(2));
contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>1</p>
<p>2</p>
</div>"));
Assert.That(calls, Is.EqualTo(2));
}
示例12: CacheInMacroShouldActAsSameSite
public void CacheInMacroShouldActAsSameSite()
{
_viewFolder.Add("home\\index.spark", @"
<viewdata model=""System.Func<string>""/>
<macro name=""foo"">
<cache><p>${ViewData.Model()}</p></cache>
</macro>
<div>
${foo()}
${foo()}
</div>");
int calls = 0;
var data = new StubViewData<Func<string>>
{
Model = () => (++calls).ToString()
};
var contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1</p>",
"<p>1</p>"));
Assert.That(calls, Is.EqualTo(1));
contents = Render("index", data);
Assert.That(contents, Contains.InOrder(
"<p>1</p>",
"<p>1</p>"));
Assert.That(calls, Is.EqualTo(1));
}
示例13: MarkupBasedMacros
public void MarkupBasedMacros()
{
var data = new StubViewData
{
{"username", "Bob"},
{"comments", new[] {
new Comment {Text = "Alpha"},
new Comment {Text = "Beta"},
new Comment {Text = "Gamma"}
}}
};
mocks.ReplayAll();
var viewContext = MakeViewContext("macros", null, data);
factory.RenderView(viewContext);
mocks.VerifyAll();
string content = sb.ToString();
Assert.That(content, Contains.InOrder(
"<p>Bob</p>", "<p>Alpha</p>",
"<p>Bob</p>", "<p>Beta</p>",
"<p>Bob</p>", "<p>Gamma</p>",
"<span class=\"yadda\">Rating: 5</span>"));
}
示例14: TemplateDoesNotRunThroughCacheHit
public void TemplateDoesNotRunThroughCacheHit()
{
_viewFolder.Add("home\\index.spark", @"
<viewdata model=""System.Func<string>""/>
<div>
<cache key='string.Empty'>
<p>${ViewData.Model()}</p>
</cache>
</div>");
int calls = 0;
var data = new StubViewData<Func<string>>
{
Model = () => (++calls).ToString()
};
var contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>1</p>
</div>"));
Assert.That(calls, Is.EqualTo(1));
contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>1</p>
</div>"));
Assert.That(calls, Is.EqualTo(1));
}
示例15: SignalWillExpireOutputCachingEntry
public void SignalWillExpireOutputCachingEntry()
{
_viewFolder.Add("home\\index.spark", @"
<viewdata model=""System.Func<string>"" datasignal='Spark.ICacheSignal'/>
<div>
<cache key='string.Empty' signal='datasignal'>
<p>${ViewData.Model()}</p>
</cache>
</div>");
var signal = new CacheSignal();
var calls = 0;
var data = new StubViewData<Func<string>>
{
Model = () => (++calls).ToString()
};
data["datasignal"] = signal;
var contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>1</p>
</div>"));
Assert.That(calls, Is.EqualTo(1));
contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>1</p>
</div>"));
Assert.That(calls, Is.EqualTo(1));
signal.FireChanged();
contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>2</p>
</div>"));
Assert.That(calls, Is.EqualTo(2));
contents = Render("index", data);
Assert.That(contents, Is.EqualTo(@"
<div>
<p>2</p>
</div>"));
Assert.That(calls, Is.EqualTo(2));
}