mirror of https://github.com/abpframework/eventhub
7 changed files with 132 additions and 128 deletions
@ -0,0 +1,64 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Xunit; |
|||
|
|||
namespace EventHub.Organizations |
|||
{ |
|||
public class OrganizationAppServiceTests : EventHubApplicationTestBase |
|||
{ |
|||
private readonly IOrganizationAppService _organizationAppService; |
|||
private readonly EventHubTestData _testData; |
|||
|
|||
public OrganizationAppServiceTests() |
|||
{ |
|||
_organizationAppService = GetRequiredService<IOrganizationAppService>(); |
|||
_testData = GetRequiredService<EventHubTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_A_Valid_Organization() |
|||
{ |
|||
await _organizationAppService.CreateAsync( |
|||
new CreateOrganizationDto |
|||
{ |
|||
Name = "test-org-8374", |
|||
DisplayName = "Test Display Name", |
|||
Description = "Test description text that is valid and long enough!" |
|||
} |
|||
); |
|||
|
|||
var organization = await GetOrganizationOrNullAsync("test-org-8374"); |
|||
organization.Name.ShouldBe("test-org-8374"); |
|||
organization.DisplayName.ShouldBe("Test Display Name"); |
|||
organization.Description.ShouldBe("Test description text that is valid and long enough!"); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Not_Create_Organization_With_Existing_Name() |
|||
{ |
|||
var exception = await Assert.ThrowsAsync<BusinessException>(() => |
|||
_organizationAppService.CreateAsync( |
|||
new CreateOrganizationDto |
|||
{ |
|||
Name = _testData.OrganizationVolosoftName, |
|||
DisplayName = "Test Display Name", |
|||
Description = "Test description text that is valid and long enough!" |
|||
} |
|||
) |
|||
); |
|||
|
|||
exception.Code.ShouldBe(EventHubErrorCodes.OrganizationNameAlreadyExists); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Get_List_Of_Organizations() |
|||
{ |
|||
var result = await _organizationAppService.GetListAsync(new PagedResultRequestDto()); |
|||
result.TotalCount.ShouldBeGreaterThanOrEqualTo(2); |
|||
result.Items.ShouldContain(o => o.Name == _testData.OrganizationVolosoftName && o.Id == _testData.OrganizationVolosoftId); |
|||
result.Items.ShouldContain(o => o.Name == _testData.OrganizationDotnetEuropeName && o.Id == _testData.OrganizationDotnetEuropeId); |
|||
} |
|||
} |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
using Shouldly; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Identity; |
|||
using Xunit; |
|||
|
|||
namespace EventHub.Samples |
|||
{ |
|||
/* This is just an example test class. |
|||
* Normally, you don't test code of the modules you are using |
|||
* (like IIdentityUserAppService here). |
|||
* Only test your own application services. |
|||
*/ |
|||
public class SampleAppServiceTests : EventHubApplicationTestBase |
|||
{ |
|||
private readonly IIdentityUserAppService _userAppService; |
|||
|
|||
public SampleAppServiceTests() |
|||
{ |
|||
_userAppService = GetRequiredService<IIdentityUserAppService>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Initial_Data_Should_Contain_Admin_User() |
|||
{ |
|||
//Act
|
|||
var result = await _userAppService.GetListAsync(new GetIdentityUsersInput()); |
|||
|
|||
//Assert
|
|||
result.TotalCount.ShouldBeGreaterThan(0); |
|||
result.Items.ShouldContain(u => u.UserName == "admin"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Identity; |
|||
using Xunit; |
|||
|
|||
namespace EventHub.Samples |
|||
{ |
|||
/* This is just an example test class. |
|||
* Normally, you don't test code of the modules you are using |
|||
* (like IdentityUserManager here). |
|||
* Only test your own domain services. |
|||
*/ |
|||
public class SampleDomainTests : EventHubDomainTestBase |
|||
{ |
|||
private readonly IIdentityUserRepository _identityUserRepository; |
|||
private readonly IdentityUserManager _identityUserManager; |
|||
|
|||
public SampleDomainTests() |
|||
{ |
|||
_identityUserRepository = GetRequiredService<IIdentityUserRepository>(); |
|||
_identityUserManager = GetRequiredService<IdentityUserManager>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Set_Email_Of_A_User() |
|||
{ |
|||
IdentityUser adminUser; |
|||
|
|||
/* Need to manually start Unit Of Work because |
|||
* FirstOrDefaultAsync should be executed while db connection / context is available. |
|||
*/ |
|||
await WithUnitOfWorkAsync(async () => |
|||
{ |
|||
adminUser = await _identityUserRepository |
|||
.FindByNormalizedUserNameAsync("ADMIN"); |
|||
|
|||
await _identityUserManager.SetEmailAsync(adminUser, "newemail@abp.io"); |
|||
await _identityUserRepository.UpdateAsync(adminUser); |
|||
}); |
|||
|
|||
adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync("ADMIN"); |
|||
adminUser.Email.ShouldBe("newemail@abp.io"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,44 +0,0 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using EventHub.Users; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Xunit; |
|||
|
|||
namespace EventHub.EntityFrameworkCore.Samples |
|||
{ |
|||
/* This is just an example test class. |
|||
* Normally, you don't test ABP framework code |
|||
* (like default AppUser repository IRepository<AppUser, Guid> here). |
|||
* Only test your custom repository methods. |
|||
*/ |
|||
public class SampleRepositoryTests : EventHubEntityFrameworkCoreTestBase |
|||
{ |
|||
private readonly IRepository<AppUser, Guid> _appUserRepository; |
|||
|
|||
public SampleRepositoryTests() |
|||
{ |
|||
_appUserRepository = GetRequiredService<IRepository<AppUser, Guid>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Query_AppUser() |
|||
{ |
|||
/* Need to manually start Unit Of Work because |
|||
* FirstOrDefaultAsync should be executed while db connection / context is available. |
|||
*/ |
|||
await WithUnitOfWorkAsync(async () => |
|||
{ |
|||
//Act
|
|||
var adminUser = await _appUserRepository |
|||
.Where(u => u.UserName == "admin") |
|||
.FirstOrDefaultAsync(); |
|||
|
|||
//Assert
|
|||
adminUser.ShouldNotBeNull(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EventHub |
|||
{ |
|||
public class EventHubTestData : ISingletonDependency |
|||
{ |
|||
/* ORGANIZATIONS *****************************************************/ |
|||
|
|||
public Guid OrganizationVolosoftId { get; internal set; } |
|||
public string OrganizationVolosoftName { get; } = "volosoft"; |
|||
|
|||
public Guid OrganizationDotnetEuropeId { get; internal set; } |
|||
public string OrganizationDotnetEuropeName { get; } = "dotnet-europe"; |
|||
} |
|||
} |
|||
@ -1,16 +1,50 @@ |
|||
using System.Threading.Tasks; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EventHub.Organizations; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace EventHub |
|||
{ |
|||
public class EventHubTestDataSeedContributor : IDataSeedContributor, ITransientDependency |
|||
{ |
|||
public Task SeedAsync(DataSeedContext context) |
|||
private readonly IRepository<Organization, Guid> _organizationRepository; |
|||
private readonly OrganizationManager _organizationManager; |
|||
private readonly EventHubTestData _eventHubTestData; |
|||
|
|||
public EventHubTestDataSeedContributor( |
|||
IRepository<Organization, Guid> organizationRepository, |
|||
EventHubTestData eventHubTestData, |
|||
OrganizationManager organizationManager) |
|||
{ |
|||
_organizationRepository = organizationRepository; |
|||
_eventHubTestData = eventHubTestData; |
|||
_organizationManager = organizationManager; |
|||
} |
|||
|
|||
public async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await CreateOrganizationsAsync(); |
|||
} |
|||
|
|||
private async Task CreateOrganizationsAsync() |
|||
{ |
|||
/* Seed additional test data... */ |
|||
var volosoft = await _organizationManager.CreateAsync( |
|||
Guid.NewGuid(), |
|||
_eventHubTestData.OrganizationVolosoftName, |
|||
"Volosoft", |
|||
"Volosoft is producing software development tools for developers. We are organizing events related to the ABP.IO platform and general software development topic." |
|||
); |
|||
_eventHubTestData.OrganizationVolosoftId = volosoft.Id; |
|||
|
|||
return Task.CompletedTask; |
|||
var dotnetEurope = await _organizationManager.CreateAsync( |
|||
Guid.NewGuid(), |
|||
_eventHubTestData.OrganizationDotnetEuropeName, |
|||
"Dotnet Europe", |
|||
"Organizing events on Microsoft's .NET Platform in European Countries." |
|||
); |
|||
_eventHubTestData.OrganizationDotnetEuropeId = dotnetEurope.Id; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue