コード例 #1
0
        public void CallsMapperMapOnce()
        {
            //Arrange

            var mockeRepository      = new Mock <IGenericEfRepository <RentItem> >();
            var stubId               = Guid.NewGuid();
            var mockedUnitOfWork     = new Mock <IUnitOfWork>();
            var mockedMapper         = new Mock <IMapingService>();
            var RentItemDtoModelStub = new RentItem();

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

            //Act
            rentItemService.GetRentItemById(stubId);

            //Assert
            mockedMapper.Verify(x => x.Map <RentItemDetaildDtoModel>(It.IsAny <RentItem>()), Times.Once);
        }
コード例 #2
0
        public void CallsRepositoryGetByIdOnceWithSameId()
        {
            //Arrange

            var mockeRepository = new Mock <IGenericEfRepository <RentItem> >();
            var stubId          = Guid.NewGuid();

            mockeRepository.Setup(x => x.GetById(stubId)).Verifiable();
            var mockedUnitOfWork     = new Mock <IUnitOfWork>();
            var mockedMapper         = new Mock <IMapingService>();
            var RentItemDtoModelStub = new RentItemDtoModel();
            var rentItemService      = new RentItemService(mockeRepository.Object, mockedUnitOfWork.Object, mockedMapper.Object);

            //Act
            rentItemService.GetRentItemById(stubId);

            //Assert
            mockeRepository.Verify(x => x.GetById(It.Is <Guid>(y => y == stubId)), Times.Once);
        }