Esempio n. 1
0
        public void ShouldReturnTaskWithResultNull_WhenItemIsNotFound()
        {
            var mockDbSet     = new Mock <DbSet <IDbModel> >();
            var mockDbContext = new Mock <IWhenItsDoneDbContext>();

            mockDbContext.Setup(mock => mock.Set <IDbModel>()).Returns(mockDbSet.Object);

            var asyncGenericRepositoryInstace = new GenericAsyncRepository <IDbModel>(mockDbContext.Object);

            var fakeData = new List <IDbModel>();

            mockDbSet.As <IDbSet <IDbModel> >().Setup(mock => mock.GetEnumerator()).Returns(fakeData.GetEnumerator());

            var actualReturnedCollection = asyncGenericRepositoryInstace.GetAllAsync();

            Assert.That(actualReturnedCollection.Result.Count, Is.EqualTo(0));
        }
Esempio n. 2
0
        public void ShouldReturnTaskOfCorrectStatus_WhenItemIsFound()
        {
            var mockDbSet     = new Mock <DbSet <IDbModel> >();
            var mockDbContext = new Mock <IWhenItsDoneDbContext>();

            mockDbContext.Setup(mock => mock.Set <IDbModel>()).Returns(mockDbSet.Object);

            var asyncGenericRepositoryInstace = new GenericAsyncRepository <IDbModel>(mockDbContext.Object);

            var fakeData = new List <IDbModel>()
            {
                new Mock <IDbModel>().Object,
                new Mock <IDbModel>().Object,
                new Mock <IDbModel>().Object,
                new Mock <IDbModel>().Object
            };

            mockDbSet.As <IDbSet <IDbModel> >().Setup(mock => mock.GetEnumerator()).Returns(fakeData.GetEnumerator());

            var actualReturnedCollection = asyncGenericRepositoryInstace.GetAllAsync();

            Assert.That(actualReturnedCollection.Status, Is.EqualTo(TaskStatus.Running).Or.EqualTo(TaskStatus.WaitingToRun).Or.EqualTo(TaskStatus.RanToCompletion));
        }
Esempio n. 3
0
        public void ShouldReturnTaskOfCorrectType_WhenItemIsFound()
        {
            var mockDbSet     = new Mock <DbSet <IDbModel> >();
            var mockDbContext = new Mock <IWhenItsDoneDbContext>();

            mockDbContext.Setup(mock => mock.Set <IDbModel>()).Returns(mockDbSet.Object);

            var asyncGenericRepositoryInstace = new GenericAsyncRepository <IDbModel>(mockDbContext.Object);

            var fakeData = new List <IDbModel>()
            {
                new Mock <IDbModel>().Object,
                new Mock <IDbModel>().Object,
                new Mock <IDbModel>().Object,
                new Mock <IDbModel>().Object
            };

            mockDbSet.As <IDbSet <IDbModel> >().Setup(mock => mock.GetEnumerator()).Returns(fakeData.GetEnumerator());

            var actualReturnedCollection = asyncGenericRepositoryInstace.GetAllAsync();

            Assert.That(actualReturnedCollection.GetType(), Is.EqualTo(typeof(Task <IEnumerable <IDbModel> >)));
        }