예제 #1
0
        public void WhenMoovieIdExist_ShouldReturnTrue()
        {
            //Arrange
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(a => a.RepositoryBase.Get <Moovie>(
                                     It.IsAny <Expression <Func <Moovie, bool> > >(),
                                     It.IsAny <Func <IQueryable <Moovie>,
                                                     IOrderedQueryable <Moovie> > >()))
            .Returns(new List <Moovie>().AsQueryable());
            mockUnitOfWork
            .Setup(moq => moq.RepositoryBase.FirstOrDefault <Moovie>(
                       It.IsAny <Expression <Func <Moovie, bool> > >(),
                       It.IsAny <Func <IQueryable <Moovie>, IOrderedQueryable <Moovie> > >()))
            .Returns(new Moovie());
            mockUnitOfWork
            .Setup(moq => moq.RepositoryBase.Delete(It.IsAny <Moovie>()));
            mockUnitOfWork
            .Setup(moq => moq.Commit());

            var mockCountryService = new Mock <ICountryService>();
            var mockGenreService   = new Mock <IGenreService>();
            var mockArtistService  = new Mock <IArtistService>();

            var service = new MoovieService(mockUnitOfWork.Object, mockArtistService.Object,
                                            mockCountryService.Object, mockGenreService.Object);

            //Act
            var result = service.Remove("");

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Status);
            Assert.Equal("Filme removido com sucesso!", result.Message);
        }
예제 #2
0
        public void WhenMoovieNameDoesNotExist_ShouldReturnFalse()
        {
            //Arrange
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(a => a.RepositoryBase.Get <Moovie>(
                                     It.IsAny <Expression <Func <Moovie, bool> > >(),
                                     It.IsAny <Func <IQueryable <Moovie>,
                                                     IOrderedQueryable <Moovie> > >()))
            .Returns(new List <Moovie>().AsQueryable());

            var mockCountryService = new Mock <ICountryService>();
            var mockGenreService   = new Mock <IGenreService>();
            var mockArtistService  = new Mock <IArtistService>();

            var service = new MoovieService(mockUnitOfWork.Object, mockArtistService.Object,
                                            mockCountryService.Object, mockGenreService.Object);

            //Act
            var result = service.Remove("");

            //Assert
            Assert.NotNull(result);
            Assert.False(result.Status);
            Assert.Equal("Filme não encontrado.", result.Message);
        }