iquarc / dataaccess Goto Github PK
View Code? Open in Web Editor NEWRepository and Unit Of Work implementation
License: MIT License
Repository and Unit Of Work implementation
License: MIT License
Hi
I'm implementing a repository.When I try to test it unitary, I receive the next error.
System.NotImplementedException: 'The member 'IEnumerable.GetEnumerator' has not been implemented on type 'FakeSet1' which inherits from 'DbSet
1'. Test doubles for 'DbSet`1' must provide implementations of methods and properties that are used.'
Did you ever have this type of error, when you try to get the entities?
I've using several classes from the base test and double test.
My code is:
[TestMethod]
public void GetAllCompetitions_Test()
{
IInterceptorsResolver resolver = GetEmptyInterceptors();
IDbContextFactory factory = GetFactory();
IRepository repository = GetTarget(factory, resolver);
IEnumerable<CompetitionDto> actual = repository.GetEntities<CompetitionDto>().ToList();
CompetitionDto expected = new CompetitionDto { Id = 424 };
Assert.AreEqual(expected, actual.FirstOrDefault());
Assert.AreEqual(1, actual.Count());
}
private static IInterceptorsResolver GetEmptyInterceptors()
{
Mock<IInterceptorsResolver> resolver = new Mock<IInterceptorsResolver>();
resolver.Setup(x => x.GetEntityInterceptors(It.IsAny<Type>()))
.Returns(new IEntityInterceptor[0]);
resolver.Setup(x => x.GetGlobalInterceptors())
.Returns(new IEntityInterceptor[0]);
return resolver.Object;
}
private static IDbContextFactory GetFactory()
{
DbContextFakeWrapper wrapper = new DbContextFakeWrapper();
List<CompetitionDto> competitions = new List<CompetitionDto>()
{
new CompetitionDto()
{
Id = 424,
Caption = "European Championships France 2016",
Short_Caption = "European Championships France",
League = "EC",
Year = 2016,
NumberOfTeams = 24,
NumberOfGames = 38,
LastUpdate = DateTime.UtcNow
}
};
DbSet<CompetitionDto> userSet = competitions.MockDbSet(wrapper);
wrapper.ContextDouble.Setup(x => x.Set<CompetitionDto>()).Returns(() => userSet);
DbContextFakeWrapper fakeWrapper = wrapper;
return fakeWrapper.ContextDouble.BuildFactoryStub();
}
private static IInterceptorsResolver GetResolver(Expression<Func<IInterceptorsResolver, IEnumerable<IEntityInterceptor>>> getInterceptorsFunction,
InterceptorDouble interceptorMock)
{
Mock<IInterceptorsResolver> stub = new Mock<IInterceptorsResolver>();
stub.Setup(getInterceptorsFunction).Returns(new[] { interceptorMock });
return stub.Object;
}
protected IRepository GetTarget(IDbContextFactory factory, IInterceptorsResolver resolver)
{
return new Repository(factory, resolver);
}
Could this project be used in .Net Standard Library? and .Net Core App?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.