public async Task CreateVideoAsync_WithValidData_VideosInDatabaseShouldReturnCorrectCount()
        {
            //Arrange
            var expectedResult = 1;

            var moqPictureService = new Mock <IPicturesService>();

            moqPictureService.Setup(x => x.GetPictureByLinkAsync("pictureLink"))
            .ReturnsAsync(new Picture
            {
                Id   = 1,
                Name = "PictureName",
            });

            var moqUsersService = new Mock <IUsersService>();

            var option = new DbContextOptionsBuilder <ChessDbContext>()
                         .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var db = new ChessDbContext(option);

            this.videosService = new VideosService(db, moqPictureService.Object, mapper, moqUsersService.Object);

            var inputModel = new AddVideoInputModel
            {
                VideoTitle = "VideoTitle",
                VideoLink  = "VideoLink"
            };

            //Act
            await this.videosService.CreateVideoAsync(inputModel);

            //Assert
            Assert.Equal(expectedResult, db.Videos.ToList().Count);
        }
        public async Task CreateVideoAsync(AddVideoInputModel model)
        {
            await this.picturesService.CreatePictureAsync(model.PictureName, model.PictureLink);

            var pictureFromDb = await this.picturesService.GetPictureByLinkAsync(model.PictureLink);

            var video = new Video
            {
                Title   = model.VideoTitle,
                Link    = model.VideoLink,
                Picture = pictureFromDb,
            };

            await this.db.Videos.AddAsync(video);

            await this.db.SaveChangesAsync();
        }
Beispiel #3
0
        public async Task <IActionResult> Add(AddVideoInputModel input)
        {
            await this.videosService.CreateVideoAsync(input);

            return(this.Redirect("/"));
        }