public static async Task GetAllAsync_HasServiceRecipients_ReturnsExpectedResult( [Frozen] Mock <IServiceRecipientService> service, [Frozen] CallOffId callOffId, Order order, List <OrderItem> orderItems, ServiceRecipientsSectionController controller) { foreach (var orderItem in orderItems) { order.AddOrUpdateOrderItem(orderItem); } var serviceRecipients = order.OrderItems .Where(o => o.CatalogueItem.CatalogueItemType == CatalogueItemType.Solution) .SelectMany(o => o.OrderItemRecipients) .Select(r => new ServiceRecipient(r.Recipient.OdsCode, r.Recipient.Name)) .ToList(); service.Setup(s => s.GetAllOrderItemRecipients(callOffId)).ReturnsAsync( serviceRecipients); var expected = new ServiceRecipientsModel { ServiceRecipients = serviceRecipients.Select(r => new ServiceRecipientModel { Name = r.Name, OdsCode = r.OdsCode }) .ToList(), }; var response = await controller.GetAllAsync(callOffId); response.Value.Should().BeEquivalentTo(expected); }
public static async Task GetAllAsync_OrderDoesNotExist_ReturnsNotFound( [Frozen] Mock <IServiceRecipientService> service, CallOffId callOffId, ServiceRecipientsSectionController controller) { service.Setup(s => s.GetAllOrderItemRecipients(callOffId)).ReturnsAsync((List <ServiceRecipient>)null); var response = await controller.GetAllAsync(callOffId); response.Result.Should().BeOfType <NotFoundResult>(); }
public static async Task GetAllAsync_NoServiceRecipient_ReturnsEmptyList( [Frozen] Mock <IServiceRecipientService> service, [Frozen] CallOffId callOffId, ServiceRecipientsSectionController controller) { service.Setup(s => s.GetAllOrderItemRecipients(callOffId)).ReturnsAsync(new List <ServiceRecipient>()); var expected = new ServiceRecipientsModel { ServiceRecipients = new List <ServiceRecipientModel>(), }; var response = await controller.GetAllAsync(callOffId); response.Value.Should().BeEquivalentTo(expected); }
public void Ctor_NullRepository_Throws(bool hasOrderRepository, bool hasServiceRepository) { var context = ServiceRecipientsTestContext.Setup(); var orderRepository = context.OrderRepositoryMock.Object; var serviceRecipientRepository = context.ServiceRecipientRepositoryMock.Object; if (!hasOrderRepository) { orderRepository = null; } if (!hasServiceRepository) { serviceRecipientRepository = null; } Assert.Throws <ArgumentNullException>(() => { var _ = new ServiceRecipientsSectionController(orderRepository, serviceRecipientRepository); }); }
private ServiceRecipientsTestContext() { PrimaryOrganisationId = Guid.NewGuid(); UserId = Guid.NewGuid(); Username = "******"; Order = new Order { OrganisationId = PrimaryOrganisationId }; OrderRepositoryMock = new Mock <IOrderRepository>(); OrderRepositoryMock.Setup(x => x.GetOrderByIdAsync(It.IsAny <string>())).ReturnsAsync(() => Order); ServiceRecipientRepositoryMock = new Mock <IServiceRecipientRepository>(); ServiceRecipients = new List <ServiceRecipient>(); ServiceRecipientRepositoryMock.Setup(x => x.ListServiceRecipientsByOrderIdAsync(It.IsAny <string>())) .ReturnsAsync(() => ServiceRecipients); ClaimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("Ordering", "Manage"), new Claim("primaryOrganisationId", PrimaryOrganisationId.ToString()), new Claim(ClaimTypes.Name, Username), new Claim(ClaimTypes.NameIdentifier, UserId.ToString()) }, "mock")); Controller = new ServiceRecipientsSectionController(OrderRepositoryMock.Object, ServiceRecipientRepositoryMock.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = ClaimsPrincipal } } }; }