コード例 #1
0
        public static async Task CreateOrderItemsAsync_ValidationFailure_ReturnsExpectedResponse(
            ErrorDetails errorDetails,
            AggregateValidationResult aggregateValidationResult,
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            controller.ProblemDetailsFactory = new TestProblemDetailsFactory();
            aggregateValidationResult.AddValidationResult(new ValidationResult(errorDetails), 0);

            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(aggregateValidationResult);

            var response = await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            response.Should().BeOfType <BadRequestObjectResult>();
            response.As <BadRequestObjectResult>().Value.Should().BeOfType <ValidationProblemDetails>();
        }
コード例 #2
0
        public static async Task CreateOrderItemAsync_ValidationFailure_AddsModelErrors(
            [Frozen] IReadOnlyList <ErrorDetails> errorDetails,
            AggregateValidationResult aggregateValidationResult,
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            controller.ProblemDetailsFactory = new TestProblemDetailsFactory();
            aggregateValidationResult.AddValidationResult(new ValidationResult(errorDetails), 0);

            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(aggregateValidationResult);

            await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            var modelState = controller.ModelState;

            modelState.ErrorCount.Should().Be(errorDetails.Count);
            modelState.Keys.Should().BeEquivalentTo(errorDetails.Select(e => e.ParentName + "[0]." + e.Field));

            var modelStateErrors = modelState.Values.Select(v => v.Errors[0].ErrorMessage);

            modelStateErrors.Should().BeEquivalentTo(errorDetails.Select(e => e.Id));
        }
コード例 #3
0
        public static async Task CreateOrderItemAsync_OrderExists_ReturnsCreatedAtActionResult(
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(new AggregateValidationResult());

            var result = await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            result.Should().BeOfType <CreatedAtActionResult>();
            result.As <CreatedAtActionResult>().Should().BeEquivalentTo(new
            {
                ActionName  = "Get",
                RouteValues = new RouteValueDictionary
                {
                    { nameof(callOffId), callOffId.ToString() },
                    { nameof(catalogueItemId), catalogueItemId.ToString() },
                },
            });
        }
コード例 #4
0
 public static void CreateOrderItemAsync_NullModel_ThrowsException(
     CallOffId callOffId,
     CatalogueItemId catalogueItemId,
     OrderItemsController controller)
 {
     Assert.ThrowsAsync <ArgumentNullException>(
         async() => await controller.CreateOrderItemAsync(callOffId, catalogueItemId, null));
 }
コード例 #5
0
        public static async Task CreateOrderItemAsync_OrderDoesNotExist_ReturnsNotFound(
            CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            var result = await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            result.Should().BeOfType <NotFoundResult>();
        }
コード例 #6
0
        public static async Task CreateOrderItemAsync_InvokesCreateOrderItemServiceCreateAsync(
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(new AggregateValidationResult());

            await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            createOrderItemService.Verify(createAsync);
        }