Mock Include With Repository PatternUnit-testing .ToListAsync() using an in-memoryHow to invoke a delegate with a null parameter?Mocking repository with Entity FrameworkEF Including Other Entities (Generic Repository pattern)Best Practice For Mocking Repository PatternEntity Framework - specifying criteria for related recordsWCF Guid DataMember not Serialized properlyEntity Framework, Navigation Properties, and the Repository PatternEntity Framework - Include Multiple Levels of PropertiesRepository Pattern Step by Step ExplanationMocking Entity Framework repository pattern

Python web-scraper to download table of transistor counts from Wikipedia

How would you control supersoldiers in a late iron-age society?

In what state are satellites left in when they are left in a graveyard orbit?

What are the specifics for a Block of Incense?

Tips for remembering the order of parameters for ln?

What does "boys rule, girls drool" mean?

Is it appropriate to CC a lot of people on an email?

Exam design: give maximum score per question or not?

Teleport everything in a large zone; or teleport all living things and make a lot of equipment disappear

Can an infinite series be thought of as adding up "infinitely many" terms?

Writing a system of Linear Equations

Unpredictability of Stock Market

Extra initial Aeneid lines in 1662 M. de Marolles version

Wouldn't Kreacher have been able to escape even without following an order?

Asked to Not Use Transactions and to Use A Workaround to Simulate One

Transit visa to Hong Kong

Why my Render has black outlines?

Are there any “Third Order” acronyms used in space exploration?

Are there objective criteria for classifying consonance v. dissonance?

How do we know that black holes are spinning?

Nature of Craving in Charm and Impressing Others

Answer Not A Fool, or Answer A Fool?

What are the typical trumpet parts in classical music?

Hobby function generators



Mock Include With Repository Pattern


Unit-testing .ToListAsync() using an in-memoryHow to invoke a delegate with a null parameter?Mocking repository with Entity FrameworkEF Including Other Entities (Generic Repository pattern)Best Practice For Mocking Repository PatternEntity Framework - specifying criteria for related recordsWCF Guid DataMember not Serialized properlyEntity Framework, Navigation Properties, and the Repository PatternEntity Framework - Include Multiple Levels of PropertiesRepository Pattern Step by Step ExplanationMocking Entity Framework repository pattern






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have been trying to unity test a query that I've created using a repository pattern I cannot seem to figure this one out. It seems that I must be doing something wrong here.



So I've Created a generic repository that may look something like:



 public interface IRepository<T> where T:class,IEntity, new()

IQueryable<T> Get();

T Get(int id);

T Add(T entity);

T Update(T entity);

void Delete(int id);



I also have a Context that may look like:



 public class ApplicationContext:DbContext

public virtual DbSet<Customer> Customers get; set;
public virtual DbSet<User> Users get; set;



so now I, of course, now have a repository that looks like IRepository<Customer> customersRepository.



In my controller, I have a query that may look like:



 var customers = _customerRepository
.Get()
.Include(customer => customer.Users)
.Where(customer=>customer.Status == "active")
.ToList();


So on to my question, I would like to test this but I am getting an error saying




Value cannot be null




my unit test looks like:



 [TestMethod]
public void GetCustomerList_ValidParameters_ShouldOnlyReturnItemsWithActiveStatus()


//Act
var customers = _customerModel.GetCustomerList(
_parentId, /*parentId*/
string.Empty, /*keywords*/
1, /*page*/
20, /*count*/
out var totalCount, /*totalCount*/
null /*orderBy*/
);

//Assert
Assert.AreEqual(expected:3, actual: customers.Count);



my data setup looks like:



 private void AddDataToRepository()


var customers = new List<Customer>()

new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId,
new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId,
new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId,
new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId,
new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId,
;

var users = new List<User>();
var usersMock = new Mock<DbSet<User>>();
_customerRepositoryMock.Setup(x => x.Get().Include(It.IsAny(typeof(User))));

_customerRepositoryMock.Setup(x => x.Get()).Returns(customers.ToDbSet());




How can I mock the users here.










share|improve this question






























    0















    I have been trying to unity test a query that I've created using a repository pattern I cannot seem to figure this one out. It seems that I must be doing something wrong here.



    So I've Created a generic repository that may look something like:



     public interface IRepository<T> where T:class,IEntity, new()

    IQueryable<T> Get();

    T Get(int id);

    T Add(T entity);

    T Update(T entity);

    void Delete(int id);



    I also have a Context that may look like:



     public class ApplicationContext:DbContext

    public virtual DbSet<Customer> Customers get; set;
    public virtual DbSet<User> Users get; set;



    so now I, of course, now have a repository that looks like IRepository<Customer> customersRepository.



    In my controller, I have a query that may look like:



     var customers = _customerRepository
    .Get()
    .Include(customer => customer.Users)
    .Where(customer=>customer.Status == "active")
    .ToList();


    So on to my question, I would like to test this but I am getting an error saying




    Value cannot be null




    my unit test looks like:



     [TestMethod]
    public void GetCustomerList_ValidParameters_ShouldOnlyReturnItemsWithActiveStatus()


    //Act
    var customers = _customerModel.GetCustomerList(
    _parentId, /*parentId*/
    string.Empty, /*keywords*/
    1, /*page*/
    20, /*count*/
    out var totalCount, /*totalCount*/
    null /*orderBy*/
    );

    //Assert
    Assert.AreEqual(expected:3, actual: customers.Count);



    my data setup looks like:



     private void AddDataToRepository()


    var customers = new List<Customer>()

    new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId,
    new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId,
    new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId,
    new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId,
    new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId,
    ;

    var users = new List<User>();
    var usersMock = new Mock<DbSet<User>>();
    _customerRepositoryMock.Setup(x => x.Get().Include(It.IsAny(typeof(User))));

    _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.ToDbSet());




    How can I mock the users here.










    share|improve this question


























      0












      0








      0








      I have been trying to unity test a query that I've created using a repository pattern I cannot seem to figure this one out. It seems that I must be doing something wrong here.



      So I've Created a generic repository that may look something like:



       public interface IRepository<T> where T:class,IEntity, new()

      IQueryable<T> Get();

      T Get(int id);

      T Add(T entity);

      T Update(T entity);

      void Delete(int id);



      I also have a Context that may look like:



       public class ApplicationContext:DbContext

      public virtual DbSet<Customer> Customers get; set;
      public virtual DbSet<User> Users get; set;



      so now I, of course, now have a repository that looks like IRepository<Customer> customersRepository.



      In my controller, I have a query that may look like:



       var customers = _customerRepository
      .Get()
      .Include(customer => customer.Users)
      .Where(customer=>customer.Status == "active")
      .ToList();


      So on to my question, I would like to test this but I am getting an error saying




      Value cannot be null




      my unit test looks like:



       [TestMethod]
      public void GetCustomerList_ValidParameters_ShouldOnlyReturnItemsWithActiveStatus()


      //Act
      var customers = _customerModel.GetCustomerList(
      _parentId, /*parentId*/
      string.Empty, /*keywords*/
      1, /*page*/
      20, /*count*/
      out var totalCount, /*totalCount*/
      null /*orderBy*/
      );

      //Assert
      Assert.AreEqual(expected:3, actual: customers.Count);



      my data setup looks like:



       private void AddDataToRepository()


      var customers = new List<Customer>()

      new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId,
      ;

      var users = new List<User>();
      var usersMock = new Mock<DbSet<User>>();
      _customerRepositoryMock.Setup(x => x.Get().Include(It.IsAny(typeof(User))));

      _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.ToDbSet());




      How can I mock the users here.










      share|improve this question














      I have been trying to unity test a query that I've created using a repository pattern I cannot seem to figure this one out. It seems that I must be doing something wrong here.



      So I've Created a generic repository that may look something like:



       public interface IRepository<T> where T:class,IEntity, new()

      IQueryable<T> Get();

      T Get(int id);

      T Add(T entity);

      T Update(T entity);

      void Delete(int id);



      I also have a Context that may look like:



       public class ApplicationContext:DbContext

      public virtual DbSet<Customer> Customers get; set;
      public virtual DbSet<User> Users get; set;



      so now I, of course, now have a repository that looks like IRepository<Customer> customersRepository.



      In my controller, I have a query that may look like:



       var customers = _customerRepository
      .Get()
      .Include(customer => customer.Users)
      .Where(customer=>customer.Status == "active")
      .ToList();


      So on to my question, I would like to test this but I am getting an error saying




      Value cannot be null




      my unit test looks like:



       [TestMethod]
      public void GetCustomerList_ValidParameters_ShouldOnlyReturnItemsWithActiveStatus()


      //Act
      var customers = _customerModel.GetCustomerList(
      _parentId, /*parentId*/
      string.Empty, /*keywords*/
      1, /*page*/
      20, /*count*/
      out var totalCount, /*totalCount*/
      null /*orderBy*/
      );

      //Assert
      Assert.AreEqual(expected:3, actual: customers.Count);



      my data setup looks like:



       private void AddDataToRepository()


      var customers = new List<Customer>()

      new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId,
      new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId,
      ;

      var users = new List<User>();
      var usersMock = new Mock<DbSet<User>>();
      _customerRepositoryMock.Setup(x => x.Get().Include(It.IsAny(typeof(User))));

      _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.ToDbSet());




      How can I mock the users here.







      c# entity-framework moq






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 12:55









      3xGuy3xGuy

      5583 silver badges20 bronze badges




      5583 silver badges20 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1
















          The issue you ran into is that while you want to mock at the repository level, the code is trying to go too deep in the sense that you were expecting to mock out the separate DBSets so that the code under test would interact with the IQueryable returned expecting a DdSet that relates to other mocked DbSets.



          I.e.
          Given a Customer contains a User: Mock a set of customers expected, mock a set of users, then the calling code somehow knows about them?



          Instead, your repository is your boundary as far as the test is concerned. The repository simply returns an IQueryable<Customer> so the mocked repository needs to send back a collection of customers with enough information to satisfy the consumer.



           private void AddDataToRepository()

          var testUser = new User UserId = 1, UserName = "Me" ;
          var customers = new List<Customer>()


          new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId, User = testUser,
          new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId, User = testUser,
          new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId, User = testUser,
          new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId, User = testUser,
          new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId, User = testUser,
          ;

          _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.AsQueryable());



          The issue is that your code is expecting to find a user on your customer, so you need to initialize your stub customer to have the user reference. (not expect the calling "Include" to know how to work that out from another set of stubs) The .Include call in the case of the test is effectively ignored. All it does in EF is inform the engine to fetch the related data when it executes the query, it doesn't actually load anything.



          I would also recommend reading up on implementing a IDbAsyncQueryProvider for your mocked Queryable results so that you can later utilize async operations against your repository methods. (i.e. ToListAsync() etc.) (Unit-testing .ToListAsync() using an in-memory)






          share|improve this answer
































            0
















            Okay, I hope this helps others, I was not able to actually Mock the include method. So what I ended up doing was making an ICustomerRepository that inherited from IRepository<Customer>. Then I just added a method CustomersWithUsers and mocked that.






            share|improve this answer



























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );














              draft saved

              draft discarded
















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55398212%2fmock-include-with-repository-pattern%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1
















              The issue you ran into is that while you want to mock at the repository level, the code is trying to go too deep in the sense that you were expecting to mock out the separate DBSets so that the code under test would interact with the IQueryable returned expecting a DdSet that relates to other mocked DbSets.



              I.e.
              Given a Customer contains a User: Mock a set of customers expected, mock a set of users, then the calling code somehow knows about them?



              Instead, your repository is your boundary as far as the test is concerned. The repository simply returns an IQueryable<Customer> so the mocked repository needs to send back a collection of customers with enough information to satisfy the consumer.



               private void AddDataToRepository()

              var testUser = new User UserId = 1, UserName = "Me" ;
              var customers = new List<Customer>()


              new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId, User = testUser,
              new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId, User = testUser,
              new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId, User = testUser,
              new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId, User = testUser,
              new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId, User = testUser,
              ;

              _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.AsQueryable());



              The issue is that your code is expecting to find a user on your customer, so you need to initialize your stub customer to have the user reference. (not expect the calling "Include" to know how to work that out from another set of stubs) The .Include call in the case of the test is effectively ignored. All it does in EF is inform the engine to fetch the related data when it executes the query, it doesn't actually load anything.



              I would also recommend reading up on implementing a IDbAsyncQueryProvider for your mocked Queryable results so that you can later utilize async operations against your repository methods. (i.e. ToListAsync() etc.) (Unit-testing .ToListAsync() using an in-memory)






              share|improve this answer





























                1
















                The issue you ran into is that while you want to mock at the repository level, the code is trying to go too deep in the sense that you were expecting to mock out the separate DBSets so that the code under test would interact with the IQueryable returned expecting a DdSet that relates to other mocked DbSets.



                I.e.
                Given a Customer contains a User: Mock a set of customers expected, mock a set of users, then the calling code somehow knows about them?



                Instead, your repository is your boundary as far as the test is concerned. The repository simply returns an IQueryable<Customer> so the mocked repository needs to send back a collection of customers with enough information to satisfy the consumer.



                 private void AddDataToRepository()

                var testUser = new User UserId = 1, UserName = "Me" ;
                var customers = new List<Customer>()


                new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId, User = testUser,
                new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId, User = testUser,
                new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId, User = testUser,
                new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId, User = testUser,
                new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId, User = testUser,
                ;

                _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.AsQueryable());



                The issue is that your code is expecting to find a user on your customer, so you need to initialize your stub customer to have the user reference. (not expect the calling "Include" to know how to work that out from another set of stubs) The .Include call in the case of the test is effectively ignored. All it does in EF is inform the engine to fetch the related data when it executes the query, it doesn't actually load anything.



                I would also recommend reading up on implementing a IDbAsyncQueryProvider for your mocked Queryable results so that you can later utilize async operations against your repository methods. (i.e. ToListAsync() etc.) (Unit-testing .ToListAsync() using an in-memory)






                share|improve this answer



























                  1














                  1










                  1









                  The issue you ran into is that while you want to mock at the repository level, the code is trying to go too deep in the sense that you were expecting to mock out the separate DBSets so that the code under test would interact with the IQueryable returned expecting a DdSet that relates to other mocked DbSets.



                  I.e.
                  Given a Customer contains a User: Mock a set of customers expected, mock a set of users, then the calling code somehow knows about them?



                  Instead, your repository is your boundary as far as the test is concerned. The repository simply returns an IQueryable<Customer> so the mocked repository needs to send back a collection of customers with enough information to satisfy the consumer.



                   private void AddDataToRepository()

                  var testUser = new User UserId = 1, UserName = "Me" ;
                  var customers = new List<Customer>()


                  new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId, User = testUser,
                  ;

                  _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.AsQueryable());



                  The issue is that your code is expecting to find a user on your customer, so you need to initialize your stub customer to have the user reference. (not expect the calling "Include" to know how to work that out from another set of stubs) The .Include call in the case of the test is effectively ignored. All it does in EF is inform the engine to fetch the related data when it executes the query, it doesn't actually load anything.



                  I would also recommend reading up on implementing a IDbAsyncQueryProvider for your mocked Queryable results so that you can later utilize async operations against your repository methods. (i.e. ToListAsync() etc.) (Unit-testing .ToListAsync() using an in-memory)






                  share|improve this answer













                  The issue you ran into is that while you want to mock at the repository level, the code is trying to go too deep in the sense that you were expecting to mock out the separate DBSets so that the code under test would interact with the IQueryable returned expecting a DdSet that relates to other mocked DbSets.



                  I.e.
                  Given a Customer contains a User: Mock a set of customers expected, mock a set of users, then the calling code somehow knows about them?



                  Instead, your repository is your boundary as far as the test is concerned. The repository simply returns an IQueryable<Customer> so the mocked repository needs to send back a collection of customers with enough information to satisfy the consumer.



                   private void AddDataToRepository()

                  var testUser = new User UserId = 1, UserName = "Me" ;
                  var customers = new List<Customer>()


                  new CustomerId = Guid.NewGuid().ToString(), Name = "ABC", Status = "active", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "DEF", Status = "canceled", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "HIJ", Status = "active", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "MNO", Status = "suspended", Parent_id = _parentId, User = testUser,
                  new CustomerId = Guid.NewGuid().ToString(), Name = "QRS", Status = "active", Parent_id = _parentId, User = testUser,
                  ;

                  _customerRepositoryMock.Setup(x => x.Get()).Returns(customers.AsQueryable());



                  The issue is that your code is expecting to find a user on your customer, so you need to initialize your stub customer to have the user reference. (not expect the calling "Include" to know how to work that out from another set of stubs) The .Include call in the case of the test is effectively ignored. All it does in EF is inform the engine to fetch the related data when it executes the query, it doesn't actually load anything.



                  I would also recommend reading up on implementing a IDbAsyncQueryProvider for your mocked Queryable results so that you can later utilize async operations against your repository methods. (i.e. ToListAsync() etc.) (Unit-testing .ToListAsync() using an in-memory)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 at 22:20









                  Steve PySteve Py

                  8,6351 gold badge13 silver badges22 bronze badges




                  8,6351 gold badge13 silver badges22 bronze badges


























                      0
















                      Okay, I hope this helps others, I was not able to actually Mock the include method. So what I ended up doing was making an ICustomerRepository that inherited from IRepository<Customer>. Then I just added a method CustomersWithUsers and mocked that.






                      share|improve this answer





























                        0
















                        Okay, I hope this helps others, I was not able to actually Mock the include method. So what I ended up doing was making an ICustomerRepository that inherited from IRepository<Customer>. Then I just added a method CustomersWithUsers and mocked that.






                        share|improve this answer



























                          0














                          0










                          0









                          Okay, I hope this helps others, I was not able to actually Mock the include method. So what I ended up doing was making an ICustomerRepository that inherited from IRepository<Customer>. Then I just added a method CustomersWithUsers and mocked that.






                          share|improve this answer













                          Okay, I hope this helps others, I was not able to actually Mock the include method. So what I ended up doing was making an ICustomerRepository that inherited from IRepository<Customer>. Then I just added a method CustomersWithUsers and mocked that.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 28 at 14:58









                          3xGuy3xGuy

                          5583 silver badges20 bronze badges




                          5583 silver badges20 bronze badges































                              draft saved

                              draft discarded















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55398212%2fmock-include-with-repository-pattern%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해