Esempio n. 1
0
        public async Task GetAllAsync_MultipleServiceRecipientsMatch_ReturnsAllTheOrdersServicesRecipients()
        {
            var context = ServiceRecipientsTestContext.Setup();

            const string orderId = "C0000014-01";

            context.Order = OrderBuilder.Create().WithOrderId(orderId).WithOrganisationId(context.PrimaryOrganisationId).Build();

            var serviceRecipients = new List <(ServiceRecipient serviceRecipient, ServiceRecipientModel expectedModel)>
            {
                CreateServiceRecipientData("ODS1", orderId),
                CreateServiceRecipientData("ODS2", orderId),
                CreateServiceRecipientData("ODS3", orderId)
            };

            context.ServiceRecipients = serviceRecipients.Select(x => x.serviceRecipient).ToList();
            var expected = new ServiceRecipientsModel();

            var expectedList = serviceRecipients.Select(x => x.expectedModel);

            expected.ServiceRecipients = expectedList;

            var response = await context.Controller.GetAllAsync(orderId);

            response.Should().BeEquivalentTo(new ActionResult <ServiceRecipientsModel>(expected));
        }
Esempio n. 2
0
        public async Task GetAllAsync_SingleServiceRecipient_ReturnsTheRecipient()
        {
            var context = ServiceRecipientsTestContext.Setup();

            const string orderId = "C0000014-01";

            var serviceRecipients = new List <(ServiceRecipient serviceRecipient, ServiceRecipientModel expectedModel)>
            {
                CreateServiceRecipientData("ODS1", orderId)
            };

            context.ServiceRecipients = serviceRecipients.Select(x => x.serviceRecipient).ToList();


            var expectedList = serviceRecipients.Select(x => x.expectedModel);

            var expected = new ServiceRecipientsModel
            {
                ServiceRecipients = expectedList
            };

            var response = await context.Controller.GetAllAsync(orderId);

            response.Should().BeEquivalentTo(new ActionResult <ServiceRecipientsModel>(expected));
        }
Esempio n. 3
0
        public async Task UpdateAsync_ServiceRecipientRepository_UpdateAsyncCalledOnce()
        {
            var context = ServiceRecipientsTestContext.Setup();

            string expectedOrderId = context.Order.OrderId;
            await context.Controller.UpdateAsync(expectedOrderId, DefaultServiceRecipientsModel);

            context.ServiceRecipientRepositoryMock.Verify(x => x.UpdateAsync(expectedOrderId, It.IsAny <IEnumerable <ServiceRecipient> >()), Times.Once);
        }
Esempio n. 4
0
        public async Task UpdateAsync_OrderRepository_GetOrderByIdAsyncCalledOnce()
        {
            var context = ServiceRecipientsTestContext.Setup();

            string expectedOrderId = context.Order.OrderId;
            await context.Controller.UpdateAsync(expectedOrderId, DefaultServiceRecipientsModel);

            context.OrderRepositoryMock.Verify(x => x.GetOrderByIdAsync(expectedOrderId), Times.Once);
        }
Esempio n. 5
0
        public async Task UpdateAsync_OrderRepository_UpdateOrderAsyncCalledOnce()
        {
            var context = ServiceRecipientsTestContext.Setup();

            var expectedOrder = context.Order;
            await context.Controller.UpdateAsync(expectedOrder.OrderId, DefaultServiceRecipientsModel);

            context.OrderRepositoryMock.Verify(x => x.UpdateOrderAsync(expectedOrder), Times.Once);
        }
Esempio n. 6
0
        public async Task GetAllAsync_OrganisationIdDoesNotMatch_ReturnsForbidden()
        {
            var context = ServiceRecipientsTestContext.Setup();

            context.Order.OrganisationId = Guid.NewGuid();

            var response = await context.Controller.GetAllAsync("myOrder");

            response.Should().BeEquivalentTo(new ActionResult <ServiceRecipientsModel>(new ForbidResult()));
        }
Esempio n. 7
0
        public async Task GetAllAsync_OrderDoesNotExist_ReturnsNotFound(string orderId)
        {
            var context = ServiceRecipientsTestContext.Setup();

            context.Order = null;

            var response = await context.Controller.GetAllAsync(orderId);

            response.Should().BeEquivalentTo(new ActionResult <ServiceRecipientsModel>(new NotFoundResult()));
        }
Esempio n. 8
0
        public async Task GetAllAsync_VerifyRepositoryMethods_CalledOnce()
        {
            var context = ServiceRecipientsTestContext.Setup();

            await context.Controller.GetAllAsync(string.Empty);

            context.OrderRepositoryMock.Verify(x => x.GetOrderByIdAsync(string.Empty), Times.Once);
            context.ServiceRecipientRepositoryMock.Verify(x => x.ListServiceRecipientsByOrderIdAsync(string.Empty),
                                                          Times.Once);
        }
Esempio n. 9
0
        public async Task GetAllAsync_NoServiceRecipient_ReturnsEmptyList()
        {
            var context  = ServiceRecipientsTestContext.Setup();
            var expected = new ServiceRecipientsModel
            {
                ServiceRecipients = new List <ServiceRecipientModel>()
            };

            var response = await context.Controller.GetAllAsync("myOrder");

            response.Should().BeEquivalentTo(new ActionResult <ServiceRecipientsModel>(expected));
        }
Esempio n. 10
0
        public async Task UpdateAsync_DefaultServiceRecipient_ServiceRecipientViewedIsTrue()
        {
            var context = ServiceRecipientsTestContext.Setup();

            context.Order = OrderBuilder
                            .Create()
                            .WithOrganisationId(context.PrimaryOrganisationId)
                            .WithServiceRecipientsViewed(false)
                            .Build();

            context.Order.ServiceRecipientsViewed.Should().BeFalse();

            await context.Controller.UpdateAsync(context.Order.OrderId, DefaultServiceRecipientsModel);

            context.Order.ServiceRecipientsViewed.Should().BeTrue();
        }
Esempio n. 11
0
        public async Task UpdateAsync_NoServiceRecipients_SetsCatalogueSolutionsViewedFalse()
        {
            var context = ServiceRecipientsTestContext.Setup();

            context.Order = OrderBuilder
                            .Create()
                            .WithOrganisationId(context.PrimaryOrganisationId)
                            .WithCatalogueSolutionsViewed(true)
                            .Build();

            var service = ServiceRecipientsModelBuilder.Create().Build();

            string expectedOrderId = context.Order.OrderId;
            await context.Controller.UpdateAsync(expectedOrderId, service);

            context.Order.CatalogueSolutionsViewed.Should().BeFalse();
        }
Esempio n. 12
0
        public async Task UpdateAsync_DefaultServiceRecipient_LastUpdatedByNameChanged()
        {
            var context = ServiceRecipientsTestContext.Setup();

            var lastUpdatedByName = "Some user";

            context.Order = OrderBuilder
                            .Create()
                            .WithLastUpdatedByName(lastUpdatedByName)
                            .WithOrganisationId(context.PrimaryOrganisationId)
                            .WithServiceRecipientsViewed(false)
                            .Build();

            context.Order.LastUpdatedByName.Should().Be(lastUpdatedByName);

            await context.Controller.UpdateAsync(context.Order.OrderId, DefaultServiceRecipientsModel);

            context.Order.LastUpdatedByName.Should().Be(context.Username);
        }
Esempio n. 13
0
        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);
            });
        }