Exemple #1
0
        public void AddSholdCallUnitOfWorkComitOnce()
        {
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            mockedUnitOfWork.Setup(x => x.Commit()).Verifiable();
            genericService.Add(new Category());
            mockedUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
Exemple #2
0
        public void AddSholdCallRepositoryAddWithSameUser()
        {
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var fakecategory     = new Category();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            mockeRepository.Setup(x => x.Add(fakecategory)).Verifiable();
            genericService.Add(fakecategory);
            mockeRepository.Verify(x => x.Add(It.Is <Category>(y => y == fakecategory)), Times.Once);
        }
Exemple #3
0
        public void ReturnNewInstanceOfNoleggioGenericService()
        {
            //Arrange
            var mockedRepository = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfwork = new Mock <IUnitOfWork>();

            //Act
            var service = new NoleggioGenericServiceMock(mockedRepository.Object, mockedUnitOfwork.Object);

            //Assert
            Assert.IsInstanceOf <NoleggioGenericService <Category> >(service);
        }
Exemple #4
0
        public void GetDeletedShouldCallRepositoryGetAllOnce()
        {
            //Arrange
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            //Act
            var actualRepository = genericService.RepositoryMock;

            //Assert
            Assert.AreEqual(mockeRepository.Object, actualRepository);
        }
Exemple #5
0
        public void DeleteSholdCallUnitOfWorkComitOnce()
        {
            //Arrange
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            mockedUnitOfWork.Setup(x => x.Commit()).Verifiable();

            //Act
            genericService.Delete(new Category());

            //Assert
            mockedUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
Exemple #6
0
        public void GetDeletedShouldCallRepositoryGetAllOnce()
        {
            //Arrange
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            mockeRepository.Setup(x => x.GetAll()).Returns(new List <Category>().AsQueryable()).Verifiable();

            //Act
            genericService.GetDeleted();

            //Assert
            mockeRepository.Verify(x => x.GetAll(), Times.Once);
        }
Exemple #7
0
        public void GetByIdShouldCallRepositoryGetByIdOnceWithSameId(object fakeId)
        {
            //Arrange
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            mockeRepository.Setup(x => x.GetById(fakeId)).Verifiable();

            //Act
            genericService.GetById(fakeId);

            //Assert
            mockeRepository.Verify(x => x.GetById(It.Is <object>(y => y == fakeId)), Times.Once);
        }
Exemple #8
0
        public void DeleteSholdCallRepositoryDeleteWithSameCategory()
        {
            //Arrange
            var mockeRepository  = new Mock <IGenericEfRepository <Category> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var fakeCategory     = new Category();
            var genericService   = new NoleggioGenericServiceMock(mockeRepository.Object, mockedUnitOfWork.Object);

            mockeRepository.Setup(x => x.Delete(fakeCategory)).Verifiable();

            //Act
            genericService.Delete(fakeCategory);

            //Assert
            mockeRepository.Verify(x => x.Delete(It.Is <Category>(y => y == fakeCategory)), Times.Once);
        }