Tuesday, February 23, 2010

Repository Factory

http://www.pnpguidance.net/Post/SampleFluentNHibernateT4TemplatesCodeGenerationLINQToSQL.aspx
http://davidhayden.com/blog/dave/category/15.aspx?Show=All
http://www.codeproject.com/KB/architecture/linqrepository.aspx
http://www.codeplex.com/RepositoryFactory
Guidance Automation Extensions - February 2008 Release
http://www.microsoft.com/downloads/details.aspx?FamilyId=DF79C099-4753-4A59-91E3-5020D9714E4E&displaylang=en
http://servicefactory.codeplex.com/releases/view/11147
http://www.microsoft.com/downloads/details.aspx?FamilyId=6C200BAC-9F33-46E3-A5A2-839FD7DC022F&displaylang=en
http://blogs.microsoft.co.il/blogs/gilf/archive/2010/01/20/using-repository-pattern-with-entity-framework.aspx

Rhino.Mocks -Unit Testing


Rhino.Mocks is an attempt to create easier way to build and use mock objects and allow better refactoring support from the current tools. It's a hybrid approach between the pure Record/Replay of EasyMock.Net's model and NMock's expectation based model. Rhino.Mocks originated from EasyMock.Net and attempt to improve on their model to create easy to use and power mocking framework. It's free for use and modification for open source and commercial software.
Licensing: Rhino Mocks is Free Software which is released under the BSD license.


What does Rhino Mocks offers?

Explicit record & replay model for expectations.
Natural Arrange, Act, Assert syntax
Support for .Net 2.0 and .Net 3.5
Working with strongly typed mocks.
Expectations based on:
Arguments matching
Constraints matching
Custom callback to verify the expected arguments using your own code
Setting actions on methods, return specific value, or throw an exception.
Some things to be aware of:
Ø You cannot create a mock object from a sealed class.
Ø You cannot intercept calls to non-virtual methods.

Reference:

-------------------------------------------------------------------------------------------------http://www.ayende.com/projects/rhino-mocks/api/files/MocksRepositoryGenerics-cs.html http://www.ayende.com/projects/rhino-mocks/api/files/MockRepository-cs.html [Mock Repository]
http://www.codeproject.com/KB/dotnet/Rhino_Mocks_Version_20.aspx
http://www.ayende.com/projects/rhino-mocks/api/index/Functions.html [Mock Functions]
http://www.ayende.com/wiki/AllPages.aspx [Mock Syntax]
http://codevanced.net/page/Talks-Mock-n-Roll.aspx [Why we need mock]
http://en.wikipedia.org/wiki/Mock_object [Mock object]http://highoncoding.com/Articles/447_Introduction_to_Mocking.aspxhttp://highoncoding.com/Articles/449_A_Look_at_CreateMock__DynamicMock_and_PartialMock_Methods_in_RhinoMocks.aspx
http://groups.google.com/group/rhinomocks/browse_thread/thread/dde2314300e0ef09/f5a9c4d7d28a0168?show_docid=f5a9c4d7d28a0168 [Sample Code]


http://www.superexpert.com/blog/archive/2008/03/23/tdd-introduction-to-rhino-mocks.aspx

Dynamic Vs StrickMock

http://www.thycotic.com/strictmock-vs-dynamicmock-what-are-you-testing-here-anyway [Event Handlers for Mocks]http://groups.google.com/group/RhinoMocks/browse_thread/thread/b4718f2b3a000943

Thursday, February 4, 2010

WCF Client Proxy IDisposable - Generic WCF Service Proxy

public class ServiceProxy : ClientBase, IDisposable where TInterface : class
{
public delegate void ServiceProxyDelegate(TInterface proxy);

public ServiceProxy()
: base(typeof(TInterface).ToString())
{
}
public ServiceProxy(string endpointConfigurationName)
: base(endpointConfigurationName)
{
}

protected override TInterface CreateChannel()
{
return base.CreateChannel();
}

public TInterface Proxy
{
get
{
return this.Channel;
}
}

public static void Call(ServiceProxyDelegate proxyDelegate)
{
Call(proxyDelegate, typeof(TInterface).ToString());
}

public static void Call(ServiceProxyDelegate proxyDelegate, string endpointConfigurationName)
{
ChannelFactory channel = new ChannelFactory(endpointConfigurationName);

try
{
proxyDelegate(channel.CreateChannel());
}
finally
{
if (channel.State == CommunicationState.Faulted)
{
channel.Abort();
}
else
{
try
{
channel.Close();
}
catch
{
channel.Abort();
}
}
}
}

public void Dispose()
{
if (this.State == CommunicationState.Faulted)
{
base.Abort();
}
else
{
try
{
base.Close();
}
catch
{
base.Abort();
}
}
}
}

And, here are some usages samples...
//delegate example1
string response = null;
ServiceModel.ServiceProxy.Call(p =>
{
response = p.DoStuff("ServiceProxyUsingTest");
}
);

//delegate example2
string response = null;
ServiceProxy.Call(p => response = p.DoStuff("ServiceProxyUsingTest"));

//using example
string response = null;
using (ServiceProxy service = new ServiceProxy())
{
response = service.Proxy.DoStuff("ServiceProxyUsingTest");
}


Ref:http://blog.weminuche.net/2008/08/test-post.html
http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11#WCFContracts
http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx

http://my.safaribooksonline.com/0130925691