diff --git a/WatchList.Core/Service/Component/IMessageBox.cs b/WatchList.Core/Service/Component/IMessageBox.cs index 3da6c0ad..0db905a5 100644 --- a/WatchList.Core/Service/Component/IMessageBox.cs +++ b/WatchList.Core/Service/Component/IMessageBox.cs @@ -4,16 +4,16 @@ namespace WatchList.Core.Service.Component { public interface IMessageBox { - public void ShowInfo(string message); + public Task ShowInfo(string message); - public void ShowWarning(string message); + public Task ShowWarning(string message); - public void ShowError(string message); + public Task ShowError(string message); - public bool ShowQuestion(string message); + public Task ShowQuestion(string message); - public bool ShowQuestionSaveItem(string message); + public Task ShowQuestionSaveItem(string message); - public DialogReplaceItemQuestion ShowDataReplaceQuestion(string titleItem); + public Task ShowDataReplaceQuestion(string titleItem); } } diff --git a/WatchList.Core/Service/DataLoading/DownloadDataService.cs b/WatchList.Core/Service/DataLoading/DownloadDataService.cs index ddac11a3..3c3b7929 100644 --- a/WatchList.Core/Service/DataLoading/DownloadDataService.cs +++ b/WatchList.Core/Service/DataLoading/DownloadDataService.cs @@ -57,7 +57,7 @@ private void AddItems(WatchItemCollection itemCollection) } } - private void UpdateItems(WatchItemCollection itemCollection) + private async Task UpdateItems(WatchItemCollection itemCollection) { var dialogResultReplaceItem = DialogReplaceItemQuestion.Unknown; @@ -73,7 +73,7 @@ private void UpdateItems(WatchItemCollection itemCollection) case QuestionResultEnum.Unknown: case QuestionResultEnum.Yes: case QuestionResultEnum.No: - dialogResultReplaceItem = _messageBox.ShowDataReplaceQuestion(item.Title); + dialogResultReplaceItem = await _messageBox.ShowDataReplaceQuestion(item.Title); break; } diff --git a/WatchList.Core/Service/WatchItemService.cs b/WatchList.Core/Service/WatchItemService.cs index c48196eb..6466f804 100644 --- a/WatchList.Core/Service/WatchItemService.cs +++ b/WatchList.Core/Service/WatchItemService.cs @@ -23,7 +23,7 @@ public WatchItemService(WatchItemRepository itemRepository, IMessageBox messageB public void Remove(Guid id) => _repository.Remove(id); - public void Add(WatchItem item) + public async Task AddAsync(WatchItem item) { var selectItem = _repository.SelectDuplicateItems(item); var countDuplicate = selectItem.Count; @@ -34,21 +34,21 @@ public void Add(WatchItem item) return; } - if (_messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage)) + if (await _messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage)) { item.Id = selectItem[0]; Update(item); } } - public void Updata(WatchItem oldItem, WatchItem modifiedItem) + public async Task UpdateAsync(WatchItem oldItem, WatchItem modifiedItem) { var selectItem = _repository.SelectDuplicateItems(modifiedItem); var countDuplicate = selectItem.Count; if (countDuplicate == 1 && oldItem.Title != modifiedItem.Title) { - if (_messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage)) + if (await _messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage)) { modifiedItem.Id = selectItem[0]; Remove(oldItem.Id); diff --git a/WatchList.MudBlazors/Dialog/WatchItemDialog.razor.cs b/WatchList.MudBlazors/Dialog/WatchItemDialog.razor.cs index fa22fe6f..394bc1be 100644 --- a/WatchList.MudBlazors/Dialog/WatchItemDialog.razor.cs +++ b/WatchList.MudBlazors/Dialog/WatchItemDialog.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using MudBlazor; using WatchList.Core.Model.ItemCinema; +using WatchList.Core.Model.ItemCinema.Components; using WatchList.Core.Service; using WatchList.MudBlazors.Extension; using WatchList.MudBlazors.Model; @@ -51,7 +52,7 @@ private async Task Add() } var item = _watchItemModel.ToWatchItem(); - WatchItemService.Add(item); + await WatchItemService.AddAsync(item); MudDialog.Close(); } @@ -68,14 +69,14 @@ private async Task Updata() if (!ValidateFields(out var message)) { - ShowMessageWarning(message); + await ShowMessageWarning(message); return; } var item = _watchItemModel.ToWatchItem(); if (!_oldWatchItem.Equals(item)) { - WatchItemService.Updata(_oldWatchItem, item); + await WatchItemService.UpdateAsync(_oldWatchItem, item); } MudDialog.Close(); @@ -116,7 +117,7 @@ private bool ValidateFields(out string message) return false; } - if (_watchItemModel.Grade <= 0) + if (_watchItemModel.Grade <= 0 && _watchItemModel.Status != StatusCinema.Planned) { message = $"Grade cinema above in zero."; return false; @@ -128,6 +129,12 @@ private bool ValidateFields(out string message) return false; } + if (_watchItemModel.Date == null && _watchItemModel.Status == StatusCinema.Viewed) + { + message = "Ener the viewing date."; + return false; + } + return true; } } diff --git a/WatchList.MudBlazors/Extension/DialogServiceShow.cs b/WatchList.MudBlazors/Extension/DialogServiceShow.cs index 54c963d7..5efc0801 100644 --- a/WatchList.MudBlazors/Extension/DialogServiceShow.cs +++ b/WatchList.MudBlazors/Extension/DialogServiceShow.cs @@ -5,13 +5,13 @@ namespace WatchList.MudBlazors.Extension { public static class DialogServiceShow { - public static bool DialogYesNoShow(this IDialogService dialogService, string title, string content) + public static async Task DialogYesNoShow(this IDialogService dialogService, string title, string content) { var parameters = new DialogParameters { { x => x.Content, content } }; - return DialogShow(parameters, dialogService, title, content); + return await DialogShowAsync(parameters, dialogService, title, content); } - public static bool DialogOkCloseShow(this IDialogService dialogService, string title, string content) + public static async Task DialogOkCloseShowAsync(this IDialogService dialogService, string title, string content) { var parameters = new DialogParameters { @@ -23,14 +23,14 @@ public static bool DialogOkCloseShow(this IDialogService dialogService, string t } } }; - return DialogShow(parameters, dialogService, title, content); + return await DialogShowAsync(parameters, dialogService, title, content); } - private static bool DialogShow(DialogParameters dialogParameters, IDialogService dialogService, string title, string content) + private static async Task DialogShowAsync(DialogParameters dialogParameters, IDialogService dialogService, string title, string content) { var options = new DialogOptions { CloseOnEscapeKey = true }; - var dialog = dialogService.Show(title, dialogParameters, options); - var result = dialog.Result.Result; + var dialog = await dialogService.ShowAsync(title, dialogParameters, options); + var result = await dialog.Result; return result == null || !result.Cancelled; } } diff --git a/WatchList.MudBlazors/Message/MessageBoxDialog.cs b/WatchList.MudBlazors/Message/MessageBoxDialog.cs index 45b8f129..e2f1bfcc 100644 --- a/WatchList.MudBlazors/Message/MessageBoxDialog.cs +++ b/WatchList.MudBlazors/Message/MessageBoxDialog.cs @@ -12,22 +12,22 @@ public class MessageBoxDialog : IMessageBox public MessageBoxDialog(IDialogService dialogService) => _dialogService = dialogService; - public DialogReplaceItemQuestion ShowDataReplaceQuestion(string titleItem) - => DialogReplaceItemQuestion.Yes; + public Task ShowDataReplaceQuestion(string titleItem) + => Task.FromResult(DialogReplaceItemQuestion.Yes); - public void ShowError(string message) + public Task ShowError(string message) => _dialogService.ShowMessageBox("Error", message, yesText: "Ok"); - public void ShowInfo(string message) + public Task ShowInfo(string message) => _dialogService.ShowMessageBox("Information", message, yesText: "Ok"); - public bool ShowQuestion(string message) + public Task ShowQuestion(string message) => _dialogService.DialogYesNoShow("Question", message); - public bool ShowQuestionSaveItem(string message) + public Task ShowQuestionSaveItem(string message) => _dialogService.DialogYesNoShow("Question", message); - public void ShowWarning(string message) + public Task ShowWarning(string message) => _dialogService.ShowMessageBox("Warning", message, yesText: "Ok"); } } diff --git a/WatchList.MudBlazors/Model/WatchItemModel.cs b/WatchList.MudBlazors/Model/WatchItemModel.cs index 83c7d0c2..8607e099 100644 --- a/WatchList.MudBlazors/Model/WatchItemModel.cs +++ b/WatchList.MudBlazors/Model/WatchItemModel.cs @@ -7,14 +7,15 @@ namespace WatchList.MudBlazors.Model public class WatchItemModel { private const int FirstValue = 1; + private const int Zero = 0; - private Guid _id = new Guid(); + private Guid _id = Guid.NewGuid(); private string _title = string.Empty; private TypeCinema _type = TypeCinema.Movie; private int _sequel = FirstValue; private StatusCinema _status = StatusCinema.Planned; private DateTime? _date = null; - private int? _grade = FirstValue; + private int? _grade = null; public WatchItemModel() { diff --git a/WatchList.MudBlazors/Pages/WatchCinemaTable.razor b/WatchList.MudBlazors/Pages/WatchCinemaTable.razor index c2c2b85d..50b3fb6a 100644 --- a/WatchList.MudBlazors/Pages/WatchCinemaTable.razor +++ b/WatchList.MudBlazors/Pages/WatchCinemaTable.razor @@ -25,21 +25,21 @@ - Title - Season/Part - Status - Data - Grade - Type + Title + Season/Part + Status + Data + Grade + Type - @context.Title - @context.Sequel - @context.Status - @context.Date - @context.Grade - @context.Type + @context.Title + @context.Sequel + @context.Status + @context.Date?.ToString("d") + @context.Grade + @context.Type diff --git a/WatchList.MudBlazors/Program.cs b/WatchList.MudBlazors/Program.cs index c437d5af..8545d8ed 100644 --- a/WatchList.MudBlazors/Program.cs +++ b/WatchList.MudBlazors/Program.cs @@ -12,8 +12,6 @@ StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration); -var path = "logs"; - // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); @@ -21,14 +19,17 @@ builder.Services.AddSingleton(new DbContextFactoryMigrator("app.db")); builder.Services.AddScoped(e => e.GetRequiredService().Create()); -builder.Services.AddSingleton(e => new AggregateLogging() +builder.Services.AddScoped(e => new AggregateLogging() { new ConsoleLogger(LogLevel.Trace), - new FileLogger(LogLevel.Trace, path), + //new FileLogger(LogLevel.Trace, path), }); +builder.Logging.AddConsole(); +builder.Services.AddLogging(); builder.Services.AddScoped(e => new WatchItemRepository(e.GetRequiredService(), e.GetRequiredService())); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Logging.AddConsole(); var app = builder.Build(); diff --git a/WatchList.MudBlazors/WatchList.MudBlazors.csproj b/WatchList.MudBlazors/WatchList.MudBlazors.csproj index 7a835c2c..f21e07e0 100644 --- a/WatchList.MudBlazors/WatchList.MudBlazors.csproj +++ b/WatchList.MudBlazors/WatchList.MudBlazors.csproj @@ -9,6 +9,8 @@ + + diff --git a/WatchList.MudBlazors/app.db b/WatchList.MudBlazors/app.db index 321be474..eb903f6d 100644 Binary files a/WatchList.MudBlazors/app.db and b/WatchList.MudBlazors/app.db differ diff --git a/WatchList.MudBlazors/app.db-shm b/WatchList.MudBlazors/app.db-shm index fe9ac284..10892245 100644 Binary files a/WatchList.MudBlazors/app.db-shm and b/WatchList.MudBlazors/app.db-shm differ diff --git a/WatchList.MudBlazors/app.db-wal b/WatchList.MudBlazors/app.db-wal index e69de29b..cebc55bb 100644 Binary files a/WatchList.MudBlazors/app.db-wal and b/WatchList.MudBlazors/app.db-wal differ diff --git a/WatchList.MudBlazors/appsettings.json b/WatchList.MudBlazors/appsettings.json index d9d9a9bf..279f77c2 100644 --- a/WatchList.MudBlazors/appsettings.json +++ b/WatchList.MudBlazors/appsettings.json @@ -1,9 +1,50 @@ { "Logging": { - "LogLevel": { - "Default": "Information", + "LogLevel": { // No provider, LogLevel applies to all the enabled providers. + "Default": "Error", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Warning" + }, + "Debug": { // Debug provider. + "LogLevel": { + "Default": "Information" // Overrides preceding LogLevel:Default setting. + } + }, + "Console": { + "IncludeScopes": true, + "LogLevel": { + "Microsoft.AspNetCore.Mvc.Razor.Internal": "Warning", + "Microsoft.AspNetCore.Mvc.Razor.Razor": "Debug", + "Microsoft.AspNetCore.Mvc.Razor": "Error", + "Default": "Information" + } + }, + "EventSource": { + "LogLevel": { + "Microsoft": "Information" + } + }, + "EventLog": { + "LogLevel": { + "Microsoft": "Information" + } + }, + "AzureAppServicesFile": { + "IncludeScopes": true, + "LogLevel": { + "Default": "Warning" + } + }, + "AzureAppServicesBlob": { + "IncludeScopes": true, + "LogLevel": { + "Microsoft": "Information" + } + }, + "ApplicationInsights": { + "LogLevel": { + "Default": "Information" + } } }, "AllowedHosts": "*" diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/AddDuplicateItemTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/AddDuplicateItemTest.cs index 4658eca1..3bbe1cf6 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/AddDuplicateItemTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/AddDuplicateItemTest.cs @@ -54,17 +54,17 @@ public class AddDuplicateItemTest [Theory] [MemberData(nameof(ListOfElementsWithDuplicateElement))] - public void Add_With_Replace_Duplicate_Element(List items, WatchItem addItem, List expectItems) + public async Task Add_With_Replace_Duplicate_ElementAsync(List items, WatchItem addItem, List expectItems) { // Arrange var dbContext = new TestAppDbContextFactory().Create(); var itemRepository = new WatchItemRepository(dbContext, new TestLogger()); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).Returns(true); + messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).ReturnsAsync(true); var service = new WatchItemService(itemRepository, messageBox.Object); dbContext.AddRange(items); dbContext.SaveChanges(); - service.Add(addItem); + await service.AddAsync(addItem); // Act var actualItems = dbContext.WatchItem.ToList(); diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByDeleteGradeRuleTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByDeleteGradeRuleTest.cs index 9ad819d6..6e007e10 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByDeleteGradeRuleTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByDeleteGradeRuleTest.cs @@ -108,7 +108,7 @@ public class DownloadDataByDeleteGradeRuleTest [Theory] [MemberData(nameof(ListsWithTwoSameElementsWithReplaceItem))] [MemberData(nameof(ListsWithTwoSameElementsWithNotReplaceItem))] - public void Add_Data_File_And_Replace_Duplicate_Element(List items, List addDownloadItem, DialogReplaceItemQuestion dialogReplaceItem, List expectItems) + public async Task Add_Data_File_And_Replace_Duplicate_Element(List items, List addDownloadItem, DialogReplaceItemQuestion dialogReplaceItem, List expectItems) { // Arrange var logger = new TestLogger(); @@ -118,7 +118,7 @@ public void Add_Data_File_And_Replace_Duplicate_Element(List items, L var watchItemRepository = new WatchItemRepository(dbContext, logger); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(dialogReplaceItem); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(dialogReplaceItem); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); var loadRuleConfig = new TestLoadRuleConfig() @@ -159,7 +159,7 @@ public async Task Add_Data_File_And_Replace_Duplicate_ElementAsync(List(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(dialogReplaceItem); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(dialogReplaceItem); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); var loadRuleConfig = new TestLoadRuleConfig() @@ -189,7 +189,7 @@ public async Task Add_Data_File_And_Replace_Duplicate_ElementAsync(List items, List addDownloadItem, Dictionary dictionaryAddItem, List expectItems) + public async Task Add_Data_File_And_One_Replace_And_Not_Replace_Duplicate_Element(List items, List addDownloadItem, Dictionary dictionaryAddItem, List expectItems) { // Arrange var logger = new TestLogger(); @@ -201,7 +201,7 @@ public void Add_Data_File_And_One_Replace_And_Not_Replace_Duplicate_Element(List var messageBox = new Mock(); foreach (var item in dictionaryAddItem) { - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(item.Key)).Returns(item.Value); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(item.Key)).ReturnsAsync(item.Value); } var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); @@ -244,7 +244,7 @@ public async Task Add_Data_File_And_One_Replace_And_Not_Replace_Duplicate_Elemen var messageBox = new Mock(); foreach (var item in dictionaryAddItem) { - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(item.Key)).Returns(item.Value); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(item.Key)).ReturnsAsync(item.Value); } var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleMoreGradeTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleMoreGradeTest.cs index a3729c40..c11a2b03 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleMoreGradeTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleMoreGradeTest.cs @@ -125,7 +125,7 @@ public class DownloadDataByRuleMoreGradeTest [MemberData(nameof(ListsAddOneItemByMoreGrade))] [MemberData(nameof(ListsNotAddItemByMoreGrade))] [MemberData(nameof(ListAddItemsByNotMoreGrade))] - public void Load_Data_File_By_Rule_Type_Cinema(List items, List addDownloadItem, Grade moreGrade, List expectItems) + public async Task Load_Data_File_By_Rule_Type_Cinema(List items, List addDownloadItem, Grade moreGrade, List expectItems) { // Arrange var logger = new TestLogger(); @@ -135,7 +135,7 @@ public void Load_Data_File_By_Rule_Type_Cinema(List items, List(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(DialogReplaceItemQuestion.AllYes); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(DialogReplaceItemQuestion.AllYes); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); var loadRuleConfig = new TestLoadRuleConfig() { MoreGrade = moreGrade }; @@ -169,7 +169,7 @@ public async Task Load_Data_File_By_Rule_Type_CinemaAsync(List items, var watchItemRepository = new WatchItemRepository(dbContext, logger); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(DialogReplaceItemQuestion.AllYes); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(DialogReplaceItemQuestion.AllYes); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); var loadRuleConfig = new TestLoadRuleConfig() { MoreGrade = moreGrade }; diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleTypeCinemaTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleTypeCinemaTest.cs index abd12f29..b4328617 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleTypeCinemaTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadDataByRuleTypeCinemaTest.cs @@ -123,7 +123,7 @@ public class DownloadDataByRuleTypeCinemaTest [MemberData(nameof(ListsAddOneItemByTypeCinema))] [MemberData(nameof(ListsAddItemsByAllTypeCinema))] [MemberData(nameof(ListsNotAddItemsByTypeCinema))] - public void Load_Data_File_By_Rule_Type_Cinema(List items, List addDownloadItem, TypeCinema typeCinema, List expectItems) + public async Task Load_Data_File_By_Rule_Type_Cinema(List items, List addDownloadItem, TypeCinema typeCinema, List expectItems) { // Arrange var logger = new TestLogger(); @@ -133,7 +133,7 @@ public void Load_Data_File_By_Rule_Type_Cinema(List items, List(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(DialogReplaceItemQuestion.AllYes); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(DialogReplaceItemQuestion.AllYes); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); var loadRuleConfig = new TestLoadRuleConfig() { TypeCinemaLoad = typeCinema }; @@ -167,7 +167,7 @@ public async Task Load_Data_File_By_Rule_Type_CinemaAsync(List items, var watchItemRepository = new WatchItemRepository(dbContext, logger); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(DialogReplaceItemQuestion.AllYes); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(DialogReplaceItemQuestion.AllYes); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger); var loadRuleConfig = new TestLoadRuleConfig() { TypeCinemaLoad = typeCinema }; diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadPagedListTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadPagedListTest.cs index 6d357b2a..74d69cfa 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadPagedListTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/DataLoadingTest/DownloadPagedListTest.cs @@ -46,7 +46,7 @@ public class DownloadPagedListTest [Theory] [MemberData(nameof(ListItemsInFileAfterLoading))] - public void Add_Data_File(List items, List addDownloadItem, List expectItems) + public async Task Add_Data_File(List items, List addDownloadItem, List expectItems) { // Arrange var logger = new TestLogger(); @@ -56,7 +56,7 @@ public void Add_Data_File(List items, List addDownloadItem var watchItemRepository = new WatchItemRepository(dbContext, logger); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(DialogReplaceItemQuestion.AllYes); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(DialogReplaceItemQuestion.AllYes); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger) { NumberOfItemPerPage = PageSize }; var loadRuleConfig = new TestLoadRuleConfig(); @@ -88,7 +88,7 @@ public async Task Add_Data_FileAsync(List items, List addD var watchItemRepository = new WatchItemRepository(dbContext, logger); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).Returns(DialogReplaceItemQuestion.AllYes); + messageBox.Setup(foo => foo.ShowDataReplaceQuestion(It.IsAny())).ReturnsAsync(DialogReplaceItemQuestion.AllYes); var service = new DownloadDataService(watchItemRepository, messageBox.Object, logger) { NumberOfItemPerPage = PageSize }; var loadRuleConfig = new TestLoadRuleConfig(); diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/NonDuplicateElementsTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/NonDuplicateElementsTest.cs index a86f04fc..4df1b6b6 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/NonDuplicateElementsTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/NonDuplicateElementsTest.cs @@ -63,19 +63,19 @@ public class NonDuplicateElementsTest [Theory] [MemberData(nameof(ListWithNewItemAdded))] - public void Add_New_Item_In_Database(List items, WatchItem addItem, List expectItems) + public async Task Add_New_Item_In_Database(List items, WatchItem addItem, List expectItems) { // Arrange var dbContext = new TestAppDbContextFactory().Create(); var itemRepository = new WatchItemRepository(dbContext, new TestLogger()); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).Returns(true); + messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).ReturnsAsync(true); var service = new WatchItemService(itemRepository, messageBox.Object); dbContext.AddRange(items); dbContext.SaveChanges(); // Act - service.Add(addItem); + service.AddAsync(addItem); var actualItems = dbContext.WatchItem.ToList(); // Assert @@ -84,19 +84,19 @@ public void Add_New_Item_In_Database(List items, WatchItem addItem, L [Theory] [MemberData(nameof(ListWithUpdatedItem))] - public void Update_Item_In_Database(List items, WatchItem oldItem, WatchItem updateItem, List expectItems) + public async Task Update_Item_In_DatabaseAsync(List items, WatchItem oldItem, WatchItem updateItem, List expectItems) { // Arrange var dbContext = new TestAppDbContextFactory().Create(); var itemRepository = new WatchItemRepository(dbContext, new TestLogger()); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).Returns(true); + messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).ReturnsAsync(true); var service = new WatchItemService(itemRepository, messageBox.Object); dbContext.AddRange(items); dbContext.SaveChanges(); // Act - service.Updata(oldItem, updateItem); + await service.UpdateAsync(oldItem, updateItem); var actualItems = dbContext.WatchItem.ToList(); // Assert diff --git a/WatchList.Test/CoreTest/WatchItemServiceTest/UpdateDuplicateItemTest.cs b/WatchList.Test/CoreTest/WatchItemServiceTest/UpdateDuplicateItemTest.cs index 35ffe8bb..4c79f011 100644 --- a/WatchList.Test/CoreTest/WatchItemServiceTest/UpdateDuplicateItemTest.cs +++ b/WatchList.Test/CoreTest/WatchItemServiceTest/UpdateDuplicateItemTest.cs @@ -54,19 +54,19 @@ public class UpdateDuplicateItemTest [Theory] [MemberData(nameof(ListOfElementsWithReplaceDuplicateElement))] - public void Update_With_Replace_Duplicate_Element(List items, WatchItem editItem, WatchItem updateItem, List expectItems) + public async Task Update_With_Replace_Duplicate_ElementAsync(List items, WatchItem editItem, WatchItem updateItem, List expectItems) { // Arrange var dbContext = new TestAppDbContextFactory().Create(); var itemRepository = new WatchItemRepository(dbContext, new TestLogger()); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).Returns(true); + messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).ReturnsAsync(true); var service = new WatchItemService(itemRepository, messageBox.Object); dbContext.AddRange(items); dbContext.SaveChanges(); // Act - service.Updata(editItem, updateItem); + await service.UpdateAsync(editItem, updateItem); var actualItems = dbContext.WatchItem.ToList(); // Assert @@ -75,19 +75,19 @@ public void Update_With_Replace_Duplicate_Element(List items, WatchIt [Theory] [MemberData(nameof(ListOfElementsWithNotReplaceDuplicateElement))] - public void Update_With_Not_Replace_Duplicate_Element(List items, WatchItem editItem, WatchItem updateItem) + public async Task Update_With_Not_Replace_Duplicate_ElementAsync(List items, WatchItem editItem, WatchItem updateItem) { // Arrange var dbContext = new TestAppDbContextFactory().Create(); var itemRepository = new WatchItemRepository(dbContext, new TestLogger()); var messageBox = new Mock(); - messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).Returns(false); + messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).ReturnsAsync(false); var service = new WatchItemService(itemRepository, messageBox.Object); dbContext.AddRange(items); dbContext.SaveChanges(); // Act - service.Updata(editItem, updateItem); + await service.UpdateAsync(editItem, updateItem); var actualItems = dbContext.WatchItem.ToList(); // Assert diff --git a/WatchList.WinForms/BoxCinemaForm.Designer.cs b/WatchList.WinForms/BoxCinemaForm.Designer.cs index d5123b88..c40e4b22 100644 --- a/WatchList.WinForms/BoxCinemaForm.Designer.cs +++ b/WatchList.WinForms/BoxCinemaForm.Designer.cs @@ -186,7 +186,7 @@ private void InitializeComponent() btnAddCinema.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained; btnAddCinema.UseAccentColor = false; btnAddCinema.UseVisualStyleBackColor = true; - btnAddCinema.Click += BtnAddCinema_Click; + btnAddCinema.Click += BtnAddCinema_ClickAsync; // // btnEditCinema // @@ -208,7 +208,7 @@ private void InitializeComponent() btnEditCinema.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained; btnEditCinema.UseAccentColor = false; btnEditCinema.UseVisualStyleBackColor = true; - btnEditCinema.Click += BtnEditRow_Click; + btnEditCinema.Click += BtnEditRow_ClickAsync; // // btnDeleteMovie // @@ -230,7 +230,7 @@ private void InitializeComponent() btnDeleteMovie.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained; btnDeleteMovie.UseAccentColor = false; btnDeleteMovie.UseVisualStyleBackColor = true; - btnDeleteMovie.Click += BtnDeleteMovie_Click; + btnDeleteMovie.Click += BtnDeleteMovie_ClickAsync; // // btnAddData // diff --git a/WatchList.WinForms/BoxCinemaForm.cs b/WatchList.WinForms/BoxCinemaForm.cs index 80a13f6a..1795a0cb 100644 --- a/WatchList.WinForms/BoxCinemaForm.cs +++ b/WatchList.WinForms/BoxCinemaForm.cs @@ -88,7 +88,7 @@ private void BtnCancelFilter_Click(object sender, EventArgs e) cmbFilterStatus.Refresh(); } - private void BtnAddCinema_Click(object sender, EventArgs e) + private async void BtnAddCinema_ClickAsync(object sender, EventArgs e) { var addForm = new AddCinemaForm(_messageBox); @@ -99,12 +99,12 @@ private void BtnAddCinema_Click(object sender, EventArgs e) _logger.LogInformation("Click save add item"); var itemCinema = addForm.GetCinema(); - _itemService.Add(itemCinema.ToWatchItem()); + await _itemService.AddAsync(itemCinema.ToWatchItem()); UpdateGridData(); } - private void BtnEditRow_Click(object sender, EventArgs e) + private async void BtnEditRow_ClickAsync(object sender, EventArgs e) { var indexEditRow = GetSelectedRowIndexes(); if (indexEditRow.Count == 1) @@ -119,16 +119,16 @@ private void BtnEditRow_Click(object sender, EventArgs e) _logger.LogInformation("Click save edit item"); var updateItem = updateForm.GetEditItemCinema(); - _itemService.Updata(oldItem.ToWatchItem(), updateItem.ToWatchItem()); + await _itemService.UpdateAsync(oldItem.ToWatchItem(), updateItem.ToWatchItem()); UpdateGridData(); } else { - _messageBox.ShowWarning("Select one item."); + await _messageBox.ShowWarning("Select one item."); } } - private void BtnDeleteMovie_Click(object sender, EventArgs e) + private async void BtnDeleteMovie_ClickAsync(object sender, EventArgs e) { var selectedRowIds = GetSelectedRowIndexes() .Select(idx => dgvCinema.Rows[idx].Get(IndexColumnId)) @@ -136,11 +136,11 @@ private void BtnDeleteMovie_Click(object sender, EventArgs e) if (selectedRowIds.Count == 0) { - _messageBox.ShowWarning(HighlightTheDesiredLine); + await _messageBox.ShowWarning(HighlightTheDesiredLine); return; } - if (!_messageBox.ShowQuestion("Delete selected items?")) + if (!await _messageBox.ShowQuestion("Delete selected items?")) { return; } @@ -152,7 +152,7 @@ private void BtnDeleteMovie_Click(object sender, EventArgs e) _itemService.Remove(id); } - LoadData(); + await LoadDataAsync(); } private void BtnDownloadDataFile_Click(object sender, EventArgs e) @@ -189,43 +189,43 @@ private void BtnDownloadDataFile_Click(object sender, EventArgs e) private void BoxCinemaForm_FormClosing(object sender, FormClosingEventArgs e) => _logger.LogTrace("Close App."); - private void BtnBackPage_Click(object sender, EventArgs e) + private async void BtnBackPage_Click(object sender, EventArgs e) { if (_pagedList.HasPreviousPage) { Page.Number--; - LoadData(); + await LoadDataAsync(); } } - private void BtnStartPage_Click(object sender, EventArgs e) + private async void BtnStartPage_Click(object sender, EventArgs e) { if (_pagedList.HasPreviousPage) { Page.Number = 1; - LoadData(); + await LoadDataAsync(); } } - private void BtnNextPage_Click(object sender, EventArgs e) + private async void BtnNextPage_Click(object sender, EventArgs e) { if (_pagedList.HasNextPage) { Page.Number++; - LoadData(); + await LoadDataAsync(); } } - private void BtnEndPage_Click(object sender, EventArgs e) + private async void BtnEndPage_Click(object sender, EventArgs e) { if (_pagedList.HasNextPage) { Page.Number = _pagedList.PageCount; - LoadData(); + await LoadDataAsync(); } } - private void CmbPageSize_Changed(object sender, EventArgs e) + private async void CmbPageSize_Changed(object sender, EventArgs e) { var pageSizeCmb = SelectedPageSize(); @@ -233,17 +233,17 @@ private void CmbPageSize_Changed(object sender, EventArgs e) { Page.Size = pageSizeCmb; Page.Number = 1; - LoadData(); + await LoadDataAsync(); } } - private void CmbSort_ChangedItem(object sender, EventArgs e) + private async void CmbSort_ChangedItem(object sender, EventArgs e) { Sort.Type = Sort.Items[cmbSortType.SelectedIndex]; - LoadData(); + await LoadDataAsync(); } - private void TextBoxPage_TextChanged(object sender, EventArgs e) + private async void TextBoxPage_TextChanged(object sender, EventArgs e) { if (!int.TryParse(textBoxPage.Text, out var pageNumber) || pageNumber > _pagedList.PageCount @@ -254,7 +254,7 @@ private void TextBoxPage_TextChanged(object sender, EventArgs e) } Page.Number = pageNumber; - LoadData(); + await LoadDataAsync(); } /// @@ -289,7 +289,7 @@ private void FillGrid(List items) /// /// Filling in tabular data from a file. /// - private void LoadData() + private async Task LoadDataAsync() { try { @@ -299,7 +299,7 @@ private void LoadData() if (IsNotFirstPageEmpty()) { Page.Number -= 1; - LoadData(); + await LoadDataAsync(); } var item = _pagedList.Items; @@ -313,7 +313,7 @@ private void LoadData() } catch (Exception error) { - _messageBox.ShowError(error.Message); + await _messageBox.ShowError(error.Message); } } @@ -325,10 +325,10 @@ private void LoadData() /// /// Create a new SearchRequest in the database for the selected ComboBox("Filter", "Sort", "PageNumber") and updates the tabular data on it. /// - private void UpdateGridData() + private async Task UpdateGridData() { _searchRequest = new WatchItemSearchRequest(Filter.GetFilter(), Sort.GetSortItem(), Page.GetPage()); - LoadData(); + await LoadDataAsync(); } /// diff --git a/WatchList.WinForms/ChildForms/AddCinemaForm.cs b/WatchList.WinForms/ChildForms/AddCinemaForm.cs index f1483634..18bd5fd9 100644 --- a/WatchList.WinForms/ChildForms/AddCinemaForm.cs +++ b/WatchList.WinForms/ChildForms/AddCinemaForm.cs @@ -36,11 +36,11 @@ public CinemaModel GetCinema() return CinemaModel.CreateNonPlanned(txtAddCinema.Text, numericSequel.Value, dateViewed, grade, _status, SelectedTypeCinema); } - private void BtnAddCinema_Click(object sender, EventArgs e) + private async void BtnAddCinema_Click(object sender, EventArgs e) { if (!ValidateFields(out var errorMessage)) { - _messageBox.ShowWarning(errorMessage); + await _messageBox.ShowWarning(errorMessage); DialogResult = DialogResult.TryAgain; } else diff --git a/WatchList.WinForms/ChildForms/EditorItemCinemaForm.cs b/WatchList.WinForms/ChildForms/EditorItemCinemaForm.cs index adb3c8c1..d5bd4a0f 100644 --- a/WatchList.WinForms/ChildForms/EditorItemCinemaForm.cs +++ b/WatchList.WinForms/ChildForms/EditorItemCinemaForm.cs @@ -39,22 +39,22 @@ public CinemaModel GetEditItemCinema() return CinemaModel.CreateNonPlanned(txtEditName.Text, numericEditSequel.Value, date, grade, status, type, id); } - private void BtnSaveEdit_Click(object sender, EventArgs e) + private async void BtnSaveEdit_Click(object sender, EventArgs e) { if (!ValidateFields(out string errorMessage)) { - _messageBox.ShowWarning(errorMessage); + await _messageBox.ShowWarning(errorMessage); DialogResult = DialogResult.TryAgain; } else { - if (HasChanges() && _messageBox.ShowQuestion("Save edit item Cinema?")) + if (HasChanges() && await _messageBox.ShowQuestion("Save edit item Cinema?")) { DialogResult = DialogResult.OK; } else { - _messageBox.ShowInfo("No changed item cinema."); + await _messageBox.ShowInfo("No changed item cinema."); Close(); } } diff --git a/WatchList.WinForms/ChildForms/MergeDatabaseForm.cs b/WatchList.WinForms/ChildForms/MergeDatabaseForm.cs index 01c88e5b..09bb4a24 100644 --- a/WatchList.WinForms/ChildForms/MergeDatabaseForm.cs +++ b/WatchList.WinForms/ChildForms/MergeDatabaseForm.cs @@ -52,9 +52,9 @@ private void SetupDefaultValues() cmbGrade.SelectedItem = Grade.AnyGrade; } - private void BtnOk_Click(object sender, EventArgs e) + private async void BtnOk_Click(object sender, EventArgs e) { - if (_messageBox.ShowQuestion("Add data from a file using the following algorithm?")) + if (await _messageBox.ShowQuestion("Add data from a file using the following algorithm?")) { DialogResult = DialogResult.OK; } diff --git a/WatchList.WinForms/Message/MessageBoxShow.cs b/WatchList.WinForms/Message/MessageBoxShow.cs index 00cf948b..06b28cbd 100644 --- a/WatchList.WinForms/Message/MessageBoxShow.cs +++ b/WatchList.WinForms/Message/MessageBoxShow.cs @@ -6,23 +6,37 @@ namespace WatchList.WinForms.Message { public class MessageBoxShow : IMessageBox { - public void ShowInfo(string message) => MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + public Task ShowInfo(string message) + { + MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + return Task.CompletedTask; + } - public void ShowWarning(string message) => MessageBox.Show(message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + public Task ShowWarning(string message) + { + MessageBox.Show(message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return Task.CompletedTask; + } - public void ShowError(string message) => MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + public Task ShowError(string message) + { + MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return Task.CompletedTask; + } - public bool ShowQuestion(string message) => MessageBox.Show(message, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; + public Task ShowQuestion(string message) + => Task.FromResult(MessageBox.Show(message, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes); - public bool ShowQuestionSaveItem(string message) => MessageBox.Show(message, "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK; + public Task ShowQuestionSaveItem(string message) => Task.FromResult(MessageBox.Show(message, "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK); - public DialogReplaceItemQuestion ShowDataReplaceQuestion(string titleItem) + public Task ShowDataReplaceQuestion(string titleItem) { using (var form = new DataReplaceMessageForm(titleItem)) { - return form.ShowDialog() == DialogResult.OK ? - DialogReplaceItemQuestion.FromValue((int)form.ResultQuestion) : - DialogReplaceItemQuestion.Unknown; + var res = form.ShowDialog() == DialogResult.OK ? + DialogReplaceItemQuestion.FromValue((int)form.ResultQuestion) : + DialogReplaceItemQuestion.Unknown; + return Task.FromResult(res); } } }