Ejemplo n.º 1
0
        public async Task <UsersSample> DeleteUsersSampleAsync(UsersSample usersSample2BDeleted)
        {
            _context.UsersSample.Remove(usersSample2BDeleted);
            await _context.SaveChangesAsync();

            return(usersSample2BDeleted);
        }
Ejemplo n.º 2
0
        //UsersSample
        public async Task <UsersSample> AddUsersSampleAsync(UsersSample newUsersSample)
        {
            await _context.UsersSample.AddAsync(newUsersSample);

            await _context.SaveChangesAsync();

            return(newUsersSample);
        }
Ejemplo n.º 3
0
        public async Task <UsersSample> UpdateUsersSampleAsync(UsersSample usersSample2BUpdated)
        {
            UsersSample oldUsersSample = await _context.UsersSample.Where(s => s.Id == usersSample2BUpdated.Id).FirstOrDefaultAsync();

            _context.Entry(oldUsersSample).CurrentValues.SetValues(usersSample2BUpdated);

            await _context.SaveChangesAsync();

            _context.ChangeTracker.Clear();
            return(oldUsersSample);
        }
        public async Task DeleteUsersSampleAsync_ShouldReturnNoContent_WhenIDIsValid()
        {
            int         id          = 1;
            UsersSample usersSample = new UsersSample();

            _projectBLMock.Setup(i => i.DeleteUsersSampleAsync(usersSample)).ReturnsAsync(usersSample);
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            var result = await usersSampleController.DeleteUsersSampleAsync(id);

            Assert.IsType <NoContentResult>(result);
        }
        public async Task DeleteUsersSampleAsync_ShouldReturnStatusCode500_WhenUserSampleIsInvalid()
        {
            int         id          = -1;
            UsersSample usersSample = null;

            _projectBLMock.Setup(i => i.DeleteUsersSampleAsync(usersSample)).Throws(new Exception());
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            var result = await usersSampleController.DeleteUsersSampleAsync(id);

            Assert.IsType <StatusCodeResult>(result);
            Assert.Equal(500, ((StatusCodeResult)result).StatusCode);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateUsersSampleAsync(int id, [FromBody] UsersSample sample)
        {
            try
            {
                await _projectBL.UpdateUsersSampleAsync(sample);

                return(NoContent());
            }
            catch
            {
                return(StatusCode(500));
            }
        }
        public async Task GetUsersSampleAsync_ShouldReturnOKObjectResult()
        {
            //arrange
            UsersSample usersSample = new UsersSample();

            _projectBLMock.Setup(i => i.GetUsersSamplesAsync());
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            //act
            var result = await usersSampleController.GetUsersSamplesAsync();

            //assert
            Assert.IsType <OkObjectResult>(result);
        }
        public async Task AddUsersSampleAsync_ShouldReturnCreatedAtAction_WhenUsersSampleIsValid()
        {
            //arrange
            UsersSample usersSample = new UsersSample();

            _projectBLMock.Setup(i => i.AddUsersSampleAsync(usersSample)).ReturnsAsync(usersSample);
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            //act
            var result = await usersSampleController.AddUsersSampleAsync(usersSample);

            //assert
            Assert.IsType <CreatedAtActionResult>(result);
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> AddUsersSampleAsync([FromBody] UsersSample sample)
        {
            try
            {
                await _projectBL.AddUsersSampleAsync(sample);

                Log.Logger.Information($"new UsersSample with ID {sample.Id} created");
                return(CreatedAtAction("AddUsersSample", sample));
            }
            catch (Exception e)
            {
                Log.Logger.Error($"Error thrown: {e.Message}");
                return(StatusCode(400));
            }
        }
        public async Task GetUsersSampleByIDAsync_ShouldReturnOKObject_WhenIDIsValid()
        {
            //arrange
            int         id          = 1;
            UsersSample usersSample = new UsersSample();

            _projectBLMock.Setup(i => i.GetUsersSampleByIDAsync(id)).ReturnsAsync(usersSample);
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            //act
            var result = await usersSampleController.GetUsersSampleByIDAsync(id);

            //assert
            Assert.IsType <OkObjectResult>(result);
        }
        public async Task UpdateUsersSampleAsync_ShouldReturnNoContent_WhenUsersSampleIsValid()
        {
            //arrange
            int         id          = 1;
            UsersSample usersSample = new UsersSample();

            _projectBLMock.Setup(i => i.UpdateUsersSampleAsync(usersSample)).ReturnsAsync(usersSample);
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            //act
            var result = await usersSampleController.UpdateUsersSampleAsync(id, usersSample);

            //assert
            Assert.IsType <NoContentResult>(result);
        }
        public async Task AddUsersSampleAsync_ShouldReturnStatusCode400_WhenUsersSampleIsInvalid()
        {
            //arrange
            UsersSample usersSample = null;

            _projectBLMock.Setup(i => i.AddUsersSampleAsync(usersSample)).Throws(new Exception());
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            //act
            var result = await usersSampleController.AddUsersSampleAsync(usersSample);

            //assert
            Assert.IsType <StatusCodeResult>(result);
            Assert.Equal(400, ((StatusCodeResult)result).StatusCode);
        }
        public async Task GetUsersSampleByIDAsync_ShouldReturnNotFound_WhenUserSampleIsNull()
        {
            //arrange
            int         id          = -2;
            UsersSample usersSample = null;

            _projectBLMock.Setup(i => i.GetUsersSampleByIDAsync(id)).ReturnsAsync(usersSample);
            UsersSampleController usersSampleController = new UsersSampleController(_projectBLMock.Object);

            //act
            var result = await usersSampleController.GetUsersSampleByIDAsync(id);

            //assert
            Assert.IsType <NotFoundResult>(result);
        }
        public async Task UpdateUsersSampleAsync_ShouldReturn_OldUsersSample()
        {
            //arrange
            UsersSample usersSample = new UsersSample
            {
                Id       = 1,
                SampleId = 98
            };
            var projectDBContext = new ProjectDBContext(options);
            var projectrepoDB    = new ProjectRepoDB(projectDBContext);

            //act
            var result = await projectrepoDB.UpdateUsersSampleAsync(usersSample);

            //assert
            Assert.Equal(usersSample.SampleId, result.SampleId);
        }
        public async Task AddUsersSampleAsync_ShouldReturnNewUsersSample()
        {
            //arrange
            UsersSample usersSample = new UsersSample
            {
                Id       = 9,
                SampleId = 1,
                UserId   = 1
            };
            ProjectDBContext projectDBContext = new ProjectDBContext(options);
            ProjectRepoDB    projectRepoDB    = new ProjectRepoDB(projectDBContext);

            //act
            var result = await projectRepoDB.AddUsersSampleAsync(usersSample);

            //assert
            Assert.Equal(usersSample.Id, result.Id);
        }
Ejemplo n.º 16
0
        //Sample
        public async Task<Sample> AddSampleAsync(Sample newSample, int userId)
        {
            //Sample sample2Add = new Sample();
            //sample2Add.SampleLink = newSample.SampleLink;
            //sample2Add.SampleName = newSample.SampleName;
            //sample2Add.Track = newSample.Track;
            //sample2Add.IsApproved = newSample.IsApproved;
            //sample2Add.IsLocked = newSample.IsLocked;
            //sample2Add.IsPrivate = newSample.IsPrivate;

            //Todo: Add BL
            newSample =  await _repo.AddSampleAsync(newSample);
            UsersSample usersSample = new UsersSample();
            usersSample.SampleId = newSample.Id;
            usersSample.IsOwner = true;
            usersSample.UserId = userId;
            await _repo.AddUsersSampleAsync(usersSample);
            return await _repo.GetSampleByIDAsync(newSample.Id);

        }
Ejemplo n.º 17
0
 //UsersSample
 public async Task<UsersSample> AddUsersSampleAsync(UsersSample newUsersSample)
 {
     return await _repo.AddUsersSampleAsync(newUsersSample);
 }
Ejemplo n.º 18
0
 public async Task<UsersSample> UpdateUsersSampleAsync(UsersSample usersSample2BUpdated)
 {
     return await _repo.UpdateUsersSampleAsync(usersSample2BUpdated);
 }
Ejemplo n.º 19
0
 public async Task<UsersSample> DeleteUsersSampleAsync(UsersSample usersSample2BDeleted)
 {
     return await _repo.DeleteUsersSampleAsync(usersSample2BDeleted);
 }