Beispiel #1
0
        public async Task HandleAsync_GivenMessage_AatfSubmissionHistoryDataAccessShouldBeCalled()
        {
            var message = new GetAatfSubmissionHistory(Guid.NewGuid());

            await handler.HandleAsync(message);

            A.CallTo(() => dataAccess.GetItemsAsync(message.AatfId)).MustHaveHappenedOnceExactly();
        }
        public async Task <List <AatfSubmissionHistoryData> > HandleAsync(GetAatfSubmissionHistory message)
        {
            authorization.EnsureCanAccessInternalArea();

            var submissionHistoryItems = await getAatfSubmissionHistoryDataAccess.GetItemsAsync(message.AatfId);

            return(submissionHistoryItems.Select(s => mapper.Map <AatfSubmissionHistory, AatfSubmissionHistoryData>(s)).OrderByDescending(s => s.ComplianceYear)
                   .ThenByDescending(s => s.Quarter)
                   .ThenByDescending(s => s.SubmittedDate)
                   .ToList());
        }
Beispiel #3
0
        public async Task HandleAsync_GivenAatfSubmissionHistory_HistoryShouldBeMapped()
        {
            var aatfSubmissionHistory     = A.CollectionOfFake <AatfSubmissionHistory>(2).ToList();
            var aatfSubmissionHistoryData = A.CollectionOfFake <AatfSubmissionHistoryData>(2).ToList();

            A.CallTo(() => dataAccess.GetItemsAsync(A <Guid> ._)).Returns(aatfSubmissionHistory);
            A.CallTo(() => mapper.Map <AatfSubmissionHistory, AatfSubmissionHistoryData>(aatfSubmissionHistory.ElementAt(0)))
            .Returns(aatfSubmissionHistoryData.ElementAt(0));
            A.CallTo(() => mapper.Map <AatfSubmissionHistory, AatfSubmissionHistoryData>(aatfSubmissionHistory.ElementAt(1)))
            .Returns(aatfSubmissionHistoryData.ElementAt(1));

            var message = new GetAatfSubmissionHistory(Guid.NewGuid());

            var result = await handler.HandleAsync(message);

            result.Should().Contain(aatfSubmissionHistoryData.ElementAt(0));
            result.Should().Contain(aatfSubmissionHistoryData.ElementAt(1));
            result.Count.Should().Be(2);
        }
Beispiel #4
0
        public async Task HandleAsync_GivenAatfSubmissionHistoryData_ShouldBeOrderedByComplianceYearQuarterAndSubmittedDate()
        {
            var message = new GetAatfSubmissionHistory(Guid.NewGuid());

            var aatfSubmissionHistoryData = new List <AatfSubmissionHistoryData>()
            {
                new AatfSubmissionHistoryData()
                {
                    ComplianceYear = 2017
                },
                new AatfSubmissionHistoryData()
                {
                    ComplianceYear = 2019, Quarter = QuarterType.Q1, SubmittedDate = new DateTime(2019, 01, 01)
                },
                new AatfSubmissionHistoryData()
                {
                    ComplianceYear = 2019, Quarter = QuarterType.Q1, SubmittedDate = new DateTime(2019, 01, 02)
                },
                new AatfSubmissionHistoryData()
                {
                    ComplianceYear = 2018, Quarter = QuarterType.Q3
                },
                new AatfSubmissionHistoryData()
                {
                    ComplianceYear = 2018, Quarter = QuarterType.Q1
                },
                new AatfSubmissionHistoryData()
                {
                    ComplianceYear = 2018, Quarter = QuarterType.Q2
                },
            }.ToArray();

            A.CallTo(() => dataAccess.GetItemsAsync(A <Guid> ._)).Returns(A.CollectionOfFake <AatfSubmissionHistory>(6).ToList());
            A.CallTo(() => mapper.Map <AatfSubmissionHistory, AatfSubmissionHistoryData>(A <AatfSubmissionHistory> ._)).ReturnsNextFromSequence(aatfSubmissionHistoryData);

            var result = await handler.HandleAsync(message);

            result.ElementAt(0).Should().BeEquivalentTo(new AatfSubmissionHistoryData()
            {
                ComplianceYear = 2019, Quarter = QuarterType.Q1, SubmittedDate = new DateTime(2019, 01, 02)
            });
            result.ElementAt(1).Should().BeEquivalentTo(new AatfSubmissionHistoryData()
            {
                ComplianceYear = 2019, Quarter = QuarterType.Q1, SubmittedDate = new DateTime(2019, 01, 01)
            });
            result.ElementAt(2).Should().BeEquivalentTo(new AatfSubmissionHistoryData()
            {
                ComplianceYear = 2018, Quarter = QuarterType.Q3
            });
            result.ElementAt(3).Should().BeEquivalentTo(new AatfSubmissionHistoryData()
            {
                ComplianceYear = 2018, Quarter = QuarterType.Q2
            });
            result.ElementAt(4).Should().BeEquivalentTo(new AatfSubmissionHistoryData()
            {
                ComplianceYear = 2018, Quarter = QuarterType.Q1
            });
            result.ElementAt(5).Should().BeEquivalentTo(new AatfSubmissionHistoryData()
            {
                ComplianceYear = 2017
            });
        }