Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts

Wednesday, April 18, 2012

Smart device/.NET CF unit testing: No mocking

Seeing as the .NET Compact Framekwork does not have/support any mocking frameworks available for unit testing, here's a reference for writing your own stubs to fake out your external dependencies when unit testing smart device projects:

http://elegantcode.com/2009/04/29/unit-testingmocking-on-net-cf/

Smart device unit testing: deploying additional resources

A handy reference with different ways of deploying additional resources (e.g. sdf files) to the device/emulator for smart device unit test projects:

http://blogs.msdn.com/b/prativen/archive/2008/02/05/deployment-in-smart-device-unit-tests.aspx

Thursday, April 12, 2012

Unit testing smart device projects - TestContext error

A couple of days ago I started creating unit tests for a Windows Mobile smart device project that I have been working on in Visual Studio 2008. I generated a unit test method for one of the methods in one of the classes and attempted to run the test. This is when I ran into an error that took me several hours to solve, so hopefully posting this helps someone.

The test method failed to run due to the following error:

Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'


Googling the error returned results that suggested it was caused by upgrading a test project from Visual Studio 2005 format to 2008, and that the reference to the UnitTestFramework.dll was still for the old version (8.0) and required updating. This did not apply to me as I had not upgraded my test project from VS2005. So I continued searching.

After hours of searching for other causes for the error without success, I stumbled upon the following references in the smart device project:

Microsoft.WindowsMobile.dll
Microsoft.WindowsMobile.Status.dll

Visual Studio was obtaining these references from the following folder:

C:\Program Files\Windows Mobile 5.0 SDK R2\Managed Libraries

However, the smart device project's target platform was the Windows Mobile 6 Professional SDK. I didn't notice this before as I did not originally create the smart device project. So I removed the references to the two DLLs and readded them from the following folder:

C:\Program Files\Windows Mobile 6 SDK\Managed Libraries

After rebuilding the smart device project, running the test method succeeded.

Wednesday, April 27, 2011

Visual Studio Smart Device Projects build slowly

If you are developing a smart device application using either Visual Studio 2005 or 2008, you may be experiencing extremely slow build times every time you make a code change. This can be very frustrating when all you want to do is continually build, deploy and debug. It is most likely that the slow build is being caused by the platform verification task (PVT), which is a post-build task that runs by default. More information can be found here on what the PVT is and why it is required. You can however disable it temporarily as it is not required to be run every time you build your smart device application.

To disable the PVT, you can perform the following steps.
  1. Open the file %windir%\Microsoft.NET\Framework\v2.0.50727\Microsoft.CompactFramework.Common.targets (if using Visual Studio 2005) or %windir%\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets (if using Visual Studio 2008) for editing.
  2. Go to the line which reads:
    ...
    
  3. Change it to:
    ...
    
  4. Add the SkipPlatformVerification environment variable to the system and set it to "true" (To re-enable Platform Verification set the environment variable to "false").
  5. Restart Visual Studio for the changes to take effect (If building from the command line using MSBuild, add /p:SkipPlatformVerification=true to your command line to turn off the task. You can specify the variable in the project file also, so that this information is persisted across sessions).

Source: Visual Studio For Devices blog

Monday, November 15, 2010

IIS7 configuration for hosting WCF services

I have recently been learning about Windows Communication Foundation Services and when I first tried to host a service in IIS7, I encountered the following error when attempting to navigate to the service URL:
HTTP Error 404.3 – Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. Detailed Error InformationModule StaticFileModule.
This error is caused by enabling IIS after Visual Studio 2008/2010 and the .NET 3.5/4.0 Framework were installed.  To rectify this:

  1. Open the Visual Studio command prompt as "Administrator".
  2. Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.
  3. Run the following command: servicemodelreg –i.
After performing the above steps, navigating to the service URL returned the following error:
HTTP Error 500.21 - Internal Server Error
Handler "svc-Integrated" has a bad module "ManagedPipelineHandler" in its module list
As I had enabled IIS after installing Visual Studio and the .NET Framework, ASP.NET had to be registered in IIS:

  1. Open the Visual Studio command prompt as "Administrator".
  2. Navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319.
  3. Run the following command: aspnet_regiis -i
I was then able to successfully load the WCF service URL.

Thursday, May 13, 2010

Visual Studio 2010, Crystal Reports, GAC... ARGHH!

I wrestled with this issue along with my workmate for quite a few hours, so hopefully this helps someone out there.

With the recent release of Visual Studio 2010, we took the opportunity to install it at work and migrate our solution across from Visual Studio 2008. We decided to leave Visual Studio 2008 installed as you can have side by side installations of 2008 and 2010. After installation was complete, we managed to get our solution and its projects converted successfully. We thought everything was going well, and it was up till this point...

We then went to build the solution and this was when Visual Studio 2010 started complaining that it could not find the Crystal Report assemblies that our projects reference. There was that big fat ugly exclamation mark in a yellow triangle icon next to each of the Crystal assemblies in the reference list. Visual Studio could not find any of the Crystal Report XI Release 2 assemblies in the GAC, even though they were there.

Perplexed, we searched the internet for a solution but could not find anything documenting our problem. Eventually, we realised that there was an entry in Add/Remove Programs called "Crystal Reports Basic for Visual Studio 2008". This must have been installed with Visual Studio 2008. Upon uninstalling this and reopening our solution in Visual Studio 2010, the Crystal assemblies were all detected in the GAC by the projects.