コード例 #1
0
        public async Task <SamplePlaylist> DeleteSamplePlaylistAsync(SamplePlaylist samplePlaylist2BDeleted)
        {
            _context.SamplePlaylist.Remove(samplePlaylist2BDeleted);
            await _context.SaveChangesAsync();

            return(samplePlaylist2BDeleted);
        }
コード例 #2
0
        public async Task <SamplePlaylist> AddSamplePlaylistAsync(SamplePlaylist newSamplePlaylist)
        {
            await _context.SamplePlaylist.AddAsync(newSamplePlaylist);

            await _context.SaveChangesAsync();

            return(newSamplePlaylist);
        }
        public async Task AddSamplePlaylistShouldAddSamplePlaylist()
        {
            var sample = new SamplePlaylist();

            _projectBLMock.Setup(x => x.AddSamplePlaylistAsync(It.IsAny <SamplePlaylist>())).Returns(Task.FromResult <SamplePlaylist>(sample));
            var sampleController = new SamplePlaylistController(_projectBLMock.Object);
            var result           = await sampleController.AddSamplePlaylistAsync(new SamplePlaylist());

            Assert.IsAssignableFrom <CreatedAtActionResult>(result);
            _projectBLMock.Verify(x => x.AddSamplePlaylistAsync((It.IsAny <SamplePlaylist>())));
        }
コード例 #4
0
        public async Task <SamplePlaylist> UpdateSamplePlaylistAsync(SamplePlaylist samplePlaylist2BUpdated)
        {
            SamplePlaylist oldSamplePlaylist = await _context.SamplePlaylist.Where(s => s.Id == samplePlaylist2BUpdated.Id).FirstOrDefaultAsync();

            _context.Entry(oldSamplePlaylist).CurrentValues.SetValues(samplePlaylist2BUpdated);

            await _context.SaveChangesAsync();

            _context.ChangeTracker.Clear();
            return(oldSamplePlaylist);
        }
        public async Task UpdateSamplePlaylistShouldUpdateSamplePlaylist()
        {
            var sample = new SamplePlaylist {
                Id = 1
            };

            _projectBLMock.Setup(x => x.UpdateSamplePlaylistAsync(It.IsAny <SamplePlaylist>())).Returns(Task.FromResult(sample));
            var sampleController = new SamplePlaylistController(_projectBLMock.Object);
            var result           = await sampleController.UpdateSamplePlaylistAsync(sample.Id, sample);

            Assert.IsAssignableFrom <NoContentResult>(result);
            _projectBLMock.Verify(x => x.UpdateSamplePlaylistAsync(sample));
        }
コード例 #6
0
        public async Task <IActionResult> UpdateSamplePlaylistAsync(int id, [FromBody] SamplePlaylist samplePlaylist)
        {
            try
            {
                await _projectBL.UpdateSamplePlaylistAsync(samplePlaylist);

                return(NoContent());
            }
            catch
            {
                return(StatusCode(500));
            }
        }
        public async Task GetSamplePlaylistByIdShouldGetSample()
        {
            var sampleId = 1;
            var sample   = new SamplePlaylist {
                Id = sampleId
            };

            _projectBLMock.Setup(x => x.GetSamplePlaylistByIDAsync(It.IsAny <int>())).Returns(Task.FromResult(sample));
            var sampleController = new SamplePlaylistController(_projectBLMock.Object);
            var result           = await sampleController.GetSamplePlaylistByIDAsync(sampleId);

            Assert.Equal(sampleId, ((SamplePlaylist)((OkObjectResult)result).Value).Id);
            _projectBLMock.Verify(x => x.GetSamplePlaylistByIDAsync(sampleId));
        }
        public async Task GetSamplesPlaylistAsyncShouldReturnSamplePlaylists()
        {
            //arrange
            SamplePlaylist sample = new SamplePlaylist();

            _projectBLMock.Setup(i => i.GetSamplePlaylistsAsync());
            SamplePlaylistController sampleController = new SamplePlaylistController(_projectBLMock.Object);

            //act
            var result = await sampleController.GetSamplePlaylistsAsync();

            //assert
            Assert.IsType <OkObjectResult>(result);
        }
        public async Task AddSamplePlaylistAsync_ShouldReturnStatusCode400_WhenSamplePlaylistIsInvalid()
        {
            //arrange
            SamplePlaylist samplePlaylist = null;

            _projectBLMock.Setup(i => i.AddSamplePlaylistAsync(samplePlaylist)).Throws(new Exception());
            SamplePlaylistController samplePlaylistController = new SamplePlaylistController(_projectBLMock.Object);

            //act
            var result = await samplePlaylistController.AddSamplePlaylistAsync(samplePlaylist);

            //assert
            Assert.IsType <StatusCodeResult>(result);
            Assert.Equal(400, ((StatusCodeResult)result).StatusCode);
        }
コード例 #10
0
        public async Task <IActionResult> AddSamplePlaylistAsync([FromBody] SamplePlaylist samplePlaylist)
        {
            try
            {
                await _projectBL.AddSamplePlaylistAsync(samplePlaylist);

                Log.Logger.Information($"new SamplePlaylist with ID {samplePlaylist.Id} created");
                return(CreatedAtAction("AddSamplePlaylist", samplePlaylist));
            }
            catch (Exception e)
            {
                Log.Logger.Error($"Error thrown: {e.Message}");
                return(StatusCode(400));
            }
        }
コード例 #11
0
        public async Task UpdateSamplePlaylistAsync_ShouldReturnOldSamplePlaylist()
        {//arrange
            SamplePlaylist samplePlaylist = new SamplePlaylist
            {
                Id       = 1,
                SampleId = 9
            };
            ProjectDBContext projectDBContext = new ProjectDBContext(options);
            ProjectRepoDB    projectRepoDB    = new ProjectRepoDB(projectDBContext);

            //act
            var result = await projectRepoDB.UpdateSamplePlaylistAsync(samplePlaylist);

            //assert
            Assert.Equal(samplePlaylist.SampleId, result.SampleId);
        }
コード例 #12
0
        public async Task AddSamplePlaylistAsync_ShouldReturnNewSamplePlaylist()
        {
            //arrange
            SamplePlaylist samplePlaylist = new SamplePlaylist
            {
                Id          = 89,
                SampleId    = 1,
                SampleSetId = 1
            };
            ProjectDBContext context       = new ProjectDBContext(options);
            ProjectRepoDB    projectRepoDB = new ProjectRepoDB(context);

            //act
            var result = await projectRepoDB.AddSamplePlaylistAsync(samplePlaylist);

            //assert
            Assert.Equal(samplePlaylist.SampleSetId, result.SampleSetId);
        }
コード例 #13
0
 public async Task<SamplePlaylist> UpdateSamplePlaylistAsync(SamplePlaylist samplePlaylist2BUpdated)
 {
     return await _repo.UpdateSamplePlaylistAsync(samplePlaylist2BUpdated);
 }
コード例 #14
0
 public async Task<SamplePlaylist> DeleteSamplePlaylistAsync(SamplePlaylist samplePlaylist2BDeleted)
 {
     return await _repo.DeleteSamplePlaylistAsync(samplePlaylist2BDeleted);
 }
コード例 #15
0
 //SamplePlaylist
 public async Task<SamplePlaylist> AddSamplePlaylistAsync(SamplePlaylist newSamplePlaylist)
 {
     return await _repo.AddSamplePlaylistAsync(newSamplePlaylist);
 }