コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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 MappingInsolvencyOrderEntityToModel_WithConfiguredModelMapping_ReturnsEqualModel()
        {
            // Arrange
            AutoMapper.Mapper.Reset();
            ModelMappingConfiguration.CreateModelMapping();

            var insolvencyOrderEntity =
                new InsolvencyOrderEntity()
            {
                InsolvencyOrderId     = 1,
                InsolvencyOrderTypeId = 2,
                InsolvencyOrderType   =
                    new InsolvencyOrderTypeEntity()
                {
                    InsolvencyOrderTypeId   = 2,
                    CallReportCode          = "code1",
                    Description             = "type desc",
                    InsolvencyOrderEntities = null
                },
                ResidenceId                = 3,
                OrderDate                  = DateTime.Parse("2014-02-15"),
                RestrictionsTypeId         = 4,
                InsolvencyRestrictionsType =
                    new InsolvencyRestrictionsTypeEntity()
                {
                    RestrictionsTypeId = 4,
                    Code                    = "A",
                    Description             = "restriction description",
                    InsolvencyOrderEntities = null
                },
                RestrictionsStartDate   = DateTime.Parse("2015-02-15"),
                RestrictionsEndDate     = DateTime.Parse("2015-04-15"),
                LineOfBusiness          = "Entertainer",
                InsolvencyServiceCaseId = 5,
                ValueOfDebt             = 5000,
                DischargeDate           = DateTime.Parse("2017-02-15"),
                InsolvencyOrderPersons  =
                    new List <InsolvencyOrderPersonEntity>()
                {
                    new InsolvencyOrderPersonEntity()
                    {
                        InsolvencyOrderPersonId = 8,
                        InsolvencyOrderId       = 1,
                        DateOfBirth             = DateTime.Parse("1990, 07, 21"),
                        Forename = "John",
                        Surname  = "Smith",
                        Title    = "Mr"
                    }
                },
                InsolvencyOrderAddresses =
                    new List <InsolvencyOrderAddressEntity>()
                {
                    new InsolvencyOrderAddressEntity()
                    {
                        InsolvencyOrderAddressId = 9,
                        InsolvencyOrderId        = 1,
                        LastKnownAddress         = "12 Low Street",
                        LastKnownPostCode        = "OX4 3PE"
                    }
                },
                InsolvencyOrderHistory =
                    new List <InsolvencyOrderHistoryEntity>()
                {
                    new InsolvencyOrderHistoryEntity()
                    {
                        InsolvencyOrderHistoryId = 10,
                        InsolvencyOrderId        = 1,
                        CaseReference            = "1234",
                        CaseYear = 2014,
                        CourtId  = 11,
                        Court    =
                            new CourtEntity()
                        {
                            CourtId   = 11,
                            CourtCode = "AB",
                            CourtName = "The Old Bailey",
                            District  = "Nine"
                        }
                    }
                },
                InsolvencyTradingDetails =
                    new List <InsolvencyTradingDetailsEntity>()
                {
                    new InsolvencyTradingDetailsEntity()
                    {
                        InsolvencyTradingId = 12,
                        InsolvencyOrderId   = 1,
                        TradingAddress      = "20 High Street",
                        TradingName         = "Tescos"
                    }
                },
                InsolvencyOrderDisputes =
                    new List <InsolvencyOrderDisputeEntity>()
                {
                    new InsolvencyOrderDisputeEntity()
                    {
                        DisputeId         = 13,
                        InsolvencyOrderId = 1,
                        Deleted           = false,
                        Dispute           =
                            new DisputeEntity()
                        {
                            DisputeId  = 13,
                            DateRaised = DateTime.Parse("2016-08-14"),
                            Deleted    = false,
                            Displayed  = true,
                            InsolvencyOrderDisputes = null,
                            RefNum = "7890"
                        },
                        InsolvencyOrder = null
                    }
                }
            };

            InsolvencyOrderModel expected =
                new InsolvencyOrderModel()
            {
                InsolvencyOrderId     = 1,
                InsolvencyOrderTypeId = 2,
                InsolvencyOrderType   =
                    new InsolvencyOrderTypeModel()
                {
                    InsolvencyOrderTypeId = 2,
                    Code        = "code1",
                    Description = "type desc"
                },
                ResidenceId        = 3,
                OrderDate          = DateTime.Parse("2014-02-15"),
                RestrictionsTypeId = 4,
                RestrictionsType   =
                    new InsolvencyOrderRestrictionsTypeModel()
                {
                    RestrictionsTypeId = 4,
                    Code        = "A",
                    Description = "restriction description"
                },
                RestrictionsStartDate   = DateTime.Parse("2015-02-15"),
                RestrictionsEndDate     = DateTime.Parse("2015-04-15"),
                LineOfBusiness          = "Entertainer",
                InsolvencyServiceCaseId = 5,
                ValueOfDebt             = 5000,
                DischargeDate           = DateTime.Parse("2017-02-15"),
                InsolvencyOrderPersons  =
                    new List <InsolvencyOrderPersonModel>()
                {
                    new InsolvencyOrderPersonModel()
                    {
                        InsolvencyOrderPersonId = 8,
                        InsolvencyOrderId       = 1,
                        DateOfBirth             = DateTime.Parse("1990, 07, 21"),
                        Forename = "John",
                        Surname  = "Smith",
                        Title    = "Mr"
                    }
                },
                InsolvencyOrderAddresses =
                    new List <InsolvencyOrderAddressModel>()
                {
                    new InsolvencyOrderAddressModel()
                    {
                        InsolvencyOrderAddressId = 9,
                        InsolvencyOrderId        = 1,
                        Address  = "12 Low Street",
                        PostCode = "OX4 3PE"
                    }
                },
                InsolvencyOrderHistories =
                    new List <InsolvencyOrderHistoryModel>()
                {
                    new InsolvencyOrderHistoryModel()
                    {
                        InsolvencyOrderHistoryId = 10,
                        InsolvencyOrderId        = 1,
                        CaseReference            = "1234",
                        CaseYear = 2014,
                        CourtId  = 11,
                        Court    =
                            new CourtModel()
                        {
                            CourtId  = 11,
                            Code     = "AB",
                            Name     = "The Old Bailey",
                            District = "Nine"
                        }
                    }
                },
                InsolvencyOrderTradingDetails =
                    new List <InsolvencyOrderTradingDetailsModel>()
                {
                    new InsolvencyOrderTradingDetailsModel()
                    {
                        InsolvencyOrderTradingDetailsId = 12,
                        InsolvencyOrderId = 1,
                        Address           = "20 High Street",
                        Name = "Tescos"
                    }
                },
                Disputes =
                    new List <DisputeModel>()
                {
                    new DisputeModel()
                    {
                        DisputeId         = 13,
                        InsolvencyOrderId = 1,
                        DateRaised        = DateTime.Parse("2016-08-14"),
                        Displayed         = true,
                        ReferenceNumber   = "7890"
                    }
                }
            };

            // Act
            var actual = AutoMapper.Mapper.Map <InsolvencyOrderModel>(insolvencyOrderEntity);

            // Assert
            Assert.IsTrue(new InsolvencyModelEqualityComparer().Equals(expected, actual));
        }