Example #1
0
        public void CreateShouldAddAndReturnTheFilmCreated()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateShouldAddAndReturnTheFilmCreated))
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var filmService = new FilmService(context);
                var addedFilm   = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "Create",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0
                }, null);

                Assert.IsNotNull(addedFilm);
                Assert.AreEqual("Create", addedFilm.Title);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            IPersonRepository <Person> ps     = new PersonService();
            IEnumerable <Person>       people = ps.Get();

            foreach (Person person in people)
            {
                Console.WriteLine(person.Nom + " " + person.Prenom);
            }
            Console.ReadLine();
            IFilmRepository <Film> fs = new FilmService();
            Film film = fs.Get(1);

            Console.WriteLine(film.Titre);
            Console.WriteLine(film.ActeurPrincipal.Nom);
            foreach (Person person in film.Acteurs)
            {
                Console.WriteLine(person.Nom + " " + person.Prenom + " " + person.Age);
            }
            Console.ReadLine();

            ///////Mapping
            Film filmTest = new Film(0, "Die Hard", null, null);
            ///////Wrapping
            //Film filmTest = new Film();
            //filmTest.Titre = "Die Hard";
            int id = fs.Create(filmTest);

            Console.WriteLine(fs.Get(id).Titre);
            Console.ReadLine();
        }
Example #3
0
        public void GetByIdShouldReturnFilmWithCorrectIdNumber()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnFilmWithCorrectIdNumber))
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var filmService = new FilmService(context);
                var addedFilm   = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "Testare",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0
                }, null);

                var theFilm = filmService.GetById(1);
                Assert.AreEqual("Testare", theFilm.Title);
            }
        }
Example #4
0
        public void DeleteShouldRemoveAndReturnFilm()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldRemoveAndReturnFilm))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var filmService = new FilmService(context);
                var toAdd       = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "DeSters",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0
                }, null);

                Assert.IsNotNull(toAdd);
                Assert.AreEqual(1, filmService.GetAll(new DateTime(), new DateTime(), 1).Entries.Count);

                var deletedFilm = filmService.Delete(1);

                Assert.IsNotNull(deletedFilm);
                Assert.AreEqual(0, filmService.GetAll(new DateTime(), new DateTime(), 1).Entries.Count);
            }
        }
Example #5
0
        public void GetAllShouldReturnCorrectNumberOfPagesForFilme()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPagesForFilme))
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var filmService = new FilmService(context);
                var addedFilm   = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "film de test 1",
                    Director    = "dir1",
                    DateAdded   = DateTime.Parse("2019-06-11T00:00:00"),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0,
                    Comentarii  = new List <Comentariu>()
                    {
                        new Comentariu
                        {
                            Important = true,
                            Text      = "asd",
                            AddedBy   = null
                        }
                    },
                }, null);

                DateTime from = DateTime.Parse("2019-06-10T00:00:00");
                DateTime to   = DateTime.Parse("2019-06-12T00:00:00");

                var allFilms = filmService.GetAll(from, to, 1);
                Assert.AreEqual(1, allFilms.Entries.Count);
            }
        }
Example #6
0
        public void UpsertShouldChangeTheFildValues()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldChangeTheFildValues))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var filmService = new FilmService(context);
                var original    = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "Original",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0
                }, null);


                var film = new Lab3.ViewModels.FilmPostModel
                {
                    Title = "upsert"
                };

                context.Entry(original).State = EntityState.Detached;

                var result = filmService.Upsert(1, film);

                Assert.IsNotNull(original);
                Assert.AreEqual("upsert", result.Title);
            }
        }
        public void GetAllShouldReturnCorrectNumberOfPages()
        {
            var options = new DbContextOptionsBuilder <FilmeDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPages))
                          .Options;

            using (var context = new FilmeDbContext(options))
            {
                var commentService = new ComentariuService(context);
                var filmService    = new FilmService(context);
                var addedFlower    = filmService.Create(new Lab3.ViewModels.FilmPostModel
                {
                    Title       = "film de test 1",
                    Director    = "dir1",
                    DateAdded   = new DateTime(),
                    Duration    = 100,
                    Description = "asdvadfbdbsb",
                    Genre       = "Comedy",
                    ReleaseYear = 2000,
                    Rating      = 3,
                    Watched     = 0,
                    Comentarii  = new List <Comentariu>()
                    {
                        new Comentariu
                        {
                            Important = true,
                            Text      = "asd",
                            AddedBy   = null
                        }
                    },
                }, null);

                var allComments = commentService.GetAll(string.Empty, 1);
                Assert.AreEqual(1, allComments.NumberOfPages);
            }
        }
Example #8
0
 [HttpPost] //Добавить пользователя в базу данных
 public ActionResult <FeaturedFims> Create(FeaturedFims featuredFims)
 {
     _filmService.Create(featuredFims);
     return(CreatedAtRoute("GetFilm", new { id = featuredFims._id }, featuredFims));
 }
        public ActionResult <Film> Create(Film film)
        {
            _filmService.Create(film);

            return(CreatedAtRoute("GetFilm", new { id = film.Id.ToString() }, film));
        }
Example #10
0
 public ActionResult AddFilm(Film f)
 {
     fs.Create(f);
     return(RedirectToAction("Film"));
 }