Пример #1
0
        public void CallEfDbRepository_GetAll_MethodOnce()
        {
            // Arange
            var mockedModelDbFactory  = new Mock <IModelDbFactory>();
            var mockedSanitizer       = new Mock <ISanitizer>();
            var mockedMapper          = new Mock <IAutoMapperService>();
            var mockedEfDbContext     = new Mock <IEfDbContextSaveChanges>();
            var mockedIEfDbRepository = new Mock <IPhotoArtSystemEfDbRepository <Photocourse> >();

            var service = new PhotocourseService(
                mockedModelDbFactory.Object,
                mockedSanitizer.Object,
                mockedMapper.Object,
                mockedEfDbContext.Object,
                mockedIEfDbRepository.Object);

            // Act
            service.GetAll();

            // Assert
            mockedIEfDbRepository.Verify(x => x.GetAll(), Times.Once);
        }
Пример #2
0
        public void ReturnProperlyResult_When_Photocourse_IsNotEmpty()
        {
            // Arange
            var mockedModelDbFactory = new Mock <IModelDbFactory>();
            var mockedSanitizer      = new Mock <ISanitizer>();
            var entityList           = new List <Photocourse>();
            var mockedEntity         = new Mock <PhotocourseTransitional>();

            var expected = new List <PhotocourseTransitional>();

            expected.Add(mockedEntity.Object);

            var mockedMapper = new Mock <IAutoMapperService>();

            mockedMapper
            .Setup(x => x.Map <IEnumerable <PhotocourseTransitional> >(It.IsAny <IEnumerable <Photocourse> >()))
            .Returns(expected);

            var mockedEfDbContext     = new Mock <IEfDbContextSaveChanges>();
            var mockedIEfDbRepository = new Mock <IPhotoArtSystemEfDbRepository <Photocourse> >();

            mockedIEfDbRepository.Setup(x => x.GetAll()).Returns(entityList.AsQueryable());

            var service = new PhotocourseService(
                mockedModelDbFactory.Object,
                mockedSanitizer.Object,
                mockedMapper.Object,
                mockedEfDbContext.Object,
                mockedIEfDbRepository.Object);

            // Act
            var actual = service.GetAll();

            // Assert
            Assert.AreSame(expected[0], actual.ToList()[0]);
        }