mirror of https://github.com/abpframework/abp
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							71 lines
						
					
					
						
							2.0 KiB
						
					
					
				
			
		
		
	
	
							71 lines
						
					
					
						
							2.0 KiB
						
					
					
				| 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<IBookAppService>();
 | |
|         }
 | |
| 
 | |
|         [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<AbpValidationException>(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"));
 | |
|         }
 | |
|     }
 | |
| } |