diff --git a/build-all.ps1 b/build-all.ps1 index 023cbdeb4a..649abc5f8c 100644 --- a/build-all.ps1 +++ b/build-all.ps1 @@ -21,7 +21,6 @@ $solutionPaths = ( "modules/client-simulation", "templates/module/aspnet-core", "templates/app/aspnet-core", - "samples/MicroserviceDemo", "abp_io/AbpIoLocalization" ) diff --git a/docs/en/Tutorials/Angular/Part-III.md b/docs/en/Tutorials/Angular/Part-III.md index ffc79de5b1..93934da396 100644 --- a/docs/en/Tutorials/Angular/Part-III.md +++ b/docs/en/Tutorials/Angular/Part-III.md @@ -8,13 +8,13 @@ This is the third part of the Angular tutorial series. See all parts: - [Part II: Create, Update and Delete books](Part-II.md) - **Part III: Integration Tests (this tutorial)** -You can access to the **source code** of the application from the [GitHub repository](https://github.com/abpframework/abp/tree/dev/samples/BookStore-Angular-MongoDb). +This part covers the **server side** tests. You can access to the **source code** of the application from the [GitHub repository](https://github.com/abpframework/abp/tree/dev/samples/BookStore-Angular-MongoDb). ### Test Projects in the Solution There are multiple test projects in the solution: -![bookstore-test-projects-v2](images/bookstore-test-projects-v2.png) +![bookstore-test-projects](images/bookstore-test-projects-v3.png) Each project is used to test the related application project. Test projects use the following libraries for testing: diff --git a/docs/en/Tutorials/Angular/images/bookstore-test-projects-v2.png b/docs/en/Tutorials/Angular/images/bookstore-test-projects-v2.png deleted file mode 100644 index 8701164d75..0000000000 Binary files a/docs/en/Tutorials/Angular/images/bookstore-test-projects-v2.png and /dev/null differ diff --git a/docs/en/Tutorials/Angular/images/bookstore-test-projects-v3.png b/docs/en/Tutorials/Angular/images/bookstore-test-projects-v3.png new file mode 100644 index 0000000000..32ea91b325 Binary files /dev/null and b/docs/en/Tutorials/Angular/images/bookstore-test-projects-v3.png differ diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.Application.Tests/BookAppService_Tests.cs b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.Application.Tests/BookAppService_Tests.cs new file mode 100644 index 0000000000..7ebf74aa9a --- /dev/null +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.Application.Tests/BookAppService_Tests.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Validation; +using Xunit; + +namespace Acme.BookStore +{ + public class BookAppService_Tests : BookStoreApplicationTestBase + { + private readonly IBookAppService _bookAppService; + + public BookAppService_Tests() + { + _bookAppService = GetRequiredService(); + } + + [Fact] + public async Task Should_Get_List_Of_Books() + { + //Act + var result = await _bookAppService.GetListAsync( + new PagedAndSortedResultRequestDto() + ); + + //Assert + result.TotalCount.ShouldBeGreaterThan(0); + result.Items.ShouldContain(b => b.Name == "Test book 1"); + } + + [Fact] + public async Task Should_Create_A_Valid_Book() + { + //Act + var result = await _bookAppService.CreateAsync( + new CreateUpdateBookDto + { + Name = "New test book 42", + Price = 10, + PublishDate = DateTime.Now, + Type = BookType.ScienceFiction + } + ); + + //Assert + result.Id.ShouldNotBe(Guid.Empty); + result.Name.ShouldBe("New test book 42"); + } + + [Fact] + public async Task Should_Not_Create_A_Book_Without_Name() + { + var exception = await Assert.ThrowsAsync(async () => + { + await _bookAppService.CreateAsync( + new CreateUpdateBookDto + { + Name = "", + Price = 10, + PublishDate = DateTime.Now, + Type = BookType.ScienceFiction + } + ); + }); + + exception.ValidationErrors + .ShouldContain(err => err.MemberNames.Any(mem => mem == "Name")); + } + } +} \ No newline at end of file diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.TestBase/BookStoreTestDataSeedContributor.cs b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.TestBase/BookStoreTestDataSeedContributor.cs index 5712782714..116e25ed25 100644 --- a/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.TestBase/BookStoreTestDataSeedContributor.cs +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.TestBase/BookStoreTestDataSeedContributor.cs @@ -1,16 +1,49 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Guids; namespace Acme.BookStore { - public class BookStoreTestDataSeedContributor : IDataSeedContributor, ITransientDependency + public class BookStoreTestDataSeedContributor + : IDataSeedContributor, ITransientDependency { - public Task SeedAsync(DataSeedContext context) + private readonly IRepository _bookRepository; + private readonly IGuidGenerator _guidGenerator; + + public BookStoreTestDataSeedContributor( + IRepository bookRepository, + IGuidGenerator guidGenerator) + { + _bookRepository = bookRepository; + _guidGenerator = guidGenerator; + } + + public async Task SeedAsync(DataSeedContext context) { - /* Seed additional test data... */ + await _bookRepository.InsertAsync( + new Book + { + Id = _guidGenerator.Create(), + Name = "Test book 1", + Type = BookType.Fantastic, + PublishDate = new DateTime(2015, 05, 24), + Price = 21 + } + ); - return Task.CompletedTask; + await _bookRepository.InsertAsync( + new Book + { + Id = _guidGenerator.Create(), + Name = "Test book 2", + Type = BookType.Science, + PublishDate = new DateTime(2014, 02, 11), + Price = 15 + } + ); } } } \ No newline at end of file