Skip to content

Commit 38eb041

Browse files
committed
Fixes #746
1 parent 5ec83b6 commit 38eb041

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Ardalis.SmartEnum;
2+
3+
namespace NimblePros.SampleToDo.Core.ProjectAggregate;
4+
5+
public class Priority : SmartEnum<Priority>
6+
{
7+
public static readonly Priority Backlog = new(nameof(Backlog), 0);
8+
public static readonly Priority Critical = new(nameof(Critical), 1);
9+
10+
protected Priority(string name, int value) : base(name, value) { }
11+
}

sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/PriorityStatus.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/Project.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ public class Project : EntityBase, IAggregateRoot
1212
public IEnumerable<ToDoItem> Items => _items.AsReadOnly();
1313
public ProjectStatus Status => _items.All(i => i.IsDone) ? ProjectStatus.Complete : ProjectStatus.InProgress;
1414

15-
public PriorityStatus Priority { get; }
15+
// Note: Probably it makes more sense to prioritize items, not projects, but this is just an example
16+
public Priority Priority { get; }
1617

17-
public Project(string name, PriorityStatus priority)
18+
public Project(string name, Priority priority)
1819
{
19-
Name = Guard.Against.NullOrEmpty(name, nameof(name));
20+
Name = Guard.Against.NullOrEmpty(name);
2021
Priority = priority;
2122
}
2223

2324
public void AddItem(ToDoItem newItem)
2425
{
25-
Guard.Against.Null(newItem, nameof(newItem));
26+
Guard.Against.Null(newItem);
2627
_items.Add(newItem);
2728

2829
var newItemAddedEvent = new NewItemAddedEvent(this, newItem);
@@ -31,6 +32,6 @@ public void AddItem(ToDoItem newItem)
3132

3233
public void UpdateName(string newName)
3334
{
34-
Name = Guard.Against.NullOrEmpty(newName, nameof(newName));
35+
Name = Guard.Against.NullOrEmpty(newName);
3536
}
3637
}

sample/src/NimblePros.SampleToDo.Infrastructure/Data/Config/ProjectConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public void Configure(EntityTypeBuilder<Project> builder)
1515
builder.Property(p => p.Priority)
1616
.HasConversion(
1717
p => p.Value,
18-
p => PriorityStatus.FromValue(p));
18+
p => Priority.FromValue(p));
1919
}
2020
}

sample/src/NimblePros.SampleToDo.UseCases/Projects/Create/CreateProjectHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public CreateProjectHandler(IRepository<Project> repository)
1616
public async Task<Result<int>> Handle(CreateProjectCommand request,
1717
CancellationToken cancellationToken)
1818
{
19-
var newProject = new Project(request.Name, PriorityStatus.Backlog);
19+
var newProject = new Project(request.Name, Priority.Backlog);
2020
var createdItem = await _repository.AddAsync(newProject, cancellationToken);
2121

2222
return createdItem.Id;

sample/src/NimblePros.SampleToDo.Web/SeedData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class SeedData
99
{
1010
public static readonly Contributor Contributor1 = new ("Ardalis");
1111
public static readonly Contributor Contributor2 = new ("Snowfrog");
12-
public static readonly Project TestProject1 = new Project("Test Project", PriorityStatus.Backlog);
12+
public static readonly Project TestProject1 = new Project("Test Project", Priority.Backlog);
1313
public static readonly ToDoItem ToDoItem1 = new ToDoItem
1414
{
1515
Title = "Get Sample Working",

sample/tests/NimblePros.SampleToDo.IntegrationTests/Data/EfRepositoryAdd.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public class EfRepositoryAdd : BaseEfRepoTestFixture
99
public async Task AddsProjectAndSetsId()
1010
{
1111
var testProjectName = "testProject";
12-
var testProjectStatus = PriorityStatus.Backlog;
12+
var testProjectPriority = Priority.Backlog;
1313
var repository = GetRepository();
14-
var project = new Project(testProjectName, testProjectStatus);
14+
var project = new Project(testProjectName, testProjectPriority);
1515

1616
await repository.AddAsync(project);
1717

1818
var newProject = (await repository.ListAsync())
1919
.FirstOrDefault();
2020

2121
Assert.Equal(testProjectName, newProject?.Name);
22-
Assert.Equal(testProjectStatus, newProject?.Priority);
22+
Assert.Equal(testProjectPriority, newProject?.Priority);
2323
Assert.True(newProject?.Id > 0);
2424
}
2525
}

sample/tests/NimblePros.SampleToDo.IntegrationTests/Data/EfRepositoryDelete.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public async Task DeletesItemAfterAddingIt()
1111
// add a project
1212
var repository = GetRepository();
1313
var initialName = Guid.NewGuid().ToString();
14-
var project = new Project(initialName, PriorityStatus.Backlog);
14+
var project = new Project(initialName, Priority.Backlog);
1515
await repository.AddAsync(project);
1616

1717
// delete the item

sample/tests/NimblePros.SampleToDo.IntegrationTests/Data/EfRepositoryUpdate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public async Task UpdatesItemAfterAddingIt()
1212
// add a project
1313
var repository = GetRepository();
1414
var initialName = Guid.NewGuid().ToString();
15-
var project = new Project(initialName, PriorityStatus.Backlog);
15+
var project = new Project(initialName, Priority.Backlog);
1616

1717
await repository.AddAsync(project);
1818

sample/tests/NimblePros.SampleToDo.UnitTests/Core/ProjectAggregate/ProjectConstructor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace NimblePros.SampleToDo.UnitTests.Core.ProjectAggregate;
66
public class ProjectConstructor
77
{
88
private string _testName = "test name";
9-
private PriorityStatus _testPriority = PriorityStatus.Backlog;
9+
private Priority _testPriority = Priority.Backlog;
1010
private Project? _testProject;
1111

1212
private Project CreateProject()

0 commit comments

Comments
 (0)