public async Task AndWrongPeriodIsPassedThenItShouldReturnEmptyPage()
        {
            // Arrange
            var periodQueryResponse = new GetPeriodQueryResponse {
                IsValid = true
            };

            _mockMediator.Setup(m => m.SendAsync(It.IsAny <GetPeriodQueryRequest>())).ReturnsAsync(periodQueryResponse).Verifiable("GetPeriod was never called");

            // Act
            var actual = await _controller.GetTransfers("regular");

            // Assert
            _mockMediator.VerifyAll();
            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <OkNegotiatedContentResult <PageOfResults <AccountTransfer> > >(actual);
            Assert.AreEqual(0, ((OkNegotiatedContentResult <PageOfResults <AccountTransfer> >)actual).Content.Items.Length);
        }
        public async Task AndInvalidPeriodIsPassedThenItShouldReturnError()
        {
            // Arrange
            var periodQueryResponse = new GetPeriodQueryResponse
            {
                IsValid   = false,
                Exception = new ValidationException(new[] { "mars attacks!" })
            };

            _mockMediator.Setup(m => m.SendAsync(It.IsAny <GetPeriodQueryRequest>())).ReturnsAsync(periodQueryResponse).Verifiable("GetPeriod was never called");

            // Act
            var actual = await _controller.GetTransfers("regular");

            // Assert
            _mockMediator.VerifyAll();
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(actual);
        }
        public async Task AndExceptionOccursThenItShouldReturnErrorResult()
        {
            // Arrange
            var periodQueryResponse = new GetPeriodQueryResponse
            {
                IsValid = true,
                Result  = new CollectionPeriod()
            };

            _mockMediator.Setup(m => m.SendAsync(It.IsAny <GetPeriodQueryRequest>())).ReturnsAsync(periodQueryResponse).Verifiable("GetPeriod was never called");
            _mockMediator.Setup(m => m.SendAsync(It.IsAny <GetTransfersQueryRequest>())).Throws <ApplicationException>().Verifiable("GetTransfersQuery was never called");

            // Act
            var actual = await _controller.GetTransfers("regular");

            // Assert
            _mockMediator.VerifyAll();
            Assert.IsNotNull(actual);
            Assert.IsNotInstanceOf <OkNegotiatedContentResult <PageOfResults <AccountTransfer> > >(actual);
            Assert.IsInstanceOf <InternalServerErrorResult>(actual);
        }
        public async Task ThenItShouldReturnTransfers()
        {
            // Arrange

            var periodQueryResponse = new GetPeriodQueryResponse
            {
                IsValid = true,
                Result  = new Period()
            };

            var transfer = new AccountTransfer
            {
                TransferId        = 1,
                SenderAccountId   = 1,
                ReceiverAccountId = 2,
                Amount            = 3,
                RequiredPaymentId = Guid.Empty,
                Type = TransferType.Levy
            };

            _mockMediator.Setup(m => m.SendAsync(It.IsAny <GetPeriodQueryRequest>())).ReturnsAsync(periodQueryResponse).Verifiable("GetPeriod was never called");
            _mockMediator.Setup(m => m.SendAsync(It.IsAny <GetTransfersQueryRequest>())).ReturnsAsync(new GetTransfersQueryResponse
            {
                IsValid = true,
                Result  = new PageOfResults <AccountTransfer> {
                    Items = new[] { transfer }
                }
            }).Verifiable("GetTransfersQuery was never called");

            // Act
            var actual = await _controller.GetTransfers("regular");

            // Assert
            _mockMediator.VerifyAll();
            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <OkNegotiatedContentResult <PageOfResults <AccountTransfer> > >(actual);
            Assert.AreSame(transfer, ((OkNegotiatedContentResult <PageOfResults <AccountTransfer> >)actual).Content.Items[0]);
        }