public async Task DepartmentRepository_Put_NotNull_Success()
        {
            var mockList = new List <Department>()
            {
                new Department()
                {
                    Name = "DepartmentRepository_GetDepartmentsPaging_NotNull_Success1",
                    Uuid = new Guid("00000000-0000-0000-0000-000000000001"),
                },
                new Department()
                {
                    Name = "DepartmentRepository_GetDepartmentsPaging_NotNull_Success2",
                    Uuid = new Guid("00000000-0000-0000-0000-000000000002"),
                },
                new Department()
                {
                    Name = "DepartmentRepository_GetDepartmentsPaging_NotNull_Success3",
                    Uuid = new Guid("00000000-0000-0000-0000-000000000003"),
                }
            };

            var departments = await _repository.CreateAsync(mockList);

            var newObj = new DepartmentNonRequest()
            {
                Name = "DepartmentRepository_Put_NotNull_Failed",
                Uuid = departments.FirstOrDefault().Uuid,
            };
            var result = await _repository.PutAsync(newObj.Uuid, newObj);

            Assert.Equal(1, result);
        }
        public async Task DepartmentRepository_Put_NotNull_Failed()
        {
            var newObj = new DepartmentNonRequest()
            {
                Name = "DepartmentRepository_Put_NotNull_Failed",
                Uuid = Guid.NewGuid(),
            };
            var result = await _repository.PutAsync(Guid.NewGuid(), newObj);

            Assert.Equal(0, result);
        }
        public async Task DepartmentsController_Put_NotNull_BadRequest()
        {
            var newUuid = Guid.NewGuid();
            DepartmentNonRequest request = new DepartmentNonRequest()
            {
                Uuid = Guid.NewGuid()
            };

            var departmentController = new DepartmentsController(_mockDepartmentService.Object);

            var result = await departmentController.Put(newUuid, request);

            Assert.IsType <BadRequestResult>(result);
        }
예제 #4
0
        public async Task <ActionResult> Put(Guid uuid, DepartmentNonRequest request)
        {
            if (uuid != request.Uuid)
            {
                return(BadRequest());
            }
            var result = await _departmentService.PutAsync(uuid, request);

            if (result > 0)
            {
                return(Ok());
            }
            return(NotFound());
        }
        public async Task DepartmentsController_Post_NotNull_NotFound()
        {
            DepartmentRequest request = new DepartmentRequest()
            {
            };
            DepartmentNonRequest response = null;

            _mockDepartmentService.Setup(e => e.PostAsync(request)).ReturnsAsync(response);

            var departmentController = new DepartmentsController(_mockDepartmentService.Object);

            var result = await departmentController.Post(request);

            Assert.IsType <NotFoundResult>(result);
        }
        public async Task <int> PutAsync(Guid uuid, DepartmentNonRequest request)
        {
            var obj = await Entities.SingleOrDefaultAsync(e => e.Uuid == uuid);

            if (obj == null)
            {
                return(0);
            }
            obj.Name     = request.Name;
            obj.UpdateAt = DateTime.Now;

            var result = await UpdateAsync(obj);

            return(result);
        }
        public async Task DepartmentsController_Put_NotNull_Ok()
        {
            var newUuid = Guid.NewGuid();
            DepartmentNonRequest request = new DepartmentNonRequest()
            {
                Uuid = newUuid
            };

            _mockDepartmentService.Setup(e => e.PutAsync(newUuid, request)).ReturnsAsync(1);

            var departmentController = new DepartmentsController(_mockDepartmentService.Object);

            var result = await departmentController.Put(newUuid, request);

            Assert.IsType <OkResult>(result);
        }
        public async Task DepartmentService_PutAsync_Null_ReturnZero()
        {
            var request = new DepartmentNonRequest()
            {
                Uuid = Guid.NewGuid(),
                Name = "123456",
            };

            Department respon = null;

            _mockDepartmentRepository.Setup(e => e.GetByUuidTrackingAsync(request.Uuid)).ReturnsAsync(respon);
            _mockDepartmentRepository.Setup(e => e.UpdateAsync(respon)).ReturnsAsync(1);
            var departmentService = new DepartmentService(_mockDepartmentRepository.Object, _mapper);

            var result = await departmentService.PutAsync(Guid.NewGuid(), request);

            Assert.Equal(0, result);
        }