tag:blogger.com,1999:blog-64091354051128301052024-02-07T02:52:42.649-07:00The Curly BraceEncounters with the .NET Framework and moreMike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.comBlogger76125tag:blogger.com,1999:blog-6409135405112830105.post-72162720588993554502014-04-03T15:51:00.003-06:002014-04-03T15:51:38.705-06:00Removal of Windows Services Fails? Use the Correct Version of InstallUtil.exeThis is a narrative, following my resolution to removing a stubborn service that simply wouldn't let go.<br />
<br />
Today, I tried using the <i>Developer Command Prompt for VS2013</i> running as administrator, to remove a Windows Service I was developing in Visual Studio 2013 and testing on my workstation. Instead of removing the service, all I got was this lousy T-shirt. And this exception:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">Exception occurred while initializing the installation:</span><br />
<span style="font-family: Courier New, Courier, monospace;">System.BadImageFormatException: Could not load file or assembly 'file:///C:\Dev\ ... \MyService.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.</span></blockquote>
Huh. That's weird. The project was started in Visual Studio 2012 and not 2013. So, I tried using the Developer Command Prompt for VS2012 running ad Administrator; sometimes that will fix the issue. I launched it, and typed (well, copied and pasted):<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">cd "C:\Dev\ ... \Release"<br />installutil /u MyService.exe</span></blockquote>
Nope! I got the command displays an error identical to the first. I tossed this second T-shirt on my pile of conference shirts, and stepped back from the problem. So, if it isn't the .NET Framework version, and the path is definitely correct, <i>something else</i> must be different. I looked up the InstallUtil.exe in the usual place, in Windows Explorer:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">C:\Windows\Microsoft.NET\Framework\v4.0.30319</span></blockquote>
But, then something caught my eye. The "Framework64" directory. Ah. Because my Windows Service is to be executed on a server, I targeted the x64 CPU instruction set in the build profile. In the developer command prompt window, I typed:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319</span><span style="font-family: Courier New, Courier, monospace;">installutil /u "C:\Dev\ ... \MyService.exe"</span></blockquote>
The utility happily complied, and I am free of the service.<br />
<br />
<b>Moral of the story:</b><br />
You must use the proper x86 or x64 utilities, to match the target platform of the binary files.Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-81533780397006012232014-03-27T11:41:00.001-06:002014-03-27T11:41:38.076-06:00Resolve Visual Studio Project Mismatch Between Processor Architecture<h2>
The Problem</h2>
Starting in Visual Studio 2012, you may have seen this .NET Framework compiler warning (it is not an error):<br>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference [project path], "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.</span></blockquote>
This is easy to resolve! The warning means one of two things:<br>
<br>
<ol>
<li>The target CPU platform (x86, x64, Itanium, etc.) of one or more projects does not match the others</li>
<li>A referenced resource (DLL) is compiled for a different CPU platform than the referring project</li>
</ol>
<div>
Fixing the problem is easy:</div>
<div>
<ol>
<li>Ensure all projects in the solution are set to the same CPU platform target</li>
<li>Ensure projects referencing DLL files are set to the same CPU platform as the DLL</li>
</ol>
<h2>
Troubleshooting</h2>
</div>
<div>
</div><a href="http://thecurlybrace.blogspot.com/2014/03/resolve-visual-studio-project-mismatch.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com3tag:blogger.com,1999:blog-6409135405112830105.post-67444018755113041432013-11-19T13:30:00.000-07:002013-11-19T13:30:00.990-07:00Entity Framework 5 to 6.0.1 Upgrade SqlProviderServices ExceptionToday, I decided to update my Entity Framework (EF) 5.0 NuGet packages to EF 6.0.1. No problem updating; NuGet did its duty, as usual. However, a great number of the Model project tests failed, and executing the application threw an exception, as expected:<br>
<br>
<blockquote class="tr_bq">
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider </span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. </span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">See http://go.microsoft.com/fwlink/?LinkId=260882 for more information</span>.</blockquote>
</blockquote>
<br>
As usual, the link provided minimal assistance. With a little prodding, I found a workaround for the issue.<br>
<br>
<b>The goal of this post is to make as few modifications to the code base as possible, to make the EF5 to EF6 upgrade.</b> Sure, there are some differences between EF5 and EF6 implementation, but we're ignoring that for now. EF6 does not require data provider configurations in the App.config file. The new ProviderService types, embedded in the System.Data.Entity.(ProviderName) namespace does this for us. But, these are the objects giving us trouble. First things first...<br>
<a href="http://thecurlybrace.blogspot.com/2013/11/entity-framework-5-to-601-upgrade.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com5tag:blogger.com,1999:blog-6409135405112830105.post-38093629771981461372013-07-22T00:14:00.004-06:002013-07-22T00:14:50.018-06:00Versioning RESTful ServicesAs I was explaining Representational State Transfer (<a href="http://en.wikipedia.org/wiki/RESTful" target="_blank">REST</a>ful) Service Oriented Architecture (<a href="http://en.wikipedia.org/wiki/Service_Oriented_Architecture" target="_blank">SOA</a>) to my customer, who require extensive modernization of an enterprise class system, they asked a very good question:<br>
<blockquote class="tr_bq">
"Things change over time. If everything is service based, how do we handle versioning of the services, without client disruption. When one applications suddenly requires different information, we can't update all of the other client applications just to accommodate the needs of the one. We also should not be duplicating services fo every client that needs something slightly different."</blockquote>
Excellent question! There are myriad reasons to update a service, but only three major courses of action to follow. One of the three will be a best fit for each situation. Sometimes, things are just that easy. The options are few; because, the ultimate goal is to maintain integrity of the URLs. You simply don't want your service URLs changing, for many reasons into which I will not delve in this post. (If you are reading this post, you should know well enough to be nodding in agreement, anyway.)<br>
<br>
To be clear, this post covers RESTful services, such as <a href="http://en.wikipedia.org/wiki/Web_API" target="_blank">Web API</a>, and not traditional WISDL-based <a href="http://en.wikipedia.org/wiki/Web_services" target="_blank">Web Services</a> or object serialization proxy services, like <a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation" target="_blank">WCF</a>. No, we're talking true REST.<br>
<a href="http://thecurlybrace.blogspot.com/2013/07/versioning-restful-services.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-26413273971307663692013-04-15T09:51:00.003-06:002013-04-15T09:52:09.252-06:00Visual Studio 2010 Code Compare Line Length LimitationThe default code differencing / compare tool in Visual Studio 2010 contains a bug: lines of code over 4095 characters overrun the buffer and are not evaluated, nor do they appear. What concerns me is that the compare tool did not alert the user that a buffer overrun may have occurred.<br />
<br />
<br />
Today, my colleague noticed a line of edited code missing from the default VS2010 code differencing / compare tool, used to locate changes in source controlled files. The edited line of code simply did not appear in the tool, and had no indication of containing a change.<br />
<br />
Looking at the code in the editor, I noticed it was a wide line. Very wide. 5057 characters wide, to be exact. The code in question was produced by a meat grinder conversion of a legacy system, not only evidenced by this wide line of code, but also that this line was a call to a method that contains 218 input parameters. (Yes, the application actually runs.)<br />
<br />
Inserting a line break after character 4095 confirmed this is a buffer overrun issue; breaking the line at character 4095 causes both lines to appear in the comparison tool, and to be marked as a change.Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-80483788152488908322012-10-17T11:45:00.003-06:002012-10-17T11:46:16.196-06:00How to generate missing Fakes shimsWhile using the Fakes (Moles) isolation framework, you will notice some mscorlib shims are missing, particularly in the System namespace. For example, System.Fakes.ShimEnvironment does not exist. Although these are missing by default, you can request the compiler to generate shims for specific objects. This post provides steps to request Fakes shim generation for System.Environment and an example of implementation.<br>
<br>
This tutorial targets Microsoft Fakes Isolation Framework on Visual Studio 2012 Ultimate or later; but, this process is also compatible with the developmental version, project name "Moles", running on Visual Studio 2008 or 2010. This tutorial assumes you have basic understanding of the MSTest framework.<br>
<a href="http://thecurlybrace.blogspot.com/2012/10/how-to-generate-missing-fakes-shims.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com6tag:blogger.com,1999:blog-6409135405112830105.post-58805010709317226472012-09-20T08:54:00.004-06:002012-09-24T09:53:45.962-06:00Fakes added to Moles postsToday, I am (finally) starting to update all of my posts on use of the Moles Isolation Framework to its official release version, called "Fakes Framework", included in <a href="http://www.microsoft.com/visualstudio/eng/downloads" target="_blank">Visual Studio 2012 Ultimate</a> and newer.<br />
<br />
To learn how to use both Moles and Fakes, click the "<a href="http://thecurlybrace.blogspot.com/p/unit-testing-with-fakes-and-moles.html" target="_blank">Unit Testing with Fakes/Moles Framework</a>" link, below the page title on this blog. Please bear with me, while I get the information updated. I am very glad to see Moles come to market!Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-20697397222799936892012-08-16T12:15:00.000-06:002012-09-24T09:53:26.398-06:00What To Do When Windows Service Will Not Delete<br />
When a service is removed from any Microsoft Windows operating system, to date, the system must be rebooted, to completely remove the service. After restarting the operating system, the service entry should be deleted. If the service still appears in the Services MMC, or a "specified service already exists" error is displayed upon installing a fresh copy of the service, you'll probably need to tweak the registry, to manually remove the service key.<br />
<br />
<b><span style="color: red;">BE VERY CAREFUL, WHEN EDITING THE SYSTEM REGISTRY!</span></b><br />
<br />
<ol>
<li>Execute regedit.exe</li>
<ol>
<li>Windows Vista/2008 and newer: type "regedit" in the start menu search box</li>
<li>Older versions: click the "Run" option, located in the start menu</li>
</ol>
<li>Press the Enter key, to launch</li>
<li>Back up your registry</li>
<ol>
<li>Click file menus: File > Export...</li>
<li>Select a location to save the registry backup file</li>
<li>Click the Save button</li>
</ol>
<li>Using the tree menu, navigate to: <b>HKEY_LOCAL_MACHINE > SYSTEM> CurrentControlSet > services</b></li>
<li>Locate the child node of "services" that matches the service you need to delete</li>
<li>Press the delete key on the keyboard -- a delete confirmation appears</li>
<li>Click the Yes button, in the delete confirmation -- the registry key is deleted</li>
<li>Close the registry editor</li>
</ol>
<br />Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-8677773883992497072012-08-16T10:56:00.003-06:002012-09-24T09:53:10.236-06:00How To Work Around "Specified Service Already Exists"If you have ever created a Windows Service, you are likely familiar with the "specified service already exists" installation error message. Most developers encounter this situation after making code changes, and attempting to install the updated service, for testing. The problem is that Windows services can not be removed without a system reboot.<br />
<br />
The solution is simple. Install the service for testing, <u>only once</u>. To test newly-compiled changes to the service:<br />
<br />
<ol>
<li>Stop the service</li>
<li>Copy new files into the service installation directory, overwriting the old ones</li>
<li>Start the service</li>
</ol>
<br />
Easy!<br />
<br />
As always, use unit tests, to test code, instead of testing through execution. There is little excuse to not test code, these days. To expedite testing and TDD, I suggest installing <a href="http://www.ncrunch.net/" target="_blank">NCrunch</a> for Visual Studio (<a href="http://www.ncrunch.net/">http://www.ncrunch.net/</a>).Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-74594664480632232182012-03-27T15:46:00.000-06:002012-09-24T09:52:18.121-06:00Creating a Comprehensive Event LoggerWould you rather try to decipher the meaning of an error in the Windows application event log, or ram a fork into the back of your hand? I thought so.<br>
<div>
<br></div>
<div>
The problem with the event logs is they are notoriously uninformative. It seems that their purpose is to taunt IT personnel, by suggesting some helpful information is available. Yeah, right. There are <a href="http://www.eventid.net/">entire Web sites dedicated to deciphering event identification numbers mean</a>. The necessity for such sites is just plain sad. Apparently, leaving what happened a mystery is a better alternative to including actual WORDS that describe the problem, in human language.</div>
<div>
<br></div>
<div>
I implore you: do not be that kind of developer! I always insist on making everything human readable, and easy to understand. By leveraging the extensible nature of .NET, we can easily log useful and meaningful information to the event log, which will help the user or IT administrator fix the problem, and/or help the developer debug the issue.</div>
<div>
<br></div>
<div>
Here's how you can use a single method, to alleviate the IT admin's urge to strangle you.<br>
</div><a href="http://thecurlybrace.blogspot.com/2012/03/creating-comprehensive-event-logger.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-56438916830554879052012-02-28T17:30:00.001-07:002012-09-24T09:52:32.174-06:00Suppress EF Compiler Warnings Error 11007 and 11008I am working on an MVVM project that parses records out of encrypted data files, on demand. There is no real data source for this project, for Entity Framework 4.1 to reference. Every time I build the model assembly, I get a huge pile of warnings for Error 11007 and 11008.<br>
<br>
Because I am a savvy developer (and slightly obsessive-compulsive), I don't want to see any compiler warnings after a build. Because I know these are non-issue warnings, I can safely disable them. Here's how to disable EF warnings in your projects:<br>
<a href="http://thecurlybrace.blogspot.com/2012/02/suppress-ef-compiler-warnings-error.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com3tag:blogger.com,1999:blog-6409135405112830105.post-53851006936882534192011-12-15T14:16:00.000-07:002012-09-24T09:50:49.374-06:00Pex and Moles to be Visual Studio 11 Feature SetIn true, "I will neither confirm nor deny" Microsoft fashion, a little bird in Redmond informed me that Pex and Moles will have no further releases, because they are being "productized". Another, larger bird stated, "dependency isolation will be <i>taken care of</i>, in Visual Studio 2012," when I asked if Moles and Pex will be rolled into VS 2012.<br />
<br />
The Visual Studio 2012 community technical preview (CTP) is available for download to anybody. However, the Moles and Pex products are not yet integrated into the application. There are several points of integration the need to be perfected, before adding it.<br />
<br />
Note, <a href="http://www.microsoft.com/visualstudio/11/en-us" target="_blank">this VS11 download</a> is a BETA version, and is incomplete. Many more features are still cooking. Stability is OK, but use it at your own risk! <b>Visual Studio 2012 Beta will (should) receive updates from Microsoft Update, to keep it current with the newest release.</b><br />
<br />
<br />
(This post is extracted from the <i><a href="http://thecurlybrace.blogspot.com/p/testing-with-microsoft-pex-moles.html">Testing with Microsoft Pex and Moles</a></i> page of this blog. I felt this information was worth putting in its own post, after sitting in a sidebar, since May 2011.)<br />
<br />
<b>UPDATE:</b> Changed the link and name to reflect the Beta release.Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-70348875742511031872011-12-15T13:56:00.004-07:002012-09-24T09:49:22.856-06:00How To Mole the System AssemblyThe System namespace may be moled, in addition to any other child namespace. For instance, you may want to detour calls away from <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">System.StringComparer</span>, which is a member of the System assembly. To mole members of the .NET Framework "System" namespace, follow these four steps:<br>
<a href="http://thecurlybrace.blogspot.com/2011/12/how-to-mole-system-assembly.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-8365664254536392112011-11-22T13:37:00.001-07:002012-09-24T09:49:58.989-06:00How To Detour a Static ConstructorStatic constructors pose a challenge. Naturally, one can not call the constructor of a static class. This also means that the Moles Framework does not provide an accessor to detour the constructor of a static class. However, Moles provides a way to erase static constructors, to prevent them from executing. Simply add the MolesDisableStaticConstructor assembly attribute to the test class:<br />
<br />
<pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: gray; border-bottom-style: solid; border-bottom-width: 1px; border-left-color: gray; border-left-style: solid; border-left-width: 1px; border-right-color: gray; border-right-style: solid; border-right-width: 1px; border-top-color: gray; border-top-style: solid; border-top-width: 1px; font-family: Consolas; font-size: 13px; padding-bottom: 5pt; padding-left: 5pt; padding-right: 5pt; padding-top: 5pt;">[<span style="color: blue;">assembly</span>: <span class="Apple-style-span" style="color: #2b91af;">MolesEraseStaticConstructor</span>(<span style="color: blue;">typeof</span>(MyStatic))]</pre>
Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com1tag:blogger.com,1999:blog-6409135405112830105.post-40398195357278729272011-11-15T10:45:00.001-07:002012-09-24T09:50:17.061-06:00Partial StubsPartial stubs are used when you want to stub only some of the members of a stub <span class="Apple-style-span" style="background-color: lime;">or mole type</span>, and allow the others to fall through to their original code. This is useful, when only some of the members of a class handle a dependency object, but not others. After all, the purpose of Moles is to isolate dependencies. It is always best to leave the smallest footprint possible, when dealing with isolation.<br />
<br />
(SeeMike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-24744165166389509442011-11-14T07:37:00.001-07:002012-09-24T09:48:18.065-06:00How Do I Detour a Mole Type Constructor?<br>
<b>Please be aware this information is based on Moles version v0.94.51023.0, 10/23/2010, and may not be accurate for prior versions.</b><br>
<br>
Stub type constructors are not able to be detoured; because, they should be instantiated in the test, and have no need to be detoured. Subsequently, no constructor detour appears in the stub type.<br>
<br>
Constructors are located in the mole type root, and are named "Constructor", followed by the argument type names. For example, the following are constructor detours for System.IO.Moles.MFile:<br>
<a href="http://thecurlybrace.blogspot.com/2011/11/how-do-i-detour-mole-type-constructor.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-72443485236222312232011-11-09T19:22:00.003-07:002011-11-22T13:45:28.779-07:00How Do I Write a Detour?If you don't use lambda expressions, take a couple of hours right now to learn it, and vastly improve your skill set. I can wait...<br>
<br>
Now that we all know lambda expressions are simple delegates set to "super easy" mode, you already know how to write a detour! <b>Detours are set the same way in both stub and mole types.</b> You have two options, when detouring a call to a stub or moles type member.<br>
<br>
Granted, these code examples are very simplistic, but you can use these to your advantage. See the <b>Tricks With Detours</b> section of the <a href="http://thecurlybrace.blogspot.com/p/testing-with-microsoft-pex-moles.html">Testing With Microsoft Pex and Moles</a> page, for some ideas.<br>
<a href="http://thecurlybrace.blogspot.com/2011/11/how-do-i-write-detour.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-42384748646357945332011-11-09T08:02:00.001-07:002011-11-09T08:32:13.778-07:00Why Are Moles Assemblies Still Added To My Project?Most people using moles, like <a href="http://stackoverflow.com/questions/6504741/why-does-moles-keep-getting-readded-to-my-project" target="_blank">Dave</a>, encounter the situation where they want to remove Moles from the project. You delete the hidden MolesAssemblies folder, but Moles just won't go away! How do you remove moles from a project?<br>
<a href="http://thecurlybrace.blogspot.com/2011/11/why-are-moles-assemblies-still-added-to.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-81013477237754273962011-11-09T07:05:00.000-07:002011-11-09T08:31:53.174-07:00When Do I Use a Stub or Mole Type?Give preference to Stub types. Using a stub type helps you adhere to sound architecture principles, when writing new code and/or using <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">Test Driven Development (TDD)</a>.<br>
<br>
<a href="http://thecurlybrace.blogspot.com/2011/11/when-do-i-use-stub-or-mole-type.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-9332577341564976232011-11-09T06:51:00.000-07:002011-11-09T08:31:18.519-07:00What Are Mole and Stub Types?<br>
Moles generates two types, in the Moles assemblies: Mole types and Stub types. Both behave very much the same, but are are used in mutually exclusive situations. See page 3 of the <a href="http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf" target="_blank">Moles Reference Manual</a>, for more information on stub and mole types.<br>
<br>
An important concept often overlooked by developers investigating the Moles Framework is that the mole and Stub types may be configured with frequently-used detours, in a private, parameterized test class method. This allows you to centralize the setting of frequently-used values, and therefore adhering to the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" target="_blank">DRY principle</a>.<br>
<a href="http://thecurlybrace.blogspot.com/2011/11/what-are-mole-and-stub-types.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-89198127276306935242011-11-02T19:25:00.002-06:002011-11-09T08:31:05.351-07:00How Do Moles Detours Work?Moles is a <span id="goog_1256032105"></span><a href="http://en.wikipedia.org/wiki/Dependency_(computer_science)" target="_blank">dependency</a><span id="goog_1256032106"></span> isolation and <a href="http://en.wikipedia.org/wiki/Mock_object" target="_blank">mocking</a> framework. Instead of building mock <a href="http://en.wikipedia.org/wiki/Method_stub" target="_blank">stubs</a> for <a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">dependency injection</a>, Moles allows the programmer to <a href="http://thecurlybrace.blogspot.com/2011/11/what-is-call-detour.html" target="_blank">detour the call</a> to portions of the actual dependency object. So, how does Moles detour calls, without touching the source code?<br>
<br>
<a href="http://thecurlybrace.blogspot.com/2011/11/how-do-moles-detours-work.html#more">Read more »</a>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-44745090530285114192011-11-02T19:05:00.000-06:002011-11-02T19:05:18.209-06:00What is a Call Detour?Detouring a call means the call to the target object (method, property, etc.) is redirected to another object. That other object will be an anonymous method or other method in the test class. Detours are <a href="http://en.wikipedia.org/wiki/Delegates_(programming)" target="_blank">delegates</a>, generally managed through a <a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx" target="_blank">Func< , ></a> object.Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-52670159859228674182011-10-24T07:42:00.001-06:002011-10-24T07:42:29.764-06:00What are .MOLES Files?After clicking the <i>Add Moles Assembly</i> option, in the Solution Explorer context menu, a file with extension .moles is added to the test project. This file contains an instruction for the compiler, that requests a mole assembly to be generated for the specified assembly. Without these files, no moles assemblies will be generated.Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-17436849562132548622011-10-24T07:33:00.003-06:002011-10-28T09:57:05.078-06:00Moles Error Says I Haven't Instrumented a Type. What Does That Mean?There are three possible causes for instrumentation exceptions:<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;"><i>Using</i> Declarations and Assembly Attributes</span></b><br />
You must ensure a <i>MoledType</i> assembly attribute is present, for the type specified by the exception. For example:<br />
<br />
<pre style="background: white; color: black; font-family: Consolas; font-size: 13;">[<span style="color: blue;">assembly</span>: <span style="color: #2b91af;">MoledType</span>(<span style="color: blue;">typeof</span>(System.IO.<span style="color: #2b91af;">File</span>))]
</pre>
<br />
Refer to the <i><a href="http://thecurlybrace.blogspot.com/2011/10/how-do-i-make-my-test-use-moles.html">How Do I Make My Test Use Moles</a></i> post, for more details.<br />
<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;">Mode of Execution</span></b><br />
If you are certain you have included all of the required using declarations and assembly attributes, examine your method of execution. Pex and Moles tests require special instructions to be sent to the compiler, to properly route calls through the Moles assembly. Third party test execution utilities, such as CodeRush, do not provide this supplemental information. A missing instrumentation exception will be thrown, when Pex and Moles tests are executed by CodeRush.<br />
<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;">Unsupported Test Framework</span></b><br />
Pex and Moles support both the Visual Studio and NUnit Test Frameworks. Other frameworks are not supported.Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0tag:blogger.com,1999:blog-6409135405112830105.post-80428977108532090972011-10-24T07:27:00.001-06:002011-10-24T07:27:44.155-06:00Why Doesn't the .Moles Assembly Appear in Solution Explorer?There are two common answers to this question:<div>
<ol>
<li>Compile the test project. The moles assemblies are generated on compile.</li>
<li>Select the project in the Solution Explorer window, and then click the <i>Show All Files</i> button. A hidden folder named <i>MolesAssemblies</i> will appear.</li>
</ol>
<div>
There should be no reason to handle the moles assemblies, since they may be frequently regenerated.</div>
</div>Mike Christianhttp://www.blogger.com/profile/06047891766552913001noreply@blogger.com0