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
2 changes: 1 addition & 1 deletion src/RepoM.Api/Git/FileRepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Set(IEnumerable<string> paths)
}
}

private IEnumerable<string> Get(string file)
private string[] Get(string file)
{
if (!_fileSystem.File.Exists(file))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace RepoM.App.Converters;

public class UtcToHumanizedLocalDateTimeConverter : IValueConverter
{
private static readonly IHumanizer _humanizer = new HardcodededMiniHumanizer(SystemClock.Instance);
private static readonly HardcodededMiniHumanizer _humanizer = new(SystemClock.Instance);

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
DateTime date = DateTime.SpecifyKind(DateTime.Parse(value.ToString() ?? string.Empty), DateTimeKind.Utc).ToLocalTime();
DateTime date = DateTime.SpecifyKind(DateTime.Parse(value?.ToString() ?? string.Empty), DateTimeKind.Utc).ToLocalTime();
return _humanizer.HumanizeTimestamp(date);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@ namespace RepoM.App.RepositoryOrdering;
internal class RepositoryComparerCompositionFactory : IRepositoryComparerFactory
{
private readonly Container _container;
private readonly ILogger<RepositoryComparerCompositionFactory> _logger;
private readonly ILogger _logger;

public RepositoryComparerCompositionFactory(Container container, ILogger<RepositoryComparerCompositionFactory> logger)
public RepositoryComparerCompositionFactory(Container container, ILogger logger)
{
_container = container ?? throw new ArgumentNullException(nameof(container));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

/// <exception cref="InvalidOperationException">Thrown when repository comparer cannot be created.</exception>
public IRepositoryComparer Create(IRepositoriesComparerConfiguration configuration)
{
try
{
return CreateInner(configuration);
}
catch (ActivationException e)
{
_logger.LogCritical(e, "Could not create a IRepositoryComparer for configuration type '{Configuration}'", configuration);
throw new InvalidOperationException($"Could not create a IRepositoryComparer for configuration type '{configuration}'", e);
}
catch (Exception e)
{
_logger.LogCritical(e, "Could not create a IRepositoryComparer for configuration type '{configuration}'", configuration);
throw;
_logger.LogCritical(e, "Factory could not create instance of IRepositoryComparer '{Message}'", e.Message);
throw new InvalidOperationException($"Factory could not create instance of IRepositoryComparer '{e.Message}'", e);
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/RepoM.Core.Plugin/Repository/RepositoryContext.cs

This file was deleted.

5 changes: 5 additions & 0 deletions tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ root = false
# CA1861: Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array
dotnet_diagnostic.CA1861.severity = none

# CA1859: Using concrete types avoids virtual or interface call overhead and enables inlining.
dotnet_diagnostic.CA1859.severity = none



###############################
# ReSharper #
###############################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
namespace RepoM.App.Tests.RepositoryOrdering;

using System;
using FakeItEasy;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using RepoM.App.RepositoryOrdering;
using RepoM.Core.Plugin.RepositoryOrdering;
using RepoM.Core.Plugin.RepositoryOrdering.Configuration;
using SimpleInjector;
using Xunit;

public class RepositoryComparerCompositionFactoryTests
{
private readonly Container _container = new();
private readonly ILogger _logger = A.Fake<ILogger>();

[Fact]
public void Ctor_ShouldThrow_WhenArgumentNull()
{
// arrange

// act
Func<RepositoryComparerCompositionFactory> act1 = () => new RepositoryComparerCompositionFactory(new Container(), null!);
Func<RepositoryComparerCompositionFactory> act2 = () => new RepositoryComparerCompositionFactory(null!, A.Dummy<ILogger>());

// assert
act1.Should().Throw<ArgumentNullException>();
act2.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Create_ShouldThrow_WhenContainerCannotCreateInstance()
{
// arrange
var sut = new RepositoryComparerCompositionFactory(_container, _logger);

// act
Func<IRepositoryComparer> act = () => sut.Create(new DummyConfiguration());

// assert
act.Should().Throw<InvalidOperationException>();
}

[Fact]
public void Create_ShouldThrow_WhenCreatedFactoryThrows()
{
// arrange
_container.RegisterSingleton<IRepositoryComparerFactory<DummyConfiguration>, FailingRepositoryComparerFactoryDummyConfiguration>();
var sut = new RepositoryComparerCompositionFactory(_container, _logger);

// act
Func<IRepositoryComparer> act = () => sut.Create(new DummyConfiguration());

// assert
act.Should().Throw<InvalidOperationException>();
}

[Fact]
public void Create_ShouldReturnInstance_WhenFactoryCreatesInstance()
{
// arrange
IRepositoryComparer comparer = A.Fake<IRepositoryComparer>();
_container.RegisterSingleton<IRepositoryComparerFactory<DummyConfiguration>>(() => new RepositoryComparerFactoryDummyConfiguration(comparer));
var sut = new RepositoryComparerCompositionFactory(_container, _logger);

// act
IRepositoryComparer result = sut.Create(new DummyConfiguration());

// assert
result.Should().Be(comparer);
}
}

public class FailingRepositoryComparerFactoryDummyConfiguration : IRepositoryComparerFactory<DummyConfiguration>
{
public IRepositoryComparer Create(DummyConfiguration configuration)
{
throw new NotImplementedException("Thrown by test");
}
}

public class RepositoryComparerFactoryDummyConfiguration : IRepositoryComparerFactory<DummyConfiguration>
{
private readonly IRepositoryComparer _instance;

public RepositoryComparerFactoryDummyConfiguration(IRepositoryComparer instance)
{
_instance = instance;
}
public IRepositoryComparer Create(DummyConfiguration configuration)
{
return _instance;
}
}

public class DummyConfiguration : IRepositoriesComparerConfiguration
{
public string Type
{
get => "DUMMY";
set => _ = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ namespace RepoM.Plugin.AzureDevOps.Tests.RepositoryFiltering;

public class HasPullRequestsMatcherTest
{
private readonly IRepository _repository;
private readonly IAzureDevOpsPullRequestService _azureDevOpsPullRequestService;
private readonly IRepository _repository = A.Fake<IRepository>();
private readonly IAzureDevOpsPullRequestService _azureDevOpsPullRequestService = A.Fake<IAzureDevOpsPullRequestService>();

public HasPullRequestsMatcherTest()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Ctor_ShouldThrow_WhenArgumentNull(bool ignoreCase)
{
_repository = A.Fake<IRepository>();
_azureDevOpsPullRequestService = A.Fake<IAzureDevOpsPullRequestService>();
// arrange

// act
Func<HasPullRequestsMatcher> act1 = () => new HasPullRequestsMatcher(null!, ignoreCase);

// assert
act1.Should().Throw<ArgumentNullException>();
}

[Theory]
Expand Down Expand Up @@ -95,24 +103,24 @@ public static IEnumerable<object[]> InvalidTerms
{
get
{
yield return new object[] { new TermRange("has", null, true, "x", false), };
yield return new object[] { new SimpleTerm(string.Empty, string.Empty), };
yield return new object[] { new SimpleTerm(string.Empty, "data"), };
yield return new object[] { new SimpleTerm("is", "data"), };
yield return new object[] { new SimpleTerm("has", "wrong-value"), };
yield return [new TermRange("has", null, true, "x", false),];
yield return [new SimpleTerm(string.Empty, string.Empty),];
yield return [new SimpleTerm(string.Empty, "data"),];
yield return [new SimpleTerm("is", "data"),];
yield return [new SimpleTerm("has", "wrong-value"),];
}
}

public static IEnumerable<object[]> ValidTerms
{
get
{
yield return new object[] { new SimpleTerm("has", "prs"), };
yield return new object[] { new SimpleTerm("has", "pr"), };
yield return new object[] { new SimpleTerm("has", "pull-request"), };
yield return new object[] { new SimpleTerm("has", "pull-requests"), };
yield return new object[] { new SimpleTerm("has", "pullrequest"), };
yield return new object[] { new SimpleTerm("has", "pullrequests"), };
yield return [new SimpleTerm("has", "prs"),];
yield return [new SimpleTerm("has", "pr"),];
yield return [new SimpleTerm("has", "pull-request"),];
yield return [new SimpleTerm("has", "pull-requests"),];
yield return [new SimpleTerm("has", "pullrequest"),];
yield return [new SimpleTerm("has", "pullrequests"),];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void RegisterServices_ShouldRegisterLuceneQueryParserAsCollection()
INamedQueryParser[] instances = _container.GetAllInstances<INamedQueryParser>().ToArray();

// assert
_ = instances.Should().HaveCount(1).And.AllBeOfType<LuceneQueryParser>();
_ = instances.Should().ContainSingle().And.AllBeOfType<LuceneQueryParser>();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ public UsageScoreCalculatorTest()
_sut = new UsageScoreCalculator(_service, _calculatorClock, _defaultConfig);
}

[Fact]
public void Ctor_ShouldThrow_WhenArgumentNull()
{
// arrange

// act
Func<UsageScoreCalculator> act1 = () => new UsageScoreCalculator(A.Dummy<IStatisticsService>(), A.Dummy<IClock>(), null!);
Func<UsageScoreCalculator> act2 = () => new UsageScoreCalculator(A.Dummy<IStatisticsService>(), null!, _defaultConfig);
Func<UsageScoreCalculator> act3 = () => new UsageScoreCalculator(null!, A.Dummy<IClock>(), _defaultConfig);

// assert
act1.Should().Throw<ArgumentNullException>();
act2.Should().Throw<ArgumentNullException>();
act3.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Score_ShouldUseRecordings_WhenCalculating()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace RepoM.Plugin.Statistics.Tests.Ordering;

using System;
using FakeItEasy;
using FluentAssertions;
using RepoM.Core.Plugin.Common;
Expand All @@ -18,6 +19,20 @@ public UsageScorerFactoryTest()
_service = new StatisticsService(_clock);
}

[Fact]
public void Ctor_ShouldThrow_WhenArgumentNull()
{
// arrange

// act
Func<UsageScorerFactory> act1 = () => new UsageScorerFactory(null!, A.Dummy<IClock>());
Func<UsageScorerFactory> act2 = () => new UsageScorerFactory(_service, null!);

// assert
act1.Should().Throw<ArgumentNullException>();
act2.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Create_ShouldReturnInstanceOfUsageScoreCalculator()
{
Expand Down
14 changes: 14 additions & 0 deletions tests/RepoM.Plugin.Statistics.Tests/RepositoryStatisticsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ namespace RepoM.Plugin.Statistics.Tests;

public class RepositoryStatisticsTest
{
[Fact]
public void Ctor_ShouldThrow_WhenArgumentNull()
{
// arrange

// act
Func<RepositoryStatistics> act1 = () => new RepositoryStatistics(null!, A.Dummy<IClock>());
Func<RepositoryStatistics> act2 = () => new RepositoryStatistics("", null!);

// assert
act1.Should().Throw<ArgumentNullException>();
act2.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Recordings_ShouldBeEmpty_WhenConstructed()
{
Expand Down
Loading