From 597466fcc6e9930bbdba6b74720d52b875e70ed2 Mon Sep 17 00:00:00 2001 From: qnill Date: Tue, 3 Oct 2017 16:42:19 +0300 Subject: [PATCH] Core-41: AutoCode added. --- RS.Core.Api/RS.Core.Api.csproj | 10 +- RS.Core.Api/Web.config | 128 ++++++++++-------- RS.Core.Api/packages.config | 6 +- RS.Core.Const/RS.Core.Const.csproj | 3 +- RS.Core.Const/ScreenCodes.cs | 6 +- RS.Core.Data/App.config | 16 +-- ...s => 201710031003481_AutoCode.Designer.cs} | 2 +- ...utoCode.cs => 201710031003481_AutoCode.cs} | 4 +- ...ode.resx => 201710031003481_AutoCode.resx} | 2 +- RS.Core.Data/RS.Core.Data.csproj | 13 +- RS.Core.Domain/App.config | 10 +- RS.Core.Domain/Model/AutoCode/AutoCode.cs | 4 +- RS.Core.Domain/RS.Core.Domain.csproj | 3 +- RS.Core.Lib/RS.Core.Lib.csproj | 3 +- .../Base/DTOs/AutoCode/AutoCodeDto.cs | 14 +- .../Base/Services/AutoCode/AutoCodeService.cs | 23 +++- RS.Core.Service/RS.Core.Service.csproj | 3 +- RS.Core.Service/app.config | 46 +++---- RS.Core.Testing/App.config | 46 +++---- .../Arrange/AutoCode/AutoCodeDtos.cs | 41 ++++++ RS.Core.Testing/RS.Core.Testing.csproj | 4 +- RS.Core.Tests/App.config | 70 +++++----- RS.Core.Tests/RS.Core.Tests.csproj | 4 +- .../UnitTests/AutoCode/AutoCodeServiceTest.cs | 87 ++++++++++++ .../UnitTests/User/UserServiceTest.cs | 2 + 25 files changed, 357 insertions(+), 193 deletions(-) rename RS.Core.Data/Migrations/{201710021705465_AutoCode.Designer.cs => 201710031003481_AutoCode.Designer.cs} (93%) rename RS.Core.Data/Migrations/{201710021705465_AutoCode.cs => 201710031003481_AutoCode.cs} (99%) rename RS.Core.Data/Migrations/{201710021705465_AutoCode.resx => 201710031003481_AutoCode.resx} (70%) create mode 100644 RS.Core.Testing/Arrange/AutoCode/AutoCodeDtos.cs create mode 100644 RS.Core.Tests/UnitTests/AutoCode/AutoCodeServiceTest.cs diff --git a/RS.Core.Api/RS.Core.Api.csproj b/RS.Core.Api/RS.Core.Api.csproj index 26fa799..599ffc3 100644 --- a/RS.Core.Api/RS.Core.Api.csproj +++ b/RS.Core.Api/RS.Core.Api.csproj @@ -15,7 +15,7 @@ Properties RS.Core RS.Core - v4.5.2 + v4.7 false true @@ -26,6 +26,7 @@ + true @@ -130,6 +131,7 @@ + ..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net45\System.Diagnostics.DiagnosticSource.dll @@ -137,12 +139,11 @@ ..\packages\Microsoft.AspNet.Cors.5.2.3\lib\net45\System.Web.Cors.dll + - - - + @@ -193,6 +194,7 @@ True ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + ..\packages\WebGrease.1.6.0\lib\WebGrease.dll diff --git a/RS.Core.Api/Web.config b/RS.Core.Api/Web.config index 8a327f3..01d63c2 100644 --- a/RS.Core.Api/Web.config +++ b/RS.Core.Api/Web.config @@ -1,4 +1,4 @@ - + -
+
- + - + + - - - + + + - + - - - - - + + + + + - - - - + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + \ No newline at end of file diff --git a/RS.Core.Api/packages.config b/RS.Core.Api/packages.config index 1d3d2f8..bea5c14 100644 --- a/RS.Core.Api/packages.config +++ b/RS.Core.Api/packages.config @@ -9,7 +9,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -53,6 +53,6 @@ - + \ No newline at end of file diff --git a/RS.Core.Const/RS.Core.Const.csproj b/RS.Core.Const/RS.Core.Const.csproj index c415be1..1dd7a00 100644 --- a/RS.Core.Const/RS.Core.Const.csproj +++ b/RS.Core.Const/RS.Core.Const.csproj @@ -9,8 +9,9 @@ Properties RS.Core.Const RS.Core.Const - v4.5.2 + v4.7 512 + true diff --git a/RS.Core.Const/ScreenCodes.cs b/RS.Core.Const/ScreenCodes.cs index f83639c..e63493f 100644 --- a/RS.Core.Const/ScreenCodes.cs +++ b/RS.Core.Const/ScreenCodes.cs @@ -1,14 +1,14 @@ namespace RS.Core.Const { /// - /// ılk3 modul kod sonrakı 2 ekran kodu - /// -- Açıklama -- + /// The screen codes are designed as 5 characters. + /// The first 3-character module code generates the other 2-character display number. /// public static class ScreenCodes { /// /// Screen: Test Screen /// - public static string TSC001 = "TSC001"; + public static string TSC01 = "TSC01"; } } \ No newline at end of file diff --git a/RS.Core.Data/App.config b/RS.Core.Data/App.config index 758da99..04d3f12 100644 --- a/RS.Core.Data/App.config +++ b/RS.Core.Data/App.config @@ -1,22 +1,22 @@ - + -
+
- + - + - - - + + + - \ No newline at end of file + diff --git a/RS.Core.Data/Migrations/201710021705465_AutoCode.Designer.cs b/RS.Core.Data/Migrations/201710031003481_AutoCode.Designer.cs similarity index 93% rename from RS.Core.Data/Migrations/201710021705465_AutoCode.Designer.cs rename to RS.Core.Data/Migrations/201710031003481_AutoCode.Designer.cs index 5ad5624..9e4548b 100644 --- a/RS.Core.Data/Migrations/201710021705465_AutoCode.Designer.cs +++ b/RS.Core.Data/Migrations/201710031003481_AutoCode.Designer.cs @@ -13,7 +13,7 @@ public sealed partial class AutoCode : IMigrationMetadata string IMigrationMetadata.Id { - get { return "201710021705465_AutoCode"; } + get { return "201710031003481_AutoCode"; } } string IMigrationMetadata.Source diff --git a/RS.Core.Data/Migrations/201710021705465_AutoCode.cs b/RS.Core.Data/Migrations/201710031003481_AutoCode.cs similarity index 99% rename from RS.Core.Data/Migrations/201710021705465_AutoCode.cs rename to RS.Core.Data/Migrations/201710031003481_AutoCode.cs index 23f2029..c2d7cb2 100644 --- a/RS.Core.Data/Migrations/201710021705465_AutoCode.cs +++ b/RS.Core.Data/Migrations/201710031003481_AutoCode.cs @@ -12,8 +12,8 @@ public override void Up() c => new { ID = c.Guid(nullable: false), - ScreenCode = c.String(nullable: false, maxLength: 20), - CodeFormat = c.String(nullable: false, maxLength: 50), + ScreenCode = c.String(nullable: false, maxLength: 5), + CodeFormat = c.String(nullable: false, maxLength: 20), LastCodeNumber = c.Int(nullable: false), CreateDT = c.DateTime(nullable: false), UpdateDT = c.DateTime(), diff --git a/RS.Core.Data/Migrations/201710021705465_AutoCode.resx b/RS.Core.Data/Migrations/201710031003481_AutoCode.resx similarity index 70% rename from RS.Core.Data/Migrations/201710021705465_AutoCode.resx rename to RS.Core.Data/Migrations/201710031003481_AutoCode.resx index 58db77d..e9154d8 100644 --- a/RS.Core.Data/Migrations/201710021705465_AutoCode.resx +++ b/RS.Core.Data/Migrations/201710031003481_AutoCode.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - H4sIAAAAAAAEAO1b227cNhB9L9B/EPRYOCvbQYDW2E1gr+3AqC+B1wn6ZnCl2TVRilIkyvCi6Jf1oZ/UXyipK0VKWmq1a+eGAEbMy+FwOHM4mqH/++ff8bsnn1iPEMU4oBP7YLRvW0DdwMN0ObETtnj1q/3u7c8/jc88/8n6VIx7LcbxmTSe2A+MhUeOE7sP4KN45GM3CuJgwUZu4DvIC5zD/f3fnIMDBziEzbEsa3ybUIZ9SH/hv04D6kLIEkSuAg9InLfznlmKal0jH+IQuTCxb2ejaRDB6BQxZFvHBCMuwwzIwrYQpQFDjEt49DGGGYsCupyFvAGRu1UIfNwCkRhyyY+q4aab2D8Um3CqiQWUm8Qs8HsCHrzOteKo0zfSrV1qjevtjOuXrcSuU91N7OOEBVOuXNtSFzuakkgMlFTLuzEdFVP2rHrHXmkH3FzEvz1rmhCWRDChkLAIkT3rQzIn2P0dVnfBn0AnNCFElo9LyPtqDbzpQxSEELHVLSxyqS9Obcupz3PUieU0aU62n/cJ9mzrmq+N5gTK03c6p8/cCIBmqspguCFxb7CtK/R0CXTJHib2ITf/c/wEXtGQQ3+kmPsOn8OiBHovLRY9DyIfsY6l3+xk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/RS.Core.Data/RS.Core.Data.csproj b/RS.Core.Data/RS.Core.Data.csproj index 20fefdd..0f077df 100644 --- a/RS.Core.Data/RS.Core.Data.csproj +++ b/RS.Core.Data/RS.Core.Data.csproj @@ -9,8 +9,9 @@ Properties RS.Core.Data RS.Core.Data - v4.5.2 + v4.7 512 + true @@ -53,9 +54,9 @@ 201709060659058_Core-v.1.0.cs - - - 201710021705465_AutoCode.cs + + + 201710031003481_AutoCode.cs @@ -75,8 +76,8 @@ 201709060659058_Core-v.1.0.cs - - 201710021705465_AutoCode.cs + + 201710031003481_AutoCode.cs diff --git a/RS.Core.Domain/App.config b/RS.Core.Domain/App.config index 7e1d79c..37f1fa7 100644 --- a/RS.Core.Domain/App.config +++ b/RS.Core.Domain/App.config @@ -1,17 +1,17 @@ - + -
+
- + - + - \ No newline at end of file + diff --git a/RS.Core.Domain/Model/AutoCode/AutoCode.cs b/RS.Core.Domain/Model/AutoCode/AutoCode.cs index 11824c9..d1fc65c 100644 --- a/RS.Core.Domain/Model/AutoCode/AutoCode.cs +++ b/RS.Core.Domain/Model/AutoCode/AutoCode.cs @@ -18,12 +18,12 @@ public class AutoCode : TableEntity /// Fixed screen codes /// /// - [Required,MaxLength(20)] + [Required,MaxLength(5)] public string ScreenCode { get; set; } /// /// Sample code format = "TC-{0}-RS" /// - [Required,MaxLength(50)] + [Required,MaxLength(20)] public string CodeFormat { get; set; } public int LastCodeNumber { get; set; } diff --git a/RS.Core.Domain/RS.Core.Domain.csproj b/RS.Core.Domain/RS.Core.Domain.csproj index fe9baaf..1b33dc5 100644 --- a/RS.Core.Domain/RS.Core.Domain.csproj +++ b/RS.Core.Domain/RS.Core.Domain.csproj @@ -9,8 +9,9 @@ Properties RS.Core.Domain RS.Core.Domain - v4.5.2 + v4.7 512 + true diff --git a/RS.Core.Lib/RS.Core.Lib.csproj b/RS.Core.Lib/RS.Core.Lib.csproj index 78d73ec..8f27673 100644 --- a/RS.Core.Lib/RS.Core.Lib.csproj +++ b/RS.Core.Lib/RS.Core.Lib.csproj @@ -9,8 +9,9 @@ Properties RS.Core.Lib RS.Core.Lib - v4.5.2 + v4.7 512 + true diff --git a/RS.Core.Service/Base/DTOs/AutoCode/AutoCodeDto.cs b/RS.Core.Service/Base/DTOs/AutoCode/AutoCodeDto.cs index ed1aa8f..d26f792 100644 --- a/RS.Core.Service/Base/DTOs/AutoCode/AutoCodeDto.cs +++ b/RS.Core.Service/Base/DTOs/AutoCode/AutoCodeDto.cs @@ -6,17 +6,23 @@ namespace RS.Core.Service.DTOs public class AutoCodeAddDto { /// - /// Sabit olarak tanımlanan ekran kodları + /// Fixed screen codes /// /// - [Required, MaxLength(20)] + [Required, MaxLength(5)] public string ScreenCode { get; set; } - [Required, MaxLength(50)] + /// + /// Sample code format = "TC-{0}-RS" + /// + [Required, MaxLength(13)] public string CodeFormat { get; set; } } public class AutoCodeUpdateDto:EntityUpdateDto { - [Required, MaxLength(50)] + /// + /// Sample code format = "TC-{0}-RS" + /// + [Required, MaxLength(13)] public string CodeFormat { get; set; } } public class AutoCodeGetDto:EntityGetDto diff --git a/RS.Core.Service/Base/Services/AutoCode/AutoCodeService.cs b/RS.Core.Service/Base/Services/AutoCode/AutoCodeService.cs index a9b7afb..fb27775 100644 --- a/RS.Core.Service/Base/Services/AutoCode/AutoCodeService.cs +++ b/RS.Core.Service/Base/Services/AutoCode/AutoCodeService.cs @@ -33,23 +33,32 @@ public bool CheckCodeFormat(string codeFormat) return codeFormat.Contains("{0}"); } + /// + /// Controls whether the display code is in the class. + /// + /// + /// + public bool CheckScreenCode(string screenCode) + { + return typeof(ScreenCodes).GetFields().Any(x => x.Name == screenCode); + } + public override Task Add(AutoCodeAddDto model, Guid userID, bool isCommit = true) { - ///Controls whether the display code is in the class. - var checkScreenCode = typeof(ScreenCodes).GetFields().Any(x => x.Name == model.ScreenCode); - if (!checkScreenCode) - Task completedTask = Task.CompletedTask; - return Task.CompletedTask(new APIResult { Message = Messages.ACW0001 }); - //new APIResult { Message = Messages.ACW0001 }; + if (!CheckScreenCode(model.ScreenCode)) + return Task.FromResult(new APIResult { Message = Messages.ACW0001 }); if (!CheckCodeFormat(model.CodeFormat)) - return new APIResult { Message = Messages.ACW0002 }; + return Task.FromResult(new APIResult { Message = Messages.ACW0002 }); return base.Add(model, userID, isCommit); } public override Task Update(AutoCodeUpdateDto model, Guid? userID = null, bool isCommit = true, bool checkAuthorize = false) { + if (!CheckCodeFormat(model.CodeFormat)) + return Task.FromResult(new APIResult { Message = Messages.ACW0002 }); + return base.Update(model, userID, isCommit, checkAuthorize); } diff --git a/RS.Core.Service/RS.Core.Service.csproj b/RS.Core.Service/RS.Core.Service.csproj index 9cc4814..51016b3 100644 --- a/RS.Core.Service/RS.Core.Service.csproj +++ b/RS.Core.Service/RS.Core.Service.csproj @@ -9,8 +9,9 @@ Properties RS.Core.Service RS.Core.Service - v4.5.2 + v4.7 512 + true diff --git a/RS.Core.Service/app.config b/RS.Core.Service/app.config index d298668..5ef097e 100644 --- a/RS.Core.Service/app.config +++ b/RS.Core.Service/app.config @@ -1,57 +1,57 @@ - + -
+
- - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - \ No newline at end of file + diff --git a/RS.Core.Testing/App.config b/RS.Core.Testing/App.config index 134e9c8..e1be448 100644 --- a/RS.Core.Testing/App.config +++ b/RS.Core.Testing/App.config @@ -1,57 +1,57 @@ - + -
+
- + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - \ No newline at end of file + diff --git a/RS.Core.Testing/Arrange/AutoCode/AutoCodeDtos.cs b/RS.Core.Testing/Arrange/AutoCode/AutoCodeDtos.cs new file mode 100644 index 0000000..fea4432 --- /dev/null +++ b/RS.Core.Testing/Arrange/AutoCode/AutoCodeDtos.cs @@ -0,0 +1,41 @@ +using RS.Core.Domain; +using System; +using System.Collections.Generic; + +namespace RS.Core.Testing.Arrange +{ + public static class AutoCodeDtos + { + public static List InMemoryList() + { + var autoCodeData = new List + { + new AutoCode + { + ID = Guid.Parse("1e5757c3-2f69-4c5f-918d-2eaa1b478850"), + CodeFormat="CF-{0}-UT", + LastCodeNumber=142, + ScreenCode="TSC01", + CreateBy=Guid.Parse("ae9569bf-3e20-4f6a-a930-a70066f8ceb8"), + CreateDT=new DateTime(2017,10,03) + }, + + new AutoCode + { + ID = Guid.Parse("ce27647e-8c2f-4aff-8558-eb0337ec59ce"), + CodeFormat="UT-AY--{0}", + LastCodeNumber=1903, + ScreenCode="TSC02", + CreateBy=Guid.Parse("ae9569bf-3e20-4f6a-a930-a70066f8ceb8"), + CreateDT=new DateTime(2017,10,02) + } + }; + + return autoCodeData; + } + public static string ScreenCodeForAutomaticCodeGenerationTest= "TSC01"; + public static string IncorrectCodeFormat = "CF-TS[9}"; + public static string CorrectCodeFormat = "CF-TS{0}"; + public static string IncorrectScreenCode = "XXX-01"; + } +} \ No newline at end of file diff --git a/RS.Core.Testing/RS.Core.Testing.csproj b/RS.Core.Testing/RS.Core.Testing.csproj index acdb41b..5d0ca0a 100644 --- a/RS.Core.Testing/RS.Core.Testing.csproj +++ b/RS.Core.Testing/RS.Core.Testing.csproj @@ -9,8 +9,9 @@ Properties RS.Core.Testing RS.Core.Testing - v4.5.2 + v4.7 512 + true @@ -53,6 +54,7 @@ + diff --git a/RS.Core.Tests/App.config b/RS.Core.Tests/App.config index 0b46aab..0098009 100644 --- a/RS.Core.Tests/App.config +++ b/RS.Core.Tests/App.config @@ -1,4 +1,4 @@ - + -
+
- - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - \ No newline at end of file + diff --git a/RS.Core.Tests/RS.Core.Tests.csproj b/RS.Core.Tests/RS.Core.Tests.csproj index ccfa130..0f6c04a 100644 --- a/RS.Core.Tests/RS.Core.Tests.csproj +++ b/RS.Core.Tests/RS.Core.Tests.csproj @@ -10,9 +10,10 @@ Properties RS.Core.Tests RS.Core.Tests - v4.5.2 + v4.7 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + true @@ -103,6 +104,7 @@ + diff --git a/RS.Core.Tests/UnitTests/AutoCode/AutoCodeServiceTest.cs b/RS.Core.Tests/UnitTests/AutoCode/AutoCodeServiceTest.cs new file mode 100644 index 0000000..fbe3b13 --- /dev/null +++ b/RS.Core.Tests/UnitTests/AutoCode/AutoCodeServiceTest.cs @@ -0,0 +1,87 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using RS.Core.Const; +using RS.Core.Domain; +using RS.Core.Service; +using RS.Core.Testing; +using RS.Core.Testing.Arrange; +using System; +using System.Data.Entity; +using System.Linq; +using System.Threading.Tasks; + +namespace RS.Core.Tests.UnitTests +{ + [TestClass] + public class AutoCodeServiceTest:BaseUnitTest + { + private IAutoCodeService _autoCodeService; + private IAutoCodeLogService _autoCodeLogService; + + [TestMethod] + public async Task TestAutoCodeGenerate() + { + //Context has been overriding and an in-memory autocode data has been added. + var mockAutoCodeSet = IMUow.Repository().GetListAsync(AutoCodeDtos.InMemoryList()); + mockContext.Setup(m => m.Set()).Returns(mockAutoCodeSet.Object); + + //Context has been overriding and add mocked AutoCodeLog DbSet. + var mockAutoCodeLogSet = new Mock>(); + mockContext.Setup(m => m.Set()).Returns(mockAutoCodeLogSet.Object); + + //Unit of work has been mocked. Mock context sent to constructor. Services works with mocked unit of work. + var mockUow = new Mock>(mockContext.Object); + _autoCodeLogService = new AutoCodeLogService(mockUow.Object); + _autoCodeService = new AutoCodeService(mockUow.Object, _autoCodeLogService); + + var result = await _autoCodeService.AutoCodeGenerate( + AutoCodeDtos.ScreenCodeForAutomaticCodeGenerationTest,UserDtos.InMemoryList().First().ID); + + //Is the expected code the same as the generated code? + Assert.AreEqual("CF-143-UT", result); + + //Has the last code number increased? + Assert.AreEqual( + 143, + mockAutoCodeSet.Object. + FirstOrDefault(x => x.ScreenCode == AutoCodeDtos.ScreenCodeForAutomaticCodeGenerationTest).LastCodeNumber); + + mockAutoCodeLogSet.Verify(m => m.Add(It.IsAny()), Times.Once); + mockUow.Verify(m => m.SaveChangesAsync(), Times.Once); + } + + [TestMethod] + public void TestCheckCodeFormat() + { + var mockUow = new Mock>(mockContext.Object); + _autoCodeLogService = new AutoCodeLogService(mockUow.Object); + AutoCodeService _autoCodeService = new AutoCodeService(mockUow.Object, _autoCodeLogService); + + var incorrectCodeFormat = _autoCodeService.CheckCodeFormat(AutoCodeDtos.IncorrectCodeFormat); + var correctCodeFormat = _autoCodeService.CheckCodeFormat(AutoCodeDtos.CorrectCodeFormat); + + Assert.IsFalse(incorrectCodeFormat); + Assert.IsTrue(correctCodeFormat); + } + + [TestMethod] + public void TestCheckScreenCode() + { + var mockUow = new Mock>(mockContext.Object); + _autoCodeLogService = new AutoCodeLogService(mockUow.Object); + AutoCodeService _autoCodeService = new AutoCodeService(mockUow.Object, _autoCodeLogService); + + var incorrectScreenCode = _autoCodeService.CheckScreenCode(AutoCodeDtos.IncorrectScreenCode); + var correctScrennCode = _autoCodeService.CheckScreenCode(ScreenCodes.TSC01); + + Assert.IsFalse(incorrectScreenCode); + Assert.IsTrue(correctScrennCode); + } + + [TestCleanup] + public void Cleanup() + { + mockContext.Object.Dispose(); + } + } +} diff --git a/RS.Core.Tests/UnitTests/User/UserServiceTest.cs b/RS.Core.Tests/UnitTests/User/UserServiceTest.cs index 68327fa..4e13ac9 100644 --- a/RS.Core.Tests/UnitTests/User/UserServiceTest.cs +++ b/RS.Core.Tests/UnitTests/User/UserServiceTest.cs @@ -39,6 +39,7 @@ public async Task TestRegister() mockUserSet.Verify(m => m.Add(It.IsAny()), Times.Once); mockUow.Verify(m => m.SaveChangesAsync(), Times.Once); } + [TestMethod] public async Task TestDuplicateUser() { @@ -56,6 +57,7 @@ public async Task TestDuplicateUser() Assert.AreEqual(result.Message, Messages.GNE0003); } + [TestMethod] public async Task TestUpdate() {