示例#1
0
        public void Update_NullDateTime_ThrowsException()
        {
            var context = CommencementDateControllerTestContext.Setup();
            var model   = new CommencementDateModel {
                CommencementDate = null
            };

            Assert.ThrowsAsync <ArgumentException>(async() => await context.Controller.Update("myOrder", model));
        }
示例#2
0
        public async Task Update_ValidDateTime_UpdatesAndReturnsNoContent()
        {
            var context = CommencementDateControllerTestContext.Setup();
            var model   = new CommencementDateModel {
                CommencementDate = DateTime.Now
            };
            var result = await context.Controller.Update("myOrder", model);

            context.OrderRepositoryMock.Verify(x => x.UpdateOrderAsync(It.Is <Order>(order => order.CommencementDate == model.CommencementDate)));
            result.Should().BeOfType <NoContentResult>();
        }
示例#3
0
        public async Task Update_NoOrderFound_ReturnsNotFound()
        {
            var context = CommencementDateControllerTestContext.Setup();

            context.Order = null;
            var model = new CommencementDateModel {
                CommencementDate = DateTime.Now
            };
            var result = await context.Controller.Update("myOrder", model);

            result.Should().BeOfType <NotFoundResult>();
        }
示例#4
0
        public async Task Update_UserHasDifferentPrimaryOrganisationId_ReturnsForbidden()
        {
            var context = CommencementDateControllerTestContext.Setup();

            context.Order.OrganisationId = Guid.NewGuid();
            var model = new CommencementDateModel {
                CommencementDate = DateTime.Now
            };
            var result = await context.Controller.Update("myOrder", model);

            result.Should().BeOfType <ForbidResult>();
        }
示例#5
0
        public async Task <IActionResult> UpdateAsync([FromRoute] Order order, CommencementDateModel model)
        {
            if (order is null)
            {
                return(NotFound());
            }

            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            await commencementDateService.SetCommencementDate(order, model.CommencementDate);

            return(NoContent());
        }
        public async Task <ActionResult> GetAsync(string orderId)
        {
            var order = await _orderRepository.GetOrderByIdAsync(orderId);

            if (order is null)
            {
                return(NotFound());
            }

            var primaryOrganisationId = User.GetPrimaryOrganisationId();

            if (primaryOrganisationId != order.OrganisationId)
            {
                return(Forbid());
            }

            var result = new CommencementDateModel {
                CommencementDate = order.CommencementDate
            };

            return(Ok(result));
        }
        public async Task <ActionResult> Update(string orderId, CommencementDateModel model)
        {
            var order = await _orderRepository.GetOrderByIdAsync(orderId);

            if (order is null)
            {
                return(NotFound());
            }

            var primaryOrganisationId = User.GetPrimaryOrganisationId();

            if (primaryOrganisationId != order.OrganisationId)
            {
                return(Forbid());
            }

            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (!model.CommencementDate.HasValue)
            {
                throw new ArgumentException(nameof(model.CommencementDate));
            }

            order.CommencementDate = model.CommencementDate.Value;

            var name = User.Identity.Name;

            order.SetLastUpdatedBy(User.GetUserId(), name);

            await _orderRepository.UpdateOrderAsync(order);

            return(NoContent());
        }