Giter Club home page Giter Club logo

dataaccess's People

Contributors

crissian avatar florinc avatar popcatalin81 avatar sergiudamian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dataaccess's Issues

Error unitary testing

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 'DbSet1'. 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);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.