zoukankan      html  css  js  c++  java
  • Asp.net mvc 2 in action笔记 5 MvcContrib 测试和其他

    MvcContrib

    第5章

    MvcContrib Grid 和带进度的文件上载的使用

    MVcContrib是社区开源的asp.net mvc增强和扩展库,如其中的Grid,即可高效的进行设计又可灵活的控制表格的布局[比Web Form 的GridView简化了不少]

    在Codeplex.com上可以找到该项目,上面有文档,特别对于Grid有详细的例子参考,如下图

    例子在MVCContrib.Extras.release.zip中

    以下是帮助[在MVCContrib.release.zip中]

    测试

    在有多个组件协作时,接口已经定义好的情况,如果某个依赖组件如A还没有实现,此时如果要进行依赖于A的程序的测试,此时可以使用测试桩来模拟;另外为了减少组件对于其他资源的依赖,如某个组件依赖数据库同时还需要相关的设置等,此时通过测试桩的方法可以减少依赖的复杂性。

    一个可用的开源库是Rhino Mocks。

    A favorite library for automating the creation of mocks and stubs is Rhino Mocks written by Oren Eini (www.ayende.com/projects/rhino-mocks.aspx).

            [Test]
            public void CacheTest()
            {            
                //setup controller w/ fake cache
                var fakeCache = MockRepository.GenerateStub<ICache>();
                var controller = new HomeController(fakeCache);
     
                //set the cache behavior
                fakeCache.Stub(x => x.Exists("test")).Return(false);
     
                //invoke the action
                controller.CacheTest();            
     
                //the item should have been added to the cache            
                fakeCache.AssertWasCalled(x => x.Add("test", "value"));
     
                //the item should be retrieved from the cache
                fakeCache.AssertWasCalled(x => x.Get<string>("test"));
            }
     
      
            [Test]
            public void SessionTest()
            {
                var controller = new HomeController();
     
                //setup fake session
                var httpContext = MockRepository.GenerateStub<HttpContextBase>();
                var mockSession = MockRepository.GenerateStub<HttpSessionStateBase>();
                httpContext.Stub(x => x.Session).Return(mockSession).Repeat.Any();
     
                //attach fake context/session to controller
                controller.ControllerContext = new ControllerContext(httpContext, new RouteData(), controller);
     
                //invoke action
                controller.ViewCart();
     
                //verify methods were called
                mockSession.VerifyAllExpectations();
            }

    其他

    MS Press的图书Programming Microsoft ASP.NET MVC2,涉及的十分全面,详细讲解了该框架的发展历史和实现分析。

    特别是其中的例子ProgMvc-Samples.zip,具体体现了涉及该框架的各个方面的扩展、定制和使用等各方面,具体参考每个工程下的todo.txt说明。

  • 相关阅读:
    LinkageSel无限级联动下拉菜单
    纯CSS+HTML自定义checkbox效果[转]
    jquery1.9+,jquery1.10+ 为什么不支持live方法了?
    电脑按键混乱,好像被锁定了Alt键
    docker 清理无用的卷
    dotnet core linux 接入支付宝H5支付,提示:System.PlatformNotSupportedException","Message":"'CspParameters' requires Windows Cryptographic API (CAPI), which is not available on this platform.
    【每天学一点Linux】centos7 docker 启动cpu100% 飙升居高不下 无法关机 无法杀死进程
    【每天学一点Linux】centos7修改selinux导致无法开机 Failed to load SELinux policy. Freezing
    webapi HttpGet标签
    强制结束虚拟机 centos home 卷丢失导致无法挂载进入 emergency mode 紧急模式
  • 原文地址:https://www.cnblogs.com/2018/p/2045912.html
Copyright © 2011-2022 走看看