Skip to content

Commit 2d73457

Browse files
committed
リファクタリング
1 parent 736a1ad commit 2d73457

File tree

70 files changed

+1062
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1062
-950
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
2+
23
using Shouldly;
34

45
namespace RemoteLogViewer.Core.Tests.Models.Ssh.FileViewer.ByteOffsetMap;
@@ -9,51 +10,51 @@ public void NewIndex_ShouldHaveCountZero_AndFindReturnsDefault() {
910
var index = new ByteOffsetIndex();
1011

1112
index.Count.ShouldBe(0);
12-
index.Find(0).ShouldBe(new (0,0));
13-
index.Find(10).ShouldBe(new (0,0));
13+
index.Find(0).ShouldBe(new(0, 0));
14+
index.Find(10).ShouldBe(new(0, 0));
1415
}
1516

1617
[Fact]
1718
public void Add_ShouldIncreaseCount_AndAffectFind() {
1819
var index = new ByteOffsetIndex();
19-
index.Add(new (5,50));
20-
index.Add(new (10,120));
20+
index.Add(new(5, 50));
21+
index.Add(new(10, 120));
2122

2223
index.Count.ShouldBe(2);
2324

2425
// targetLine が最初のエントリと等しい場合は、条件が "< targetLine"なので既定値が返る
25-
index.Find(5).ShouldBe(new (0,0));
26+
index.Find(5).ShouldBe(new(0, 0));
2627
// targetLine が5 と10 の間なら行5 のエントリが返る
27-
index.Find(7).ShouldBe(new (5,50));
28+
index.Find(7).ShouldBe(new(5, 50));
2829
// targetLine が10 と等しい場合も行5 のエントリが返る
29-
index.Find(10).ShouldBe(new (5,50));
30+
index.Find(10).ShouldBe(new(5, 50));
3031
// targetLine が最後の行番号より大きければ最後のエントリが返る
31-
index.Find(100).ShouldBe(new (10,120));
32+
index.Find(100).ShouldBe(new(10, 120));
3233
}
3334

3435
[Fact]
3536
public void AddRange_ShouldAppendEntriesInOrder() {
3637
var index = new ByteOffsetIndex();
37-
index.Add(new (2,20));
38-
index.AddRange([new (5, 55), new (9, 99)]);
38+
index.Add(new(2, 20));
39+
index.AddRange([new(5, 55), new(9, 99)]);
3940

4041
index.Count.ShouldBe(3);
4142

42-
index.Find(1).ShouldBe(new (0,0));
43-
index.Find(3).ShouldBe(new (2,20));
44-
index.Find(6).ShouldBe(new (5,55));
45-
index.Find(10).ShouldBe(new (9,99));
43+
index.Find(1).ShouldBe(new(0, 0));
44+
index.Find(3).ShouldBe(new(2, 20));
45+
index.Find(6).ShouldBe(new(5, 55));
46+
index.Find(10).ShouldBe(new(9, 99));
4647
}
4748

4849
[Fact]
4950
public void Reset_ShouldClearAllEntries() {
5051
var index = new ByteOffsetIndex();
51-
index.Add(new (1,10));
52-
index.Add(new (2,30));
52+
index.Add(new(1, 10));
53+
index.Add(new(2, 30));
5354
index.Count.ShouldBe(2);
5455

5556
index.Reset();
5657
index.Count.ShouldBe(0);
57-
index.Find(100).ShouldBe(new (0,0));
58+
index.Find(100).ShouldBe(new(0, 0));
5859
}
5960
}

RemoteLogViewer.Core.Tests/Models/Ssh/FileViewer/Operation/BuildByteOffsetMapOperationTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using Microsoft.Extensions.Logging;
2+
23
using Moq;
4+
35
using R3;
6+
47
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
58
using RemoteLogViewer.Core.Models.Ssh.FileViewer.Operation;
69
using RemoteLogViewer.Core.Services.Ssh;
10+
711
using Shouldly;
812

913
namespace RemoteLogViewer.Core.Tests.Models.Ssh.FileViewer.Operation;

RemoteLogViewer.Core.Tests/Models/Ssh/FileViewer/Operation/GrepOperationTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// TextLine
22

33
using Microsoft.Extensions.Logging;
4+
45
using Moq;
6+
57
using R3;
8+
69
using RemoteLogViewer.Core.Models.Ssh.FileViewer;
710
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
811
using RemoteLogViewer.Core.Models.Ssh.FileViewer.Operation;
912
using RemoteLogViewer.Core.Services.Ssh;
13+
1014
using Shouldly;
1115

1216
namespace RemoteLogViewer.Core.Tests.Models.Ssh.FileViewer.Operation;
@@ -35,17 +39,17 @@ public async Task RunAsync_ShouldPublishLinesAndProgress() {
3539
op.ReceivedLineCount.CurrentValue.ShouldBe(0);
3640

3741
subject.OnNext(l1);
38-
await WaitUntilAsync(() => list.Count,1);
42+
await WaitUntilAsync(() => list.Count, 1);
3943
list.ShouldBe([l1]);
4044
op.IsRunning.CurrentValue.ShouldBeTrue();
41-
op.Progress.CurrentValue.ShouldBe(l1.LineNumber / 1000d,0.001);
45+
op.Progress.CurrentValue.ShouldBe(l1.LineNumber / 1000d, 0.001);
4246
op.ReceivedLineCount.CurrentValue.ShouldBe(10);
4347

4448
subject.OnNext(l2);
45-
await WaitUntilAsync(() => list.Count,2);
49+
await WaitUntilAsync(() => list.Count, 2);
4650
list.ShouldBe([l1, l2]);
4751
op.IsRunning.CurrentValue.ShouldBeTrue();
48-
op.Progress.CurrentValue.ShouldBe(l2.LineNumber / 1000d,0.001);
52+
op.Progress.CurrentValue.ShouldBe(l2.LineNumber / 1000d, 0.001);
4953
op.ReceivedLineCount.CurrentValue.ShouldBe(200);
5054

5155
subject.OnCompleted();
@@ -74,11 +78,11 @@ public async Task RunAsync_Cancel_ShouldStopEarly() {
7478

7579
subject.OnNext(l1);
7680
subject.OnNext(l2);
77-
await WaitUntilAsync(() => list.Count,2);
81+
await WaitUntilAsync(() => list.Count, 2);
7882

7983
list.ShouldBe([l1, l2]);
8084
op.IsRunning.CurrentValue.ShouldBeTrue();
81-
op.Progress.CurrentValue.ShouldBe(l2.LineNumber / 1000d,0.001);
85+
op.Progress.CurrentValue.ShouldBe(l2.LineNumber / 1000d, 0.001);
8286
op.ReceivedLineCount.CurrentValue.ShouldBe(200);
8387

8488
cts.Cancel();

RemoteLogViewer.Core.Tests/Models/Ssh/FileViewer/Operation/SaveRangeContentOperationTests.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// TextLine
22

33
using Microsoft.Extensions.Logging;
4+
45
using Moq;
6+
57
using R3;
8+
69
using RemoteLogViewer.Core.Models.Ssh.FileViewer;
710
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
811
using RemoteLogViewer.Core.Models.Ssh.FileViewer.Operation;
912
using RemoteLogViewer.Core.Services.Ssh;
13+
1014
using Shouldly;
1115

1216
namespace RemoteLogViewer.Core.Tests.Models.Ssh.FileViewer.Operation;
@@ -22,17 +26,17 @@ private IByteOffsetIndex CreateIndex(params ByteOffset[] values) {
2226
public async Task ExecuteAsync_ShouldWriteAllLinesAndUpdateProgress() {
2327
var subject = new Subject<TextLine>();
2428
var sshMock = new Mock<ISshService>();
25-
sshMock.Setup(s => s.GetLinesAsync("file.log",1,3, null, It.IsAny<ByteOffset>(), It.IsAny<CancellationToken>()))
29+
sshMock.Setup(s => s.GetLinesAsync("file.log", 1, 3, null, It.IsAny<ByteOffset>(), It.IsAny<CancellationToken>()))
2630
.Returns((string _, long _, long _, string? _, ByteOffset bo, CancellationToken t) => subject.ToAsyncEnumerable(t));
2731

2832
using var opRegistry = new OperationRegistry();
2933
var loggerMock = new Mock<ILogger<SaveRangeContentOperation>>();
30-
var index = this.CreateIndex(new ByteOffset(0,0));
34+
var index = this.CreateIndex(new ByteOffset(0, 0));
3135
var op = new SaveRangeContentOperation(opRegistry, index, loggerMock.Object);
3236

3337
var ms = new MemoryStream();
3438
using var writer = new StreamWriter(ms, new System.Text.UTF8Encoding(encoderShouldEmitUTF8Identifier: false), leaveOpen: true);
35-
var task = op.ExecuteAsync(sshMock.Object, "file.log", writer,1,3, null, CancellationToken.None);
39+
var task = op.ExecuteAsync(sshMock.Object, "file.log", writer, 1, 3, null, CancellationToken.None);
3640

3741
subject.OnNext(new TextLine(1, "A"));
3842
subject.OnNext(new TextLine(2, "B"));
@@ -45,7 +49,7 @@ public async Task ExecuteAsync_ShouldWriteAllLinesAndUpdateProgress() {
4549
op.IsRunning.CurrentValue.ShouldBeFalse();
4650
op.TotalLines.CurrentValue.ShouldBe(3);
4751
op.SavedLines.CurrentValue.ShouldBe(3);
48-
op.Progress.CurrentValue.ShouldBe(1.0,0.001);
52+
op.Progress.CurrentValue.ShouldBe(1.0, 0.001);
4953
text.ShouldBe("A\nB\nC".Replace("\n", Environment.NewLine));
5054
}
5155

@@ -54,16 +58,16 @@ public async Task ExecuteAsync_Cancel_ShouldStopEarly() {
5458
var cts = new CancellationTokenSource();
5559
var subject = new Subject<TextLine>();
5660
var sshMock = new Mock<ISshService>();
57-
sshMock.Setup(s => s.GetLinesAsync("file.log",1,5, null, It.IsAny<ByteOffset>(), It.IsAny<CancellationToken>()))
61+
sshMock.Setup(s => s.GetLinesAsync("file.log", 1, 5, null, It.IsAny<ByteOffset>(), It.IsAny<CancellationToken>()))
5862
.Returns((string _, long _, long _, string? _, ByteOffset bo, CancellationToken t) => subject.ToAsyncEnumerable(t));
5963

6064
using var opRegistry = new OperationRegistry();
6165
var loggerMock = new Mock<ILogger<SaveRangeContentOperation>>();
62-
var index = this.CreateIndex(new ByteOffset(0,0));
66+
var index = this.CreateIndex(new ByteOffset(0, 0));
6367
var op = new SaveRangeContentOperation(opRegistry, index, loggerMock.Object);
6468
var ms = new MemoryStream();
6569
using var writer = new StreamWriter(ms, new System.Text.UTF8Encoding(encoderShouldEmitUTF8Identifier: false), leaveOpen: true);
66-
var task = op.ExecuteAsync(sshMock.Object, "file.log", writer,1,5, null, cts.Token);
70+
var task = op.ExecuteAsync(sshMock.Object, "file.log", writer, 1, 5, null, cts.Token);
6771

6872
try {
6973
subject.OnNext(new TextLine(1, "A"));
@@ -72,14 +76,14 @@ public async Task ExecuteAsync_Cancel_ShouldStopEarly() {
7276
await WaitUntilAsync(() => op.SavedLines.CurrentValue, 3);
7377
cts.Cancel();
7478
await task;
75-
}catch (OperationCanceledException) {}
79+
} catch (OperationCanceledException) { }
7680
await writer.FlushAsync();
7781
var text = System.Text.Encoding.UTF8.GetString(ms.ToArray()).TrimEnd();
7882

7983
op.IsRunning.CurrentValue.ShouldBeFalse();
8084
op.TotalLines.CurrentValue.ShouldBe(5);
8185
op.SavedLines.CurrentValue.ShouldBe(3);
82-
op.Progress.CurrentValue.ShouldBe(0.6,0.05);
86+
op.Progress.CurrentValue.ShouldBe(0.6, 0.05);
8387
text.ShouldBe("A\nB\nC".Replace("\n", Environment.NewLine));
8488
}
8589

@@ -88,11 +92,11 @@ public async Task ExecuteAsync_InvalidRange_ShouldDoNothing() {
8892
var sshMock = new Mock<ISshService>();
8993
using var opRegistry = new OperationRegistry();
9094
var loggerMock = new Mock<ILogger<SaveRangeContentOperation>>();
91-
var index = this.CreateIndex(new ByteOffset(0,0));
95+
var index = this.CreateIndex(new ByteOffset(0, 0));
9296
var op = new SaveRangeContentOperation(opRegistry, index, loggerMock.Object);
9397
var ms = new MemoryStream();
9498
using var writer = new StreamWriter(ms, new System.Text.UTF8Encoding(encoderShouldEmitUTF8Identifier: false), leaveOpen: true);
95-
await op.ExecuteAsync(sshMock.Object, "file.log", writer,5,3, null, CancellationToken.None);
99+
await op.ExecuteAsync(sshMock.Object, "file.log", writer, 5, 3, null, CancellationToken.None);
96100
await writer.FlushAsync();
97101
op.SavedLines.CurrentValue.ShouldBe(0);
98102
op.TotalLines.CurrentValue.ShouldBe(0);
@@ -105,11 +109,11 @@ public async Task ExecuteAsync_NullPath_ShouldDoNothing() {
105109
var sshMock = new Mock<ISshService>();
106110
using var opRegistry = new OperationRegistry();
107111
var loggerMock = new Mock<ILogger<SaveRangeContentOperation>>();
108-
var index = this.CreateIndex(new ByteOffset(0,0));
112+
var index = this.CreateIndex(new ByteOffset(0, 0));
109113
var op = new SaveRangeContentOperation(opRegistry, index, loggerMock.Object);
110114
var ms = new MemoryStream();
111115
using var writer = new StreamWriter(ms, new System.Text.UTF8Encoding(encoderShouldEmitUTF8Identifier: false), leaveOpen: true);
112-
await op.ExecuteAsync(sshMock.Object, null, writer,1,3, null, CancellationToken.None);
116+
await op.ExecuteAsync(sshMock.Object, null, writer, 1, 3, null, CancellationToken.None);
113117
await writer.FlushAsync();
114118
op.IsRunning.CurrentValue.ShouldBeFalse();
115119
op.SavedLines.CurrentValue.ShouldBe(0);

RemoteLogViewer.Core.Tests/TestHelpers/AsyncHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22

3-
namespace RemoteLogViewer.Core.Tests.TestHelpers;
3+
namespace RemoteLogViewer.Core.Tests.TestHelpers;
4+
45
internal class AsyncHelper {
56
public static async Task WaitUntilAsync<T>(Func<T> valueFunc, T expected, int timeoutMs = 1000, int intervalMs = 5) {
67
var sw = Stopwatch.StartNew();

RemoteLogViewer.Core.Tests/Utils/Extensions/ObservableExTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using Microsoft.Extensions.Time.Testing;
2+
23
using R3;
4+
35
using RemoteLogViewer.Core.Utils.Extensions;
6+
47
using Shouldly;
58

69
namespace RemoteLogViewer.Core.Tests.Utils.Extensions;
@@ -162,7 +165,7 @@ public async Task Throttle_ShouldThrottleValues() {
162165

163166
// Assert
164167
// 間引かれるはず
165-
results.ShouldBe([3,6,8 ]);
168+
results.ShouldBe([3, 6, 8]);
166169
}
167170
#endregion
168171

RemoteLogViewer.Core/Models/Ssh/FileViewer/Operation/BuildByteOffsetMapOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.Generic;
22
using System.Runtime.CompilerServices;
33
using System.Threading;
4+
45
using Microsoft.Extensions.Logging;
6+
57
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
68
using RemoteLogViewer.Core.Services.Ssh;
79
using RemoteLogViewer.Core.Utils;

RemoteLogViewer.Core/Models/Ssh/FileViewer/Operation/GrepOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Collections.Generic;
22
using System.Runtime.CompilerServices;
33
using System.Threading;
4+
45
using Microsoft.Extensions.Logging;
6+
57
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
68
using RemoteLogViewer.Core.Services.Ssh;
79
using RemoteLogViewer.Core.Utils;
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
using System.Collections.Generic;
22
using System.Threading;
3+
34
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
45
using RemoteLogViewer.Core.Services.Ssh;
56

67
namespace RemoteLogViewer.Core.Models.Ssh.FileViewer.Operation;
78

89
public interface IBuildByteOffsetMapOperation : IDisposable {
9-
public ReadOnlyReactiveProperty<bool> IsRunning { get; }
10-
public ReadOnlyReactiveProperty<ulong> ProcessedBytes { get; }
11-
public ReadOnlyReactiveProperty<double> Progress { get; }
10+
public ReadOnlyReactiveProperty<bool> IsRunning {
11+
get;
12+
}
13+
public ReadOnlyReactiveProperty<ulong> ProcessedBytes {
14+
get;
15+
}
16+
public ReadOnlyReactiveProperty<double> Progress {
17+
get;
18+
}
1219
public IAsyncEnumerable<ByteOffset> RunAsync(ISshService sshService, string? filePath, int chunkSize, ulong totalBytes, ByteOffset? startByteOffset, CancellationToken ct);
1320
public void Reset();
1421
}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
using System.Collections.Generic;
22
using System.Threading;
3+
34
using RemoteLogViewer.Core.Models.Ssh.FileViewer.ByteOffsetMap;
45
using RemoteLogViewer.Core.Services.Ssh;
56

67
namespace RemoteLogViewer.Core.Models.Ssh.FileViewer.Operation;
78

89
public interface IGrepOperation : IDisposable {
9-
public ReadOnlyReactiveProperty<bool> IsRunning { get; }
10-
public ReactiveProperty<long> TotalLineCount { get; }
11-
public ReadOnlyReactiveProperty<long> ReceivedLineCount { get; }
12-
public ReadOnlyReactiveProperty<double> Progress { get; }
10+
public ReadOnlyReactiveProperty<bool> IsRunning {
11+
get;
12+
}
13+
public ReactiveProperty<long> TotalLineCount {
14+
get;
15+
}
16+
public ReadOnlyReactiveProperty<long> ReceivedLineCount {
17+
get;
18+
}
19+
public ReadOnlyReactiveProperty<double> Progress {
20+
get;
21+
}
1322
public IAsyncEnumerable<TextLine> RunAsync(ISshService sshService, string? filePath, string? query, string? encoding, ByteOffset startOffset, long startLine, int maxResults, bool ignoreCase, bool useRegex, CancellationToken ct);
1423
}

0 commit comments

Comments
 (0)