Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Friday, 25 October 2013

Restricting access to a webservice in ASP.NET

Restricting access to a webservice can be done via web.config but if you would want to make the decision at runtime then here is an example of how you could achieve this
 

protected void Application_BeginRequest(Object sender, EventArgs e)
{
  if (/*Condition*/)
  {
    if (HttpContext.Current.Request.Url.ToString().Contains("Admin.asmx"))
    {
       HttpContext.Current.Response.StatusCode = 404;
    }
   }
}
Genius ain't anything more than elegant common sense.
Josh Billings

Wednesday, 16 October 2013

Mock frameworks for .NET Part 2

As we have already seen the basics of Mock framework, let's look at some of Mock frameworks that are available and understand what they do or don't support.

NMock


Software License Apache License 2.0
Last Active Jul-2011
Latest Version NMock3
Supported .NET Version .NET 4.0
Build Server Integration No
Code Coverate Integration No
Mock Interfaces Yes
Mock Everything No
Mock Legacy Code No
Auto Recursive Fakes No
Fake Dependencies No
Url http://nmock3.codeplex.com/

TypeMock


Software License Commercial
Last Active Jul-2013
Latest Version Isolater 7.4.1
Supported .NET Version .NET 4.0
Build Server Integration Yes (Microsoft TFS, MSBuild, Nant, Final Builder)
Code Coverate Integration Yes (CoverageEye, NCover, PartCover, DevPartner, Clover.NET, ExactMagic's TestMatrix, MSTest Code Coverage (Visual Studio and Team System), dotTrace, ReSharper, AQtime)
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code Yes
Auto Recursive Fakes Yes
Fake Dependencies Yes
Url http://www.typemock.com/isolator-product-page

Rhino Mocks


Software License BSD license
Last Active Jan-2010
Latest Version Rhino Mocks 3.6
Supported .NET Version .NET 3.5
Build Server Integration No
Code Coverate Integration No
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code No
Auto Recursive Fakes No
Fake Dependencies No
Url http://hibernatingrhinos.com/oss/rhino-mocks

Moq


Software License BSD license
Last Active Apr-2011
Latest Version Moq 4.0
Supported .NET Version .NET 3.5
Build Server Integration No
Code Coverate Integration No
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code No
Auto Recursive Fakes No
Fake Dependencies No
Url https://code.google.com/p/moq/

Nsubstitute


Software License BSD license
Last Active Aug-13
Latest Version NSubstitute-1.6.1.0
Supported .NET Version .NET 4.0
Build Server Integration No
Code Coverate Integration No
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code No
Auto Recursive Fakes No
Fake Dependencies No
Url http://nsubstitute.github.io/

JustMock


Software License Full Version - Commercial, Lite - Free
Last Active Oct-2013
Latest Version V 2013.3.1015.0
Supported .NET Version .NET 4.0
Build Server Integration Yes (TFS, CruiseControl.NET, Team City & Jenkins etc)
Code Coverate Integration Yes (NCover, PartCover, JetBrains dotTrace, PostSharp etc)
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code Yes
Auto Recursive Fakes Yes
Fake Dependencies Yes
Url http://www.telerik.com/products/mocking.aspx

FakeItEasy


Software License MIT License
Last Active Oct-2013
Latest Version v 1.13.1
Supported .NET Version .NET 3.5
Build Server Integration No
Code Coverate Integration No
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code No
Auto Recursive Fakes Yes
Fake Dependencies No
Url https://github.com/FakeItEasy/FakeItEasy

Microsoft Flakes


Software License Commercial with Visual Studio
Last Active Mar-2013
Latest Version -
Supported .NET Version .NET 4.0
Build Server Integration No
Code Coverate Integration No
Mock Interfaces Yes
Mock Everything Yes
Mock Legacy Code No
Auto Recursive Fakes No
Fake Dependencies No
Url http://msdn.microsoft.com/en-us/library/hh549175.aspx


Now you should be able to select the right framework that suits your needs.

It's fine to celebrate success but it is more important to heed the lessons of failure.
Bill Gates

Monday, 7 October 2013

Mock frameworks for .NET Part 1

Mock frameworks are used for unit testing your code and are used for Test Driven Development (TDD). A mock framework should support Arrange Act Assert (AAA) pattern. There are various mock frameworks available and choosing the right one is not easy. Before looking at various frameworks available let's understand some basics of what a framework should have to be known as a Mock framework.

Mock Interfaces & abstract classes

Interfaces or Abstract classes allows Mock framework to be able to create stubs, A stub is a small block of code that is replacement of another component or code block. TDD approach of R-G-R (Red-Green-Refactor) is an example where a stub might be useful. In order to make a test successfull (Green), you would need a stub for places where actual definition is either not written or unknown.

Mock Everything in .NET

Able to mock everything in a class, such as
  • mock dependent objects
  • non-virtual methods
  • sealed classes
  • static methods
  • static classes
  • non-public members
  • non-public types

Mock Legacy Code

Assume some legacy code that has got some core business logic but has been designed/coded way before TDD has even started
  • no interfaces
  • no abstract classes
  • has dependencies

Auto Recursive Fakes

Once a mock is created some methods and properties will automatically return non null values such as interfaces, delegate, virtual class etc. This is also known as recursive mock.

Fake Dependencies

If a mock is dependent on another object, framework should allow to either populate or assign dependency so as to make the test succeed. Most of the frameworks will support it by default.

Unit Test Integration

Allow easy integration with unit test tools such as NUnit, MSTest, Xunit etc.

Build Server Integration

Mock framework should allow you to be able to automate unit tests as part of your build & continuous integration. It should be able to support various build servers such as TFS, MSBuild, Nant, CruiseControl.NET etc

Code coverage Integration

Mock framework should allow to be integrated with 3rd party code coverage so as to produce various metrics that can easily point out areas of code that has not been covered by a unit test or has been wrongly written. It should be able to support various 3rd party code coverage software such as NCover, MSTest Code Coverage, ReSharper etc.

All of the these are only related to .net code. The mock framework features that are required for javascript mocking is out of scope of this article. The list of mock frameworks can be seen at Mock frameworks for .NET Part 2

Intelligence is the ability to adapt to change.
Stephen Hawking
Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers