public void ShouldNotThrowExceptionWhenStartHistoryIsMissing()
        {
            // Setup
            var time    = DateTime.Parse("2012-1-1");
            var actions = new
            {
                actions = new[] {
                    JsonObjectHelpers.MoveToListAction(time, "card-id", "list-1-id", "list-2-id")
                }
            };
            var list1 = new List {
                Id = "list-1-id"
            };
            var list2 = new List {
                Id = "list-2-id"
            };
            var lists = List.CreateLookupFunction(list1, list2);
            var card  = new Card {
                Id = "card-id", List = list1
            };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // Verify
            var actualListHistory   = GetActualHistory(card);
            var expectedListHistory = new[]
            {
                new { List = list1, StartTime = (DateTime?)null, EndTime = (DateTime?)time },
                new { List = list2, StartTime = (DateTime?)time, EndTime = (DateTime?)null },
            };

            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
        public void ShouldHandlerConvertCardFromCheckList()
        {
            // Setup
            var time1 = DateTime.Parse("2012-01-01");
            var list1 = new List {Id = "list-1-id"};
            var card = new Card {Id = "card-id", List = list1};
            var lists = List.CreateLookupFunction(list1);
            var convertCardAction = new
                {
                    type = Action.ConvertToCardFromCheckItem,
                    date = time1.ToString("o")
                };

            var actions = new
                {
                    actions = new[]
                        {
                            convertCardAction
                        }
                };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // Verify
            var actualListHistory = GetActualHistory(card);
            var expectedListHistory = new[]
                {
                    new {List = list1, StartTime = (DateTime?)time1, EndTime = (DateTime?) null},
                };
            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
        public void ShouldReturnTimeInListWhenCardInListOnce()
        {
            // Setup
            var time1 = DateTime.UtcNow;
            var time2 = time1.AddMinutes(1);
            var list1 = new List {
                Name = "LIST1"
            };
            var list2 = new List {
                Name = "LIST2"
            };
            var card = new Card();

            card.ListHistory.Add(new ListHistoryItem {
                List = list1, StartTimeUtc = time1, EndTimeUtc = time2
            });
            card.ListHistory.Add(new ListHistoryItem {
                List = list2, StartTimeUtc = time2, EndTimeUtc = null
            });

            // Exercise
            var actual = card.TimeInList("LIST1");

            // Verify
            var expected = TimeSpan.FromMinutes(1);

            Assert.That(actual, Is.EqualTo(expected));
        }
Example #4
0
 /// <summary>
 /// Creates a dictionary of a number of lists, using the <see cref="List.Id"/> as the key.
 /// </summary>
 public static ListLookupFunction CreateLookupFunction(params List[] lists)
 {
     var dict = lists.ToDictionary(x => x.Id);
     return id =>
         {
             List result;
             if (dict.TryGetValue(id, out result)) return result;
             result = new List { Id = id };
             dict.Add(id, result);
             return result;
         };
 }
        public void IncludeCurrentTimeInProgress()
        {
            // Setup
            var time1 = DateTime.UtcNow.AddMinutes(-5);
            var list1 = new List { Name = "LIST1" };
            var card = new Card();
            card.ListHistory.Add(new ListHistoryItem { List = list1, StartTimeUtc = time1 });

            // Exercise
            var actual = card.TimeInList("LIST1");

            // Verify
            var expected = TimeSpan.FromMinutes(5);
            var tolerance = TimeSpan.FromSeconds(5);
            Assert.That(actual, Is.EqualTo(expected).Within(tolerance));
        }
        public void ShouldReturnTimeInListWhenCardInListOnce()
        {
            // Setup
            var time1 = DateTime.UtcNow;
            var time2 = time1.AddMinutes(1);
            var list1 = new List { Name = "LIST1" };
            var list2 = new List { Name = "LIST2" };
            var card = new Card();
            card.ListHistory.Add(new ListHistoryItem { List = list1, StartTimeUtc = time1, EndTimeUtc = time2 });
            card.ListHistory.Add(new ListHistoryItem { List = list2, StartTimeUtc = time2, EndTimeUtc = null });

            // Exercise
            var actual = card.TimeInList("LIST1");

            // Verify
            var expected = TimeSpan.FromMinutes(1);
            Assert.That(actual, Is.EqualTo(expected));
        }
        public void ShouldTraceHistoryForToBoardAndThenMoved()
        {
            // Setup
            var list1 = new List {
                Id = "list-1-id"
            };
            var list2 = new List {
                Id = "list-2-id"
            };
            var list3 = new List {
                Id = "list-3-id"
            };
            var lists = List.CreateLookupFunction(list1, list2, list3);
            var time1 = DateTime.Parse("2012-01-01 12:00");
            var time2 = time1.AddHours(1);
            var time3 = time2.AddHours(2);

            var actions = new
            {
                actions = new object[] {
                    // Keep order, Trello sends newest items first in list
                    JsonObjectHelpers.MoveToListAction(time3, "card-id", "list-2-id", "list-3-id"),
                    JsonObjectHelpers.MoveCardAction(time2, "card-id"),
                    JsonObjectHelpers.CreateCardAction(time1, "card-id", "list-1-id")
                }
            };
            var card = new Card {
                Id = "card-id", List = list3
            };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // verify
            var actualListHistory   = GetActualHistory(card);
            var expectedListHistory = new[] {
                new { List = list1, StartTime = (DateTime?)time1, EndTime = (DateTime?)time2 },
                new { List = list2, StartTime = (DateTime?)time2, EndTime = (DateTime?)time3 },
                new { List = list3, StartTime = (DateTime?)time3, EndTime = (DateTime?)null }
            };

            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
        public void IncludeCurrentTimeInProgress()
        {
            // Setup
            var time1 = DateTime.UtcNow.AddMinutes(-5);
            var list1 = new List {
                Name = "LIST1"
            };
            var card = new Card();

            card.ListHistory.Add(new ListHistoryItem {
                List = list1, StartTimeUtc = time1
            });

            // Exercise
            var actual = card.TimeInList("LIST1");

            // Verify
            var expected  = TimeSpan.FromMinutes(5);
            var tolerance = TimeSpan.FromSeconds(5);

            Assert.That(actual, Is.EqualTo(expected).Within(tolerance));
        }
        public void ShouldHandlerConvertCardFromCheckList()
        {
            // Setup
            var time1 = DateTime.Parse("2012-01-01");
            var list1 = new List {
                Id = "list-1-id"
            };
            var card = new Card {
                Id = "card-id", List = list1
            };
            var lists             = List.CreateLookupFunction(list1);
            var convertCardAction = new
            {
                type = Action.ConvertToCardFromCheckItem,
                date = time1.ToString("o")
            };

            var actions = new
            {
                actions = new[]
                {
                    convertCardAction
                }
            };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // Verify
            var actualListHistory   = GetActualHistory(card);
            var expectedListHistory = new[]
            {
                new { List = list1, StartTime = (DateTime?)time1, EndTime = (DateTime?)null },
            };

            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
Example #10
0
        public void ShouldTraceHistoryForCardMovedToNewBoard()
        {
            // Setup
            var list1 = new List {
                Id = "list-1-id"
            };
            var list2 = new List {
                Id = "list-2-id"
            };
            var createTime      = DateTime.Parse("2012-01-01");
            var moveToBoardTime = createTime.AddMinutes(5);

            var createCardAction = JsonObjectHelpers.CreateCardAction(createTime, "card-id", "list-1-id");
            var moveCardAction   = JsonObjectHelpers.MoveCardAction(moveToBoardTime, "card-id");
            var lists            = List.CreateLookupFunction(list1, list2);
            var card             = new Card {
                Id = "card-id", List = list2
            };
            var actions = new { actions = new[] {
                                    // Keep order, Trello sends newest items first in list
                                    moveCardAction,
                                    createCardAction
                                } };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // verify
            var actualListHistory   = GetActualHistory(card);
            var expectedListHistory = new[] {
                new { List = list1, StartTime = (DateTime?)createTime, EndTime = (DateTime?)moveToBoardTime },
                new { List = list2, StartTime = (DateTime?)moveToBoardTime, EndTime = (DateTime?)null }
            };

            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
Example #11
0
        public void ShouldNotThrowExceptionWhenStartHistoryIsMissing()
        {
            // Setup
            var time = DateTime.Parse("2012-1-1");
            var actions = new
            {
                actions = new[] {
                JsonObjectHelpers.MoveToListAction(time, "card-id", "list-1-id", "list-2-id") }
            };
            var list1 = new List { Id = "list-1-id" };
            var list2 = new List { Id = "list-2-id" };
            var lists = List.CreateLookupFunction(list1, list2);
            var card = new Card { Id = "card-id", List = list1 };
            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // Verify
            var actualListHistory = GetActualHistory(card);
            var expectedListHistory = new[]
                {
                    new {List = list1, StartTime = (DateTime?)null, EndTime = (DateTime?)time },
                    new {List = list2, StartTime = (DateTime?)time, EndTime = (DateTime?) null},
                };
            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
Example #12
0
        public void ShouldTraceHistoryForToBoardAndThenMoved()
        {
            // Setup
            var list1 = new List { Id = "list-1-id" };
            var list2 = new List { Id = "list-2-id" };
            var list3 = new List { Id = "list-3-id" };
            var lists = List.CreateLookupFunction(list1, list2, list3);
            var time1 = DateTime.Parse("2012-01-01 12:00");
            var time2 = time1.AddHours(1);
            var time3 = time2.AddHours(2);

            var actions = new
            {
                actions = new object[] {
                    // Keep order, Trello sends newest items first in list
                    JsonObjectHelpers.MoveToListAction(time3, "card-id", "list-2-id", "list-3-id"),
                    JsonObjectHelpers.MoveCardAction(time2, "card-id") ,
                    JsonObjectHelpers.CreateCardAction(time1, "card-id", "list-1-id")
                }
            };
            var card = new Card { Id = "card-id", List = list3 };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // verify
            var actualListHistory = GetActualHistory(card);
            var expectedListHistory = new[] {
                new { List = list1, StartTime = (DateTime?)time1, EndTime = (DateTime?)time2 },
                new { List = list2, StartTime = (DateTime?)time2, EndTime = (DateTime?)time3 },
                new { List = list3, StartTime = (DateTime?)time3, EndTime = (DateTime?)null }};
            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
Example #13
0
        public void ShouldTraceHistoryForCardMovedToNewBoard()
        {
            // Setup
            var list1 = new List { Id = "list-1-id" };
            var list2 = new List { Id = "list-2-id" };
            var createTime = DateTime.Parse("2012-01-01");
            var moveToBoardTime = createTime.AddMinutes(5);

            var createCardAction = JsonObjectHelpers.CreateCardAction(createTime, "card-id", "list-1-id");
            var moveCardAction = JsonObjectHelpers.MoveCardAction(moveToBoardTime, "card-id");
            var lists = List.CreateLookupFunction(list1, list2);
            var card = new Card { Id = "card-id", List = list2 };
            var actions = new { actions = new[] {
                // Keep order, Trello sends newest items first in list
                moveCardAction,
                createCardAction  }
            };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // verify
            var actualListHistory = GetActualHistory(card);
            var expectedListHistory = new[] {
                new { List = list1, StartTime = (DateTime?)createTime, EndTime = (DateTime?)moveToBoardTime },
                new { List = list2, StartTime = (DateTime?)moveToBoardTime, EndTime = (DateTime?)null }};
            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
Example #14
0
 private static List CreateList(JToken jToken)
 {
     var id = (string) jToken["id"];
     var name = (string) jToken["name"];
     var list = new List {Id = id, Name = name};
     return list;
 }