Browse Source

Don't allow set endtime before starttime.

pull/15/head
Halil İbrahim Kalkan 6 years ago
parent
commit
0bb13e535d
  1. 1
      eventhub/src/EventHub.Domain.Shared/EventHubErrorCodes.cs
  2. 1
      eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json
  3. 7
      eventhub/src/EventHub.Domain/Events/Event.cs
  4. 18
      eventhub/src/EventHub.Domain/Events/EventManager.cs
  5. 28
      eventhub/test/EventHub.Domain.Tests/Events/EventTests.cs

1
eventhub/src/EventHub.Domain.Shared/EventHubErrorCodes.cs

@ -4,5 +4,6 @@
{
public const string OrganizationNameAlreadyExists = "EventHub:OrganizationNameAlreadyExists";
public const string NotAuthorizedToCreateEventInThisOrganization = "EventHub:NotAuthorizedToCreateEventInThisOrganization";
public const string EventEndTimeCantBeEarlierThanStartTime = "EventHub:EventEndTimeCantBeEarlierThanStartTime";
}
}

1
eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json

@ -18,6 +18,7 @@
"DisplayName:Capacity": "Capacity",
"EventHub:OrganizationNameAlreadyExists": "The organization {Name} already exists. Please use another name.",
"EventHub:NotAuthorizedToCreateEventInThisOrganization": "You are not authorized to create events for the organization {OrganizationName}",
"EventHub:EventEndTimeCantBeEarlierThanStartTime": "Event end time can not be earlier than the start time.",
"Events": "Events",
"Members": "Members",
"SeeOrganization": "See Organization",

7
eventhub/src/EventHub.Domain/Events/Event.cs

@ -25,7 +25,7 @@ namespace EventHub.Events
}
public Event(
internal Event(
Guid id,
Guid organizationId,
string title,
@ -54,6 +54,11 @@ namespace EventHub.Events
public Event SetTime(DateTime startTime, DateTime endTime)
{
if (startTime > endTime)
{
throw new BusinessException(EventHubErrorCodes.EventEndTimeCantBeEarlierThanStartTime);
}
StartTime = startTime;
EndTime = endTime;
return this;

18
eventhub/src/EventHub.Domain/Events/EventManager.cs

@ -7,20 +7,22 @@ namespace EventHub.Events
{
public class EventManager : DomainService
{
public async Task<Event> CreateAsync(
public ValueTask<Event> CreateAsync(
Organization organization,
string title,
DateTime startTime,
DateTime endTime,
string description)
{
return new Event(
GuidGenerator.Create(),
organization.Id,
title,
startTime,
endTime,
description
return ValueTask.FromResult(
new Event(
GuidGenerator.Create(),
organization.Id,
title,
startTime,
endTime,
description
)
);
}
}

28
eventhub/test/EventHub.Domain.Tests/Events/EventTests.cs

@ -0,0 +1,28 @@
using System;
using Shouldly;
using Volo.Abp;
using Xunit;
namespace EventHub.Events
{
public class EventTests
{
[Fact]
public void Should_Not_Allow_End_Time_To_Be_Earlier_Than_Start_Time()
{
var exception = Assert.Throws<BusinessException>(() =>
{
new Event(
Guid.NewGuid(),
Guid.NewGuid(),
"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."
);
});
exception.Code.ShouldBe(EventHubErrorCodes.EventEndTimeCantBeEarlierThanStartTime);
}
}
}
Loading…
Cancel
Save