Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Update tutorials's unit test code for 8.0 changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
maliming committed Dec 25, 2023
1 parent 7cb45c1 commit 50b431a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 16 deletions.
8 changes: 4 additions & 4 deletions en/tutorials/book-store/part-10.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<TStartupModule> : BookStoreApplicationTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IBookAppService _bookAppService;
private readonly IAuthorAppService _authorAppService;

public BookAppService_Tests()
protected BookAppService_Tests()
{
_bookAppService = GetRequiredService<IBookAppService>();
_authorAppService = GetRequiredService<IAuthorAppService>();
Expand Down
51 changes: 43 additions & 8 deletions en/tutorials/book-store/part-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ 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;
using System.Linq;

namespace Acme.BookStore.Books;

{{if DB=="Mongo"}}
[Collection(BookStoreTestConsts.CollectionDefinitionName)] {{ end}}
public class BookAppService_Tests : BookStoreApplicationTestBase
public abstract class BookAppService_Tests<TStartupModule> : BookStoreApplicationTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IBookAppService _bookAppService;

public BookAppService_Tests()
protected BookAppService_Tests()
{
_bookAppService = GetRequiredService<IBookAppService>();
}
Expand All @@ -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<BookStoreEntityFrameworkCoreTestModule>
{

}
````
{{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<BookStoreMongoDbTestModule>
{

}
````
{{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.

Expand Down Expand Up @@ -163,20 +198,20 @@ 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;
using System.Linq;

namespace Acme.BookStore.Books;

{{if DB=="Mongo"}}
[Collection(BookStoreTestConsts.CollectionDefinitionName)] {{ end}}
public class BookAppService_Tests : BookStoreApplicationTestBase
public abstract class BookAppService_Tests<TStartupModule> : BookStoreApplicationTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IBookAppService _bookAppService;

public BookAppService_Tests()
protected BookAppService_Tests()
{
_bookAppService = GetRequiredService<IBookAppService>();
}
Expand Down
43 changes: 39 additions & 4 deletions en/tutorials/book-store/part-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<TStartupModule> : BookStoreApplicationTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IAuthorAppService _authorAppService;

public AuthorAppService_Tests()
protected AuthorAppService_Tests()
{
_authorAppService = GetRequiredService<IAuthorAppService>();
}
Expand Down Expand Up @@ -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<BookStoreEntityFrameworkCoreTestModule>
{

}
````
{{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<BookStoreMongoDbTestModule>
{

}
````
{{end}}

Created some tests for the application service methods, which should be clear to understand.

## The Next Part
Expand Down

0 comments on commit 50b431a

Please sign in to comment.