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


C# StubViewData类代码示例

本文整理汇总了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();
 }
开发者ID:pr0nin,项目名称:spark,代码行数:8,代码来源:SparkViewFactoryTester.cs

示例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();
 }
开发者ID:rsmolnikov,项目名称:spark,代码行数:8,代码来源:SparkViewFactoryTester.cs

示例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();
 }
开发者ID:pr0nin,项目名称:spark,代码行数:10,代码来源:PythonViewCompilerTests.cs

示例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>"));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:14,代码来源:SparkViewFactoryTester.cs

示例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>"
                            ));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:18,代码来源:SparkViewFactoryTester.cs

示例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>"));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:61,代码来源:CacheElementTester.cs

示例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>&lt;strong&gt;hi&lt;/strong&gt;</p>",
                            "yadda",
                            "<p>42</p>"));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:19,代码来源:SparkViewFactoryTester.cs

示例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));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:31,代码来源:CacheElementTester.cs

示例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"));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:14,代码来源:SparkViewFactoryTester.cs

示例10: MakeViewContext

 StubViewContext MakeViewContext(string viewName, string masterName, StubViewData data)
 {
     return new StubViewContext { ControllerName = "Home", ViewName = viewName, MasterName = masterName, Output = sb, Data = data };
 }
开发者ID:rsmolnikov,项目名称:spark,代码行数:4,代码来源:SparkViewFactoryTester.cs

示例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));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:35,代码来源:CacheElementTester.cs

示例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));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:32,代码来源:CacheElementTester.cs

示例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>"));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:24,代码来源:SparkViewFactoryTester.cs

示例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));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:29,代码来源:CacheElementTester.cs

示例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));
        }
开发者ID:rsmolnikov,项目名称:spark,代码行数:47,代码来源:CacheElementTester.cs


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