コード例 #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.GetAllByUserId(It.IsAny <Guid>());

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

            var mockedUserOne = new Mock <ApplicationUser>();

            mockedUserOne.Setup(s => s.Id).Returns("1");

            var mockedUserTwo = new Mock <ApplicationUser>();

            mockedUserOne.Setup(s => s.Id).Returns("2");

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

            var expectedCollection = new List <ToDoListModel>()
            {
                new ToDoListModel()
                {
                    Name = "Sample List", ApplicationUserId = mockedUserOne.Object
                },
                new ToDoListModel()
                {
                    Name = "Sample List 1", ApplicationUserId = mockedUserOne.Object
                },
                new ToDoListModel()
                {
                    Name = "Sample List 2", ApplicationUserId = mockedUserTwo.Object
                },
                new ToDoListModel()
                {
                    Name = "Sample List 3", ApplicationUserId = mockedUserTwo.Object
                },
                new ToDoListModel()
                {
                    Name = "Sample List 4", ApplicationUserId = mockedUserTwo.Object
                }
            };

            mockedToDoListModelRepository.Setup(r => r.All).Returns(() =>
            {
                return(expectedCollection.Where(l => l.ApplicationUserId == mockedUserOne.Object).AsQueryable());
            });

            //Act
            var actualResult = toDoListModelService.GetAllByUserId(mockedUserOne.Object);

            //Assert
            Assert.That(actualResult.Count(), Is.EqualTo(2));
        }
コード例 #3
0
        public void Throw_WhenIdIsNull()
        {
            //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&Assert
            Assert.Throws <ArgumentNullException>(() =>
            {
                toDoListModelService.GetAllByUserId(null);
            });
        }
コード例 #4
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);
        }
コード例 #5
0
        public void CallUnitOfWorkCommit_OnlyOnce()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedToDoList   = new Mock <ToDoListModel>();

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

            //Act
            toDoListModelService.UpdateToDoList(mockedToDoList.Object);

            //Assert
            mockedUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
コード例 #6
0
        public void CallRepositortDelete_OnlyOnce()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedToDoList   = new Mock <ToDoListModel>();

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

            //Act
            toDoListModelService.DeleteToDoList(mockedToDoList.Object);

            //Assert
            mockedToDoListModelRepository.Verify(r => r.Delete(It.IsAny <ToDoListModel>()), Times.Once);
        }
コード例 #7
0
        public void CallRepositortGetById_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);

            var obj = Guid.NewGuid();

            //Act
            toDoListModelService.GetListById(obj);
            //Assert
            mockedToDoListModelRepository.Verify(r => r.GetById(It.IsAny <object>()), Times.Once);
        }
コード例 #8
0
        public void Throw_WhenNameIsNull()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedUser       = new Mock <ApplicationUser>();

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

            //Act&Assert
            Assert.Throws <ArgumentNullException>(() =>
            {
                toDoListModelService.CreateToDoList(mockedUser.Object, null, isPublic);
            });
        }
コード例 #9
0
        public void CallUnitOfWorkCommitOnlyOnce()
        {
            //Arrange
            var mockedUserRepository          = new Mock <IEFGenericRepository <ApplicationUser> >();
            var mockedToDoListModelRepository = new Mock <IEFGenericRepository <ToDoListModel> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedUser       = new Mock <ApplicationUser>();

            var toDoListModelService = new ToDoList.Services.ToDoListModelService(mockedToDoListModelRepository.Object, mockedUserRepository.Object, mockedUnitOfWork.Object);
            var name     = "Sample Name";
            var isPublic = false;

            mockedUser.Setup(x => x.ToDoLists.Add(It.IsAny <ToDoListModel>()));
            //Act
            toDoListModelService.CreateToDoList(mockedUser.Object, name, isPublic);

            //Assert
            mockedUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
コード例 #10
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);
        }