Skip to content

Commit 23ce62d

Browse files
committed
fix(FileSystemTaskRepository): CanLoadTasksWhoseNameHaveWhitespaces
1 parent 6d1506e commit 23ce62d

3 files changed

Lines changed: 33 additions & 13 deletions

File tree

Desktop.Tests/Integration/FileSystemTaskRepositoryTest.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FluentAssertions;
55
using NUnit.Framework;
66
using static Desktop.Tests.TestAPI.TaskFactory;
7+
using static Desktop.Tasks.FileSystemTaskRepository;
78
using Task = Desktop.Domain.Task;
89
using SystemTask = System.Threading.Tasks.Task;
910

@@ -85,6 +86,26 @@ public async SystemTask CanLoadSeveralPersistedTasks()
8586
result.Succeeded.Should().BeTrue();
8687
}
8788

89+
[Test]
90+
[Category("Regression")]
91+
public async SystemTask CanLoadTasksWhoseNameHaveWhitespaces()
92+
{
93+
var taskName = "Task named with whitespaces";
94+
PersistTask(taskName);
95+
var sut = new FileSystemTaskRepository();
96+
97+
var result = await sut.All();
98+
99+
result.Tasks.Should().BeEquivalentTo(
100+
[
101+
new Task(
102+
name: taskName,
103+
description: string.Empty)
104+
],
105+
options => options.ComparingByMembers<Task>().Excluding(x => x.Id));
106+
result.Succeeded.Should().BeTrue();
107+
}
108+
88109
[Test]
89110
public async SystemTask CanPersistTasksWhenNoOtherExistedBefore()
90111
{
@@ -193,7 +214,8 @@ private static void PersistTask(string name, string description = null)
193214

194215
File.AppendAllText(
195216
PersistedTasksFileName,
196-
$"{id} {name} {description ?? string.Empty}{Environment.NewLine}");
217+
$"{id}{LineElementSeparator}{name}{LineElementSeparator}{description ?? string.Empty}" +
218+
$"{Environment.NewLine}");
197219
}
198220

199221
[TearDown]

Desktop/TODO.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
- fix(file system repository): tasks names with whitespaces are trimmed so that only the first word is displayed
2-
- feat: Flow metrics (MonteCSharp integration)
1+
- feat: Flow metrics (MonteCSharp integration)
32
- test: ensure coverage for the sln and review testing strategy
43
- feat: Tasks may have other child Tasks
54
- feat: show tasks in as project tree

Desktop/Tasks/FileSystemTaskRepository.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Desktop.Tasks;
77
public class FileSystemTaskRepository : ITaskRepository
88
{
99
private const string PersistedTasksFileName = "Tasks.txt";
10+
public const string LineElementSeparator = "|";
1011

1112
public Task<ResultWithValue> All()
1213
{
@@ -23,19 +24,16 @@ public Task<ResultWithValue> All()
2324

2425
private static Task ToTask(string line)
2526
{
27+
var lineElements = line.Split(LineElementSeparator);
28+
2629
return new Task(
27-
id: Guid.Parse(SplitBySpaces(line).ElementAt(0)),
28-
name: SplitBySpaces(line).ElementAt(1),
29-
description: SplitBySpaces(line).Length > 1
30-
? SplitBySpaces(line).Last()
30+
id: Guid.Parse(lineElements.ElementAt(0)),
31+
name: lineElements.ElementAt(1),
32+
description: lineElements.Length > 1
33+
? lineElements.Last()
3134
: string.Empty);
3235
}
3336

34-
private static string[] SplitBySpaces(string line)
35-
{
36-
return line.Split(' ');
37-
}
38-
3937
public async Task<ResultWithoutValue> Save(Task task)
4038
{
4139
var existingTasks = await All();
@@ -44,7 +42,8 @@ public async Task<ResultWithoutValue> Save(Task task)
4442

4543
await File.AppendAllTextAsync(
4644
PersistedTasksFileName,
47-
$"{task.Id} {task.Name} {task.Description}{Environment.NewLine}");
45+
$"{task.Id}{LineElementSeparator}{task.Name}{LineElementSeparator}{task.Description}" +
46+
$"{Environment.NewLine}");
4847

4948
return ResultWithoutValue.Success();
5049
}

0 commit comments

Comments
 (0)