Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch fails for tests using VS2012 Fakes
BKStrelioff
#1 Posted : Monday, April 1, 2013 8:15:54 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/17/2012(UTC)
Posts: 23

Was thanked: 4 time(s) in 4 post(s)
For example, the following tests pass when run under NUnit, but fail under NCrunch:

#region usings

using System;
using System.Fakes;
using System.IO;
using System.Net;
using System.Net.Fakes;
using System.Text;

using Microsoft.QualityTools.Testing.Fakes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace Bks.Framework.Common.Tests
{

/// <summary>
/// </summary>
[ TestClass ]
public class DnsResolverTest
{
#region Instance Public Methods

/// <summary>
/// </summary>
[ TestMethod ]
public void TestMetho01 ( )
{
using ( ShimsContext.Create ( ) )
{
ShimUri.ConstructorString = ( uri, temp ) => // MCrunch says Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException: System.Uri
{
throw new NotImplementedException ( "Not valid in a unit test" );
};

var request = WebRequest.CreateHttp ( "http://msdn.microsoft.com/en-us/library/hh549176.aspx#ShimsContext" );
Assert.IsNotNull ( request );
var response = request.GetResponse ( );
Assert.IsNotNull ( response );
}
}


/// <summary>
/// </summary>
[ TestMethod ]
public void TestMethod1 ( )
{
using ( ShimsContext.Create ( ) )
{
var responseShim = new ShimHttpWebResponse ( );
var requestShim = new ShimHttpWebRequest ( );

ShimWebRequest.CreateString = ( uri ) => requestShim.Instance; // NCrunch says Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException:
requestShim.GetRequestStream = ( ) => new MemoryStream ( );
requestShim.GetResponse = ( ) => responseShim.Instance;
responseShim.GetResponseStream = ( ) => new MemoryStream ( Encoding.ASCII.GetBytes ( "Hello World" ) );
Assert.AreEqual ( "Hello World", GetWebData ( "http://www.bing.com" ) );
}
}

#endregion

#region Private Methods

private string GetWebData ( string baseUrl )
{
var myRequest = ( HttpWebRequest ) WebRequest.Create ( "http://msdn.microsoft.com/en-us/library/hh549176.aspx#ShimsContext" );

var response = myRequest.GetResponse ( );
var responseStream = response.GetResponseStream ( );
var responseReader = new StreamReader ( responseStream );
var result = responseReader.ReadToEnd ( );
return result;
}

#endregion
}

}
Remco
#2 Posted : Monday, April 1, 2013 8:35:09 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Right now, NCrunch doesn't have support for MS Fakes Shims. These shims require a specialised profiler to be loaded into the test environment, which NCrunch unfortunately doesn't handle yet.

Plans exist to introduce support for Fakes as part of NCrunch V2 (due in Q4 this year) - http://www.ncrunch.net/support/frameworks
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.030 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download