public async Task Should_return_NotFound_when_delivery_to_complete_does_not_exist()
        {
            string id = "Id";

            _service
            .Setup(s => s.CompleteAsync(id))
            .Returns(Task.FromException(new DeliveryNotFoundException(id)));

            var subject = this.CreateSubject();

            var result = await subject.Complete(id);

            result.ShouldBeOfType <NotFoundObjectResult>();
            var value = ActionResultHelper.GetObject <ErrorDetail>(result);

            value.ErrorCode.ShouldBe("delivery_not_found");
        }
        public async Task Should_return_Conflicted_when_delivery_to_complete_not_in_right_status()
        {
            string id = "Id";

            _service
            .Setup(s => s.CompleteAsync(id))
            .Returns(Task.FromException(new DeliveryOperationInvalidForStatusException(id, State.completed)));

            var subject = this.CreateSubject();

            var result = await subject.Complete(id);

            result.ShouldBeOfType <ConflictObjectResult>();
            var value = ActionResultHelper.GetObject <ErrorDetail>(result);

            value.ErrorCode.ShouldBe("delivery_operation_invalid");
        }
        public async Task Should_return_Conflicted_when_it_is_late_to_approve_the_delivery()
        {
            string id = "Id";

            _service
            .Setup(s => s.ApproveAsync(id))
            .Returns(Task.FromException(new DeliveryTimeElapsedException(id, DateTime.Now.AddHours(-1))));

            var subject = this.CreateSubject();

            var result = await subject.Approve(id);

            result.ShouldBeOfType <ConflictObjectResult>();
            var value = ActionResultHelper.GetObject <ErrorDetail>(result);

            value.ErrorCode.ShouldBe("delivery_time_elapsed");
        }
        public async Task Should_return_Ok_when_delivery_id_exist()
        {
            var delivery = new Domain.Models.Delivery {
                State = State.cancelled
            };

            _service.Setup(s => s.GetByIdAsync(delivery.Id)).ReturnsAsync(() => delivery);

            var subject = this.CreateSubject();

            var result = await subject.Get(delivery.Id);

            result.ShouldBeOfType <OkObjectResult>();
            var value = ActionResultHelper.GetObject <Domain.Models.Delivery>(result);

            value.Id.ShouldBe(delivery.Id);
            value.State.ShouldBe(delivery.State);
        }
        public async Task Should_return_Conflicted_when_delivery_order_exist()
        {
            var delivery = new Delivery {
                Order = new Order(), Recipient = new Recipient()
            };

            _service
            .Setup(s => s.CreateAsync(It.IsAny <Domain.Models.Delivery>()))
            .Returns(Task.FromException(new OrderAlreadyDeliveredException("id")));

            var subject = this.CreateSubject();

            var result = await subject.Create(delivery);

            result.ShouldBeOfType <ConflictObjectResult>();
            var value = ActionResultHelper.GetObject <ErrorDetail>(result);

            value.ErrorCode.ShouldBe("order_already_delivered");
        }