public void FormattingADisputeCollectionAsHal_WithValidDisputesModelCollection_ReturnsExpectedCollection()
        {
            // Arrange
            const int numberOfItemsInCollection = 1000;
            const int numberOfPagesInCollection = 100;
            const int currentPage = 20;

            var collectionKey         = DomainResources.Disputes.ToLowerInvariant();
            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();

            var disputes           = new List <DisputeModel>();
            var disputesCollection = new CollectionResource <DisputeModel>(
                new CollectionResourceInfo(numberOfItemsInCollection, numberOfPagesInCollection, currentPage), disputes);

            mockedPagingLinks
            .Setup(pagingLinks => pagingLinks.GetPagingLinks(It.IsAny <Uri>(), currentPage, numberOfPagesInCollection))
            .Returns(new List <Link>());

            var responseObject =
                new DisputeCollectionResponse(
                    mockedAddressResolver.Object,
                    mockedPagingLinks.Object,
                    mockedRequestReader.Object);

            var resultsToFormat = DisputeTestData.CreateDisputeActuals();

            // Act
            var halFormattedResponse = responseObject.FormatForHal(disputesCollection);

            // Assert
            halFormattedResponse.ShouldHaveEmbeddedCollection(collectionKey, resultsToFormat);
        }
        public void FormattingADisputeCollectionAsHal_WithACallToGetALinkToTheParentRecordInTheConfiguration_CallsGetLink()
        {
            // Arrange
            const int    numberOfItemsInCollection = 1000;
            const int    numberOfPagesInCollection = 100;
            const int    currentPage = 20;
            const string routeName   = DomainResources.Disputes;
            const string linkName    = CommonLinks.Parent;

            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();
            var responseObject        =
                new DisputeCollectionResponse(
                    mockedAddressResolver.Object,
                    mockedPagingLinks.Object,
                    mockedRequestReader.Object);

            mockedPagingLinks
            .Setup(pagingLinks => pagingLinks.GetPagingLinks(It.IsAny <Uri>(), currentPage, numberOfPagesInCollection))
            .Returns(new List <Link>());

            var disputes           = new List <DisputeModel>();
            var disputesCollection = new CollectionResource <DisputeModel>(
                new CollectionResourceInfo(numberOfItemsInCollection, numberOfPagesInCollection, currentPage), disputes);

            // Act
            responseObject.FormatForHal(disputesCollection);

            // Assert
            mockedAddressResolver.Verify(mock => mock.GetLink(routeName, linkName), Times.Once);
        }
        public void FormattingADisputeCollectionAsHal_WithDataProvided_CreatesHalResponseModelEqualToTheCollectionInformation()
        {
            // Arrange
            const int numberOfItemsInCollection = 1000;
            const int numberOfPagesInCollection = 100;
            const int currentPage = 20;

            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();
            var responseObject        =
                new DisputeCollectionResponse(
                    mockedAddressResolver.Object,
                    mockedPagingLinks.Object,
                    mockedRequestReader.Object);

            mockedPagingLinks
            .Setup(pagingLinks => pagingLinks.GetPagingLinks(It.IsAny <Uri>(), currentPage, numberOfPagesInCollection))
            .Returns(new List <Link>());

            var disputes           = new List <DisputeModel>();
            var disputesCollection = new CollectionResource <DisputeModel>(
                new CollectionResourceInfo(numberOfItemsInCollection, numberOfPagesInCollection, currentPage), disputes);

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

            // Assert
            halResponse.ShouldHaveModel(disputesCollection.Information);
        }
        public void FormattingADisputeCollectionAsHal_SettingHalForceTrue_ConfiguresForceHalTrue()
        {
            // Arrange
            const int numberOfItemsInCollection = 1000;
            const int numberOfPagesInCollection = 100;
            const int currentPage = 20;

            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();
            var responseObject        =
                new DisputeCollectionResponse(
                    mockedAddressResolver.Object,
                    mockedPagingLinks.Object,
                    mockedRequestReader.Object);

            mockedPagingLinks
            .Setup(pagingLinks => pagingLinks.GetPagingLinks(It.IsAny <Uri>(), currentPage, numberOfPagesInCollection))
            .Returns(new List <Link>());

            var disputes           = new List <DisputeModel>();
            var disputesCollection =
                new CollectionResource <DisputeModel>(
                    new CollectionResourceInfo(numberOfItemsInCollection, numberOfPagesInCollection, currentPage),
                    disputes);

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

            // Assert
            Assert.IsTrue(halResponse.Config.ForceHAL);
        }
        public void FormattingADisputeCollectionAsHal_WithNullDataProvided_ThrowsArgumentNullException()
        {
            // Arrange
            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();
            var responseObject        = new DisputeCollectionResponse(
                mockedAddressResolver.Object,
                mockedPagingLinks.Object,
                mockedRequestReader.Object);

            CollectionResource <DisputeModel> disputesCollection = null;

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

            // Assert
            Assert.ThrowsException <ArgumentNullException>((Action)CreateHalResponse);
        }
        public void FormattingADisputeCollectionAsHal_WithNullDataProvided_HasCorrectParameterNameInException()
        {
            // Arrange
            const string expectedParameterName = "collection";

            var mockedRequestReader   = new Mock <IRequestReader>();
            var mockedAddressResolver = new Mock <IAddressResolver>();
            var mockedPagingLinks     = new Mock <IPagingLinks>();
            var responseObject        =
                new DisputeCollectionResponse(
                    mockedAddressResolver.Object,
                    mockedPagingLinks.Object,
                    mockedRequestReader.Object);

            CollectionResource <DisputeModel> disputesCollection = null;

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

            // Assert
            ExceptionAssert.HasCorrectParameterNameForArgumentException(CreateHalResponse, expectedParameterName);
        }