Browse Source

Add missing organization application tests for update

pull/17/head
EngincanV 6 years ago
parent
commit
a35fed2e14
  1. 3
      src/EventHub.Application/Organizations/OrganizationAppService.cs
  2. 1
      src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs
  3. 62
      test/EventHub.Application.Tests/Organizations/OrganizationAppServiceTests.cs

3
src/EventHub.Application/Organizations/OrganizationAppService.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using EventHub.Permissions; using EventHub.Permissions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Authorization;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users; using Volo.Abp.Users;
@ -81,7 +82,7 @@ namespace EventHub.Organizations
if (organization.OwnerUserId != CurrentUser.GetId()) if (organization.OwnerUserId != CurrentUser.GetId())
{ {
return; throw new AbpAuthorizationException();
} }
organization.SetDisplayName(input.DisplayName); organization.SetDisplayName(input.DisplayName);

1
src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs

@ -51,6 +51,7 @@ namespace EventHub.Web.Pages.Organizations
} }
catch (Exception exception) catch (Exception exception)
{ {
ShowAlert(exception);
return Page(); return Page();
} }
} }

62
test/EventHub.Application.Tests/Organizations/OrganizationAppServiceTests.cs

@ -1,7 +1,13 @@
using System.Threading.Tasks; using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly; using Shouldly;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Authorization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Users;
using Xunit; using Xunit;
namespace EventHub.Organizations namespace EventHub.Organizations
@ -10,16 +16,25 @@ namespace EventHub.Organizations
{ {
private readonly IOrganizationAppService _organizationAppService; private readonly IOrganizationAppService _organizationAppService;
private readonly EventHubTestData _testData; private readonly EventHubTestData _testData;
private ICurrentUser _currentUser;
public OrganizationAppServiceTests() public OrganizationAppServiceTests()
{ {
_organizationAppService = GetRequiredService<IOrganizationAppService>(); _organizationAppService = GetRequiredService<IOrganizationAppService>();
_testData = GetRequiredService<EventHubTestData>(); _testData = GetRequiredService<EventHubTestData>();
} }
protected override void AfterAddApplication(IServiceCollection services)
{
_currentUser = Substitute.For<ICurrentUser>();
services.AddSingleton(_currentUser);
}
[Fact] [Fact]
public async Task Should_Create_A_Valid_Organization() public async Task Should_Create_A_Valid_Organization()
{ {
Login(_testData.UserAdminId);
await _organizationAppService.CreateAsync( await _organizationAppService.CreateAsync(
new CreateOrganizationDto new CreateOrganizationDto
{ {
@ -38,6 +53,8 @@ namespace EventHub.Organizations
[Fact] [Fact]
public async Task Should_Not_Create_Organization_With_Existing_Name() public async Task Should_Not_Create_Organization_With_Existing_Name()
{ {
Login(_testData.UserAdminId);
var exception = await Assert.ThrowsAsync<BusinessException>(() => var exception = await Assert.ThrowsAsync<BusinessException>(() =>
_organizationAppService.CreateAsync( _organizationAppService.CreateAsync(
new CreateOrganizationDto new CreateOrganizationDto
@ -68,5 +85,46 @@ namespace EventHub.Organizations
result.Id.ShouldBe(_testData.OrganizationVolosoftId); result.Id.ShouldBe(_testData.OrganizationVolosoftId);
result.Name.ShouldBe(_testData.OrganizationVolosoftName); result.Name.ShouldBe(_testData.OrganizationVolosoftName);
} }
[Fact]
public async Task Should_Update_Organization_If_User_Is_Owner()
{
Login(_testData.UserAdminId);
await _organizationAppService.UpdateAsync(
_testData.OrganizationVolosoftId,
new UpdateOrganizationDto
{
DisplayName = "VOLOSOFT",
Description = "Test description text that is valid and long enough for updating!",
Website = "https://volosoft.com/",
MediumUsername = "volosoft"
});
}
[Fact]
public async Task Should_Not_Update_Organization_If_User_Not_Owner()
{
Login(_testData.UserAdminId);
var exception = await Assert.ThrowsAsync<AbpAuthorizationException>(() =>
_organizationAppService.UpdateAsync(
_testData.OrganizationDotnetEuropeId,
new UpdateOrganizationDto
{
DisplayName = "Dotnet Europe (DE)",
Description = "Test description text that is valid and long enough for updating!",
Website = "https://dotnet-europe.com/"
})
);
exception.ShouldNotBeNull();
}
private void Login(Guid userId)
{
_currentUser.Id.Returns(userId);
_currentUser.IsAuthenticated.Returns(true);
}
} }
} }

Loading…
Cancel
Save