public void CallsREpostitoryAddWithCorrectRentItemWithAnImageInImageList()
        {
            //Arrange
            var mockeRepository = new Mock <IGenericEfRepository <RentItem> >();

            mockeRepository.Setup(x => x.Add(It.IsAny <RentItem>())).Verifiable();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedMapper     = new Mock <IMapingService>();
            var rentItemStub     = new RentItem();
            var imageStub        = new Image();

            mockedMapper.Setup(x => x.Map <RentItem>(It.IsAny <RentItemDtoModel>())).Returns(rentItemStub);
            mockedMapper.Setup(x => x.Map <Image>(It.IsAny <ImagesDtoModel>())).Returns(imageStub);

            mockedMapper.Setup(x => x.Map <RentItem>(It.IsAny <RentItemDtoModel>())).Returns(rentItemStub);
            var rentItemService       = new RentItemService(mockeRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object);
            var imagesListWithAnImage = new List <ImagesDtoModel>()
            {
                new ImagesDtoModel()
            };

            //Act
            rentItemService.Add(new RentItemDtoModel(), imagesListWithAnImage);
            rentItemStub.Images.Add(imageStub);

            //Assert
            mockeRepository.Verify(x => x.Add(It.Is <RentItem>(y => y.Equals(rentItemStub))), Times.Once);
        }
Example #2
0
        public void CallsREpostitoryAddOnce()
        {
            //Arrange
            var mockeRepository = new Mock <IGenericEfRepository <RentItem> >();

            mockeRepository.Setup(x => x.Add(It.IsAny <RentItem>())).Verifiable();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedMapper     = new Mock <IMapingService>();
            var rentItemService  = new RentItemService(mockeRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object);

            //Act
            rentItemService.Add(new RentItemDtoModel());

            //Assert
            mockeRepository.Verify(x => x.Add(It.IsAny <RentItem>()), Times.Once);
        }
Example #3
0
        public void CallsMapperMapOnceWithSameRentItemDtoModel()
        {
            //Arrange
            var mockeRepository = new Mock <IGenericEfRepository <RentItem> >();

            var mockedUnitOfWork     = new Mock <IUnitOfWork>();
            var mockedMapper         = new Mock <IMapingService>();
            var RentItemDtoModelStub = new RentItemDtoModel();

            mockedMapper.Setup(x => x.Map <RentItem>(RentItemDtoModelStub)).Verifiable();
            var rentItemService = new RentItemService(mockeRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object);

            //Act
            rentItemService.Add(RentItemDtoModelStub);

            //Assert
            mockedMapper.Verify(x => x.Map <RentItem>(It.Is <RentItemDtoModel>(y => y.Equals(RentItemDtoModelStub))), Times.Once);
        }
        public void CallsUnitOfWork_CommitOnceWithEmtpyImageList()
        {
            //Arrange
            var mockeRepository = new Mock <IGenericEfRepository <RentItem> >();

            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            mockedUnitOfWork.Setup(x => x.Commit()).Verifiable();
            var mockedMapper     = new Mock <IMapingService>();
            var rentItemService  = new RentItemService(mockeRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object);
            var emtptyImagesList = new List <ImagesDtoModel>();

            //Act
            rentItemService.Add(new RentItemDtoModel(), emtptyImagesList);

            //Assert
            mockedUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
        public void CallsMapperMapTwiceWithOneImageInImageList()
        {
            //Arrange
            var mockeRepository = new Mock <IGenericEfRepository <RentItem> >();

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedMapper     = new Mock <IMapingService>();

            mockedMapper.Setup(x => x.Map <RentItem>(It.IsAny <RentItemDtoModel>())).Returns(new RentItem()).Verifiable();
            mockedMapper.Setup(x => x.Map <Image>(It.IsAny <ImagesDtoModel>())).Returns(new Image()).Verifiable();
            var rentItemService       = new RentItemService(mockeRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object);
            var imagesListWithAnImage = new List <ImagesDtoModel>()
            {
                new ImagesDtoModel()
            };

            //Act
            rentItemService.Add(new RentItemDtoModel(), imagesListWithAnImage);

            //Assert
            mockedMapper.Verify(x => x.Map <RentItem>(It.IsAny <RentItemDtoModel>()), Times.Once);
            mockedMapper.Verify(x => x.Map <Image>(It.IsAny <ImagesDtoModel>()), Times.Once);
        }