コード例 #1
0
        public async void 最終ページを指定した場合表示できる件数のみ取得()
        {
            // Arrange
            var pageIndex     = 3;
            var displayCounts = 30;
            var announcement  = new Announcement(
                new AnnouncementTitle("大会のお知らせ"),
                "<h3>○○大会のおしらせ</h3>",
                AnnouncementGenre.News,
                new RegisteredDate(new DateTime(2020, 4, 1)),
                new EndDate(new DateTime(2020, 4, 30)),
                new AttachedFilePath("/attached/filePath")
                );

            var mockRepository = new Mock <IAnnouncementRepository>();

            mockRepository.Setup(r => r.Find())
            .ReturnsAsync(Enumerable.Range(0, 100).Select(o => announcement).ToList())
            .Verifiable();
            var mockFileAccessor = new Mock <IFileAccessor>();
            var usecase          = new AnnouncementUseCase(mockRepository.Object, mockFileAccessor.Object);

            // Act
            var act = await usecase.GetAnnouncements(pageIndex, displayCounts);

            // Assert
            mockRepository.Verify();
            Assert.Equal(10, act.List.Count());
            Assert.Equal(pageIndex, act.PageIndex);
            Assert.Equal(100, act.TotalCount);
            Assert.Equal(displayCounts, act.DisplayCount);
        }
コード例 #2
0
        public async void お知らせの一覧を登録日の降順で取得()
        {
            // Arrange
            var pageIndex     = 0;
            var displayCounts = 5;
            var announcement1 = new Announcement(
                new AnnouncementTitle("大会のお知らせ1"),
                "<h3>○○大会のおしらせ</h3>",
                AnnouncementGenre.News,
                new RegisteredDate(new DateTime(2020, 4, 1)),
                new EndDate(new DateTime(2020, 4, 30)),
                new AttachedFilePath("/attached/filePath")
                );

            var announcement2 = new Announcement(
                new AnnouncementTitle("大会のお知らせ2"),
                "<h3>○○大会のおしらせ</h3>",
                AnnouncementGenre.News,
                new RegisteredDate(new DateTime(2020, 4, 2)),
                new EndDate(new DateTime(2020, 4, 30)),
                new AttachedFilePath("/attached/filePath")
                );

            var announcement3 = new Announcement(
                new AnnouncementTitle("大会のお知らせ3"),
                "<h3>○○大会のおしらせ</h3>",
                AnnouncementGenre.News,
                new RegisteredDate(new DateTime(2020, 4, 3)),
                new EndDate(new DateTime(2020, 4, 30)),
                new AttachedFilePath("/attached/filePath")
                );

            var announcement4 = new Announcement(
                new AnnouncementTitle("大会のお知らせ4"),
                "<h3>○○大会のおしらせ</h3>",
                AnnouncementGenre.News,
                new RegisteredDate(new DateTime(2020, 4, 4)),
                new EndDate(new DateTime(2020, 4, 30)),
                new AttachedFilePath("/attached/filePath")
                );

            var announcement5 = new Announcement(
                new AnnouncementTitle("大会のお知らせ5"),
                "<h3>○○大会のおしらせ</h3>",
                AnnouncementGenre.News,
                new RegisteredDate(new DateTime(2020, 4, 5)),
                new EndDate(new DateTime(2020, 4, 30)),
                new AttachedFilePath("/attached/filePath")
                );

            var mockRepository = new Mock <IAnnouncementRepository>();

            mockRepository.Setup(r => r.Find())
            .ReturnsAsync(new List <Announcement>()
            {
                announcement1, announcement2, announcement3, announcement4, announcement5
            })
            .Verifiable();
            var mockFileAccessor = new Mock <IFileAccessor>();
            var usecase          = new AnnouncementUseCase(mockRepository.Object, mockFileAccessor.Object);

            // Act
            var act = await usecase.GetAnnouncements(pageIndex, displayCounts);

            // Assert
            mockRepository.Verify();
            Assert.Equal(5, act.List.Count());
            Assert.Equal(new DateTime(2020, 4, 5), act.List.First().RegisteredDate.Value);
            Assert.Equal(new DateTime(2020, 4, 4), act.List.Skip(1).First().RegisteredDate.Value);
            Assert.Equal(new DateTime(2020, 4, 3), act.List.Skip(2).First().RegisteredDate.Value);
            Assert.Equal(new DateTime(2020, 4, 2), act.List.Skip(3).First().RegisteredDate.Value);
            Assert.Equal(new DateTime(2020, 4, 1), act.List.Skip(4).First().RegisteredDate.Value);
            Assert.Equal(pageIndex, act.PageIndex);
            Assert.Equal(5, act.TotalCount);
            Assert.Equal(displayCounts, act.DisplayCount);
        }