Example #1
0
        public void ReturnCorrectType_WhenCalled()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object);

            var expectedCollection = new List <ToDoListModel>()
            {
                new ToDoListModel()
                {
                    Name = "Sample List"
                }
            };

            mockedToDoListModelRepository.Setup(r => r.All).Returns(() =>
            {
                return(expectedCollection.AsQueryable());
            });
            //Act
            var actualResult = toDoListModelService.GetAll();

            //Assert
            Assert.That(actualResult, Is.InstanceOf <IEnumerable <ToDoListModel> >());
        }
Example #2
0
        public void CallRepositoryAll_OnlyOnce()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object);

            //Act
            toDoListModelService.GetAll();

            //Assert
            mockedToDoListModelRepository.Verify(x => x.All, Times.Once);
        }
Example #3
0
        public void ReturnNull_WhenCalledAndCollectionIsNull()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object);

            mockedToDoListModelRepository.Setup(r => r.All).Returns(() =>
            {
                return(null);
            });
            //Act
            var actualResult = toDoListModelService.GetAll();

            //Assert
            Assert.IsNull(actualResult);
        }