-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a class representing paused trigger groups along with EF configur…
…ation.
- Loading branch information
1 parent
d14516c
commit 8ec9215
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...zNet.EntityFrameworkCore/Entities/Configurations/PausedTriggerGroupEntityConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace QuartzNet.EntityFrameworkCore.Entities.Configurations; | ||
|
||
public class PausedTriggerGroupEntityConfiguration : IEntityTypeConfiguration<PausedTriggerGroup> | ||
{ | ||
public void Configure(EntityTypeBuilder<PausedTriggerGroup> builder) | ||
{ | ||
builder.ToTable("PausedTriggerGroups", "Quartz"); | ||
builder.HasKey("SchedulerName", "TriggerGroup"); | ||
builder.Property(x => x.SchedulerName).IsRequired().HasMaxLength(120); | ||
builder.Property(x => x.TriggerGroup).IsRequired().HasMaxLength(150); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/QuartzNet.EntityFrameworkCore/Entities/PausedTriggerGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace QuartzNet.EntityFrameworkCore.Entities; | ||
|
||
public class PausedTriggerGroup | ||
{ | ||
public string SchedulerName { get; } | ||
public string TriggerGroup { get; } | ||
|
||
public PausedTriggerGroup(string schedulerName, string triggerGroup) | ||
{ | ||
if (schedulerName is null) | ||
{ | ||
throw new ArgumentNullException(nameof(schedulerName)); | ||
} | ||
|
||
if (schedulerName.Length is 0) | ||
{ | ||
throw new ArgumentException("The schedulerName parameter cannot be an empty string.", nameof(schedulerName)); | ||
} | ||
SchedulerName = schedulerName; | ||
|
||
if (triggerGroup is null) | ||
{ | ||
throw new ArgumentNullException(nameof(triggerGroup)); | ||
} | ||
|
||
if (triggerGroup.Length is 0) | ||
{ | ||
throw new ArgumentException("The triggerGroup parameter cannot be an empty string.", nameof(triggerGroup)); | ||
} | ||
TriggerGroup = triggerGroup; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...workCore.Tests.Unit/Entities/Configurations/PausedTriggerGroupEntityConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using Microsoft.EntityFrameworkCore; | ||
using QuartzNet.EntityFrameworkCore.Entities; | ||
using QuartzNet.EntityFrameworkCore.Entities.Configurations; | ||
|
||
namespace QuartzNet.EntityFrameworkCore.Tests.Unit.Entities.Configurations; | ||
|
||
public class PausedTriggerGroupEntityConfigurationTests : EntityTypeConfigurationTestsBase<PausedTriggerGroupEntityConfiguration, PausedTriggerGroup> | ||
{ | ||
[Fact] | ||
public void Configure_ConfiguresThePausedTriggerGroupEntityAsExpected() | ||
{ | ||
var sut = CreateSut(); | ||
var entityBuilder = GetEntityBuilder(); | ||
|
||
sut.Configure(entityBuilder); | ||
var metadata = entityBuilder.Metadata; | ||
|
||
using var scope = new AssertionScope(); | ||
metadata.GetSchema().Should().Be("Quartz"); | ||
metadata.GetTableName().Should().Be("PausedTriggerGroups"); | ||
var schedulerNameProperty = metadata.FindDeclaredProperty("SchedulerName"); | ||
ValidateModelProperty(schedulerNameProperty, x => | ||
{ | ||
x?.IsNullable.Should().BeFalse(); | ||
x?.GetMaxLength().Should().Be(120); | ||
x?.GetContainingKeys().Should().HaveCount(1); | ||
}); | ||
|
||
var triggerGroupProperty = metadata.FindDeclaredProperty("TriggerGroup"); | ||
ValidateModelProperty(triggerGroupProperty, x => | ||
{ | ||
x?.IsNullable.Should().BeFalse(); | ||
x?.GetMaxLength().Should().Be(150); | ||
x?.GetContainingKeys().Should().HaveCount(1); | ||
}); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
tests/QuartzNet.EntityFrameworkCore.Tests.Unit/Entities/PausedTriggerGroupTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using FluentAssertions; | ||
using QuartzNet.EntityFrameworkCore.Entities; | ||
|
||
namespace QuartzNet.EntityFrameworkCore.Tests.Unit.Entities; | ||
|
||
public class PausedTriggerGroupTests | ||
{ | ||
#region Private members. | ||
private string _schedulerName ="test scheduler"; | ||
private string _triggerGroup ="test group"; | ||
|
||
private PausedTriggerGroup CreateSut() => new(_schedulerName, _triggerGroup); | ||
#endregion | ||
|
||
#region Constructor tests. | ||
[Fact] | ||
public void AnArgumentNullExceptionShouldBeThrownWhenTheSchedulerNamePassedInIsNull() | ||
{ | ||
_schedulerName = null!; | ||
|
||
var act =CreateSut; | ||
|
||
act.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AnArgumentExceptionShouldBeThrownWhenTheSchedulerNamePassedInIsAnEmptyString() | ||
{ | ||
_schedulerName = String.Empty; | ||
|
||
var act = CreateSut; | ||
|
||
act.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[Fact] | ||
public void AnArgumentNullExceptionShouldBeThrownWhenTheTriggerGroupPassedInIsNull() | ||
{ | ||
_triggerGroup = null!; | ||
|
||
var act = CreateSut; | ||
|
||
act.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AnArgumentExceptionShouldBeThrownWhenTheTriggerGroupPassedInIsAnEmptyString() | ||
{ | ||
_triggerGroup = String.Empty; | ||
|
||
var act = CreateSut; | ||
|
||
act.Should().Throw<ArgumentException>(); | ||
} | ||
|
||
[Fact] | ||
public void APausedTriggerGroupInstanceShouldBeEnstantiatedWhenAllParametersAreValid() | ||
{ | ||
var result = CreateSut(); | ||
|
||
result.Should().NotBeNull(); | ||
} | ||
#endregion | ||
} |