From 39110f00860de3b117ac48a5963413553227d496 Mon Sep 17 00:00:00 2001 From: Ali bordbar <35336396+aliBordbar1992@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:11:06 +0330 Subject: [PATCH 1/3] Update Testing.md mentioned using WithUnitOfWorkAsync in Dealing with unit of work section --- docs/en/Testing.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/en/Testing.md b/docs/en/Testing.md index e58defc619..6ad6bc5443 100644 --- a/docs/en/Testing.md +++ b/docs/en/Testing.md @@ -719,6 +719,37 @@ We've used the `IUnitOfWorkManager` service to create a unit of work scope, then > Note that we've tested the `FirstOrDefaultAsync` to demonstrate the unit of work problem. Normally, as a good principle, you should write tests only your own code. +You could also use `WithUnitOfWorkAsync` to achieve the same functionality instead of writing the same using block in your tests. + +Here is the same test scenario using `WithUnitOfWorkAsync`: + +````csharp +public abstract class IssueRepository_Tests : MyProjectDomainTestBase + where TStartupModule : IAbpModule +{ + private readonly IRepository _issueRepository; + private readonly IUnitOfWorkManager _unitOfWorkManager; + + protected IssueRepository_Tests() + { + _issueRepository = GetRequiredService>(); + _unitOfWorkManager = GetRequiredService(); + } + + public async Task Should_Query_By_Title() + { + await WithUnitOfWorkAsync(() => + { + IQueryable queryable = await _issueRepository.GetQueryableAsync(); + var issue = queryable.FirstOrDefaultAsync(i => i.Title == "My issue title"); + issue.ShouldNotBeNull(); + }); + } +} +```` + +There are multiple overloads of the `WithUnitOfWorkAsync` method that you can use based on your specific needs. + ### Working with DbContext In some cases, you may want to directory work with the Entity Framework's `DbContext` object to perform database operations in your test methods. In this case, you can use `IDbContextProvider`service to obtain a `DbContext` instance inside a unit of work. From ac5b1a8d5d92cf620e55da2ff25c0cfdf13909d1 Mon Sep 17 00:00:00 2001 From: Salih Date: Mon, 1 Apr 2024 17:05:52 +0300 Subject: [PATCH 2/3] Fix info text --- .../TagHelpers/Form/AbpInputTagHelperService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index e9cbd0a997..fbc212981a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -111,7 +111,7 @@ public class AbpInputTagHelperService : AbpTagHelperService inputHtml + label : label + inputHtml; - return innerContent + infoHtml + validation; + return innerContent + validation + infoHtml; } protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml, bool isCheckbox) From 29144e0b49f791e3554722cb9d83707274e28360 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 2 Apr 2024 16:54:57 +0800 Subject: [PATCH 3/3] Use the method provided by .NET8 ToSnakeCase --- .../System/AbpStringExtensions.cs | 60 +------------------ 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs b/framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs index 3d44fa988a..52258a12ee 100644 --- a/framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs +++ b/framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Security.Cryptography; using System.Text; +using System.Text.Json; using System.Text.RegularExpressions; using JetBrains.Annotations; using Volo.Abp; @@ -352,64 +353,7 @@ public static class AbpStringExtensions /// public static string ToSnakeCase(this string str) { - if (string.IsNullOrWhiteSpace(str)) - { - return str; - } - - var builder = new StringBuilder(str.Length + Math.Min(2, str.Length / 5)); - var previousCategory = default(UnicodeCategory?); - - for (var currentIndex = 0; currentIndex < str.Length; currentIndex++) - { - var currentChar = str[currentIndex]; - if (currentChar == '_') - { - builder.Append('_'); - previousCategory = null; - continue; - } - - var currentCategory = char.GetUnicodeCategory(currentChar); - switch (currentCategory) - { - case UnicodeCategory.UppercaseLetter: - case UnicodeCategory.TitlecaseLetter: - if (previousCategory == UnicodeCategory.SpaceSeparator || - previousCategory == UnicodeCategory.LowercaseLetter || - previousCategory != UnicodeCategory.DecimalDigitNumber && - previousCategory != null && - currentIndex > 0 && - currentIndex + 1 < str.Length && - char.IsLower(str[currentIndex + 1])) - { - builder.Append('_'); - } - - currentChar = char.ToLower(currentChar); - break; - - case UnicodeCategory.LowercaseLetter: - case UnicodeCategory.DecimalDigitNumber: - if (previousCategory == UnicodeCategory.SpaceSeparator) - { - builder.Append('_'); - } - break; - - default: - if (previousCategory != null) - { - previousCategory = UnicodeCategory.SpaceSeparator; - } - continue; - } - - builder.Append(currentChar); - previousCategory = currentCategory; - } - - return builder.ToString(); + return str.IsNullOrWhiteSpace() ? str : JsonNamingPolicy.SnakeCaseLower.ConvertName(str); } ///