コード例 #1
0
        public void Constructor_NullParameter_ThrowsArgumentNullException(
            bool isOrderRepositoryNull,
            bool isCreateOrderServiceNull,
            bool isServiceRecipientRepositoryNull)
        {
            void Test()
            {
                var _ = OrdersControllerBuilder
                        .Create()
                        .WithOrderRepository(isOrderRepositoryNull ? null : Mock.Of <IOrderRepository>())
                        .WithCreateOrderService(isCreateOrderServiceNull ? null : Mock.Of <ICreateOrderService>())
                        .WithServiceRecipientRepository(isServiceRecipientRepositoryNull ? null : Mock.Of <IServiceRecipientRepository>())
                        .Build();
            }

            Assert.Throws <ArgumentNullException>(Test);
        }
コード例 #2
0
            private OrdersControllerTestContext(Guid primaryOrganisationId)
            {
                Name                  = "Test User";
                NameIdentity          = Guid.NewGuid();
                PrimaryOrganisationId = primaryOrganisationId;
                OrderRepositoryMock   = new Mock <IOrderRepository>();

                CreateOrderServiceMock = new Mock <ICreateOrderService>();
                CreateOrderServiceMock.Setup(x => x.CreateAsync(It.IsAny <CreateOrderRequest>()))
                .ReturnsAsync(() => CreateOrderResult);

                Orders = new List <Order>();
                OrderRepositoryMock.Setup(x => x.ListOrdersByOrganisationIdAsync(It.IsAny <Guid>()))
                .ReturnsAsync(() => Orders);

                OrderRepositoryMock.Setup(x => x.GetOrderByIdAsync(It.IsAny <string>())).ReturnsAsync(() => Order);

                ServiceRecipientRepositoryMock = new Mock <IServiceRecipientRepository>();
                ServiceRecipientRepositoryMock
                .Setup(x => x.GetCountByOrderIdAsync(It.IsNotNull <string>()))
                .ReturnsAsync(() => ServiceRecipientListCount);

                ClaimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(
                                                          new[]
                {
                    new Claim("Ordering", "Manage"),
                    new Claim("primaryOrganisationId", PrimaryOrganisationId.ToString()),
                    new Claim(ClaimTypes.Name, Name),
                    new Claim(ClaimTypes.NameIdentifier, NameIdentity.ToString())
                }, "mock"));

                OrdersController = OrdersControllerBuilder
                                   .Create()
                                   .WithOrderRepository(OrderRepositoryMock.Object)
                                   .WithServiceRecipientRepository(ServiceRecipientRepositoryMock.Object)
                                   .WithCreateOrderService(CreateOrderServiceMock.Object)
                                   .Build();

                OrdersController.ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext {
                        User = ClaimsPrincipal
                    }
                };
            }