The short answer is: you don’t. You see, having a mocking library at hand (no matter how cool it is) doesn’t automatically make it the best tool for every testing need.
A generic repository is much easier to replace for testing with a simple fake and allows to use simple state-based testing agaist it, rather than mock verifications.
A fairly typical generic repository might look like the following:
public interface IRepository<T> where T : IEntity
{
T Get(Guid id);
void SaveOrUpdate(T entity);
void Delete(T entity);
IQueryable<T> Query();
}
You might use integer or long for IDs, you might not have an IEntity interface but a base class, you might not have a Query feature there, but that’s beside the point. The point is that such an interface, whatever the variations, is trivial to fake:...
Read full article
For this walk-through, you’ll need the most excelent CloudBerry S3 Explorer. Somehow, these guys manage to support in the UI more stuff than Amazon itself does in its management console
. And you only need the free version.
So first the requirements:
- You want to have full control of who and for how long accesses the S3 payloads/objects.
- You want to automatically leverage Amazon’s CloudFront CDN so that customers get the fastest downloads
So here’s how to go about it:
- Create a new bucket in S3 that will serve as the origin for CloudFront. At this point, unless you specify something different, the bucket is private.
- In the CloudBerry S3 Explorer, right-click the bucket, and select CloudFront –> New CloudFront Distribution Wizard
- Choose the kind of delivery for the payloads. In my case, I just picked Download....

Read full article
This is a pretty common request, and the simple answer is available in SO: right after the C# targets import, add the following:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists(\'app.$(Configuration).config\')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>...
Read full article
- Open the folder in the skydrive site using the browser (it would be under Shared menu on the left). The url will look something like: https://skydrive.live.com/?cid=529BD9445B66F60D&id=529BD9445B66F60D%21189#cid=529BD9445B66F60D&id=529BD9445B66F60D%21189. Now the “cid” query parameter in the URL.
- Right-click on Network (in windows explorer), then “Map Network Drive”
- Specify Folder as: https://d.docs.live.net/[cid]/[folder_name]. For the sample URL above, it would be https://d.docs.live.net/529bd9445b66f60d/CQRS (note the folder name isn’t in the URL, you need to know it beforehand, and it has to match what it’s named on the site).
- Check the “Use alternate credentials” option in the dialog:
- Click Finish. Enter your Live ID credentials when asked. Done!
Not everything works that great (i.e. copying large files via drag&drop doesn’t work, renaming folders, etc., at least in my experience), but it’s pretty darn convenient most of the time. I’m not sure the same thing works for your own personal folders. I don’t use SkyDrive at all, but it certainly does for shared ones (nice when you need a simple way to share docs within a team, privately and without requiring any software to be installed for syncing…)....
Read full article
Currently in the .NET world, most OSS projects are available via a NuGet package. Users have a very easy path towards *using* the project right away.
But let’s say they encounter some isssue (maybe a bug, maybe a potential improvement) with the library. At this point, going from user to contributor (of a fix, or a good bug repro or even a spike for a new feature) is a very steep and non trivial multi-step process of registering with some open source hosting site (codeplex, github, bitbucket, etc.), learning how to grab the latest sources, build the project, formulate a patch (or fork the code), learn the source control software they use (mercurial, git, svn, tfs), install whatever tools are needed for it, read about the contributors workflow for the project (do you fork & send pull requests? do you just send a patch file? do you just send a snippet? a unit test? etc.), and on, and on, and on. Granted, you may be lucky and already know the source control system the project uses, but in really, I’d say the chances are pretty low. I believe most developers *using* OSS are far from familiar with them, much less with contributing back to various projects. We OSS devs like to be on the cutting edge all the time, ya’ know, always jumping on the new SCC system, the new hosting site, the new agile way of managing work items, bug tracking, code reviews, etc. etc. etc.. But most of our OSS users are largely the “...
Read full article
Say you have a class that needs to collaborate with another, say a repository:
public class OrderProcessor
{
public void ProcessPayment(Guid orderId, Payment payment)
{
using (var repo = new OrmRepository())
{
var order = repo.Find<Order>(orderId);
order.Pay(payment);
repo.Save(order);
}
}
}
Now that clearly is very hard to test ‘cause it’s directly instantiating the repository. So we know we have to refactor that and pass the repository instead, so that tests can replace the implementation and make assertions about the interaction (if we want to):
public class OrderProcessor
{
private OrmRepository repository;
public OrderProcessor(OrmRepository repository)
{
this.repository = repository;
}
public void ProcessPayment(Guid orderId, Payment payment)
{
var order = this.repository.Find<Order>(orderId);
order.Pay(payment);
this.repository.Save(order);
}
}...
Read full article
[Disclaimer: I don’t think this disclaimer is needed, but just to be on the safe side. The opinions expressed herein are my own personal opinions and do not represent in any way my company's view, that of any customer current or past, or any current, past or future project related to these concepts that I may participate in]
In my previous post I showed how you can evolve the way you code your domain objects (or entities) so that they can benefit from the Event Sourcing pattern, and I also showed that it’s pretty simple at its core. That post ended up being a little disconnected from the one where I show how do to cool analysis based on those events. It was on purpose, as I needed to introduce another concept, and the post was getting too big already
.
Lets recap briefly what happens on a domain object when we invoke an operation:...
Read full article
I’ve shown in my previous post how interesting domain events can be mined using the Reactive Extensions for .NET. Now we need to raise those events when things happen to our domain. The typical way you’d publish events from your domain is simply adding .NET events. Say we have a Patient class, with a method Admit that causes the patient to be in the hospital and tracks the date when he was admitted:
public class Patient
{
public DateTimeOffset? AdmittedDate { get; private set; }
public bool IsInHospital { get; private set; }
public void Admit(DateTimeOffset when)
{
if (this.IsInHospital)
throw new InvalidOperationException("Already in hospital!");
this.IsInHospital = true;
this.AdmittedDate = when;
}
}
The domain object method typically does some precondition validation (like the one above, the patient can’t be admitted twice), then mutates the state as needed. At some point the resulting object state will be persisted somehow, but it’s a good goal to have ...
Read full article
Reactive Extensions (Rx) is one of the coolest additions to .NET ever. However, they have been largely ignored by the mainstream, in a significant part because (IMO) it’s seen as a UI technique, with samples that show how to handle mouse moves, drag & drop and so on. Its focus on asynchronous programming too makes it look like a niche technique that might even be worth skipping over as we wait for C# 5.0 async keyword (see Mike’s blog entry on a possible clarification of where it might fit in the async world).
There is, however, one mainstream application of reactive extensions that seems to have been missed by most: business intelligence. Here’s one concrete example: pretty soon, hospitals will face penalties for patient readmission, so you need a way to get an alert whenever patients are readmitted before a certain elapsed time (say 5 days or whatever). Another one: you want to preventively block a user’s account after 5 consecutive login failures within a minute (looks like an automated attack), or shoot an sms to the support team when failure rates for your app go above 5 crashes a day, or keep a report of top trending products in a store, and so on. ...
Read full article
Quite often, it's necessary to validate an object state when it's initialized. With constructor arguments, this is easy to do as it can be done at the end or beginning of the constructor code. With object initializers, it's nearly impossible, as there's no way to know programmatically when the object initialization is finished.
There's a built-in mechanism for this that is being used in WinForms and WPF: the ISupportInitialize interface. The initialization code generated by both toolkits checks to determine if the object implements the interface. If it does, it will call BeginInit() before invoking all property setters, and EndInit() at the end. This provides a nice hook for validating all properties and maybe interrelated ones....
Read full article
More Posts
« Previous page -
Next page »