public async Task Should_Include_Closed_Milestone_If_Specified()
    {
        // Given
        var dbContextOptions = new DbContextOptionsBuilder <GitBucketDbContext>()
                               .UseInMemoryDatabase(databaseName: "Should_Include_Closed_Milestone_If_Specified")
                               .Options;

        var dbContext = new GitBucketDbContext(dbContextOptions);
        var options   = new MilestoneOptions {
            ExecutedDate = new DateTime(2018, 7, 1), IncludeClosed = true
        };

        dbContext.Milestones.Add(new Milestone
        {
            MilestoneId    = 1,
            Title          = "v0.1.0",
            RepositoryName = "test1",
            DueDate        = new DateTime(2018, 7, 1),
            ClosedDate     = new DateTime(2018, 7, 1),
            Description    = "Implement xxx feature",
            UserName       = "******",
            Issues         = new[]
            {
                new Issue
                {
                    IssueId          = 1,
                    AssignedUserName = "******",
                    UserName         = "******",
                    RepositoryName   = "test1",
                    OpenedUserName   = "******",
                    Title            = "Implement xxx feature",
                }
            }
        });

        dbContext.SaveChanges();

        var service = new MilestoneService(dbContext, FakeConsole);

        // When
        var result = await service.ShowMilestones(options);

        // Then
        Assert.Equal(0, result);
        Assert.Equal(3, FakeConsole.Messages.Count);
        Assert.Empty(FakeConsole.WarnMessages);
        Assert.Empty(FakeConsole.ErrorMessages);

        Assert.Equal("There are 1 milestone.", FakeConsole.Messages[0]);
        Assert.Equal(string.Empty, FakeConsole.Messages[1]);

        Assert.Equal("* [root/test1], [v0.1.0], [2018/07/01], [Implement xxx feature], [user1]", FakeConsole.Messages[2]);
    }
    public async Task Should_Return_If_No_Milestone()
    {
        // Given
        var dbContextOptions = new DbContextOptionsBuilder <GitBucketDbContext>()
                               .UseInMemoryDatabase(databaseName: "Should_Return_If_No_Milestone")
                               .Options;

        var dbContext = new GitBucketDbContext(dbContextOptions);
        var options   = new MilestoneOptions {
            ExecutedDate = new DateTime(2018, 7, 29)
        };
        var service = new MilestoneService(dbContext, FakeConsole);

        // When
        var result = await service.ShowMilestones(options);

        // Then
        Assert.Equal(0, result);
        Assert.Single(FakeConsole.Messages);
        Assert.Empty(FakeConsole.WarnMessages);
        Assert.Empty(FakeConsole.ErrorMessages);

        Assert.Equal("There are no milestone.", FakeConsole.Messages[0]);
    }
    public async Task Should_Show_Multiple_Milestones()
    {
        // Given
        var dbContextOptions = new DbContextOptionsBuilder <GitBucketDbContext>()
                               .UseInMemoryDatabase(databaseName: "Should_Show_Multiple_Milestones")
                               .Options;

        var dbContext = new GitBucketDbContext(dbContextOptions);
        var options   = new MilestoneOptions {
            ExecutedDate = new DateTime(2018, 7, 1), IncludeClosed = true
        };

        dbContext.Milestones.AddRange(new List <Core.Models.Milestone>
        {
            new Milestone
            {
                MilestoneId    = 1,
                Title          = "v0.1.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 6, 30),
                ClosedDate     = null,
                Description    = "Error",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 1,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            },
            new Milestone
            {
                MilestoneId    = 2,
                Title          = "v0.2.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 7, 1),
                ClosedDate     = new DateTime(2018, 7, 1),
                Description    = "Closed",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 2,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            },
            new Milestone
            {
                MilestoneId    = 3,
                Title          = "v0.3.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 7, 7),
                ClosedDate     = null,
                Description    = "Warn",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 3,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            },
            new Milestone
            {
                MilestoneId    = 4,
                Title          = "v0.4.0",
                RepositoryName = "test1",
                DueDate        = new DateTime(2018, 7, 8),
                ClosedDate     = null,
                Description    = "Info",
                UserName       = "******",
                Issues         = new[]
                {
                    new Issue
                    {
                        IssueId          = 4,
                        AssignedUserName = "******",
                        UserName         = "******",
                        RepositoryName   = "test1",
                        OpenedUserName   = "******",
                        Title            = "Implement xxx feature",
                    }
                }
            }
        });

        dbContext.SaveChanges();

        var service = new MilestoneService(dbContext, FakeConsole);

        // When
        var result = await service.ShowMilestones(options);

        // Then
        Assert.Equal(0, result);
        Assert.Equal(4, FakeConsole.Messages.Count);
        Assert.Single(FakeConsole.WarnMessages);
        Assert.Single(FakeConsole.ErrorMessages);

        Assert.Equal("There are 4 milestones.", FakeConsole.Messages[0]);
        Assert.Equal(string.Empty, FakeConsole.Messages[1]);

        Assert.Equal("* [root/test1], [v0.1.0], [2018/06/30], [Error], [user1]", FakeConsole.ErrorMessages[0]);
        Assert.Equal("* [root/test1], [v0.2.0], [2018/07/01], [Closed], [user1]", FakeConsole.Messages[2]);
        Assert.Equal("* [root/test1], [v0.3.0], [2018/07/07], [Warn], [user1]", FakeConsole.WarnMessages[0]);
        Assert.Equal("* [root/test1], [v0.4.0], [2018/07/08], [Info], [user1]", FakeConsole.Messages[3]);
    }