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 ShouldResetNameAndPointsWhenAssignedToNull() { var card = new Card { TrelloName = "(5) Name" }; card.TrelloName = null; Assert.That(card.Name, Is.Null); Assert.That(card.Points, Is.Null); }
public void ShouldWork() { // Setup var gatewayMock = GetMock<ITrelloRestGateway>(); var parserMock = GetMock<IJsonParser>(); var repository = GetInstance<CardRepository>(); var card = new Card { Id = "card-id" }; gatewayMock .Setup(x => x.GetCardsForBoard("BOARD-ID")) .Returns("cards-json"); gatewayMock .Setup(x => x.GetCardWithHistory("card-id")) .Returns("card-history-json"); parserMock .Setup(x => x.GetCards("cards-json")) .Returns(new [] { card}); // Exercise var cards = repository.GetCardsForBoard("BOARD-ID"); // Verify Assert.That(cards.ToArray(), Is.EqualTo(new[] { card })); parserMock.Verify(x => x.ProcessCardHistory(card, "card-history-json", It.IsAny<ListLookupFunction>())); }
public void ResettingTrelloNameShouldResetPointAndName() { var card = new Card { TrelloName = "(5) Name" }; card.TrelloName = null; Assert.That(card.Name, Is.Null); Assert.That(card.Points, Is.Null); }
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 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)); }
private static object GetActualHistory(Card card) { var actualListHistory = card.ListHistory.Select(x => new { x.List, StartTime = x.StartTimeUtc, EndTime = x.EndTimeUtc }).ToArray(); return actualListHistory; }
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 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)); }
public void PointShouldEqualCardPointsWhenGiven() { var card = new Card { TrelloName = "(5) Name" }; Assert.That(card.Points, Is.EqualTo(5)); }
public void PointShouldBeNullWhenNoPointsGiven() { var card = new Card { TrelloName = "Name" }; Assert.That(card.Points, Is.Null); }
public void NameShouldReturnTrelloNameWhenNoStoryPointGiven() { var card = new Card { TrelloName = "Name" }; Assert.That(card.Name, Is.EqualTo("Name")); }
public void NameShouldReturnStrippedTrelloNameWhenPointGiven() { var card = new Card { TrelloName = "(5) Name" }; Assert.That(card.Name, Is.EqualTo("Name")); }
public void ProcessCardHistory(Card card, string cardJson, ListLookupFunction getList) { var jObject = JObject.Parse(cardJson); var actions = (JArray)jObject["actions"]; if (actions == null) throw new ApplicationException("No actions found"); var actionsOrdered = actions.OrderBy(x => x["date"].Value<DateTime>()); foreach (var action in actionsOrdered) { var cardId = (string)action["id"]; var type = action["type"].Value<string>(); var time = action["date"].Value<DateTime>(); switch (type) { case Action.CreateCard : var listId = action["data"]["list"]["id"].Value<string>(); var list = getList(listId); card.ListHistory.Add(new ListHistoryItem { List = list, StartTimeUtc = time }); break; case Action.UpdateCard: var data = action["data"]; var listBefore = data["listBefore"]; var listAfter = data["listAfter"]; if (listBefore != null || listAfter != null) { if (listBefore == null) throw new ApplicationException("UpdateCard parse error. listAfter specified, but listBefore not specified. Card: " + cardId); if (listAfter == null) throw new ApplicationException("UpdateCard parse error. listBefore specified, but listAfter not specified. Card: " + cardId); var sourceList = getList(listBefore["id"].Value<string>()); var destList = getList(listAfter["id"].Value<string>()); if (card.ListHistory.Count == 0) card.ListHistory.Add(new ListHistoryItem()); var listItem = card.ListHistory.Last(); listItem.EndTimeUtc = time; if (listItem.List == null) listItem.List = sourceList; else if (listItem.List != sourceList) throw new ApplicationException("UpdateCard parse error. listBefore does not match previous list."); card.ListHistory.Add(new ListHistoryItem { List = destList, StartTimeUtc = time }); } break; case Action.MoveCardToBoard: card.ListHistory.Last().EndTimeUtc = time; card.ListHistory.Add(new ListHistoryItem { List = null, // Unknown at present StartTimeUtc = time }); break; case Action.ConvertToCardFromCheckItem : card.ListHistory.Add(new ListHistoryItem { StartTimeUtc = time }); break; } } var lastItem = card.ListHistory.Last(); lastItem.List = lastItem.List ?? card.List; }
public void ShouldStripPointsFromNameWhenPointsGiven() { var card = new Card { TrelloName = "(5) Name" }; Assert.That(card.Name, Is.EqualTo("Name")); }
public void ShouldReturnZeroWhenUnknownList() { var card = new Card(); var actual = card.TimeInList("dummy"); Assert.That(actual, Is.EqualTo(TimeSpan.Zero)); }
public void ShouldInitializeNameWhenNoPointsGiven() { var card = new Card { TrelloName = "Name" }; Assert.That(card.Name, Is.EqualTo("Name")); }