Ejemplo n.º 1
0
        public void GivenFilmServiceWhenAttempingToAddAFilmWhenTheRepoFailedThenTheResultIsFailed()
        {
            var filmRepository = new Mock <IFilmRepository>();

            filmRepository
            .Setup(r => r.GetAll())
            .Returns(new GetFilmsResult {
                Result = RepositoryResult.Failed
            });

            var filmService = new AddFilmService(filmRepository.Object);

            var result = filmService.AddFilm("Shawshank Redemption", 1994);

            Assert.That(result, Is.EqualTo(AddFilmResult.Failed));
        }
Ejemplo n.º 2
0
        public void GivenFilmServiceWhenGetAllFilmsFailsToGetFilmsThenNoFilmsShouldBeReturned()
        {
            var filmRepository = new Mock <IFilmRepository>();

            filmRepository
            .Setup(r => r.GetAll())
            .Returns(new GetFilmsResult {
                Result = RepositoryResult.Failed
            });

            var filmService = new AddFilmService(filmRepository.Object);

            var result = filmService.GetWishlist();

            Assert.That(result.Count(), Is.EqualTo(0));
        }
Ejemplo n.º 3
0
        public void GivenFilmsWhenAddFilmFailsThenTheResultIsReturnedAsFailed()
        {
            var filmRepository = new Mock <IFilmRepository>();

            filmRepository
            .Setup(r => r.GetAll())
            .Returns(new GetFilmsResult {
                Result = RepositoryResult.Successful, Value = new List <FilmEntity>()
            });
            filmRepository
            .Setup(r => r.Add(It.Is <Film>(f => f.Title == "Shawshank Redemption" && f.Year == 1994)))
            .Returns(RepositoryResult.Failed);

            var filmService = new AddFilmService(filmRepository.Object);

            var result = filmService.AddFilm("Shawshank Redemption", 1994);

            Assert.That(result, Is.EqualTo(AddFilmResult.Failed));
        }
Ejemplo n.º 4
0
        public void GivenSomeFilmsWhenGetAllFilmsIsCalledThenAllTheFilmsShouldBeReturned()
        {
            var filmRepository = new Mock <IFilmRepository>();
            var films          = new [] { new FilmEntity {
                                              Title = "Shawshank Redemption", Year = 1994
                                          } };

            filmRepository
            .Setup(r => r.GetAll())
            .Returns(new GetFilmsResult {
                Result = RepositoryResult.Successful, Value = films
            });

            var filmService = new AddFilmService(filmRepository.Object);

            var shawshank = filmService.GetWishlist().First(f => f.Title == "Shawshank Redemption");

            Assert.That(shawshank.Title, Is.EqualTo("Shawshank Redemption"));
            Assert.That(shawshank.Year, Is.EqualTo(1994));
        }
Ejemplo n.º 5
0
        public void GivenFilmServiceWhenAttempingToAddADuplicationFilmThenTheResultIsDuplicate()
        {
            var filmRepository = new Mock <IFilmRepository>();
            var filmEntities   = new List <FilmEntity> {
                new FilmEntity {
                    Title = "Shawshank Redemption", Year = 1994
                }
            };

            filmRepository
            .Setup(r => r.GetAll())
            .Returns(new GetFilmsResult {
                Result = RepositoryResult.Successful, Value = filmEntities
            });

            var filmService = new AddFilmService(filmRepository.Object);

            var result = filmService.AddFilm("Shawshank Redemption", 1994);

            Assert.That(result, Is.EqualTo(AddFilmResult.Duplicate));
        }