Skip to content

Commit

Permalink
Run ReSharper code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Octobob committed Jul 20, 2022
1 parent 477838b commit 079e8ea
Show file tree
Hide file tree
Showing 48 changed files with 2,029 additions and 2,088 deletions.
23 changes: 7 additions & 16 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using Nuke.Common;
using Nuke.Common.Execution;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.OctoVersion;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using System;

[UnsetVisualStudioEnvironmentVariables]
class Build : NukeBuild
Expand All @@ -16,15 +8,14 @@ class Build : NukeBuild
[Solution] readonly Solution Solution;

[Parameter("Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable OCTOVERSION_CurrentBranch.",
Name = "OCTOVERSION_CurrentBranch")]
readonly string BranchName;
Name = "OCTOVERSION_CurrentBranch")]
readonly string BranchName;

[Parameter("Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI.")]
readonly bool AutoDetectBranch = IsLocalBuild;
[Parameter("Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI.")] readonly bool AutoDetectBranch = IsLocalBuild;

[OctoVersion(UpdateBuildNumber = true, BranchParameter = nameof(BranchName),
AutoDetectBranchParameter = nameof(AutoDetectBranch), Framework = "net6.0")]
readonly OctoVersionInfo OctoVersionInfo;
[OctoVersion(UpdateBuildNumber = true, BranchParameter = nameof(BranchName),
AutoDetectBranchParameter = nameof(AutoDetectBranch), Framework = "net6.0")]
readonly OctoVersionInfo OctoVersionInfo;

AbsolutePath SourceDirectory => RootDirectory / "source";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
Expand Down
10 changes: 4 additions & 6 deletions source/Tests/AssertionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using Octopus.Ocl;

namespace Tests
namespace Tests;

public static class AssertionExtensions
{
public static class AssertionExtensions
{
public static OclBodyAssertions Should(this OclBody? subject)
=> new OclBodyAssertions(subject);
}
public static OclBodyAssertions Should(this OclBody? subject) => new(subject);
}
95 changes: 47 additions & 48 deletions source/Tests/Converters/BlockOclConverterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,61 @@
using Octopus.Ocl;
using Octopus.Ocl.Converters;

namespace Tests.Converters
namespace Tests.Converters;

public class BlockOclConverterFixture
{
public class BlockOclConverterFixture
[Test]
public void NameCaseIsKept()
{
[Test]
public void NameCaseIsKept()
{
var context = new OclConversionContext(new OclSerializerOptions());
var data = new object();
var result = (OclBlock)new DefaultBlockOclConverter().ToElements(context, typeof(WithIndexer).GetProperty(nameof(WithIndexer.MyProp))!, data).Single();
result.Name.Should().Be("my_prop");
}
var context = new OclConversionContext(new OclSerializerOptions());
var data = new object();
var result = (OclBlock)new DefaultBlockOclConverter().ToElements(context, typeof(WithIndexer).GetProperty(nameof(WithIndexer.MyProp))!, data).Single();
result.Name.Should().Be("my_prop");
}

[Test]
public void AttributesComeBeforeBlocks()
[Test]
public void AttributesComeBeforeBlocks()
{
var context = new OclConversionContext(new OclSerializerOptions());
var data = new
{
var context = new OclConversionContext(new OclSerializerOptions());
var data = new
MyBlock = new { BlockProp = "OtherValue" },
MyProp = "MyValue"
};
var result = (OclBlock)new DefaultBlockOclConverter().ToElements(context, typeof(WithIndexer).GetProperty(nameof(WithIndexer.MyProp)), data).Single();
result.First()
.Should()
.BeEquivalentTo(new OclAttribute("my_prop", "MyValue"));
}

[Test]
public void IndexersAreIgnored()
{
var context = new OclConversionContext(new OclSerializerOptions());
var data =
new Dummy
{
MyBlock = new { BlockProp = "OtherValue" },
MyProp = "MyValue"
Foo = new WithIndexer()
};
var result = (OclBlock)new DefaultBlockOclConverter().ToElements(context, typeof(WithIndexer).GetProperty(nameof(WithIndexer.MyProp)), data).Single();
result.First()
.Should()
.BeEquivalentTo(new OclAttribute("my_prop", "MyValue"));
}

[Test]
public void IndexersAreIgnored()
{
var context = new OclConversionContext(new OclSerializerOptions());
var data =
new Dummy
var result = (OclBlock)new DefaultBlockOclConverter().ToElements(context, typeof(Dummy).GetProperty(nameof(Dummy.Foo)), data.Foo).Single();
result.Should()
.Be(
new OclBlock("foo")
{
Foo = new WithIndexer()
};
var result = (OclBlock)new DefaultBlockOclConverter().ToElements(context, typeof(Dummy).GetProperty(nameof(Dummy.Foo)), data.Foo).Single();
result.Should()
.Be(
new OclBlock("foo")
{
new OclAttribute("my_prop", "MyValue")
}
);
}
new OclAttribute("my_prop", "MyValue")
}
);
}

class WithIndexer
{
public string MyProp => "MyValue";
public string this[int index] => throw new NotImplementedException();
}
class WithIndexer
{
public string MyProp => "MyValue";
public string this[int index] => throw new NotImplementedException();
}

class Dummy
{
public object? Foo { get; set; }
}
class Dummy
{
public object? Foo { get; set; }
}
}
25 changes: 12 additions & 13 deletions source/Tests/Converters/DefaultAttributeOclConverterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
using Octopus.Ocl;
using Octopus.Ocl.Converters;

namespace Tests.Converters
namespace Tests.Converters;

public class DefaultAttributeOclConverterFixture
{
public class DefaultAttributeOclConverterFixture
[Test]
public void NameCaseIsKept()
{
[Test]
public void NameCaseIsKept()
{
var context = new OclConversionContext(new OclSerializerOptions());
var result = (OclAttribute)new DefaultAttributeOclConverter().ToElements(context, typeof(Dummy).GetProperty(nameof(Dummy.Test))!, "Value").Single();
result.Name.Should().Be("test");
}
var context = new OclConversionContext(new OclSerializerOptions());
var result = (OclAttribute)new DefaultAttributeOclConverter().ToElements(context, typeof(Dummy).GetProperty(nameof(Dummy.Test))!, "Value").Single();
result.Name.Should().Be("test");
}

class Dummy
{
public string Test { get; } = "Value";
}
class Dummy
{
public string Test { get; } = "Value";
}
}
99 changes: 49 additions & 50 deletions source/Tests/Converters/DefaultCollectionOclConverterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,63 @@
using Octopus.Ocl;
using Octopus.Ocl.Converters;

namespace Tests.Converters
namespace Tests.Converters;

public class DefaultCollectionOclConverterFixture
{
public class DefaultCollectionOclConverterFixture
{
const string Value = "Daffy";
const string Value = "Daffy";

readonly OclConversionContext context = new OclConversionContext(new OclSerializerOptions());
readonly OclConversionContext context = new(new OclSerializerOptions());

[Test]
public void FromElement_IEnumerableTargetWithCurrentAsNullReturnsAList()
=> ExecuteFromElement<IEnumerable<string>>(null)
.Should()
.BeOfType<List<string>>()
.And
.BeEquivalentTo(new[] { Value });
[Test]
public void FromElement_IEnumerableTargetWithCurrentAsNullReturnsAList()
=> ExecuteFromElement<IEnumerable<string>>(null)
.Should()
.BeOfType<List<string>>()
.And
.BeEquivalentTo(new[] { Value });

[Test]
public void FromElement_IListTargetWithCurrentAsNullReturnsAList()
=> ExecuteFromElement<IEnumerable<string>>(null)
.Should()
.BeOfType<List<string>>()
.And
.BeEquivalentTo(new[] { Value });
[Test]
public void FromElement_IListTargetWithCurrentAsNullReturnsAList()
=> ExecuteFromElement<IEnumerable<string>>(null)
.Should()
.BeOfType<List<string>>()
.And
.BeEquivalentTo(new[] { Value });

[Test]
public void FromElement_HashSetTargetWithCurrentAsNullReturnsAHashSet()
=> ExecuteFromElement<HashSet<string>>(null)
.Should()
.BeOfType<HashSet<string>>()
.And
.BeEquivalentTo(new[] { Value });
[Test]
public void FromElement_HashSetTargetWithCurrentAsNullReturnsAHashSet()
=> ExecuteFromElement<HashSet<string>>(null)
.Should()
.BeOfType<HashSet<string>>()
.And
.BeEquivalentTo(new[] { Value });

[Test]
public void FromElement_CustomCollectionIsSupported()
=> ExecuteFromElement<MyCollection>(null)
.Should()
.BeOfType<MyCollection>()
.And
.BeEquivalentTo(new[] { Value });
[Test]
public void FromElement_CustomCollectionIsSupported()
=> ExecuteFromElement<MyCollection>(null)
.Should()
.BeOfType<MyCollection>()
.And
.BeEquivalentTo(new[] { Value });

[Test]
public void FromElement_ReusesCurrentCollection()
{
var existing = new HashSet<string>
{ "ExistingItem" };
ExecuteFromElement<HashSet<string>>(existing)
.Should()
.BeSameAs(existing)
.And
.BeEquivalentTo(new[] { "ExistingItem", Value });
}
[Test]
public void FromElement_ReusesCurrentCollection()
{
var existing = new HashSet<string>
{ "ExistingItem" };
ExecuteFromElement<HashSet<string>>(existing)
.Should()
.BeSameAs(existing)
.And
.BeEquivalentTo(new[] { "ExistingItem", Value });
}

object? ExecuteFromElement<TTarget>(object? currentValue)
=> new DefaultCollectionOclConverter()
.FromElement(context, typeof(TTarget), new OclAttribute("Test", Value), currentValue);
object? ExecuteFromElement<TTarget>(object? currentValue)
=> new DefaultCollectionOclConverter()
.FromElement(context, typeof(TTarget), new OclAttribute("Test", Value), currentValue);

class MyCollection : HashSet<string>
{
}
class MyCollection : HashSet<string>
{
}
}
Loading

0 comments on commit 079e8ea

Please sign in to comment.