Browse Source

Added OrganizationManagerTests.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
119496c4fd
  1. 56
      eventhub/test/EventHub.Domain.Tests/Organizations/OrganizationManagerTests.cs
  2. 35
      eventhub/test/EventHub.TestBase/EventHubTestBase.cs

56
eventhub/test/EventHub.Domain.Tests/Organizations/OrganizationManagerTests.cs

@ -0,0 +1,56 @@
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp;
using Volo.Abp.Users;
using Xunit;
namespace EventHub.Organizations
{
public class OrganizationManagerTests : EventHubDomainTestBase
{
private readonly OrganizationManager _organizationManager;
private readonly EventHubTestData _testData;
public OrganizationManagerTests()
{
_organizationManager = GetRequiredService<OrganizationManager>();
_testData = GetRequiredService<EventHubTestData>();
}
[Fact]
public async Task Should_Create_A_Valid_Organization()
{
await WithUnitOfWorkAsync(async () =>
{
var organization = await _organizationManager.CreateAsync(
CurrentUser.GetId(),
"test-org-1294",
"Test Display Name",
"Test description text that is valid and long enough!"
);
organization.Name.ShouldBe("test-org-1294");
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()
{
await WithUnitOfWorkAsync(async () =>
{
var exception = await Assert.ThrowsAsync<BusinessException>(() =>
_organizationManager.CreateAsync(
CurrentUser.GetId(),
_testData.OrganizationVolosoftName,
"Test Display Name",
"Test description text that is valid and long enough!"
)
);
exception.Code.ShouldBe(EventHubErrorCodes.OrganizationNameAlreadyExists);
});
}
}
}

35
eventhub/test/EventHub.TestBase/EventHubTestBase.cs

@ -7,6 +7,7 @@ using Volo.Abp.Domain.Repositories;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
using Volo.Abp.Testing;
using Volo.Abp.Users;
namespace EventHub
{
@ -15,6 +16,13 @@ namespace EventHub
public abstract class EventHubTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected ICurrentUser CurrentUser { get; }
public EventHubTestBase()
{
CurrentUser = GetRequiredService<ICurrentUser>();
}
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
@ -33,9 +41,16 @@ namespace EventHub
using (var uow = uowManager.Begin(options))
{
await action();
await uow.CompleteAsync();
try
{
await action();
await uow.CompleteAsync();
}
catch
{
await uow.RollbackAsync();
throw;
}
}
}
}
@ -53,9 +68,17 @@ namespace EventHub
using (var uow = uowManager.Begin(options))
{
var result = await func();
await uow.CompleteAsync();
return result;
try
{
var result = await func();
await uow.CompleteAsync();
return result;
}
catch
{
await uow.RollbackAsync();
throw;
}
}
}
}

Loading…
Cancel
Save