From 5aae01c76b7bd3ef349fbbbbfa93b56cd82e7d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Michalik?= Date: Wed, 8 Dec 2021 19:39:57 +0100 Subject: [PATCH] Cleanup in test project structure and naming --- .../{ => Builders}/TestTodoListBuilder.cs | 80 +++++++++---------- ...doItemSummaryViewmodelCollectionBuilder.cs | 2 +- ....cs => WhenOrderByImportanceDescending.cs} | 6 +- .../WhenTodoItemIsConvertedToEditFields.cs | 1 + 4 files changed, 46 insertions(+), 43 deletions(-) rename Todo.Tests/{ => Builders}/TestTodoListBuilder.cs (95%) rename Todo.Tests/{ => Builders}/TodoItemSummaryViewmodelCollectionBuilder.cs (96%) rename Todo.Tests/{ExtensionMethods.cs => WhenOrderByImportanceDescending.cs} (87%) diff --git a/Todo.Tests/TestTodoListBuilder.cs b/Todo.Tests/Builders/TestTodoListBuilder.cs similarity index 95% rename from Todo.Tests/TestTodoListBuilder.cs rename to Todo.Tests/Builders/TestTodoListBuilder.cs index 85be83c3..9ad549ba 100644 --- a/Todo.Tests/TestTodoListBuilder.cs +++ b/Todo.Tests/Builders/TestTodoListBuilder.cs @@ -1,41 +1,41 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Identity; -using Todo.Data.Entities; - -namespace Todo.Tests -{ - /* - * This class makes it easier for tests to create new TodoLists with TodoItems correctly hooked up - */ - public class TestTodoListBuilder - { - private readonly string title; - private readonly IdentityUser owner; - private readonly List<(string, Importance)> items = new List<(string, Importance)>(); - - public TestTodoListBuilder(IdentityUser owner, string title) - { - this.title = title; - this.owner = owner; - } - - public TestTodoListBuilder WithItem(string itemTitle, Importance importance) - { - items.Add((itemTitle, importance)); - return this; - } - - public TodoList Build() - { - var todoList = new TodoList(owner, title); - var todoItems = items.Select(itm => new TodoItem(todoList.TodoListId, owner.Id, itm.Item1, itm.Item2)); - todoItems.ToList().ForEach(tlItm => - { - todoList.Items.Add(tlItm); - tlItm.TodoList = todoList; - }); - return todoList; - } - } +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Identity; +using Todo.Data.Entities; + +namespace Todo.Tests.Builders +{ + /* + * This class makes it easier for tests to create new TodoLists with TodoItems correctly hooked up + */ + public class TestTodoListBuilder + { + private readonly string title; + private readonly IdentityUser owner; + private readonly List<(string, Importance)> items = new List<(string, Importance)>(); + + public TestTodoListBuilder(IdentityUser owner, string title) + { + this.title = title; + this.owner = owner; + } + + public TestTodoListBuilder WithItem(string itemTitle, Importance importance) + { + items.Add((itemTitle, importance)); + return this; + } + + public TodoList Build() + { + var todoList = new TodoList(owner, title); + var todoItems = items.Select(itm => new TodoItem(todoList.TodoListId, owner.Id, itm.Item1, itm.Item2)); + todoItems.ToList().ForEach(tlItm => + { + todoList.Items.Add(tlItm); + tlItm.TodoList = todoList; + }); + return todoList; + } + } } \ No newline at end of file diff --git a/Todo.Tests/TodoItemSummaryViewmodelCollectionBuilder.cs b/Todo.Tests/Builders/TodoItemSummaryViewmodelCollectionBuilder.cs similarity index 96% rename from Todo.Tests/TodoItemSummaryViewmodelCollectionBuilder.cs rename to Todo.Tests/Builders/TodoItemSummaryViewmodelCollectionBuilder.cs index 7480e507..b57a8008 100644 --- a/Todo.Tests/TodoItemSummaryViewmodelCollectionBuilder.cs +++ b/Todo.Tests/Builders/TodoItemSummaryViewmodelCollectionBuilder.cs @@ -2,7 +2,7 @@ using Todo.Data.Entities; using Todo.Models.TodoItems; -namespace Todo.Tests +namespace Todo.Tests.Builders { public class TodoItemSummaryViewmodelCollectionBuilder { diff --git a/Todo.Tests/ExtensionMethods.cs b/Todo.Tests/WhenOrderByImportanceDescending.cs similarity index 87% rename from Todo.Tests/ExtensionMethods.cs rename to Todo.Tests/WhenOrderByImportanceDescending.cs index 09d2c499..910d1a7f 100644 --- a/Todo.Tests/ExtensionMethods.cs +++ b/Todo.Tests/WhenOrderByImportanceDescending.cs @@ -1,20 +1,22 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.AspNetCore.Identity; using Todo.Data.Entities; using Todo.Models.TodoItems; using Todo.Services; +using Todo.Tests.Builders; using Xunit; namespace Todo.Tests { - public class ExtensionMethods + public class WhenOrderByImportanceDescending { [Theory] [InlineData(new[] { Importance.Low, Importance.Low, Importance.High }, new[] { Importance.High, Importance.Low, Importance.Low })] [InlineData(new[] { Importance.Low, Importance.Low, Importance.Low }, new[] { Importance.Low, Importance.Low, Importance.Low })] [InlineData(new[] { Importance.High, Importance.Medium, Importance.Low }, new[] { Importance.High, Importance.Medium, Importance.Low })] [InlineData(new[] { Importance.Low, Importance.Medium, Importance.High }, new[] { Importance.High, Importance.Medium, Importance.Low })] - public void OrderByImportanceDescending(Importance[] testCaseImportances, Importance[] expected) + public void TodoItemSummaryViewmodelsOrderedByImportance(Importance[] testCaseImportances, Importance[] expected) { var todoItemSummaryViewmodelsGiven = GetTodoItemSummaryViewmodelList(testCaseImportances); diff --git a/Todo.Tests/WhenTodoItemIsConvertedToEditFields.cs b/Todo.Tests/WhenTodoItemIsConvertedToEditFields.cs index 2025be1b..be9de7e3 100644 --- a/Todo.Tests/WhenTodoItemIsConvertedToEditFields.cs +++ b/Todo.Tests/WhenTodoItemIsConvertedToEditFields.cs @@ -3,6 +3,7 @@ using Todo.Data.Entities; using Todo.EntityModelMappers.TodoItems; using Todo.Models.TodoItems; +using Todo.Tests.Builders; using Xunit; namespace Todo.Tests