Esempio n. 1
0
        public void IsMovieAlreadyPresent_ShouldThrowArgumentExceptionAndCorrectMessage_WhenMovieAlreadyInDb()
        {
            var options = TestUtils.GetOptions(nameof(IsMovieAlreadyPresent_ShouldThrowArgumentExceptionAndCorrectMessage_WhenMovieAlreadyInDb));

            using (var arrangeContext = new MovInfoContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessLogicValidator>();
                var service = new MovieServices(arrangeContext, mockBusinessValidator.Object);

                var addedMovie = service.AddMovieAsync(
                    TestSamples.exampleMovie.Name,
                    TestSamples.exampleMovie.DateCreated,
                    new List <long> {
                    1, 2, 3
                },
                    new List <long> {
                    1, 2, 3
                },
                    TestSamples.exampleMovie.Trailer,
                    TestSamples.exampleMovie.Bio,
                    TestSamples.exampleMovie.MainImageName,
                    TestSamples.allowedRoles);

                arrangeContext.SaveChanges();
            }

            using (var assertContext = new MovInfoContext(options))
            {
                var mockWrapUserManager = new Mock <IWrapUserManager>();
                var mockHttpContext     = new Mock <IHttpContextAccessor>();

                var sut = new BusinessLogicValidator(mockHttpContext.Object, mockWrapUserManager.Object);

                var ex = Assert.ThrowsException <ArgumentException>(() => sut.IsMovieAlreadyPresent(assertContext, TestSamples.exampleMovie.Name, TestSamples.exampleMovie.DateCreated.Year));
                Assert.AreEqual(ex.Message, BusinessLogicValidatorMessages.MovieAlreadyPresent);
            }
        }