Browse Source

Added EventManagerTests.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
37c0353a90
  1. 22
      eventhub/src/EventHub.Application.Contracts/Events/EventDto.cs
  2. 2
      eventhub/src/EventHub.Application.Contracts/Events/IEventAppService.cs
  3. 3
      eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs
  4. 7
      eventhub/src/EventHub.Application/Events/EventAppService.cs
  5. 30
      eventhub/test/EventHub.Application.Tests/Events/EventAppServiceTests.cs
  6. 45
      eventhub/test/EventHub.Domain.Tests/Events/EventManagerTests.cs
  7. 15
      eventhub/test/EventHub.TestBase/EventHubTestBase.cs
  8. 2
      eventhub/test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

22
eventhub/src/EventHub.Application.Contracts/Events/EventDto.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Application.Dtos;
namespace EventHub.Events
{
public class EventDto : EntityDto<Guid>
{
public Guid OrganizationId { get; set; }
public string Title { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string Description { get; set; }
public bool IsOnline { get; set; }
public int? Capacity { get; set; }
}
}

2
eventhub/src/EventHub.Application.Contracts/Events/IEventAppService.cs

@ -5,6 +5,6 @@ namespace EventHub.Events
{
public interface IEventAppService : IApplicationService
{
Task CreateAsync(CreateEventDto input);
Task<EventDto> CreateAsync(CreateEventDto input);
}
}

3
eventhub/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs

@ -1,4 +1,5 @@
using AutoMapper;
using EventHub.Events;
using EventHub.Organizations;
namespace EventHub
@ -9,6 +10,8 @@ namespace EventHub
{
CreateMap<Organization, OrganizationInListDto>();
CreateMap<Organization, OrganizationProfileDto>();
CreateMap<Event, EventDto>();
}
}
}

7
eventhub/src/EventHub.Application/Events/EventAppService.cs

@ -25,7 +25,7 @@ namespace EventHub.Events
}
[Authorize]
public async Task CreateAsync(CreateEventDto input)
public async Task<EventDto> CreateAsync(CreateEventDto input)
{
var organization = await _organizationRepository.GetAsync(input.OrganizationId);
@ -43,7 +43,12 @@ namespace EventHub.Events
input.Description
);
@event.IsOnline = input.IsOnline;
@event.Capacity = input.Capacity;
await _eventRepository.InsertAsync(@event);
return ObjectMapper.Map<Event, EventDto>(@event);
}
}
}

30
eventhub/test/EventHub.Application.Tests/Events/EventAppServiceTests.cs

@ -1,5 +1,7 @@
using System;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp;
using Xunit;
namespace EventHub.Events
@ -18,7 +20,7 @@ namespace EventHub.Events
[Fact]
public async Task Should_Create_A_New_Valid_Event()
{
await _eventAppService.CreateAsync(
var eventDto = await _eventAppService.CreateAsync(
new CreateEventDto
{
OrganizationId = _testData.OrganizationVolosoftId,
@ -29,6 +31,32 @@ namespace EventHub.Events
IsOnline = true
}
);
eventDto.OrganizationId.ShouldBe(_testData.OrganizationVolosoftId);
eventDto.Title.ShouldBe("Introduction to the ABP Framework");
eventDto.Description.ShouldBe("In this event, we will introduce the ABP Framework and explore the fundamental features.");
eventDto.IsOnline.ShouldBeTrue();
}
[Fact]
public async Task Should_Not_Create_Event_For_Not_Authorized_Organization()
{
var exception = await Assert.ThrowsAsync<BusinessException>(async () =>
{
await _eventAppService.CreateAsync(
new CreateEventDto
{
OrganizationId = _testData.OrganizationDotnetEuropeId,
Title = "Introduction to the ABP Framework",
Description = "In this event, we will introduce the ABP Framework and explore the fundamental features.",
StartTime = DateTime.Now.AddDays(1),
EndTime = DateTime.Now.AddDays(1).AddHours(3),
IsOnline = true
}
);
});
exception.Code.ShouldBe(EventHubErrorCodes.NotAuthorizedToCreateEventInThisOrganization);
}
}
}

45
eventhub/test/EventHub.Domain.Tests/Events/EventManagerTests.cs

@ -0,0 +1,45 @@
using System;
using System.Threading.Tasks;
using EventHub.Organizations;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Xunit;
namespace EventHub.Events
{
public class EventManagerTests : EventHubDomainTestBase
{
private readonly EventHubTestData _testData;
private readonly EventManager _eventManager;
private readonly IRepository<Organization, Guid> _organizationRepository;
public EventManagerTests()
{
_testData = GetRequiredService<EventHubTestData>();
_eventManager = GetRequiredService<EventManager>();
_organizationRepository = GetRequiredService<IRepository<Organization, Guid>>();
}
[Fact]
public async Task Should_Create_A_Valid_Event()
{
await WithUnitOfWorkAsync(async () =>
{
var volosoftOrganization = await _organizationRepository.GetAsync(
_testData.OrganizationVolosoftId
);
var @event = await _eventManager.CreateAsync(
volosoftOrganization,
"Introduction to the ABP Framework",
DateTime.Now.AddDays(1),
DateTime.Now.AddDays(1).AddHours(3),
"In this event, we will introduce the ABP Framework and explore the fundamental features."
);
@event.OrganizationId.ShouldBe(volosoftOrganization.Id);
@event.Title.ShouldBe("Introduction to the ABP Framework");
});
}
}
}

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

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using EventHub.Events;
using EventHub.Organizations;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
@ -86,10 +87,16 @@ namespace EventHub
protected virtual async Task<Organization> GetOrganizationOrNullAsync(string name)
{
var organizationRepository = GetRequiredService<IRepository<Organization, Guid>>();
return await WithUnitOfWorkAsync(async () =>
{
return await organizationRepository.FirstOrDefaultAsync(o => o.Name == name);
}
return await WithUnitOfWorkAsync(
() => organizationRepository.FirstOrDefaultAsync(o => o.Name == name)
);
}
protected virtual async Task<Event> GetEventOrNullAsync(Guid id)
{
var organizationRepository = GetRequiredService<IRepository<Event, Guid>>();
return await WithUnitOfWorkAsync(
() => organizationRepository.FindAsync(id)
);
}
}

2
eventhub/test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

@ -46,7 +46,7 @@ namespace EventHub
var dotnetEurope = await _organizationRepository.InsertAsync(
await _organizationManager.CreateAsync(
_currentUser.GetId(),
Guid.NewGuid(), //TODO: create a second user and set its id!
_eventHubTestData.OrganizationDotnetEuropeName,
"Dotnet Europe",
"Organizing events on Microsoft's .NET Platform in European Countries."

Loading…
Cancel
Save