Skip to content

Instantly share code, notes, and snippets.

@waldyrfelix
Created July 11, 2012 21:48
Show Gist options
  • Save waldyrfelix/3093834 to your computer and use it in GitHub Desktop.
Save waldyrfelix/3093834 to your computer and use it in GitHub Desktop.
Mock de um UnitOfWork retornada a partir de um ServiceLocator
public static Mock<IUnitOfWork> MockUnitOfWork()
{
var mockUnitOfWork = new Mock<IUnitOfWork>();
var mockUnitOfWorkFactory = new Mock<IUnitOfWorkFactory>();
mockUnitOfWorkFactory.Setup(_ => _.Criar())
.Returns(mockUnitOfWork.Object);
var mockServiceLocator = new Mock<IServiceLocator>();
mockServiceLocator.Setup(_ => _.GetInstance<IUnitOfWorkFactory>())
.Returns(mockUnitOfWorkFactory.Object);
ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);
return mockUnitOfWork;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment