1
Vote

FindProductKeyAsync

description

Does anyone had a problem with this test method in ProductRepositoryTest.cs?
Durring testing xunit or MSTest hangs on
var product = await unitOfWork.RepositoryAsync<Product>().FindAsync(2);

comments

OzBobWA wrote Feb 3 at 3:02 AM

I had a similar problem and found a solution with Mocking the Repositories.
    using Repository.Pattern.Repositories;
    using System.Linq;
    using Repository.Pattern.Ef6.Factories;
    
    public class FakeContext : FakeDbContext
    {
        public FakeContext()
        {
            Repository.Pattern.Ef6.AddFakeDbSet<Test, TestDbSet>();
                }
         }

    readonly IRepositoryProvider _repositoryProvider = new RepositoryProvider(new RepositoryFactories());
        
        [TestMethod]
        public void FindTestGuidAsync()
        {
            using (IDataContextAsync fakeContext = new FakeContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(fakeContext, _repositoryProvider))
            {
                ar testGuid = System.Guid.NewGuid();
                var testNewGuid = testGuid.ToString();
                var newtest = new test { testID = 2, testUID = testGuid };

                unitOfWork.Repository<test>().Insert(newtest);

                unitOfWork.SaveChanges();

                var testerF = unitOfWork.RepositoryAsync<test>().Find(2);
                Assert.AreEqual(testerF.testID, 2);
                
                var tester = unitOfWork.RepositoryAsync<test>().Query()
                    .Select().Where(cpu => cpu.testUID.Equals(testGuid))
                    .First();

                Assert.AreEqual(tester.testID, 2);
            }
        }