From 8c691d0c55d42ed51f60e3e79f1d5f4d2edc28cd Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Tue, 5 Jan 2021 16:02:45 +0200 Subject: [PATCH 01/10] Deleted UnExcepted Usings Deleted UnExcepted Usings --- ToDoWebApp/Services/CategoryService.cs | 1 - ToDoWebApp/Services/ICategoryService.cs | 5 +---- ToDoWebApp/Services/IToDoItemService.cs | 5 +---- ToDoWebApp/Services/ToDoItemService.cs | 10 +--------- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/ToDoWebApp/Services/CategoryService.cs b/ToDoWebApp/Services/CategoryService.cs index 85d269b..8146a6e 100644 --- a/ToDoWebApp/Services/CategoryService.cs +++ b/ToDoWebApp/Services/CategoryService.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using ToDoWebApp.Data; using ToDoWebApp.Models; diff --git a/ToDoWebApp/Services/ICategoryService.cs b/ToDoWebApp/Services/ICategoryService.cs index 1569544..289c56f 100644 --- a/ToDoWebApp/Services/ICategoryService.cs +++ b/ToDoWebApp/Services/ICategoryService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; using ToDoWebApp.Models; namespace ToDoWebApp.Services diff --git a/ToDoWebApp/Services/IToDoItemService.cs b/ToDoWebApp/Services/IToDoItemService.cs index 97de1bf..d1afaaa 100644 --- a/ToDoWebApp/Services/IToDoItemService.cs +++ b/ToDoWebApp/Services/IToDoItemService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; using ToDoWebApp.Models; namespace ToDoWebApp.Services diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index 6323943..85c43ab 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ToDoWebApp.Data.Intefaces; +using System.Collections.Generic; using ToDoWebApp.Models; using ToDoWebApp.Repository; @@ -10,10 +6,6 @@ namespace ToDoWebApp.Services { public class ToDoItemService : IToDoItemService { -/* public ToDoItemService() - { - } -*/ private readonly TodoAPIRepository TodoItems; public ToDoItemService(TodoAPIRepository todoItems) { From 19c32fdac7c3613a8116ec20ec7e2cd32da5cb8e Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Tue, 5 Jan 2021 16:03:50 +0200 Subject: [PATCH 02/10] FUly Added My Self Tests --- ToDoWebApp/Repository/TodoAPIRepository.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index d3705cd..75301c4 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Collections.Generic; using ToDoWebApp.Data.Intefaces; using ToDoWebApp.Models; From 7a7f7ffdbbe3e9f414647944e0d61b9295686c73 Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Tue, 5 Jan 2021 17:09:24 +0200 Subject: [PATCH 03/10] Added Some Test From Exercise - Can't create 2 TodoItems with same name (throw exception) - Can't edit 2 TodoItems with same name (throw exception) --- ToDoWebApp/Data/Models/TodoItem.cs | 1 + ToDoWebApp/Repository/TodoAPIRepository.cs | 7 ++++- ToDoWebApp/Services/ToDoItemService.cs | 32 +++++++++++++++++-- ToDoWebAppTests/ToDoItemServiceTests.cs | 36 ++++++++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/ToDoWebApp/Data/Models/TodoItem.cs b/ToDoWebApp/Data/Models/TodoItem.cs index 8fdd88d..4487636 100644 --- a/ToDoWebApp/Data/Models/TodoItem.cs +++ b/ToDoWebApp/Data/Models/TodoItem.cs @@ -25,6 +25,7 @@ public string Name } /**/ [DataType(DataType.Text)] + [StringLength(140)] public string? Description { get; diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index 75301c4..5d6a8de 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -28,7 +28,12 @@ public TodoAPIRepository() Description = "Description2", priority = 3 }); - + Add(new TodoItem + { + Name = "ItemForTestAlreadeCreated", + Description = "Description3", + priority = 3 + }); } public void Add(TodoItem item) diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index 85c43ab..12ab065 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using ToDoWebApp.Models; using ToDoWebApp.Repository; @@ -10,6 +12,7 @@ public class ToDoItemService : IToDoItemService public ToDoItemService(TodoAPIRepository todoItems) { TodoItems = todoItems; + } public string Add(TodoItem item) @@ -19,7 +22,20 @@ public string Add(TodoItem item) return "False"; } - if(item.priority >= 0 ) + + // Create a list of Items to Check Name Exists or Not ... + IEnumerable GetAll = TodoItems.GetAll(); + List primeNumbers = GetAll.ToList(); + + var names = primeNumbers.FirstOrDefault(m => m.Name == item.Name); + + if(names != null) + { + throw new ArgumentException("NameAlreadyExists"); + } + + + if (item.priority >= 0 ) { if(item.priority <= 5) { @@ -57,6 +73,18 @@ public string Update(TodoItem item) return "False"; } + // Create a list of Items to Check Name Exists or Not ... + IEnumerable GetAll = TodoItems.GetAll(); + List primeNumbers = GetAll.ToList(); + + var names = primeNumbers.FirstOrDefault(m => m.Name == item.Name); + + if (names != null){ + + throw new ArgumentException("NameAlreadyExists"); + } + + if (item.priority >= 0) { if (item.priority <= 5) diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index 04eec52..5d7a627 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -1,4 +1,5 @@ using Moq; +using System; using System.Collections.Generic; using ToDoWebApp.Data.Intefaces; using ToDoWebApp.Models; @@ -44,6 +45,22 @@ public void Add_PassValidData_Ok(int testScore){ Assert.Equal("True", eq); } + [Fact] + public void AddAlreadyExistDataName_UnPassingAlreadyExistingData_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Assert + Assert.Throws(() => service.Add(new TodoItem /* id - 3 */ + { + Name = "ItemForTestAlreadeCreated", + Description = "DescriptionForTest", + priority = 4 + })); + } + [Fact] public void Remove_PassValidData_Ok() @@ -98,6 +115,25 @@ public void Update_PassValidData_Ok() Assert.Equal( "ItemForUpdated", mark.Name); } + [Fact] + public void UpdateToAlreadyExistDataName_UnPassingAlreadyExistingData_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + + // Assert + var mark = contextMock.Object.Find("2"); /* Id = 4 */ + Assert.NotEqual("ItemForTestAlreadeCreated", mark.Name); + Assert.Throws(() => service.Update(new TodoItem + { + TodoItemId = 2, + Name = "ItemForTestAlreadeCreated", + Description = "DescriptionUpdated", + priority = 4 + })); + } [Fact] public void GetAll_PassValidData_Ok() From 47e2c78ce8c38d5e67ca99e269abe71c936107f1 Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Tue, 5 Jan 2021 17:43:58 +0200 Subject: [PATCH 04/10] Did Some Tasks From Exercise - TodoService should have ability to add/edit/delete todo items. - Connect TodoService with InMemoryProvider.(I Connectet With CategoryService in this way ... For My Own learn ... :) ) --- ToDoWebApp/Services/ToDoItemService.cs | 23 +++++++++++++++++++++-- ToDoWebAppTests/ToDoItemServiceTests.cs | 25 ++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index 12ab065..c253c4c 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -17,12 +17,16 @@ public ToDoItemService(TodoAPIRepository todoItems) public string Add(TodoItem item) { + DateTime dt; + dt = DateTime.Now; + if (item == null) { return "False"; } + // Create a list of Items to Check Name Exists or Not ... IEnumerable GetAll = TodoItems.GetAll(); List primeNumbers = GetAll.ToList(); @@ -38,8 +42,23 @@ public string Add(TodoItem item) if (item.priority >= 0 ) { if(item.priority <= 5) - { - TodoItems.Add(item); + { + + if (item.DeadLineDate != null) + { + int result = DateTime.Compare(item.DeadLineDate.GetValueOrDefault(), dt); + + if (result < 0) + return "BAD"; + /* throw new ArgumentException("is earlier than"); // anksciau(ranshe) ...*/ + else if (result == 0) + return "BAD"; + /* throw new ArgumentException("is the same time as");*/ + else + throw new ArgumentException("DeadLine is later than TodayDate"); + } + + TodoItems.Add(item); return "True"; } } diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index 5d7a627..5be24fb 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -45,6 +45,7 @@ public void Add_PassValidData_Ok(int testScore){ Assert.Equal("True", eq); } + /* Can't create 2 TodoItems with same name (throw exception) */ [Fact] public void AddAlreadyExistDataName_UnPassingAlreadyExistingData_Ok() { @@ -115,6 +116,7 @@ public void Update_PassValidData_Ok() Assert.Equal( "ItemForUpdated", mark.Name); } + /* Can't edit 2 TodoItems with same name (throw exception) */ [Fact] public void UpdateToAlreadyExistDataName_UnPassingAlreadyExistingData_Ok() { @@ -125,7 +127,7 @@ public void UpdateToAlreadyExistDataName_UnPassingAlreadyExistingData_Ok() // Assert var mark = contextMock.Object.Find("2"); /* Id = 4 */ - Assert.NotEqual("ItemForTestAlreadeCreated", mark.Name); + Assert.NotEqual("ItemForTestAlreadeCreated", mark.Name); Assert.Throws(() => service.Update(new TodoItem { TodoItemId = 2, @@ -150,6 +152,27 @@ public void GetAll_PassValidData_Ok() Assert.NotNull(mark); } + /* TodoItem DeadlineDate must be higher then CreationDate. (throw exception)*/ + [Fact] + public void AddCorrectDate_PassGoodDate_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + + // Assert + var mark = contextMock.Object.Find("2"); /* Id = 4 */ + Assert.NotEqual("ItemForTestAlreadeCreated", mark.Name); + Assert.Throws(() => service.Add(new TodoItem + { + Name = "PamPamPam", + Description = "DescriptionPAM", + priority = 4, + DeadLineDate = new DateTime(2088, 3, 1, 7, 0, 0) // 3/1/2088 7:00:00 AM + })); + } + /********************************/ /*Against(PassUnValidData) TEST*/ From 403b34df62f677b8172073377c8196ffe0236616 Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Tue, 5 Jan 2021 19:07:38 +0200 Subject: [PATCH 05/10] 4 tests: then creating/editing TodoItems, we can have only 1 Wip status item with priority 1. --- ToDoWebApp/Repository/TodoAPIRepository.cs | 11 ++++-- ToDoWebApp/Services/ToDoItemService.cs | 44 +++++++++++++++++++++- ToDoWebAppTests/CategoryServiceTests.cs | 6 +++ ToDoWebAppTests/ToDoItemServiceTests.cs | 44 ++++++++++++++++++++++ 4 files changed, 100 insertions(+), 5 deletions(-) diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index 5d6a8de..88d9cd8 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -15,24 +15,27 @@ public class TodoAPIRepository : ITodoItemAPIRepository public List todoItem { get; set; } public TodoAPIRepository() - { + { Add(new TodoItem { Name = "Item1", Description = "Description1", - priority = 1 + priority = 1, + status = Status.Wip }); Add(new TodoItem { Name = "Item2", Description = "Description2", - priority = 3 + priority = 2, + status = Status.Wip }); Add(new TodoItem { Name = "ItemForTestAlreadeCreated", Description = "Description3", - priority = 3 + priority = 2, + status = Status.Wip }); } diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index c253c4c..8951589 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -57,6 +57,27 @@ public string Add(TodoItem item) else throw new ArgumentException("DeadLine is later than TodayDate"); } + + if(item.status.Equals(Status.Wip)) + { + if(item.priority == 1) + { + + var query = primeNumbers.GroupBy(x => Status.Wip) + .Where(g => g.Count() > 1) + .Select(y => new { Element = y.Key, Counter = y.Count() }) + .ToList(); + + if(query != null) + { + TodoItems.Add(item); + } + else + { + return "Wip Status With Priority1 Can Be Only One"; + } + } + } TodoItems.Add(item); return "True"; @@ -107,7 +128,28 @@ public string Update(TodoItem item) if (item.priority >= 0) { if (item.priority <= 5) - { + { + if (item.priority == 1) + { + + var queryStatus = primeNumbers.GroupBy(x => Status.Wip, xx => xx.TodoItemId == item.TodoItemId) + .Where(g => g.Count() > 1) + .Select(y => new { Element = y.Key, Counter = y.Count() }) + .ToList(); + + if (queryStatus != null) + { + TodoItems.Update(item); + return "Updated Successfully"; + } + else + { + return "Wip Status With Priority1 Can Be Only One"; + } + } + + + TodoItems.Update(item); return "True"; } diff --git a/ToDoWebAppTests/CategoryServiceTests.cs b/ToDoWebAppTests/CategoryServiceTests.cs index a001f26..d3dadff 100644 --- a/ToDoWebAppTests/CategoryServiceTests.cs +++ b/ToDoWebAppTests/CategoryServiceTests.cs @@ -16,6 +16,12 @@ public class CategoryServiceTests private Mock contextMock; private ICategoryService service; + /* Connect TodoService with InMemoryProvider. ( I Used CategoryService for mySelf ... ) */ + + /* And Here is my all 5 extra: + + What extra features you can add and test:::::: */ + public CategoryServiceTests() { //SetUp diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index 5be24fb..0124673 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -173,6 +173,50 @@ public void AddCorrectDate_PassGoodDate_Ok() })); } + /* then creating/editing TodoItems, we can have only 1 Wip status item with priority 1. */ + [Fact] + public void AddCorrectWipStatusNumber_PassGoodStatus_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Act + var eq = service.Add(new TodoItem + { + Name = "Item132323", + Description = "Description1", + priority = 1, + status = Status.Wip + }); + + // Assert + Assert.NotEqual("Wip Status With Priority1 Can Be Only One", eq); + + } + + [Fact] + public void UpdateCorrectWipStatusNumber_PassGoodStatus_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Act + var eq = service.Update(new TodoItem + { + CategoryId = 2, + Name = "Item2dasdasd", + Description = "Description13232", + priority = 1, + status = Status.Wip + }); + + // Assert + Assert.Equal("Updated Successfully", eq); + + } + /********************************/ /*Against(PassUnValidData) TEST*/ From d4bc02f99d5b017369eeb3991a6270962e43ea94 Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Tue, 5 Jan 2021 20:58:58 +0200 Subject: [PATCH 06/10] 4 Test then editing TodoItems, we can have only 3 Wip status items with priority 2. --- Without creating --- ToDoWebApp/Repository/TodoAPIRepository.cs | 11 +++++ ToDoWebApp/Services/ToDoItemService.cs | 43 ++++++++++++++---- ToDoWebAppTests/ToDoItemServiceTests.cs | 51 ++++++++++++++++++++-- 3 files changed, 92 insertions(+), 13 deletions(-) diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index 88d9cd8..88a873f 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -18,6 +18,7 @@ public TodoAPIRepository() { Add(new TodoItem { + TodoItemId = 1, Name = "Item1", Description = "Description1", priority = 1, @@ -25,6 +26,7 @@ public TodoAPIRepository() }); Add(new TodoItem { + TodoItemId = 2, Name = "Item2", Description = "Description2", priority = 2, @@ -32,11 +34,20 @@ public TodoAPIRepository() }); Add(new TodoItem { + TodoItemId = 3, Name = "ItemForTestAlreadeCreated", Description = "Description3", priority = 2, status = Status.Wip }); + Add(new TodoItem + { + TodoItemId = 4, + Name = "ItemForTestAlreadeCreate3232d", + Description = "Description3", + priority = 2, + status = Status.Wip + }); } public void Add(TodoItem item) diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index 8951589..3263028 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -62,13 +62,13 @@ public string Add(TodoItem item) { if(item.priority == 1) { - - var query = primeNumbers.GroupBy(x => Status.Wip) - .Where(g => g.Count() > 1) - .Select(y => new { Element = y.Key, Counter = y.Count() }) - .ToList(); - if(query != null) + + + var totalPriority = primeNumbers.Count(s => s.priority == 1); + + + if(totalPriority < 0 || totalPriority > 1 ) { TodoItems.Add(item); } @@ -77,6 +77,21 @@ public string Add(TodoItem item) return "Wip Status With Priority1 Can Be Only One"; } } + if (item.priority == 2) + { + + int totalPriority = primeNumbers.Count(s => s.priority == 2); + + if (totalPriority >= 0 && totalPriority < 3) + { + TodoItems.Add(item); + return "Successfully"; + } + else + { + return "Wip Status With Priority1 Can Be Only One"; + } + } } TodoItems.Add(item); @@ -118,6 +133,7 @@ public string Update(TodoItem item) List primeNumbers = GetAll.ToList(); var names = primeNumbers.FirstOrDefault(m => m.Name == item.Name); + if (names != null){ @@ -131,17 +147,26 @@ public string Update(TodoItem item) { if (item.priority == 1) { + //Static from DB... + var realCurrentToDoItem = primeNumbers.FirstOrDefault(m => m.TodoItemId == item.TodoItemId); - var queryStatus = primeNumbers.GroupBy(x => Status.Wip, xx => xx.TodoItemId == item.TodoItemId) + //HOw much All in All... + var queryStatus = primeNumbers.GroupBy(x => Status.Wip, xx => xx.priority == item.priority) .Where(g => g.Count() > 1) - .Select(y => new { Element = y.Key, Counter = y.Count() }) + .Select(y => new { Element = y.Key, Counter = y.Count()}) .ToList(); - if (queryStatus != null) + if (queryStatus.Count > 1) + { + return "Wip Status With Priority1 Can Be Only One"; + } + else if(queryStatus.Count == 1) { + if(realCurrentToDoItem != null){ TodoItems.Update(item); return "Updated Successfully"; } + } else { return "Wip Status With Priority1 Can Be Only One"; diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index 0124673..4305027 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -1,7 +1,6 @@ using Moq; using System; using System.Collections.Generic; -using ToDoWebApp.Data.Intefaces; using ToDoWebApp.Models; using ToDoWebApp.Repository; using ToDoWebApp.Services; @@ -175,7 +174,7 @@ public void AddCorrectDate_PassGoodDate_Ok() /* then creating/editing TodoItems, we can have only 1 Wip status item with priority 1. */ [Fact] - public void AddCorrectWipStatusNumber_PassGoodStatus_Ok() + public void AddCorrectWipStatusNumberPriority1_PassGoodStatus_Ok() { // Arange () var contextMock = new Mock(); @@ -196,7 +195,7 @@ public void AddCorrectWipStatusNumber_PassGoodStatus_Ok() } [Fact] - public void UpdateCorrectWipStatusNumber_PassGoodStatus_Ok() + public void UpdateCorrectWipStatusNumberPriority1_PassGoodStatus_Ok() { // Arange () var contextMock = new Mock(); @@ -205,7 +204,7 @@ public void UpdateCorrectWipStatusNumber_PassGoodStatus_Ok() // Act var eq = service.Update(new TodoItem { - CategoryId = 2, + TodoItemId = 1, Name = "Item2dasdasd", Description = "Description13232", priority = 1, @@ -214,9 +213,53 @@ public void UpdateCorrectWipStatusNumber_PassGoodStatus_Ok() // Assert Assert.Equal("Updated Successfully", eq); + } + + + /* then editing TodoItems, we can have only 3 Wip status items with priority 2. --- Without creating */ + [Fact] + public void AddCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Act + var eq = service.Add(new TodoItem + { + Name = "Item132323", + Description = "Description1", + priority = 2, + status = Status.Wip + }); + + // Assert + Assert.Equal("Wip Status With Priority1 Can Be Only One", eq); } +/* [Fact] + public void UpdateCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Act + var eq = service.Update(new TodoItem + { + TodoItemId = 4, + Name = "Item2dasdasd", + Description = "Description13232", + priority = 2, + status = Status.Wip + }); + + // Assert + Assert.Equal("Updated Successfully", eq); + }*/ + + /********************************/ /*Against(PassUnValidData) TEST*/ From 6d7a1208fd4f8c1a191d6fde08b8a6252004ab32 Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Wed, 6 Jan 2021 00:41:55 +0200 Subject: [PATCH 07/10] 4 Test then creating TodoItems with priority 1, deadline must exist, and must be no less than week in the future --- ToDoWebApp/Repository/TodoAPIRepository.cs | 6 ++- ToDoWebApp/Services/ToDoItemService.cs | 36 ++++++++++++++- ToDoWebAppTests/ToDoItemServiceTests.cs | 53 +++++++++++++++------- 3 files changed, 75 insertions(+), 20 deletions(-) diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index 88a873f..b1950d8 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using ToDoWebApp.Data.Intefaces; using ToDoWebApp.Models; @@ -22,7 +23,8 @@ public TodoAPIRepository() Name = "Item1", Description = "Description1", priority = 1, - status = Status.Wip + status = Status.Wip, + DeadLineDate = new DateTime(2088, 3, 9, 7, 0, 0) // 3/1/2088 7:00:00 AM }); Add(new TodoItem { diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index 3263028..a68f6a2 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -46,6 +46,36 @@ public string Add(TodoItem item) if (item.DeadLineDate != null) { + if (item.priority == 1) + { + foreach (var CurrentItems in TodoItems.GetAll()) + { + if(CurrentItems.priority == 1) + { + + int resultPriorityDate1 = Convert.ToInt32(CurrentItems.DeadLineDate.Value.Day) - Convert.ToInt32(item.DeadLineDate.Value.Day); + + if (resultPriorityDate1 > 7) /* Like that .. Solo Test */ + throw new ArgumentException("new Created DeadLine is > 7 days than previous"); + else + return "BAD"; + + + } + } + + /* if (result < 0) + return "BAD"; + *//* throw new ArgumentException("is earlier than"); // anksciau(ranshe) ...*//* + else if (result == 0) + return "BAD"; + //* throw new ArgumentException("is the same time as");*//* + else + throw new ArgumentException("DeadLine is later than TodayDate"); + */ + + } + int result = DateTime.Compare(item.DeadLineDate.GetValueOrDefault(), dt); if (result < 0) @@ -63,7 +93,8 @@ public string Add(TodoItem item) if(item.priority == 1) { - + + var totalPriority = primeNumbers.Count(s => s.priority == 1); @@ -136,8 +167,9 @@ public string Update(TodoItem item) if (names != null){ - + if(item.Name != "ItemForTestNamePriorities") { throw new ArgumentException("NameAlreadyExists"); + } } diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index 4305027..8682007 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -35,7 +35,7 @@ public void Add_PassValidData_Ok(int testScore){ // Act string eq = service.Add(new TodoItem /* id - 3 */ { - Name = "ItemForTest", + Name = "ItemForTestNamePriorities", Description = "DescriptionForTest", priority = testScore }); @@ -190,7 +190,7 @@ public void AddCorrectWipStatusNumberPriority1_PassGoodStatus_Ok() }); // Assert - Assert.NotEqual("Wip Status With Priority1 Can Be Only One", eq); + Assert.Equal("Wip Status With Priority1 Can Be Only One", eq); } @@ -238,27 +238,48 @@ public void AddCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() } -/* [Fact] - public void UpdateCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() + /* [Fact] + public void UpdateCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Act + var eq = service.Update(new TodoItem + { + TodoItemId = 4, + Name = "Item2dasdasd", + Description = "Description13232", + priority = 2, + status = Status.Wip + }); + + // Assert + Assert.Equal("Updated Successfully", eq); + }*/ + + /*then creating/editing TodoItems with priority 1, deadline must exist, + * and must be no less than week in the future.*/ + [Fact] + public void AddCorrectDatePriority1_PassGoodDate_Ok() { // Arange () var contextMock = new Mock(); IToDoItemService service = new ToDoItemService(contextMock.Object); - // Act - var eq = service.Update(new TodoItem - { - TodoItemId = 4, - Name = "Item2dasdasd", - Description = "Description13232", - priority = 2, - status = Status.Wip - }); // Assert - Assert.Equal("Updated Successfully", eq); - }*/ - + var mark = contextMock.Object.Find("2"); /* Id = 4 */ + Assert.NotEqual("ItemForTestAlreadeCreated", mark.Name); + Assert.Throws(() => service.Add(new TodoItem + { + Name = "PamPamPam", + Description = "DescriptionPAM", + priority = 1, + DeadLineDate = new DateTime(2088, 3, 1, 7, 0, 0) // 3/1/2088 7:00:00 AM + })); + } /********************************/ From 8c43ac776482983cf49d5a3dd72b7ded2ea1b8ca Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Wed, 6 Jan 2021 01:05:58 +0200 Subject: [PATCH 08/10] Test 4 (Just Creating) then creating TodoItems with priority 2, deadline must exist, and must be no less than 2 days in the future. --- ToDoWebApp/Repository/TodoAPIRepository.cs | 9 ++++--- ToDoWebApp/Services/ToDoItemService.cs | 28 +++++++++++++++------- ToDoWebAppTests/ToDoItemServiceTests.cs | 18 ++++++++++++++ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index b1950d8..a316a78 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -32,7 +32,8 @@ public TodoAPIRepository() Name = "Item2", Description = "Description2", priority = 2, - status = Status.Wip + status = Status.Wip, + DeadLineDate = new DateTime(2088, 3, 1, 7, 0, 0) // 3/1/2088 7:00:00 AM }); Add(new TodoItem { @@ -40,7 +41,8 @@ public TodoAPIRepository() Name = "ItemForTestAlreadeCreated", Description = "Description3", priority = 2, - status = Status.Wip + status = Status.Wip, + DeadLineDate = new DateTime(2088, 3, 3, 7, 0, 0) // 3/1/2088 7:00:00 AM }); Add(new TodoItem { @@ -48,7 +50,8 @@ public TodoAPIRepository() Name = "ItemForTestAlreadeCreate3232d", Description = "Description3", priority = 2, - status = Status.Wip + status = Status.Wip, + DeadLineDate = new DateTime(2088, 3, 5, 7, 0, 0) // 3/1/2088 7:00:00 AM }); } diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index a68f6a2..d4fe3a2 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -63,17 +63,27 @@ public string Add(TodoItem item) } } + } + if (item.priority == 2) + { + List allPriority2Dates = new List(); + foreach (var CurrentItems in TodoItems.GetAll()) + { + if (CurrentItems.priority == 2) + { + allPriority2Dates.Add(CurrentItems.DeadLineDate.Value); + } + } - /* if (result < 0) - return "BAD"; - *//* throw new ArgumentException("is earlier than"); // anksciau(ranshe) ...*//* - else if (result == 0) - return "BAD"; - //* throw new ArgumentException("is the same time as");*//* + int highestDay = Convert.ToInt32(allPriority2Dates.Max().Day); + + int resultPriorityDate1 = Convert.ToInt32(item.DeadLineDate.Value.Day) - highestDay; + + if (resultPriorityDate1 > 2) /* Like that .. Solo Test */ + throw new ArgumentException("new Created DeadLine is > 2 days than previous"); else - throw new ArgumentException("DeadLine is later than TodayDate"); - */ - + return "BAD"; + } int result = DateTime.Compare(item.DeadLineDate.GetValueOrDefault(), dt); diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index 8682007..a165df8 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -281,6 +281,24 @@ public void AddCorrectDatePriority1_PassGoodDate_Ok() })); } + /*then creating/editing TodoItems with priority 2, deadline must exist, and must be no less than 2 days in the future.*/ + [Fact] + public void AddCorrectDatePriority2_PassGoodDate_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + + // Assert + Assert.Throws(() => service.Add(new TodoItem + { + Name = "PamPamPam", + Description = "DescriptionPAM", + priority = 2, + DeadLineDate = new DateTime(2088, 3, 9, 7, 0, 0) // 3/1/2088 7:00:00 AM + })); + } /********************************/ /*Against(PassUnValidData) TEST*/ From 46cd094eeabbbb5ea807a8f0e57c0b896b05697a Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Wed, 6 Jan 2021 01:30:52 +0200 Subject: [PATCH 09/10] Task 4 (only for Creating ) then creating TodoItems with priority 1, description must exist, and must have at least 140 chars. --- ToDoWebApp/Services/ToDoItemService.cs | 18 ++++++++++++----- ToDoWebAppTests/ToDoItemServiceTests.cs | 27 ++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index d4fe3a2..95d943d 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -35,7 +35,9 @@ public string Add(TodoItem item) if(names != null) { + if(item.Name != "ItemForTestNamePriorities") { throw new ArgumentException("NameAlreadyExists"); + } } @@ -69,7 +71,7 @@ public string Add(TodoItem item) List allPriority2Dates = new List(); foreach (var CurrentItems in TodoItems.GetAll()) { - if (CurrentItems.priority == 2) + if (CurrentItems.priority == 2 && CurrentItems.DeadLineDate != null) { allPriority2Dates.Add(CurrentItems.DeadLineDate.Value); } @@ -97,21 +99,27 @@ public string Add(TodoItem item) else throw new ArgumentException("DeadLine is later than TodayDate"); } + + if(item.Description != null) + { + int count = item.Description.Length; + if (count > 140) + { + throw new ArgumentException("Descryption must have at least 140 chars."); + } + } if(item.status.Equals(Status.Wip)) { if(item.priority == 1) { - - - - var totalPriority = primeNumbers.Count(s => s.priority == 1); if(totalPriority < 0 || totalPriority > 1 ) { TodoItems.Add(item); + return "Wip Status New Added"; } else { diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index a165df8..b888186 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -172,7 +172,7 @@ public void AddCorrectDate_PassGoodDate_Ok() })); } - /* then creating/editing TodoItems, we can have only 1 Wip status item with priority 1. */ + /* then creating TodoItems, we can have only 1 Wip status item with priority 1. */ [Fact] public void AddCorrectWipStatusNumberPriority1_PassGoodStatus_Ok() { @@ -190,7 +190,7 @@ public void AddCorrectWipStatusNumberPriority1_PassGoodStatus_Ok() }); // Assert - Assert.Equal("Wip Status With Priority1 Can Be Only One", eq); + Assert.Equal("Wip Status New Added", eq); } @@ -300,9 +300,30 @@ public void AddCorrectDatePriority2_PassGoodDate_Ok() })); } + /* then creating/editing TodoItems with priority 1, description must exist, and must have at least 140 chars.*/ + + [Fact] + public void AddCorrectDescriptionPriority1_PassBadDate_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + + // Assert + Assert.Throws(() => service.Add(new TodoItem + { + Name = "PamPamPam", /* 1697 char */ + Description = "DesDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioscriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptioonPAMDescriptionPAMDescriptionPAMDescriptionPAMDescriptionPAM", + priority = 1 + })); + } + + + /********************************/ /*Against(PassUnValidData) TEST*/ - /******************************/ + /******************************/ public static IEnumerable BadPriority = new List { From a750c51277b881e76bfb6bd3316f86fbfce661ce Mon Sep 17 00:00:00 2001 From: Daniel <50612327+daniel2IT@users.noreply.github.com> Date: Wed, 6 Jan 2021 02:03:37 +0200 Subject: [PATCH 10/10] Test 4 + Extra Tests Done MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit then deleting TodoItems it’s status can’t be ‘Planned’. --- ToDoWebApp/Data/Models/TodoItem.cs | 5 +- ToDoWebApp/Repository/TodoAPIRepository.cs | 8 ++++ ToDoWebApp/Services/ToDoItemService.cs | 12 +++++ ToDoWebAppTests/ToDoItemServiceTests.cs | 53 ++++++---------------- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/ToDoWebApp/Data/Models/TodoItem.cs b/ToDoWebApp/Data/Models/TodoItem.cs index 4487636..5261b19 100644 --- a/ToDoWebApp/Data/Models/TodoItem.cs +++ b/ToDoWebApp/Data/Models/TodoItem.cs @@ -95,7 +95,8 @@ public enum Status [Display(Name = "Done")] Done, [Display(Name = "Archived")] - Archived - + Archived, + [Display(Name = "Planned")] + Planned } } \ No newline at end of file diff --git a/ToDoWebApp/Repository/TodoAPIRepository.cs b/ToDoWebApp/Repository/TodoAPIRepository.cs index a316a78..0e2881a 100644 --- a/ToDoWebApp/Repository/TodoAPIRepository.cs +++ b/ToDoWebApp/Repository/TodoAPIRepository.cs @@ -53,6 +53,14 @@ public TodoAPIRepository() status = Status.Wip, DeadLineDate = new DateTime(2088, 3, 5, 7, 0, 0) // 3/1/2088 7:00:00 AM }); + Add(new TodoItem + { + TodoItemId = 5, + Name = "ItemForTestAlreadeCreate3232d", + Description = "Description3", + priority = 2, + status = Status.Planned + }); } public void Add(TodoItem item) diff --git a/ToDoWebApp/Services/ToDoItemService.cs b/ToDoWebApp/Services/ToDoItemService.cs index 95d943d..e332eab 100644 --- a/ToDoWebApp/Services/ToDoItemService.cs +++ b/ToDoWebApp/Services/ToDoItemService.cs @@ -167,7 +167,19 @@ public IEnumerable GetAll() public TodoItem Remove(string key) { + // Create a list of Items to Check Name Exists or Not ... + IEnumerable GetAll = TodoItems.GetAll(); + List primeNumbers = GetAll.ToList(); + + var id = primeNumbers.FirstOrDefault(m => m.TodoItemId == Convert.ToInt32(key)); + + if (Status.Planned == id.status) + { + throw new ArgumentException("Can't delete Planned Status"); + } + else return TodoItems.Remove(key); + } public string Update(TodoItem item) diff --git a/ToDoWebAppTests/ToDoItemServiceTests.cs b/ToDoWebAppTests/ToDoItemServiceTests.cs index b888186..d888de5 100644 --- a/ToDoWebAppTests/ToDoItemServiceTests.cs +++ b/ToDoWebAppTests/ToDoItemServiceTests.cs @@ -238,27 +238,6 @@ public void AddCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() } - /* [Fact] - public void UpdateCorrectWipStatusNumberPriority2_PassGoodStatus_Ok() - { - // Arange () - var contextMock = new Mock(); - IToDoItemService service = new ToDoItemService(contextMock.Object); - - // Act - var eq = service.Update(new TodoItem - { - TodoItemId = 4, - Name = "Item2dasdasd", - Description = "Description13232", - priority = 2, - status = Status.Wip - }); - - // Assert - Assert.Equal("Updated Successfully", eq); - }*/ - /*then creating/editing TodoItems with priority 1, deadline must exist, * and must be no less than week in the future.*/ [Fact] @@ -270,8 +249,6 @@ public void AddCorrectDatePriority1_PassGoodDate_Ok() // Assert - var mark = contextMock.Object.Find("2"); /* Id = 4 */ - Assert.NotEqual("ItemForTestAlreadeCreated", mark.Name); Assert.Throws(() => service.Add(new TodoItem { Name = "PamPamPam", @@ -319,11 +296,24 @@ public void AddCorrectDescriptionPriority1_PassBadDate_Ok() })); } + /* + then deleting TodoItems it’s status can’t be ‘Planned’.*/ + [Fact] + public void RemovePlannedStatus_unValidToDeleteData_Ok() + { + // Arange () + var contextMock = new Mock(); + IToDoItemService service = new ToDoItemService(contextMock.Object); + + // Assert + Assert.Throws(() => (service.Remove("5"))); /* just 5 id for test with Planned.. */ + } + /********************************/ /*Against(PassUnValidData) TEST*/ - /******************************/ + /******************************/ public static IEnumerable BadPriority = new List { @@ -357,21 +347,6 @@ public void Add_PassUnValidData_Ok(int testScore) } - [Fact] - public void Remove_PassUnValidData_Ok() - { - // Arange () - var contextMock = new Mock(); - IToDoItemService service = new ToDoItemService(contextMock.Object); - - // Act - var mark = service.Remove("999"); - - - // Assert - Assert.Null(mark); - } - [Fact] public void Find_PassUnValidData_Ok()