Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ Report progression with ease by using multilple components such as Bars, Spinner

```csharp
using var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(BarDescriptor.Default)
.Build(Worker.AllItems);
Expand Down Expand Up @@ -44,6 +38,14 @@ var descriptor = BarDescriptor.Default;
### Define the reporter to use the component
```csharp
var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(descriptor)
.Build(Worker.AllItems);
Expand All @@ -59,3 +61,21 @@ reporter.Start();
reporter.ReportSuccess()
reporter.ReportFailure()
```

### Collect stats while running
```csharp
var onProgress = (Stats stats) =>
{
// TODO: Do something useful
};

var onCompletion = (Stats stats) =>
{
// TODO: Do something useful
};

var reporter = new ReporterBuilder()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.Build(Worker.AllItems);
```
12 changes: 12 additions & 0 deletions src/Progress.Samples.Bar.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
using Progress.Descriptors;
using Progress.Samples;

var onProgress = (Stats stats) =>
{
// TODO: Do something useful
};

var onCompletion = (Stats stats) =>
{
// TODO: Do something useful
};

using var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(BarDescriptor.Default)
.Build(Worker.AllItems);
Expand Down
12 changes: 12 additions & 0 deletions src/Progress.Samples.HearthBeat.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
using Progress.Descriptors;
using Progress.Samples;

var onProgress = (Stats stats) =>
{
// TODO: Do something useful
};

var onCompletion = (Stats stats) =>
{
// TODO: Do something useful
};

using var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(HearthBeatDescriptor.Default)
.Build(Worker.AllItems);
Expand Down
13 changes: 13 additions & 0 deletions src/Progress.Samples.Pulse.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
using Progress.Descriptors;
using Progress.Samples;

var onProgress = (Stats stats) =>
{
// TODO: Do something useful
};

var onCompletion = (Stats stats) =>
{
// TODO: Do something useful
};


using var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(PulseDescriptor.Default)
.Build(Worker.AllItems);
Expand Down
13 changes: 13 additions & 0 deletions src/Progress.Samples.Spinner.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
using Progress.Descriptors;
using Progress.Samples;

var onProgress = (Stats stats) =>
{
// TODO: Do something useful
};

var onCompletion = (Stats stats) =>
{
// TODO: Do something useful
};


using var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(SpinnerDescriptor.Default)
.Build(Worker.AllItems);
Expand Down
52 changes: 52 additions & 0 deletions src/Progress.UnitTest/ReporterBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,56 @@ public void GivenSummary_WhenBuilding_ThenReporterIsSetUp()
// Assert
actual.DisplayItemsSummary.Should().BeTrue();
}

[Fact]
public void GivenProgressNotifications_WhenBuilding_ThenReporterIsSetUp()
{
// Arrange
var callback = (Stats stats) => { };
var builder = new ReporterBuilder()
.NotifyingProgress(callback);

// Act
var actual = builder.Build(100);

// Arrange
actual.OnProgress.Should().NotBeNull();
actual.OnProgress.Should().Be(callback);
actual.StatsFrequency.Should().Be(TimeSpan.FromSeconds(5));
}

[Fact]
public void GivenProgressNotificationsWithFrequency_WhenBuilding_ThenReporterIsSetUp()
{
// Arrange
var callback = (Stats stats) => { };
var frequency = TimeSpan.FromSeconds(20);
var builder = new ReporterBuilder()
.NotifyingProgress(callback, frequency);

// Act
var actual = builder.Build(100);

// Arrange
actual.OnProgress.Should().NotBeNull();
actual.OnProgress.Should().Be(callback);
actual.StatsFrequency.Should().Be(frequency);
}

[Fact]
public void GivenCompletionNotifications_WhenBuilding_ThenReporterIsSetUp()
{
// Arrange
var callback = (Stats stats) => { };
var builder = new ReporterBuilder()
.NotifyingCompletion(callback);

// Act
var actual = builder.Build(100);

// Arrange
actual.OnCompletion.Should().NotBeNull();
actual.OnCompletion.Should().Be(callback);
}

}
68 changes: 66 additions & 2 deletions src/Progress.UnitTest/ReporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@ public class ReporterTests
{
public ReporterTests()
{
StringBuilder builder = new StringBuilder();
StringBuilder builder = new();
TextWriter writer = new StringWriter(builder);
Console.SetOut(writer);
}

[Fact]
public void GivenDefaults_WhenInitializing_ThenExpectedSettings()
{
// Arrange
var reporter = new Reporter(100, BarDescriptor.Default.Build());

// Assert
reporter.DisplayStartingTime.Should().BeTrue();
reporter.DisplayRemainingTime.Should().BeTrue();
reporter.DisplayElapsedTime.Should().BeTrue();
reporter.DisplayEstimatedTimeOfArrival.Should().BeTrue();
reporter.DisplayItemsOverview.Should().BeTrue();
reporter.DisplayItemsSummary.Should().BeTrue();
reporter.NotifyProgressStats.Should().BeTrue();
reporter.NotifyCompletionStats.Should().BeTrue();
reporter.ReportFrequency.Should().Be(TimeSpan.FromSeconds(1));
reporter.StatsFrequency.Should().Be(TimeSpan.FromSeconds(5));
reporter.OnProgress.Should().BeNull();
reporter.OnCompletion.Should().BeNull();
}

[Fact]
public void GivenNothingToComplete_WhenInitializing_ThenThrowsException()
{
Expand Down Expand Up @@ -94,4 +115,47 @@ public void GivenStoppedOperation_WhenResuming_ThenSuccess()
// Act
reporter.Resume();
}
}

[Fact]
public async Task GivenProgressNotifications_WhenRunning_ThenCallbackIsCalled()
{
// Arrange
bool isCalled = false;
var reporter = new Reporter(100, BarDescriptor.Default.Build())
{
NotifyProgressStats = true,
StatsFrequency = TimeSpan.FromSeconds(1),
OnProgress = (stats) => isCalled = true
};


// Act
reporter.Start();
await Task.Delay(TimeSpan.FromMilliseconds(1500));

// Assert
isCalled.Should().BeTrue();
}

[Fact]
public async Task GivenCompletionNotifications_WhenFinished_ThenCallbackIsCalled()
{
// Arrange
bool isCalled = false;
var reporter = new Reporter(1, BarDescriptor.Default.Build())
{
NotifyCompletionStats = true,
ReportFrequency = TimeSpan.FromMicroseconds(500),
OnCompletion = (stats) => isCalled = true
};

reporter.Start();

// Act
reporter.ReportSuccess();
await Task.Delay(TimeSpan.FromMilliseconds(1000));

// Assert
isCalled.Should().BeTrue();
}
}
26 changes: 20 additions & 6 deletions src/Progress/Content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ Report progression with ease by using multilple components such as Bars, Spinner

```csharp
using var reporter = new ReporterBuilder()
.DisplayingStartingTime()
.DisplayingElapsedTime()
.DisplayingTimeOfArrival()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(BarDescriptor.Default)
.Build(Worker.AllItems);
Expand Down Expand Up @@ -49,6 +43,8 @@ var reporter = new ReporterBuilder()
.DisplayingRemainingTime()
.DisplayingItemsSummary()
.DisplayingItemsOverview()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.UsingReportingFrequency(TimeSpan.FromMilliseconds(50))
.UsingComponentDescriptor(BarDescriptor.Default)
.Build(Worker.AllItems);
Expand All @@ -74,3 +70,21 @@ reporter.Resume();
reporter.ReportSuccess()
reporter.ReportFailure()
```

### Collect stats while running
```csharp
var onProgress = (Stats stats) =>
{
// TODO: Do something useful
};

var onCompletion = (Stats stats) =>
{
// TODO: Do something useful
};

var reporter = new ReporterBuilder()
.NotifyingProgress(onProgress)
.NotifyingCompletion(onCompletion)
.Build(Worker.AllItems);
```
2 changes: 1 addition & 1 deletion src/Progress/Progress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<PropertyGroup>
<PackageId>Progress</PackageId>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Gerard Castello</Authors>
<Title>Report progress with ease</Title>
Expand Down
Loading