﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VioletGrass.ProjectModel.Issues.Annotations;
using Xunit;

namespace VioletGrass.ProjectModel.Issues.ChangeOrders
{
    public class ChangeMilestoneTest
    {
        [Fact]
        public void ApplySimple()
        {
            var now = DateTimeOffset.Now;
            Issue existingIssue = new Issue("1", "Foo", "Bar", IssueStates.Open, "tthiery", now, false, null, null, new string[0], new Annotation[0]);

            var changeOrder = new ChangeMilestone("v0.2", "tthiery");
            changeOrder.Now = now;

            var modifiedIssue = changeOrder.Apply(existingIssue);

            Assert.Equal("1", modifiedIssue.Id);
            Assert.Equal("Foo", modifiedIssue.Title);
            Assert.Equal("Bar", modifiedIssue.Text);
            Assert.Equal("tthiery", modifiedIssue.Creator);
            Assert.Equal(now, modifiedIssue.Created);
            Assert.Null(modifiedIssue.Assignee);
            Assert.NotNull(modifiedIssue.Labels);
            Assert.Equal(0, modifiedIssue.Labels.Length);
            Assert.Equal("v0.2", modifiedIssue.Milestone);
            Assert.NotNull(modifiedIssue.Annotations);
            Assert.Equal(1, modifiedIssue.Annotations.Length);

            var annotation0 = modifiedIssue.Annotations[0] as MilestoneChange;
            Assert.NotNull(annotation0);
            Assert.Equal("tthiery", annotation0.Creator);
            Assert.Equal(now, annotation0.Created);
            Assert.Equal(now, annotation0.LastUpdated);
            Assert.Null(annotation0.OldMilestone);
            Assert.Equal("v0.2", annotation0.NewMilestone);
        }
    }
}
