예제 #1
0
        public void WhenMoovieIdDoesNotExist_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());
            mockUnitOfWork
            .Setup(moq => moq.RepositoryBase.FirstOrDefault <Moovie>(
                       It.IsAny <Expression <Func <Moovie, bool> > >(),
                       It.IsAny <Func <IQueryable <Moovie>, IOrderedQueryable <Moovie> > >()))
            .Returns <Moovie>(null);

            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.GetBasicInfo("");

            //Assert
            Assert.NotNull(result);
            Assert.False(result.Status);
            Assert.Equal("Filme não encontrado.", result.Message);
        }
예제 #2
0
        public void WhenMoovieIdExist_ShouldReturnTrue()
        {
            //Arrange
            var moovie = new Moovie()
            {
                Id          = Guid.NewGuid(),
                Name        = "",
                ReleaseDate = DateTime.Now.Brasilia(),
                Director    = new Artist()
                {
                    Name = ""
                },
                Country = new Country()
                {
                    Name = ""
                },
                Genre = new Genre()
                {
                    Name = ""
                },
                Observations = ""
            };

            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>()
            {
                moovie
            }.AsQueryable());
            mockUnitOfWork
            .Setup(moq => moq.RepositoryBase.FirstOrDefault <Moovie>(
                       It.IsAny <Expression <Func <Moovie, bool> > >(),
                       It.IsAny <Func <IQueryable <Moovie>, IOrderedQueryable <Moovie> > >()))
            .Returns(moovie);

            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.GetBasicInfo("");

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Status);
            Assert.Equal("Filme localizado.", result.Message);
            Assert.NotNull(result.Object);
        }