public void CreateVidoeShouldCreateVideoAndReturnItsId()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_CreatingVideos").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new VideoService(dbContext);

            var model = new VideoViewModel
            {
                Title       = "Title",
                Description = "something",
                YoutubeLink = "something",
            };

            var video = service.CreateVideo(model);

            Assert.Equal(1, video);
        }
 public async Task <ApiResponse <Video> > CreateVideo(VideoDto video)
 {
     try
     {
         return(await _videoService.CreateVideo(video));
     }
     catch (Exception ex)
     {
         return(new ApiResponse <Video>()
         {
             Success = false, Errors = new List <string>()
             {
                 ex.Message
             }
         });
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            //List<Video> videos = new List<Video>();

            string[] menuItems =
            {
                "List all videos",
                "show one video by id",
                "Add video",
                "Delete video",
                "Edit video",
                "Exit"
            };

            var selection = 0;

            while (selection != 5)
            {
                selection = ShowMenu(menuItems);
                Console.ReadLine();

                switch (selection)
                {
                case 1:
                    Console.WriteLine("List all videos");
                    for (int i = 0; i < VideoService.GetVideos().Count; i++)
                    {
                        //Console.WriteLine((i +1) + ":" + menuItems[i]);
                        Console.WriteLine($"{(i + 1)}:{VideoService.GetVideos()[i]}");
                    }

                    Console.ReadLine();
                    break;

                case 2:
                    Console.WriteLine("show single video by id");
                    Console.Write("write id of the video you want:");

                    while (!int.TryParse(Console.ReadLine(), out selection))
                    {
                        Console.WriteLine("You need to select an id");
                    }


                    int showid = selection;

                    if (VideoService.GetVideos().Find(x => x.Id == selection) == null)
                    {
                        Console.WriteLine("could not find video");
                        Console.ReadLine();
                    }

                    Console.WriteLine(VideoService.GetVideos().Find(x => x.Id == selection));
                    Console.ReadLine();



                    break;

                case 3:
                    // TODO: add input validation
                    Console.WriteLine("Add video");
                    Console.WriteLine("Enter title");
                    string title = Console.ReadLine();

                    Console.WriteLine("Enter release date");
                    Console.ReadLine();
                    Console.WriteLine("Enter year");
                    int year = int.Parse(Console.ReadLine());
                    Console.ReadLine();
                    Console.WriteLine("Enter month");
                    int month = int.Parse(Console.ReadLine());

                    Console.ReadLine();
                    Console.WriteLine("Enter day");
                    int day = int.Parse(Console.ReadLine());

                    DateTime date = new DateTime(year, month, day);

                    Console.ReadLine();
                    Console.WriteLine("Enter storyline");
                    string storyline = Console.ReadLine();

                    Console.ReadLine();
                    Console.WriteLine("Enter genre");
                    string action = Console.ReadLine();

                    VideoService.CreateVideo(new Video(title, date, storyline, action));

                    Console.ReadLine();
                    break;

                case 4:
                    // TODO: finish creating deletion.
                    Console.WriteLine("Delete video");
                    Console.ReadLine();
                    Console.Write("write the id of the video you wish to delete:");


                    break;

                case 5:
                    Console.WriteLine("Edit video");
                    Console.ReadLine();
                    break;

                case 6:
                    Console.WriteLine("Exit");
                    Console.ReadLine();
                    break;
                }
            }
        }