public void ConfiguringAnInsolvencyAsHal_WithDisputesProvided_EmbedsDisputesIntoHalResponse()
        {
            // Arrange
            var expectedDispute = new DisputeModel
            {
                DateRaised        = new DateTime(2017, 10, 12),
                Displayed         = true,
                DisputeId         = 1,
                InsolvencyOrderId = 2,
                ReferenceNumber   = "fdshiu308j"
            };

            var expectedInsolvency = new InsolvencyOrderModel {
                Disputes = new List <DisputeModel> {
                    expectedDispute
                }
            };

            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            includeReader.Setup(x => x.GetIncludes()).Returns(new string[] { "disputes" });

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            // Act
            var halResponse = responseObject.FormatForHal(expectedInsolvency);

            // Assert
            halResponse.ShouldHaveEmbeddedCollection(DomainResources.Disputes_camelCase, expectedInsolvency.Disputes);
        }
        public void ConfiguringAnInsolvencyAsHal_SettingHalForceTrue_ConfiguresForceHalTrue()
        {
            // Arrange
            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);
            var insolvency     = new InsolvencyOrderModel();

            // Act
            var halResponse = responseObject.FormatForHal(insolvency);

            // Assert
            Assert.IsTrue(halResponse.Config.ForceHAL);
        }
        public void ConfiguringAnInsolvencyAsHal_WithAValidInsolvency_ShouldSetResponseProperties()
        {
            // Arrange
            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var expectedInsolvency = Helpers.TestHelpers.CreateInsolvency();
            var responseObject     = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            // Act
            var halRootObject = responseObject.FormatForHal(expectedInsolvency);

            // Assert
            halRootObject.ShouldHaveModel(expectedInsolvency);
        }
        public void ConfiguringAnInsolvencyAsHal_WithNullDataProvided_ThrowsArgumentNullException()
        {
            // Arrange
            InsolvencyOrderModel insolvency = null;
            var addressResolverMock         = new Mock <IAddressResolver>();
            var includeReader = new Mock <IIncludeReader>();

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            // Act
            void CreateHalResponse() => responseObject.FormatForHal(insolvency);

            // Assert
            Assert.ThrowsException <ArgumentNullException>((Action)CreateHalResponse);
        }
        public void ConfiguringAnInsolvencyAsHal_WithDataProvided_CreatesHalConfigurationModelEqualToTheProvidedData()
        {
            // Arrange
            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            var expectedInsolvency = new InsolvencyOrderModel();

            // Act
            var halResponse = responseObject.FormatForHal(expectedInsolvency);

            // Assert
            halResponse.ShouldHaveModel(expectedInsolvency);
        }
        public void ConfiguringAnInsolvencyAsHal_WithDataProvided_CreatesHalConfigurationForTheData()
        {
            // Arrange
            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            var insolvency = new InsolvencyOrderModel();

            // Act
            var halResponse = responseObject.FormatForHal(insolvency);

            // Assert
            Assert.IsNotNull(halResponse);
        }
        public void ConfiguringAnInsolvencyAsHal_WithACallToGetALinkToTheInsolvencyCollectionInTheConfiguration_CallsGetLink()
        {
            // Arrange
            const string routeName = DomainResources.InsolvencyOrders;
            const string linkName  = CommonLinks.Parent;

            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var responseObject     = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);
            var expectedInsolvency = new InsolvencyOrderModel();

            // Act
            responseObject.FormatForHal(expectedInsolvency);

            // Assert
            addressResolverMock.Verify(mock => mock.GetLink(routeName, linkName), Times.Once);
        }
        public void ConfiguringAnInsolvencyAsHal_WithACallToGetTheSelfLinkInTheConfiguration_CallsGetLinkForTwoLinks()
        {
            // Arrange
            const int NumberOfGetLinkCalls = 7;

            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var responseObject     = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);
            var expectedInsolvency = new InsolvencyOrderModel();

            var numberOfTimesGetLinkWasCalled = Times.Exactly(NumberOfGetLinkCalls);

            // Act
            responseObject.FormatForHal(expectedInsolvency);

            // Assert
            addressResolverMock.Verify(mock => mock.GetLink(It.IsAny <string>(), It.IsAny <string>()), numberOfTimesGetLinkWasCalled);
        }
        public void ConfiguringAnInsolvencyAsHal_WithNullDataProvided_HasCorrectParameterNameInException()
        {
            // Arrange
            const string expectedParameterName = "item";

            InsolvencyOrderModel insolvency = null;
            var addressResolverMock         = new Mock <IAddressResolver>();
            var includeReader = new Mock <IIncludeReader>();

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            // Act
            void CreateHalResponse() => responseObject.FormatForHal(insolvency);

            // Assert
            ExceptionAssert.HasCorrectParameterNameForArgumentException(
                CreateHalResponse,
                expectedParameterName);
        }
        public void ConfiguringAnInsolvencyAsHal_WithZeroDisputesProvided_EmbedsEmptyDisputeIntoHalResponse()
        {
            // Arrange
            var expectedInsolvency = new InsolvencyOrderModel {
                Disputes = new List <DisputeModel>()
            };

            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            includeReader.Setup(x => x.GetIncludes()).Returns(new string[] { "disputes" });

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            // Act
            var halResponse = responseObject.FormatForHal(expectedInsolvency);

            // Assert
            halResponse.ShouldHaveEmbeddedCollection(DomainResources.Disputes_camelCase, expectedInsolvency.Disputes);
        }
        public void ConfiguringAnInsolvencyAsHal_WithAllLinkCallsInTheConfiguration_DoesntAskForMoreLinksThanItNeeds()
        {
            // Arrange
            const int insolvencyOrderId    = 12345;
            const int NumberOfGetLinkCalls = 7;

            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            var responseObject     = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);
            var expectedInsolvency = new InsolvencyOrderModel {
                InsolvencyOrderId = insolvencyOrderId
            };

            var callsToGetLink = Times.Exactly(NumberOfGetLinkCalls);

            // Act
            responseObject.FormatForHal(expectedInsolvency);

            // Assert
            addressResolverMock.Verify(mock => mock.GetLink(It.IsAny <string>(), It.IsAny <string>()), callsToGetLink);
        }
        public void ConfiguringAnInsolvencyAsHal_WithAValidInsolvency_ShouldSetEmbeddedLinks()
        {
            // Arrange
            var expectedLinks = new List <Link>
            {
                new Link(DomainResources.InsolvencyOrder, CommonLinks.Self),
                new Link(DomainResources.InsolvencyOrders, CommonLinks.Parent),
            };

            var expectedInsolvency  = Helpers.TestHelpers.CreateInsolvency();
            var addressResolverMock = new Mock <IAddressResolver>();
            var includeReader       = new Mock <IIncludeReader>();

            addressResolverMock.Setup(s => s.GetLink(It.IsAny <string>(), It.IsAny <string>()))
            .Returns((string routeName, string linkName) => new Link(routeName, linkName));

            var responseObject = new InsolvencyOrderResponse(addressResolverMock.Object, includeReader.Object);

            // Act
            var halRootObject = responseObject.FormatForHal(expectedInsolvency);

            // Assert
            halRootObject.ShouldHaveLinks(expectedLinks);
        }