From 50b431a7fddbd7598e890104dfaa56c7f0343804 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 25 Dec 2023 13:21:15 +0800 Subject: [PATCH] Update tutorials's unit test code for 8.0 changes. --- en/tutorials/book-store/part-10.md | 8 ++--- en/tutorials/book-store/part-4.md | 51 +++++++++++++++++++++++++----- en/tutorials/book-store/part-8.md | 43 ++++++++++++++++++++++--- 3 files changed, 86 insertions(+), 16 deletions(-) diff --git a/en/tutorials/book-store/part-10.md b/en/tutorials/book-store/part-10.md index 2671e351..eaa3090a 100644 --- a/en/tutorials/book-store/part-10.md +++ b/en/tutorials/book-store/part-10.md @@ -615,19 +615,19 @@ using System.Threading.Tasks; using Acme.BookStore.Authors; using Shouldly; using Volo.Abp.Application.Dtos; +using Volo.Abp.Modularity; using Volo.Abp.Validation; using Xunit; namespace Acme.BookStore.Books; -{{if DB=="Mongo"}} -[Collection(BookStoreTestConsts.CollectionDefinitionName)] {{end}} -public class BookAppService_Tests : BookStoreApplicationTestBase +public abstract class BookAppService_Tests : BookStoreApplicationTestBase + where TStartupModule : IAbpModule { private readonly IBookAppService _bookAppService; private readonly IAuthorAppService _authorAppService; - public BookAppService_Tests() + protected BookAppService_Tests() { _bookAppService = GetRequiredService(); _authorAppService = GetRequiredService(); diff --git a/en/tutorials/book-store/part-4.md b/en/tutorials/book-store/part-4.md index a04fe069..643a57bc 100644 --- a/en/tutorials/book-store/part-4.md +++ b/en/tutorials/book-store/part-4.md @@ -72,6 +72,7 @@ Create a test class named `BookAppService_Tests` in the `Books` folder of the `A using System.Threading.Tasks; using Shouldly; using Volo.Abp.Application.Dtos; +using Volo.Abp.Modularity; using Xunit; using System; using Volo.Abp.Validation; @@ -79,13 +80,12 @@ using System.Linq; namespace Acme.BookStore.Books; -{{if DB=="Mongo"}} -[Collection(BookStoreTestConsts.CollectionDefinitionName)] {{ end}} -public class BookAppService_Tests : BookStoreApplicationTestBase +public abstract class BookAppService_Tests : BookStoreApplicationTestBase + where TStartupModule : IAbpModule { private readonly IBookAppService _bookAppService; - public BookAppService_Tests() + protected BookAppService_Tests() { _bookAppService = GetRequiredService(); } @@ -105,6 +105,41 @@ public class BookAppService_Tests : BookStoreApplicationTestBase } ```` +{{if DB == "EF"}} +Add a new implementation class of `BookAppService_Tests` class, named `EfCoreBookAppService_Tests` in the `EntityFrameworkCore\Applications\Books` namespace (folder) of the `Acme.BookStore.EntityFrameworkCore.Tests` project: + +````csharp +using Acme.BookStore.Books; +using Xunit; + +namespace Acme.BookStore.EntityFrameworkCore.Applications.Books; + +[Collection(BookStoreTestConsts.CollectionDefinitionName)] +public class EfCoreBookAppService_Tests : BookAppService_Tests +{ + +} +```` +{{end}} + +{{if DB == "Mongo"}} +Add a new implementation class of `BookAppService_Tests` class, named `MongoDBBookAppService_Tests` in the `MongoDb\Applications\Books` namespace (folder) of the `Acme.BookStore.MongoDB.Tests` project: + +````csharp +using Acme.BookStore.MongoDB; +using Acme.BookStore.Books; +using Xunit; + +namespace Acme.BookStore.MongoDb.Applications.Books; + +[Collection(BookStoreTestConsts.CollectionDefinitionName)] +public class MongoDBBookAppService_Tests : BookAppService_Tests +{ + +} +```` +{{end}} + * `Should_Get_List_Of_Books` test simply uses `BookAppService.GetListAsync` method to get and check the list of books. * We can safely check the book "1984" by its name, because we know that this books is available in the database since we've added it in the seed data. @@ -163,6 +198,7 @@ The final test class should be as shown below: using System.Threading.Tasks; using Shouldly; using Volo.Abp.Application.Dtos; +using Volo.Abp.Modularity; using Xunit; using System; using Volo.Abp.Validation; @@ -170,13 +206,12 @@ using System.Linq; namespace Acme.BookStore.Books; -{{if DB=="Mongo"}} -[Collection(BookStoreTestConsts.CollectionDefinitionName)] {{ end}} -public class BookAppService_Tests : BookStoreApplicationTestBase +public abstract class BookAppService_Tests : BookStoreApplicationTestBase + where TStartupModule : IAbpModule { private readonly IBookAppService _bookAppService; - public BookAppService_Tests() + protected BookAppService_Tests() { _bookAppService = GetRequiredService(); } diff --git a/en/tutorials/book-store/part-8.md b/en/tutorials/book-store/part-8.md index 271aff93..d0511692 100644 --- a/en/tutorials/book-store/part-8.md +++ b/en/tutorials/book-store/part-8.md @@ -477,17 +477,17 @@ Finally, we can write some tests for the `IAuthorAppService`. Add a new class, n using System; using System.Threading.Tasks; using Shouldly; +using Volo.Abp.Modularity; using Xunit; namespace Acme.BookStore.Authors; -{{if DB=="Mongo"}} -[Collection(BookStoreTestConsts.CollectionDefinitionName)] {{ end}} -public class AuthorAppService_Tests : BookStoreApplicationTestBase +public abstract class AuthorAppService_Tests : BookStoreApplicationTestBase + where TStartupModule : IAbpModule { private readonly IAuthorAppService _authorAppService; - public AuthorAppService_Tests() + protected AuthorAppService_Tests() { _authorAppService = GetRequiredService(); } @@ -549,6 +549,41 @@ public class AuthorAppService_Tests : BookStoreApplicationTestBase } ```` +{{if DB == "EF"}} +Add a new implementation class of `AuthorAppService_Tests` class, named `EfCoreAuthorAppService_Tests` in the `EntityFrameworkCore\Applications\Authors` namespace (folder) of the `Acme.BookStore.EntityFrameworkCore.Tests` project: + +````csharp +using Acme.BookStore.Authors; +using Xunit; + +namespace Acme.BookStore.EntityFrameworkCore.Applications.Authors; + +[Collection(BookStoreTestConsts.CollectionDefinitionName)] +public class EfCoreAuthorAppService_Tests : AuthorAppService_Tests +{ + +} +```` +{{end}} + +{{if DB == "Mongo"}} +Add a new implementation class of `AuthorAppService_Tests` class, named `MongoDBAuthorAppService_Tests` in the `MongoDb\Applications\Authors` namespace (folder) of the `Acme.BookStore.MongoDB.Tests` project: + +````csharp +using Acme.BookStore.MongoDB; +using Acme.BookStore.Authors; +using Xunit; + +namespace Acme.BookStore.MongoDb.Applications.Authors; + +[Collection(BookStoreTestConsts.CollectionDefinitionName)] +public class MongoDBAuthorAppService_Tests : AuthorAppService_Tests +{ + +} +```` +{{end}} + Created some tests for the application service methods, which should be clear to understand. ## The Next Part