Esempio n. 1
0
        public static void Constructor_NullContact_InitializesContactToExpectedValue(
            OrderingParty party)
        {
            var model = new OrderingPartyModel(party, null);

            model.PrimaryContact.Should().BeNull();
        }
Esempio n. 2
0
        public static void Constructor_InitializesAddressToExpectedValue(
            [Frozen] OrderingParty party)
        {
            var model = new OrderingPartyModel(party, null);

            model.Address.Should().BeEquivalentTo(party.Address, o => o.Excluding(a => a.Id));
        }
Esempio n. 3
0
 public static void SetOrderingParty_NullOrder_ThrowsException(
     OrderingParty orderingParty,
     Contact contact,
     OrderingPartyService service)
 {
     Assert.ThrowsAsync <ArgumentNullException>(async() => await service.SetOrderingParty(null, orderingParty, contact));
 }
Esempio n. 4
0
        public async Task <ActionResult> UpdateAsync(CallOffId callOffId, OrderingPartyModel model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var order = await orderingPartyService.GetOrder(callOffId);

            if (order is null)
            {
                return(NotFound());
            }

            var orderingParty = new OrderingParty
            {
                Name    = model.Name,
                OdsCode = model.OdsCode,
                Address = contactDetailsService.AddOrUpdateAddress(order.OrderingParty.Address, model.Address),
            };

            Contact contact = contactDetailsService.AddOrUpdatePrimaryContact(
                order.OrderingPartyContact,
                model.PrimaryContact);

            await orderingPartyService.SetOrderingParty(order, orderingParty, contact);

            return(NoContent());
        }
        internal OrderingPartyModel(OrderingParty orderingParty, Contact primaryContact)
        {
            Name    = orderingParty.Name;
            OdsCode = orderingParty.OdsCode;

            var address = orderingParty.Address;

            Address = address is null
                ? null
                : new AddressModel
            {
                Line1    = address.Line1,
                Line2    = address.Line2,
                Line3    = address.Line3,
                Line4    = address.Line4,
                Line5    = address.Line5,
                Town     = address.Town,
                County   = address.County,
                Postcode = address.Postcode,
                Country  = address.Country,
            };

            PrimaryContact = primaryContact is null
                ? null
                : new ContactModel
            {
                FirstName       = primaryContact.FirstName,
                LastName        = primaryContact.LastName,
                EmailAddress    = primaryContact.Email,
                TelephoneNumber = primaryContact.Phone,
            };
        }
Esempio n. 6
0
 public static void SetOrderingParty_NullContact_ThrowsException(
     Order order,
     OrderingParty orderingParty,
     OrderingPartyService service)
 {
     Assert.ThrowsAsync <ArgumentNullException>(async() => await service.SetOrderingParty(order, orderingParty, null));
 }
Esempio n. 7
0
        public static async Task CreateOrderAsync_InvokesCreatesOrder(
            [Frozen] Mock <IOrderService> service,
            [Frozen] Mock <HttpContext> httpContextMock,
            Order order,
            OrderingParty orderingParty,
            string description,
            OrdersController controller)
        {
            var model = new CreateOrderModel {
                OrganisationId = orderingParty.Id, Description = description
            };
            var claims = new[] { new Claim("primaryOrganisationId", model.OrganisationId.ToString()) };
            var user   = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock"));

            httpContextMock.Setup(c => c.User).Returns(user);
            service.Setup(o => o.CreateOrder(model.Description, model.OrganisationId !.Value)).Callback(() =>
            {
                order = new Order
                {
                    CallOffId     = order.CallOffId,
                    OrderingParty = new OrderingParty
                    {
                        Id = model.OrganisationId !.Value,
                    },
                };
            }).ReturnsAsync(order);

            await controller.CreateOrderAsync(model);

            service.Verify(o => o.CreateOrder(model.Description, model.OrganisationId !.Value), Times.Once);
        }
Esempio n. 8
0
        public static async Task CreateOrderAsync_ReturnsExpectedResult(
            [Frozen] Mock <IOrderService> service,
            [Frozen] Mock <HttpContext> httpContextMock,
            Order order,
            OrderingParty orderingParty,
            OrdersController controller)
        {
            var model = new CreateOrderModel {
                OrganisationId = orderingParty.Id, Description = "Description"
            };
            var claims = new[] { new Claim("primaryOrganisationId", model.OrganisationId.ToString()) };
            var user   = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock"));

            httpContextMock.Setup(c => c.User).Returns(user);
            service.Setup(o => o.CreateOrder(model.Description, model.OrganisationId !.Value)).Callback(() =>
            {
                order = new Order
                {
                    CallOffId     = order.CallOffId,
                    OrderingParty = new OrderingParty
                    {
                        Id = model.OrganisationId !.Value,
                    },
                };
            }).ReturnsAsync(order);

            var result = await controller.CreateOrderAsync(model);

            result.Should().BeOfType <CreatedAtActionResult>();
            result.As <CreatedAtActionResult>().ActionName.Should().Be("Get");
            result.As <CreatedAtActionResult>().RouteValues.Should().ContainKey("callOffId");
        }
Esempio n. 9
0
        public static async Task CreateOrderAsync_UserFromRelatedOrganisation_CreatesOrder(
            [Frozen] Mock <IOrderService> service,
            [Frozen] Mock <HttpContext> httpContextMock,
            Order order,
            OrderingParty orderingParty,
            string description,
            OrdersController controller)
        {
            var model = new CreateOrderModel {
                OrganisationId = orderingParty.Id, Description = description
            };
            var claims = new[] { new Claim("relatedOrganisationId", model.OrganisationId.ToString()) };
            var user   = new ClaimsPrincipal(new ClaimsIdentity(claims, "mock"));

            httpContextMock.Setup(c => c.User).Returns(user);
            service.Setup(o => o.CreateOrder(model.Description, model.OrganisationId !.Value)).Callback(() =>
            {
                order = new Order
                {
                    CallOffId     = order.CallOffId,
                    Description   = model.Description,
                    OrderingParty = orderingParty,
                };
            }).ReturnsAsync(order);

            await controller.CreateOrderAsync(model);

            order.OrderingParty.Should().Be(orderingParty);
            order.Description.Should().Be(description);
        }
Esempio n. 10
0
        public static void Constructor_InitializesOdsCodeToExpectedValue(
            [Frozen] OrderingParty party)
        {
            var model = new OrderingPartyModel(party, null);

            model.OdsCode.Should().Be(party.OdsCode);
        }
Esempio n. 11
0
        public static void Constructor_NullAddress_InitializesAddressToExpectedValue(
            [Frozen] OrderingParty party)
        {
            party.Address = null;
            var model = new OrderingPartyModel(party, null);

            model.Address.Should().BeNull();
        }
        public static async Task <OrderingParty> GetByOdsCode(this OrderingParty orderingParty, string connectionString)
        {
            var query = "SELECT * FROM OrderingParty WHERE OdsCode=@OdsCode";

            var results = await SqlExecutor.ExecuteAsync <OrderingParty>(connectionString, query, orderingParty);

            return(results.SingleOrDefault());
        }
        public OrderBuilder(string description, User user, OrderingParty orderingParty)
        {
            order = new Order
            {
                Description   = description,
                OrderingParty = orderingParty,
            };

            order.SetLastUpdatedBy(user.Id, $"{user.FirstName} {user.LastName}");
        }
Esempio n. 14
0
        public static async Task GetAsync_InvokesGetOrderList(
            [Frozen] Mock <IOrderService> service,
            [Frozen] OrderingParty orderingParty,
            IList <Order> orders,
            OrdersController controller)
        {
            service.Setup(o => o.GetOrders(orderingParty.Id)).ReturnsAsync(orders);

            await controller.GetAllAsync(orderingParty.Id);

            service.Verify(o => o.GetOrders(orderingParty.Id), Times.Once);
        }
Esempio n. 15
0
        public static async Task GetAllAsync_OrdersExist_ReturnsExpectedResult(
            [Frozen] Mock <IOrderService> service,
            [Frozen] OrderingParty orderingParty,
            IList <Order> orders,
            OrdersController controller)
        {
            service.Setup(o => o.GetOrders(orderingParty.Id)).ReturnsAsync(orders);

            var expectedResult = orders.Select(o => new OrderListItemModel(o));

            var result = await controller.GetAllAsync(orderingParty.Id);

            result.Value.Should().BeEquivalentTo(expectedResult);
        }
Esempio n. 16
0
        public static async Task CreateOrder_ReturnsOrder(
            [Frozen] ApplicationDbContext context,
            string description,
            OrderingParty orderingParty,
            OrderService service)
        {
            context.OrderingParty.Add(orderingParty);
            await context.SaveChangesAsync();

            var order = await service.CreateOrder(description, orderingParty.Id);

            order.OrderingParty.Should().BeEquivalentTo(orderingParty);
            order.Description.Should().Be(order.Description);
        }
Esempio n. 17
0
        public static void Constructor_InitializesContactToExpectedValue(
            OrderingParty party,
            Contact contact)
        {
            var model = new OrderingPartyModel(party, contact);

            model.PrimaryContact.Should().BeEquivalentTo(new
            {
                contact.FirstName,
                contact.LastName,
                EmailAddress    = contact.Email,
                TelephoneNumber = contact.Phone,
            });
        }
Esempio n. 18
0
        public static async Task CreateOrder_SavedToDb(
            [Frozen] ApplicationDbContext context,
            string description,
            OrderingParty orderingParty,
            OrderService service)
        {
            context.OrderingParty.Add(orderingParty);
            await context.SaveChangesAsync();

            var order = await service.CreateOrder(description, orderingParty.Id);

            var expectedOrder = context.Set <Order>().First(o => o.Equals(order));

            expectedOrder.Description.Should().Be(order.Description);
            expectedOrder.OrderingParty.Should().BeEquivalentTo(orderingParty);
        }
        public async Task <Order> CreateOrder(string description, Guid organisationId)
        {
            OrderingParty orderingParty = (await GetOrderingParty(organisationId)) ?? new OrderingParty {
                Id = organisationId
            };

            var order = new Order
            {
                Description   = description,
                OrderingParty = orderingParty,
            };

            context.Add(order);
            await context.SaveChangesAsync();

            return(order);
        }
Esempio n. 20
0
        public static async Task SetOrderingParty_UpdatesOrderingParty(
            Order order,
            OrderingParty orderingParty,
            Contact contact,
            OrderingPartyService service)
        {
            order.OrderingParty.Name.Should().NotBe(orderingParty.Name);
            order.OrderingParty.OdsCode.Should().NotBe(orderingParty.OdsCode);
            order.OrderingParty.Address.Should().NotBe(orderingParty.Address);
            order.OrderingPartyContact.Should().NotBe(contact);

            await service.SetOrderingParty(order, orderingParty, contact);

            order.OrderingParty.Name.Should().Be(orderingParty.Name);
            order.OrderingParty.OdsCode.Should().Be(orderingParty.OdsCode);
            order.OrderingParty.Address.Should().Be(orderingParty.Address);
            order.OrderingPartyContact.Should().Be(contact);
        }
Esempio n. 21
0
        public async Task SetOrderingParty(Order order, OrderingParty orderingParty, Contact contact)
        {
            if (order is null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            if (orderingParty is null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            if (contact is null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            order.OrderingParty.Name    = orderingParty.Name;
            order.OrderingParty.OdsCode = orderingParty.OdsCode;
            order.OrderingParty.Address = orderingParty.Address;
            order.OrderingPartyContact  = contact;

            await context.SaveChangesAsync();
        }