Browse Source

Created EventRegistrationAppService.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
0377b4d80c
  1. 13
      eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs
  2. 44
      eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs
  3. 1
      eventhub/src/EventHub.Domain/Properties/AssemblyInfo.cs
  4. 72
      eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs

13
eventhub/src/EventHub.Application.Contracts/Events/Registrations/IEventRegistrationAppService.cs

@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace EventHub.Events.Registrations
{
public interface IEventRegistrationAppService : IApplicationService
{
Task RegisterAsync(Guid id);
Task UnregisterAsync(Guid id);
}
}

44
eventhub/src/EventHub.Application/Events/Registrations/EventRegistrationAppService.cs

@ -0,0 +1,44 @@
using System;
using System.Threading.Tasks;
using EventHub.Users;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users;
namespace EventHub.Events.Registrations
{
public class EventRegistrationAppService : EventHubAppService, IEventRegistrationAppService
{
private readonly EventRegistrationManager _eventRegistrationManager;
private readonly IRepository<AppUser, Guid> _userRepository;
private readonly IRepository<Event, Guid> _eventRepository;
public EventRegistrationAppService(
EventRegistrationManager eventRegistrationManager,
IRepository<AppUser, Guid> userRepository,
IRepository<Event, Guid> eventRepository)
{
_eventRegistrationManager = eventRegistrationManager;
_userRepository = userRepository;
_eventRepository = eventRepository;
}
[Authorize]
public async Task RegisterAsync(Guid id)
{
await _eventRegistrationManager.RegisterAsync(
await _eventRepository.GetAsync(id),
await _userRepository.GetAsync(CurrentUser.GetId())
);
}
[Authorize]
public async Task UnregisterAsync(Guid id)
{
await _eventRegistrationManager.UnregisterAsync(
await _eventRepository.GetAsync(id),
await _userRepository.GetAsync(CurrentUser.GetId())
);
}
}
}

1
eventhub/src/EventHub.Domain/Properties/AssemblyInfo.cs

@ -1,3 +1,4 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly:InternalsVisibleToAttribute("EventHub.Application.Tests")]
[assembly:InternalsVisibleToAttribute("EventHub.Domain.Tests")] [assembly:InternalsVisibleToAttribute("EventHub.Domain.Tests")]
[assembly:InternalsVisibleToAttribute("EventHub.TestBase")] [assembly:InternalsVisibleToAttribute("EventHub.TestBase")]

72
eventhub/test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs

@ -0,0 +1,72 @@
using System;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users;
using Xunit;
namespace EventHub.Events.Registrations
{
public class EventRegistrationAppServiceTests : EventHubApplicationTestBase
{
private readonly IEventRegistrationAppService _eventRegistrationAppService;
private readonly IRepository<EventRegistration, Guid> _eventRegistrationRepository;
private readonly EventHubTestData _testData;
private readonly ICurrentUser _currentUser;
public EventRegistrationAppServiceTests()
{
_eventRegistrationAppService = GetRequiredService<IEventRegistrationAppService>();
_eventRegistrationRepository = GetRequiredService<IRepository<EventRegistration, Guid>>();
_testData = GetRequiredService<EventHubTestData>();
_currentUser = GetRequiredService<ICurrentUser>();
}
[Fact]
public async Task Should_Register_To_An_Event()
{
await _eventRegistrationAppService.RegisterAsync(
_testData.AbpMicroservicesFutureEventId
);
(await GetRegistrationOrNull(
_testData.AbpMicroservicesFutureEventId,
_currentUser.GetId()
)).ShouldNotBeNull();
}
[Fact]
public async Task Should_Unregister_From_An_Event()
{
await WithUnitOfWorkAsync(async () =>
{
await _eventRegistrationRepository.InsertAsync(
new EventRegistration(
Guid.NewGuid(),
_testData.AbpMicroservicesFutureEventId,
_currentUser.GetId()
)
);
});
await _eventRegistrationAppService.UnregisterAsync(
_testData.AbpMicroservicesFutureEventId
);
(await GetRegistrationOrNull(
_testData.AbpMicroservicesFutureEventId,
_currentUser.GetId())
).ShouldBeNull();
}
private async Task<EventRegistration> GetRegistrationOrNull(Guid eventId, Guid userId)
{
return await WithUnitOfWorkAsync(async () =>
{
return await _eventRegistrationRepository.FirstOrDefaultAsync(
x => x.EventId == eventId && x.UserId == userId
);
});
}
}
}
Loading…
Cancel
Save