From 119496c4fd16dabca97c327b0cf794f287f45d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 23 Jan 2021 20:38:16 +0300 Subject: [PATCH] Added OrganizationManagerTests. --- .../Organizations/OrganizationManagerTests.cs | 56 +++++++++++++++++++ .../EventHub.TestBase/EventHubTestBase.cs | 35 ++++++++++-- 2 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 eventhub/test/EventHub.Domain.Tests/Organizations/OrganizationManagerTests.cs diff --git a/eventhub/test/EventHub.Domain.Tests/Organizations/OrganizationManagerTests.cs b/eventhub/test/EventHub.Domain.Tests/Organizations/OrganizationManagerTests.cs new file mode 100644 index 0000000..2597a7b --- /dev/null +++ b/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(); + _testData = GetRequiredService(); + } + + [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(() => + _organizationManager.CreateAsync( + CurrentUser.GetId(), + _testData.OrganizationVolosoftName, + "Test Display Name", + "Test description text that is valid and long enough!" + ) + ); + + exception.Code.ShouldBe(EventHubErrorCodes.OrganizationNameAlreadyExists); + }); + } + } +} diff --git a/eventhub/test/EventHub.TestBase/EventHubTestBase.cs b/eventhub/test/EventHub.TestBase/EventHubTestBase.cs index 022ad61..9d23248 100644 --- a/eventhub/test/EventHub.TestBase/EventHubTestBase.cs +++ b/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 : AbpIntegratedTest where TStartupModule : IAbpModule { + protected ICurrentUser CurrentUser { get; } + + public EventHubTestBase() + { + CurrentUser = GetRequiredService(); + } + 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; + } } } }