Browse Source

Add missing tests

pull/20/head
Berkan 6 years ago
parent
commit
f1946f2d09
  1. 47
      test/EventHub.Application.Tests/Events/EventAppServiceTests.cs
  2. 43
      test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs
  3. 20
      test/EventHub.Domain.Tests/Events/EventTests.cs
  4. 3
      test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

47
test/EventHub.Application.Tests/Events/EventAppServiceTests.cs

@ -1,5 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using EventHub.Events.Registrations;
using JetBrains.Annotations;
using Shouldly; using Shouldly;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Timing; using Volo.Abp.Timing;
@ -10,11 +12,13 @@ namespace EventHub.Events
public class EventAppServiceTests : EventHubApplicationTestBase public class EventAppServiceTests : EventHubApplicationTestBase
{ {
private readonly IEventAppService _eventAppService; private readonly IEventAppService _eventAppService;
private readonly IEventRegistrationAppService _eventRegistrationAppService;
private readonly EventHubTestData _testData; private readonly EventHubTestData _testData;
public EventAppServiceTests() public EventAppServiceTests()
{ {
_eventAppService = GetRequiredService<IEventAppService>(); _eventAppService = GetRequiredService<IEventAppService>();
_eventRegistrationAppService = GetRequiredService<IEventRegistrationAppService>();
_testData = GetRequiredService<EventHubTestData>(); _testData = GetRequiredService<EventHubTestData>();
} }
@ -29,7 +33,9 @@ namespace EventHub.Events
Description = "In this event, we will introduce the ABP Framework and explore the fundamental features.", Description = "In this event, we will introduce the ABP Framework and explore the fundamental features.",
StartTime = DateTime.Now.AddDays(1), StartTime = DateTime.Now.AddDays(1),
EndTime = DateTime.Now.AddDays(1).AddHours(3), EndTime = DateTime.Now.AddDays(1).AddHours(3),
IsOnline = true IsOnline = true,
Capacity = 2,
Language = "en"
} }
); );
@ -38,6 +44,8 @@ namespace EventHub.Events
eventDto.Description.ShouldBe("In this event, we will introduce the ABP Framework and explore the fundamental features."); eventDto.Description.ShouldBe("In this event, we will introduce the ABP Framework and explore the fundamental features.");
eventDto.IsOnline.ShouldBeTrue(); eventDto.IsOnline.ShouldBeTrue();
eventDto.UrlCode.ShouldNotBeNullOrWhiteSpace(); eventDto.UrlCode.ShouldNotBeNullOrWhiteSpace();
eventDto.Capacity.ShouldBe(2);
eventDto.Language.ShouldBe("en");
} }
[Fact] [Fact]
@ -112,5 +120,42 @@ namespace EventHub.Events
eventDetailDto.Title.ShouldBe(_testData.AbpBlazorPastEventTitle); eventDetailDto.Title.ShouldBe(_testData.AbpBlazorPastEventTitle);
eventDetailDto.UrlCode.ShouldBe(_testData.AbpBlazorPastEventUrlCode); eventDetailDto.UrlCode.ShouldBe(_testData.AbpBlazorPastEventUrlCode);
} }
[Fact]
public async Task Should_Get_Location()
{
var eventDto = await _eventAppService.CreateAsync(
new CreateEventDto
{
OrganizationId = _testData.OrganizationVolosoftId,
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(2),
EndTime = DateTime.Now.AddDays(2).AddHours(3),
IsOnline = true,
Capacity = 2,
Language = "en",
City = "Istanbul",
OnlineLink = "http://abp.io"
}
);
await _eventRegistrationAppService.RegisterAsync(eventDto.Id);
var result = await _eventAppService.GetLocationAsync(eventDto.Id);
result.ShouldNotBeNull();
result.IsOnline.ShouldBeTrue();
result.OnlineLink.ShouldBe("http://abp.io");
result.City.ShouldBeNull();
}
[Fact]
public async Task Should_Get_All_Countries()
{
var result = await _eventAppService.GetCountriesLookupAsync();
result.ShouldNotBeNull();
result.Count.ShouldBeGreaterThan(1);
}
} }
} }

43
test/EventHub.Application.Tests/Events/Registrations/EventRegistrationAppServiceTests.cs

@ -1,6 +1,9 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly; using Shouldly;
using Volo.Abp;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users; using Volo.Abp.Users;
using Xunit; using Xunit;
@ -12,19 +15,26 @@ namespace EventHub.Events.Registrations
private readonly IEventRegistrationAppService _eventRegistrationAppService; private readonly IEventRegistrationAppService _eventRegistrationAppService;
private readonly IRepository<EventRegistration, Guid> _eventRegistrationRepository; private readonly IRepository<EventRegistration, Guid> _eventRegistrationRepository;
private readonly EventHubTestData _testData; private readonly EventHubTestData _testData;
private readonly ICurrentUser _currentUser; private ICurrentUser _currentUser;
public EventRegistrationAppServiceTests() public EventRegistrationAppServiceTests()
{ {
_eventRegistrationAppService = GetRequiredService<IEventRegistrationAppService>(); _eventRegistrationAppService = GetRequiredService<IEventRegistrationAppService>();
_eventRegistrationRepository = GetRequiredService<IRepository<EventRegistration, Guid>>(); _eventRegistrationRepository = GetRequiredService<IRepository<EventRegistration, Guid>>();
_testData = GetRequiredService<EventHubTestData>(); _testData = GetRequiredService<EventHubTestData>();
_currentUser = GetRequiredService<ICurrentUser>(); }
protected override void AfterAddApplication(IServiceCollection services)
{
_currentUser = Substitute.For<ICurrentUser>();
services.AddSingleton(_currentUser);
} }
[Fact] [Fact]
public async Task Should_Register_To_An_Event() public async Task Should_Register_To_An_Event()
{ {
Login(_testData.UserAdminId);
await _eventRegistrationAppService.RegisterAsync( await _eventRegistrationAppService.RegisterAsync(
_testData.AbpMicroservicesFutureEventId _testData.AbpMicroservicesFutureEventId
); );
@ -38,6 +48,8 @@ namespace EventHub.Events.Registrations
[Fact] [Fact]
public async Task Should_Unregister_From_An_Event() public async Task Should_Unregister_From_An_Event()
{ {
Login(_testData.UserAdminId);
await WithUnitOfWorkAsync(async () => await WithUnitOfWorkAsync(async () =>
{ {
await _eventRegistrationRepository.InsertAsync( await _eventRegistrationRepository.InsertAsync(
@ -59,6 +71,27 @@ namespace EventHub.Events.Registrations
).ShouldBeNull(); ).ShouldBeNull();
} }
[Fact]
public async Task Should_Not_Be_Registered_For_Capacity_Is_Full()
{
Login(_testData.UserAdminId);
await _eventRegistrationAppService.RegisterAsync(
_testData.AbpMicroservicesFutureEventId
);
Login(_testData.UserJohnId);
var exception = await Assert.ThrowsAsync<BusinessException>(async () =>
{
await _eventRegistrationAppService.RegisterAsync(
_testData.AbpMicroservicesFutureEventId
);
});
exception.Code.ShouldBe(EventHubErrorCodes.CapacityOfEventFull);
}
[Fact] [Fact]
public async Task Should_Get_List_Of_Attendees() public async Task Should_Get_List_Of_Attendees()
{ {
@ -99,5 +132,11 @@ namespace EventHub.Events.Registrations
); );
}); });
} }
private void Login(Guid userId)
{
_currentUser.Id.Returns(userId);
_currentUser.IsAuthenticated.Returns(true);
}
} }
} }

20
test/EventHub.Domain.Tests/Events/EventTests.cs

@ -25,5 +25,25 @@ namespace EventHub.Events
exception.Code.ShouldBe(EventHubErrorCodes.EventEndTimeCantBeEarlierThanStartTime); exception.Code.ShouldBe(EventHubErrorCodes.EventEndTimeCantBeEarlierThanStartTime);
} }
[Fact]
public void Should_Be_CountryId_And_City_Null_If_Event_Online()
{
var @event = new Event(
Guid.NewGuid(),
Guid.NewGuid(),
"1a8j3v0d",
"Introduction to the ABP Framework",
DateTime.Now,
DateTime.Now.AddDays(2),
"In this event, we will introduce the ABP Framework and explore the fundamental features.");
@event.SetLocation(true, "http://abp.io", Guid.NewGuid(), "Istanbul");
@event.IsOnline.ShouldBeTrue();
@event.OnlineLink.ShouldBe("http://abp.io");
@event.CountryId.ShouldBeNull();
@event.City.ShouldBeNull();
}
} }
} }

3
test/EventHub.TestBase/EventHubTestDataSeedContributor.cs

@ -100,6 +100,9 @@ namespace EventHub
_clock.Now.ClearTime().AddDays(1).AddHours(17), _clock.Now.ClearTime().AddDays(1).AddHours(17),
"This is a future event about the ABP Framework and Microservices that is set for tomorrow." "This is a future event about the ABP Framework and Microservices that is set for tomorrow."
) )
{
Capacity = 1
}
); );
} }
} }

Loading…
Cancel
Save