Example #1
0
        public void ReturnProperlyResult_From_EfDbRepository()
        {
            // Arange
            Fixture fixture              = new Fixture();
            var     id                   = fixture.Create <Guid>();
            var     mockedEntity         = new Mock <Photocourse>();
            var     expectedMockedEntity = new Mock <PhotocourseTransitional>();
            var     mockedModelDbFactory = new Mock <IModelDbFactory>();
            var     mockedSanitizer      = new Mock <ISanitizer>();
            var     mockedMapper         = new Mock <IAutoMapperService>();

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

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

            mockedIEfDbRepository.Setup(x => x.GetById(id)).Returns(mockedEntity.Object);

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

            // Act
            var actual = service.GetById(id);

            // Assert
            Assert.AreSame(expectedMockedEntity.Object, actual);
        }
Example #2
0
        public void CallEfDbRepository_GetById_MethodOnce()
        {
            // Arange
            Fixture fixture = new Fixture();
            var     id      = fixture.Create <Guid>();
            var     mockedModelDbFactory  = new Mock <IModelDbFactory>();
            var     mockedEntity          = new Mock <Photocourse>();
            var     mockedSanitizer       = new Mock <ISanitizer>();
            var     mockedMapper          = new Mock <IAutoMapperService>();
            var     mockedEfDbContext     = new Mock <IEfDbContextSaveChanges>();
            var     mockedIEfDbRepository = new Mock <IPhotoArtSystemEfDbRepository <Photocourse> >();

            mockedIEfDbRepository.Setup(x => x.GetById(id)).Returns(mockedEntity.Object);

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

            // Act
            var result = service.GetById(id);

            // Assert
            mockedIEfDbRepository.Verify(x => x.GetById(id), Times.Once);
        }