Exemplo n.º 1
0
        public async Task TestGetAllFilms_ReturnAllFilmsSuccessfully()
        {
            // Arrange
            int           page   = 1;
            string        search = null;
            FilmListModel model  = new FilmListModel()
            {
                Films = filmsList, TotalCount = filmsList.Count()
            };

            filmService.Setup(film => film.GetFilmsAsync(page, search)).ReturnsAsync(model);
            FilmsController controller = new FilmsController(filmService.Object, mapper);

            // Act
            var result = await controller.GetAllFilms();

            // Assert
            var okResult = result.Result as OkObjectResult;

            Assert.NotNull(okResult);

            var objectResult = okResult.Value as FilmListViewModel;

            Assert.NotNull(objectResult);
            Assert.Equal(filmsList.Count, objectResult.Films.Count());
            Assert.Equal(2006, objectResult.Films.FirstOrDefault().Year);

            filmService.Verify(f => f.GetFilmsAsync(page, search), Times.Once);
        }
Exemplo n.º 2
0
        public async Task EditFilmWithInvalidData()
        {
            var film = new Film()
            {
                Title = "Godfather", Year = 1972, Length = 175
            };
            var newFilmData = new Film()
            {
                Title = "Godfather II", Year = 1410, Length = 175
            };

            var service = new Mock <IFilmRepository>();

            service.Setup(x => x.GetFilm(0)).ReturnsAsync(film);
            service.Setup(x => x.FilmExists(0)).Returns(true);
            var controller = new FilmsController(service.Object);

            controller.ModelState.AddModelError("", "");

            var result = await controller.Edit(0, newFilmData);

            var model = ((ViewResult)result).Model as Film;

            Assert.AreEqual(newFilmData, model);
        }
Exemplo n.º 3
0
        public async void Post_ReturnsBadRequestObjectWithMessageToAddFilmFirst_ForNewFilmWhichContainsCast()
        {
            //Arrange
            var repository = new FakeFilmRepository();

            repository.Add(new Director()
            {
                Id = 1, FirstName = "Quentin", LastName = "Tarantino"
            });
            repository.Add(new Actor()
            {
                Id = 1, FirstName = "Kurt", LastName = "Russell", ActorFilms = new List <ActorFilm>()
                {
                    new ActorFilm()
                    {
                        FilmId = 1, ActorId = 1
                    }
                }
            });
            repository.Add(new Film()
            {
                Id = 1, DirectorId = 1, Title = "The Hateful Eight", Cast = new List <ActorFilm>()
                {
                    new ActorFilm()
                    {
                        FilmId = 1, ActorId = 1
                    }
                }
            });

            await repository.SaveChangesAsync();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <FilmProfile>();
            });

            var mapper = config.CreateMapper();

            var controller = new FilmsController(repository, mapper);

            var newFilm = new FilmModel()
            {
                Cast = new List <ActorModel>()
                {
                    new ActorModel()
                    {
                        FirstName = "Kurt", LastName = "Russell"
                    }
                }, Title = "The Hateful Eight"
            };

            //Act
            var result = await controller.Post(newFilm);

            //Assert
            Assert.IsType <BadRequestObjectResult>(result.Result);
            Assert.Equal("Please add film first. Update films cast with updatefilm method", (result.Result as BadRequestObjectResult).Value);
        }
        public void TryEdit_ByIncorrectId_ReturnNotFound()
        {
            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Edit(1, films.ElementAt(1), null) as NotFoundResult;

            Assert.AreEqual(404, res.StatusCode);
        }
        public void TryEdit_IncorretcModel_Exception()
        {
            repos.Setup(m => m.updateFilm(It.IsAny <Film>())).Throws(new DbUpdateException("error", new Exception()));

            FilmsController controller = new FilmsController(repos.Object);

            Assert.ThrowsException <Exception>(() => controller.Edit(2, films.ElementAt(1), null));
        }
        public void CheckFilmExist_AnExistedModel_ReturnTrue()
        {
            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.FilmExists(1);

            Assert.IsTrue(res);
        }
        public void CheckFilmExist_AnUnexistedModel_ReturnFalse()
        {
            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.FilmExists(10);

            Assert.IsFalse(res);
        }
        public void GetFilmByIdSmokeTest()
        {
            var controller = new FilmsController();
            var result     = controller.Get(101) as OkObjectResult;
            var film       = result.Value as Film;

            new FilmsControllerTest().FilmTest(film);
        }
        public void GetDetails_WithIdNull_ReturnNotFound()
        {
            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Details(null) as NotFoundResult;

            Assert.AreEqual(404, res.StatusCode);
        }
Exemplo n.º 10
0
        public void TestInit()
        {
            var builder = new DbContextOptionsBuilder <FilmsDBContext>().UseNpgsql("Server=localhost;port=5432;Database=FilmsDBTP3;uid=postgres;password=postgres;");

            _context        = new FilmsDBContext(builder.Options);
            _dataRepository = new FilmManager(_context);
            _controller     = new FilmsController(_dataRepository);
        }
Exemplo n.º 11
0
        public void GetFilmByIdSmokeTest()
        {
            var controller = new FilmsController();
            var result     = controller.GetFilm(10);

            Assert.Equal(result.Film_ID, 10);
            Assert.Equal(result.Title, "ALADDIN CALENDAR");
            Assert.Equal(result.Release_Year, 2006);
        }
Exemplo n.º 12
0
        public void CreateFilm_ReturnView()
        {
            FilmsController fContr = new FilmsController(repos.Object);

            var res = fContr.Create() as ViewResult;


            Assert.IsNotNull("Create", res.ViewName);
        }
Exemplo n.º 13
0
        public void CreateFilmTest()
        {
            var service    = new Mock <IFilmRepository>();
            var controller = new FilmsController(service.Object);

            var result = controller.Create();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemplo n.º 14
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm        form       = new MainForm();
            FilmsController controller = new FilmsController(form);

            Application.Run(form);
        }
Exemplo n.º 15
0
        public void CheckIndex_ReturnValidNumberOfObjectInView()
        {
            FilmsController fContr = new FilmsController(repos.Object);

            var res = ((IEnumerable <Film>)(fContr.Index() as ViewResult).
                       ViewData.Model).ToList();

            Assert.AreEqual(4, res.Count);
        }
Exemplo n.º 16
0
        public void TryEdit_UsingCorrectModel_RedirectToIndex()
        {
            repos.Setup(m => m.updateFilm(films.ElementAt(1))).Returns(true);

            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Edit(2, films.ElementAt(1), null) as RedirectToActionResult;

            Assert.AreEqual("Index", res.ActionName);
        }
        public void ShouldDeleteFilm()
        {
            FilmsController controller = new FilmsController();

            controller.Delete(2);

            var result = controller.Get(2) as OkNegotiatedContentResult <Film>;

            Assert.IsNull(result);
        }
Exemplo n.º 18
0
        public void TryEdit_AnExistigFilm_ReturnEditView()
        {
            repos.Setup(m => m.getFilmById(1)).Returns(films.Find(x => x.ID == 1));

            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Edit(1) as ViewResult;

            Assert.AreEqual("Edit", res.ViewName);
        }
Exemplo n.º 19
0
        public void CheckCreate_CreteValidModel_RedirectToIndex()
        {
            repos.Setup(m => m.addFilm(films.ElementAt(1))).Returns(true);

            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Create(films.ElementAt(1)) as RedirectToActionResult;

            Assert.AreEqual("Index", res.ActionName);
        }
        public void ShouldGetFilmsAtivo()
        {
            FilmsController controller = new FilmsController();

            var result = controller.Get(true) as OkNegotiatedContentResult <List <Film> >;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(4, result.Content.Count());
        }
Exemplo n.º 21
0
        public void CheckBuy_AnExistigFilm_ReturnBuyView()
        {
            repos.Setup(m => m.getFilmById(1)).Returns(films.Find(x => x.ID == 1));

            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Buy(1) as ViewResult;

            Assert.AreEqual("Buy", res.ViewName);
        }
Exemplo n.º 22
0
        public void CheckDelete_DeleteCorrectModel_RedirectToIndex()
        {
            repos.Setup(m => m.getFilmById(1)).Returns(films.Find(x => x.ID == 1));
            repos.Setup(m => m.deleteFilm(It.IsAny <Film>())).Returns(true);
            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.DeleteConfirmed(1) as RedirectToActionResult;

            Assert.AreEqual("Index", res.ActionName);
        }
        public void ShouldGetFilm()
        {
            FilmsController controller = new FilmsController();

            var result = controller.Get(1) as OkNegotiatedContentResult <Film>;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual("Filme do Teste Get ID", result.Content.Nome);
        }
Exemplo n.º 24
0
        public void GetDetails_OfExistigFilm_ReturnViewOfValidFilm()
        {
            repos.Setup(m => m.getFilmById(1)).Returns(films.Find(x => x.ID == 1));

            FilmsController controller = new FilmsController(repos.Object);

            var res = (Film)(controller.Details(1) as ViewResult).Model;

            Assert.AreEqual(1, res.ID);
        }
Exemplo n.º 25
0
        public void Films()
        {
            //arrange
            FilmsController controller = new FilmsController();

            //act
            ViewResult result = controller.Index() as ViewResult;

            //assert
            Assert.IsNotNull("");
        }
Exemplo n.º 26
0
        public void getFilms()
        {
            mockContext.Setup(c => c.Films).Returns(dbSetFilms);
            var service = new FilmsController(mockContext.Object);

            List <Film> allFilms = service.getAllFilms().ToList();

            Assert.AreEqual(allFilms[0].Name, "Ime1");
            Assert.AreEqual(allFilms[1].Name, "Ime2");
            Assert.AreEqual(allFilms[2].Name, "Ime3");
        }
Exemplo n.º 27
0
        public void GetDetails_OfUnexistigFilm_ReturnNotFound()
        {
            Film film5 = null;

            repos.Setup(m => m.getFilmById(5)).Returns(film5);

            FilmsController controller = new FilmsController(repos.Object);

            var res = controller.Details(5) as NotFoundResult;

            Assert.AreEqual(404, res.StatusCode);
        }
Exemplo n.º 28
0
        public void getArchivedFilms()
        {
            mockContext.Setup(c => c.ArchivedFilms).Returns(dbSetArchivedFilms);
            var service = new FilmsController(mockContext.Object);

            List <ArchivedFilm> allArchivedFilms = service.getAllArchivedFilms().ToList();

            Assert.AreEqual(allArchivedFilms[0].Genre, "Drama");
            Assert.AreEqual(allArchivedFilms[1].LastScreening, "14.09.2018");
            Assert.AreEqual(allArchivedFilms[0].Name, "Adrift");
            Assert.AreEqual(allArchivedFilms[1].Id, 102);
            Assert.AreEqual(allArchivedFilms[1].ReleaseDate, "March 02, 2017 (United States)");
        }
Exemplo n.º 29
0
        public void getClients()
        {
            mockContext.Setup(c => c.Clients).Returns(dbSetClients);
            var service = new FilmsController(mockContext.Object);

            List <Client> allClients = service.getAllClients().ToList();

            Assert.AreEqual(allClients[0].Name, "User1");
            Assert.AreEqual(allClients[1].Name, "User2");
            Assert.AreEqual(allClients[2].Email, "*****@*****.**");
            Assert.AreEqual(allClients[3].ClientId, 123);
            Assert.AreEqual(allClients[4].Name, "User5");
        }
Exemplo n.º 30
0
        public async Task EmptyDBofFilms()
        {
            var service = new Mock <IFilmRepository>();

            service.Setup(x => x.GetFilms()).ReturnsAsync(new List <Film>());
            var controller = new FilmsController(service.Object);

            var result = await controller.Index(String.Empty);

            var viewResult = (ViewResult)result;
            var model      = ((ViewResult)result).Model as List <Film>;

            Assert.AreEqual(0, model.Count);
        }