Browse Source

added more tests

pull/74/merge
Halil İbrahim Kalkan 5 years ago
parent
commit
4872859872
  1. 22
      src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs
  2. 27
      test/EventHub.Domain.Tests/Events/Event_Tests.cs
  3. 73
      test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationManager_UnitTests.cs

22
src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs

@ -1,17 +1,26 @@
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Services;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.Timing;
namespace EventHub.Events.Registrations
{
public class EventRegistrationManager : DomainService
public class EventRegistrationManager : IDomainService
{
private readonly IEventRegistrationRepository _eventRegistrationRepository;
private readonly IGuidGenerator _guidGenerator;
private readonly IClock _clock;
public EventRegistrationManager(IEventRegistrationRepository eventRegistrationRepository)
public EventRegistrationManager(
IEventRegistrationRepository eventRegistrationRepository,
IGuidGenerator guidGenerator,
IClock clock)
{
_eventRegistrationRepository = eventRegistrationRepository;
_guidGenerator = guidGenerator;
_clock = clock;
}
public async Task RegisterAsync(
@ -38,7 +47,7 @@ namespace EventHub.Events.Registrations
await _eventRegistrationRepository.InsertAsync(
new EventRegistration(
GuidGenerator.Create(),
_guidGenerator.Create(),
@event.Id,
user.Id
)
@ -69,12 +78,7 @@ namespace EventHub.Events.Registrations
public bool IsPastEvent(Event @event)
{
if (Clock.Now > @event.EndTime)
{
return true;
}
return false;
return _clock.Now > @event.EndTime;
}
}
}

27
test/EventHub.Domain.Tests/Events/Event_Tests.cs

@ -21,6 +21,33 @@ namespace EventHub.Events
);
}
[Fact]
public void Should_Update_Event_Time()
{
// ARRANGE
var evnt = new Event(
Guid.NewGuid(),
Guid.NewGuid(),
"1a8j3v0d",
"Introduction to the ABP Framework",
DateTime.Now,
DateTime.Now.AddHours(2),
"In this event, we will introduce the ABP Framework..."
);
var newStartTime = DateTime.Now.AddHours(1);
var newEndTime = DateTime.Now.AddHours(2);
//ACT
evnt.SetTime(newStartTime, newEndTime);
//ASSERT
evnt.StartTime.ShouldBe(newStartTime);
evnt.EndTime.ShouldBe(newEndTime);
evnt.GetLocalEvents()
.ShouldContain(x => x.EventData is EventTimeChangingEventData);
}
[Fact]
public void Should_Not_Allow_End_Time_Earlier_Than_Start_Time()
{

73
test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationManager_UnitTests.cs

@ -0,0 +1,73 @@
using NSubstitute;
using Shouldly;
using System;
using System.Threading.Tasks;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.Timing;
using Xunit;
namespace EventHub.Events.Registrations
{
public class EventRegistrationManager_UnitTests
{
[Fact]
public void IsPastEvent()
{
var clock = Substitute.For<IClock>();
clock.Now.Returns(DateTime.Now);
var registrationManager = new EventRegistrationManager(
null, null, clock
);
var evnt = new Event(
Guid.NewGuid(),
Guid.NewGuid(),
"1a8j3v0d",
"Introduction to the ABP Framework",
DateTime.Now.AddDays(-10), // Start time
DateTime.Now.AddDays(-9), // End time
"In this event, we will introduce the ABP Framework..."
);
registrationManager.IsPastEvent(evnt).ShouldBeTrue();
}
[Fact]
public async Task RegisterAsync()
{
var evnt = new Event(
Guid.NewGuid(),
Guid.NewGuid(),
"1a8j3v0d",
"Introduction to the ABP Framework",
DateTime.Now.AddDays(1),
DateTime.Now.AddDays(2),
"In this event, we will introduce the ABP Framework..."
);
var user = new IdentityUser(Guid.NewGuid(), "john", "john@abp.io");
var repository = Substitute.For<IEventRegistrationRepository>();
repository.ExistsAsync(evnt.Id, user.Id).Returns(Task.FromResult(false));
var guidGenerator = SimpleGuidGenerator.Instance;
var clock = Substitute.For<IClock>();
clock.Now.Returns(DateTime.Now);
var registrationManager = new EventRegistrationManager(
repository, guidGenerator, clock
);
await registrationManager.RegisterAsync(evnt, user);
await repository
.Received()
.InsertAsync(
Arg.Is<EventRegistration>(er => er.EventId == evnt.Id && er.UserId == user.Id)
);
}
}
}
Loading…
Cancel
Save