Skip to content

Commit

Permalink
Merge pull request #4 from BasycOpenSource/develop
Browse files Browse the repository at this point in the history
4th
  • Loading branch information
Basyras authored Dec 30, 2022
2 parents 99c2249 + 420a9ff commit 0b21b21
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
10 changes: 4 additions & 6 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// https://github.com/dotnet/format/issues/1094
// https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings

using Basyc.Extensions.Nuke.Targets;
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;

///Nuke support plugins are available for:
/// - JetBrains ReSharper https://nuke.build/resharper
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode <summary>
// https://github.com/dotnet/format/issues/1094
// https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings

[GitHubActions(
"continuous",
GitHubActionsImage.UbuntuLatest,
Expand All @@ -33,7 +32,6 @@
FetchDepth = 0)]
internal class Build : NukeBuild, IBasycBuildAll
{

//[Parameter] string NuGetSource => TryGetValue(() => NuGetSource);
//[Parameter][Secret] string NuGetApiKey => TryGetValue(() => NuGetApiKey);
//[Parameter][Secret] string NuGetApiPrivateKeyPfxBase64 => TryGetValue(() => NuGetApiPrivateKeyPfxBase64);
Expand All @@ -50,6 +48,6 @@ public static int Main()
{
IBasycBuildBase.BuildProjectName = "_build";
IBasycBuildBase.UnitTestSuffix = ".UnitTests";
return Execute<Build>(x => ((IBasycBuildAll)x).UnitTestAll);
return Execute<Build>(x => ((IBasycBuildAll)x).UnitTestAffected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using static Basyc.Extensions.Nuke.Tasks.DotNetTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

Expand All @@ -14,6 +13,7 @@ public interface IBasycBuildRelease : IBasycBuildBase
protected string NuGetApiKey { get; }

Target StaticCodeAnalysisAll => _ => _
.Before(CompileAll)
.Executes(() =>
{
BasycFormatVerifyNoChanges(Solution!.Path);
Expand All @@ -36,6 +36,7 @@ public interface IBasycBuildRelease : IBasycBuildBase
});

Target CompileAll => _ => _
.After(StaticCodeAnalysisAll)
.After(RestoreAll)
.DependsOn(RestoreAll)
.Executes(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ public static TemporarySolution NewTempSolution(Solution solution, string? build
.ForEach(newSolution.RemoveProject);
if (buildProjectName is not null)
{
newSolution.RemoveProject(newSolution.GetProject(buildProjectName));
newSolution.Save();
var buildProject = newSolution.GetProject(buildProjectName);
if (buildProject is not null)
{
newSolution.RemoveProject(buildProject);
}
}

newSolution.Save();
return new TemporarySolution(newSolution);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Basyc.MessageBus.Manager.Application.Tests.Durations;

public class DurationMapBuilderTests
{
private static readonly ServiceIdentity TestServiceIndentity = new ServiceIdentity("TestService");
private static readonly ServiceIdentity TestServiceIndentity = new("TestService");

[Fact]
public void When_BuildingEmpty_Should_BeEmpty()
Expand All @@ -22,7 +22,7 @@ public void When_BuildWithoutStartCounting_Should_StartAutomatically()
var mapBuilder = new DurationMapBuilder(TestServiceIndentity, "1");
var durationMap = mapBuilder.Build();
mapBuilder.HasStarted.Should().BeTrue();
mapBuilder.StartTime.Should().NotBe(default(DateTimeOffset));
mapBuilder.StartTime.Should().NotBe(default);
}

[Fact]
Expand All @@ -31,7 +31,7 @@ public void When_AddAndStartSegmentWithoutStartCounting_Should_StartAutomaticall
var mapBuilder = new DurationMapBuilder(TestServiceIndentity, "1");
_ = mapBuilder.StartNewSegment("segmentName");
mapBuilder.HasStarted.Should().BeTrue();
mapBuilder.StartTime.Should().NotBe(default(DateTimeOffset));
mapBuilder.StartTime.Should().NotBe(default);
}

[Fact]
Expand All @@ -42,9 +42,9 @@ public void When_AddAndStartSegment_Should_HaveOneSegment()
_ = mapBuilder.StartNewSegment(segment1Name);
var durationMap = mapBuilder.Build();
durationMap.Segments.Length.Should().Be(1);
DurationSegment firstSegment = durationMap.Segments.First();
firstSegment.EndTime.Should().NotBe(default(DateTimeOffset));
durationMap.TotalDuration.Should().NotBe(default(TimeSpan));
var firstSegment = durationMap.Segments.First();
firstSegment.EndTime.Should().NotBe(default);
durationMap.TotalDuration.Should().NotBe(default);
durationMap.TotalDuration.Should().Be(firstSegment.EndTime - firstSegment.StartTime);
}

Expand All @@ -63,10 +63,10 @@ public void When_StartingMultipleSegment_Should_ContainAll(int numberOfSegments)

var durationMap = durationMapBuilder.Build();
durationMap.Segments.Length.Should().Be(numberOfSegments);
TimeSpan totalSegmentsDuration = TimeSpan.FromSeconds(0);
var totalSegmentsDuration = TimeSpan.FromSeconds(0);
foreach (var segment in durationMap.Segments)
{
segment.EndTime.Should().NotBe(default(DateTimeOffset));
segment.EndTime.Should().NotBe(default);
totalSegmentsDuration += segment.EndTime - segment.StartTime;
}

Expand All @@ -79,7 +79,7 @@ public void When_StartingMultipleSegment_Should_ContainAll(int numberOfSegments)
[Fact]
public void AddAndStartSegment_Should_ReturnNewSegment()
{
List<IDurationSegmentBuilder> allSegments = new List<IDurationSegmentBuilder>();
var allSegments = new List<IDurationSegmentBuilder>();
var mapBuilder = new DurationMapBuilder(TestServiceIndentity, "1");

for (int segmentIndex = 0; segmentIndex < 4; segmentIndex++)
Expand All @@ -90,10 +90,10 @@ public void AddAndStartSegment_Should_ReturnNewSegment()
}
}

[Theory]
[Theory(Skip = "Clock is not accurate sometimes fails")]
[InlineData(0, new int[] { })]
[InlineData(2, new int[] { 100, 150 })]
[InlineData(4, new int[] { 100, 150, 50, 150 })]
[InlineData(2, new int[] { 100, 150 })]
public void When_AddingSegments_Should_TotalDurationBeSumOfAll(int numberOfSegments, int[] durationsMs)
{
durationsMs.Length.Should().Be(numberOfSegments);
Expand All @@ -102,7 +102,7 @@ public void When_AddingSegments_Should_TotalDurationBeSumOfAll(int numberOfSegme

for (int segmentIndex = 0; segmentIndex < numberOfSegments; segmentIndex++)
{
var segmentDuration = durationsMs[segmentIndex];
int segmentDuration = durationsMs[segmentIndex];
var segment = mapBuilder.StartNewSegment("segmentName");
//await Task.Delay(segmentDuration); //Not accurate
Thread.Sleep(segmentDuration);
Expand All @@ -112,7 +112,7 @@ public void When_AddingSegments_Should_TotalDurationBeSumOfAll(int numberOfSegme
var durationMap = mapBuilder.Build();
durationMap.Segments.Length.Should().Be(numberOfSegments);
durationMap.Segments.All(x => x.NestedSegments.Length == 0).Should().BeTrue();
TimeSpan totalSegmentsDuration = TimeSpan.FromMilliseconds(durationsMs.Sum());
var totalSegmentsDuration = TimeSpan.FromMilliseconds(durationsMs.Sum());

//https://stackoverflow.com/questions/31742521/accuracy-of-task-delay
durationMap.TotalDuration.Should().BeCloseTo(totalSegmentsDuration, DurationTestsHelper.TaskDelayPrecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public static class DurationTestsHelper
{
public const int TaskDelayPrecisionMs = 100;
public const int TaskDelayPrecisionMs = 150;
public static TimeSpan TaskDelayPrecision = TimeSpan.FromMilliseconds(TaskDelayPrecisionMs);
}

0 comments on commit 0b21b21

Please sign in to comment.