Skip to content

Commit

Permalink
SCAN4NET-24: File-scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-paidis-sonarsource committed Aug 22, 2024
1 parent 9c9ed39 commit 072d62c
Show file tree
Hide file tree
Showing 276 changed files with 28,057 additions and 28,333 deletions.
11 changes: 5 additions & 6 deletions Tests/LogArgs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

using System.IO;

namespace LogArgs
namespace LogArgs;

public static class Program
{
public static class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
File.WriteAllLines("LogArgs.log", args);
}
File.WriteAllLines("LogArgs.log", args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,76 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestUtilities;

namespace SonarScanner.MSBuild.Common.Test
{
[TestClass]
public class AggregatePropertiesProviderTests
{
public TestContext TestContext { get; set; }
namespace SonarScanner.MSBuild.Common.Test;

#region Tests
[TestClass]
public class AggregatePropertiesProviderTests
{
public TestContext TestContext { get; set; }

[TestMethod]
public void AggProperties_NullOrEmptyList()
{
// 1. Null -> error
Action act = () => new AggregatePropertiesProvider(null);
act.Should().ThrowExactly<ArgumentNullException>();
#region Tests

// 2. Empty list of providers -> valid but returns nothing
var provider = new AggregatePropertiesProvider(new IAnalysisPropertyProvider[] { });
[TestMethod]
public void AggProperties_NullOrEmptyList()
{
// 1. Null -> error
Action act = () => new AggregatePropertiesProvider(null);
act.Should().ThrowExactly<ArgumentNullException>();

provider.GetAllProperties().Should().BeEmpty();
var success = provider.TryGetProperty("any key", out var actualProperty);
// 2. Empty list of providers -> valid but returns nothing
var provider = new AggregatePropertiesProvider(new IAnalysisPropertyProvider[] { });

success.Should().BeFalse("Not expecting a property to be returned");
actualProperty.Should().BeNull("Returned property should be null");
}
provider.GetAllProperties().Should().BeEmpty();
var success = provider.TryGetProperty("any key", out var actualProperty);

[TestMethod]
public void AggProperties_Aggregation()
{
// Checks the aggregation works as expected
success.Should().BeFalse("Not expecting a property to be returned");
actualProperty.Should().BeNull("Returned property should be null");
}

// 0. Setup
var provider1 = new ListPropertiesProvider();
provider1.AddProperty("shared.key.A", "value A from one");
provider1.AddProperty("shared.key.B", "value B from one");
provider1.AddProperty("p1.unique.key.1", "p1 unique value 1");
[TestMethod]
public void AggProperties_Aggregation()
{
// Checks the aggregation works as expected

var provider2 = new ListPropertiesProvider();
provider2.AddProperty("shared.key.A", "value A from two");
provider2.AddProperty("shared.key.B", "value B from two");
provider2.AddProperty("p2.unique.key.1", "p2 unique value 1");
// 0. Setup
var provider1 = new ListPropertiesProvider();
provider1.AddProperty("shared.key.A", "value A from one");
provider1.AddProperty("shared.key.B", "value B from one");
provider1.AddProperty("p1.unique.key.1", "p1 unique value 1");

var provider3 = new ListPropertiesProvider();
provider3.AddProperty("shared.key.A", "value A from three"); // this provider only has one of the shared values
provider3.AddProperty("p3.unique.key.1", "p3 unique value 1");
var provider2 = new ListPropertiesProvider();
provider2.AddProperty("shared.key.A", "value A from two");
provider2.AddProperty("shared.key.B", "value B from two");
provider2.AddProperty("p2.unique.key.1", "p2 unique value 1");

// 1. Ordering
var aggProvider = new AggregatePropertiesProvider(provider1, provider2, provider3);
var provider3 = new ListPropertiesProvider();
provider3.AddProperty("shared.key.A", "value A from three"); // this provider only has one of the shared values
provider3.AddProperty("p3.unique.key.1", "p3 unique value 1");

aggProvider.AssertExpectedPropertyCount(5);
// 1. Ordering
var aggProvider = new AggregatePropertiesProvider(provider1, provider2, provider3);

aggProvider.AssertExpectedPropertyValue("shared.key.A", "value A from one");
aggProvider.AssertExpectedPropertyValue("shared.key.B", "value B from one");
aggProvider.AssertExpectedPropertyCount(5);

aggProvider.AssertExpectedPropertyValue("p1.unique.key.1", "p1 unique value 1");
aggProvider.AssertExpectedPropertyValue("p2.unique.key.1", "p2 unique value 1");
aggProvider.AssertExpectedPropertyValue("p3.unique.key.1", "p3 unique value 1");
aggProvider.AssertExpectedPropertyValue("shared.key.A", "value A from one");
aggProvider.AssertExpectedPropertyValue("shared.key.B", "value B from one");

// 2. Reverse the order and try again
aggProvider = new AggregatePropertiesProvider(provider3, provider2, provider1);
aggProvider.AssertExpectedPropertyValue("p1.unique.key.1", "p1 unique value 1");
aggProvider.AssertExpectedPropertyValue("p2.unique.key.1", "p2 unique value 1");
aggProvider.AssertExpectedPropertyValue("p3.unique.key.1", "p3 unique value 1");

aggProvider.AssertExpectedPropertyCount(5);
// 2. Reverse the order and try again
aggProvider = new AggregatePropertiesProvider(provider3, provider2, provider1);

aggProvider.AssertExpectedPropertyValue("shared.key.A", "value A from three");
aggProvider.AssertExpectedPropertyValue("shared.key.B", "value B from two");
aggProvider.AssertExpectedPropertyCount(5);

aggProvider.AssertExpectedPropertyValue("p1.unique.key.1", "p1 unique value 1");
aggProvider.AssertExpectedPropertyValue("p2.unique.key.1", "p2 unique value 1");
aggProvider.AssertExpectedPropertyValue("p3.unique.key.1", "p3 unique value 1");
}
aggProvider.AssertExpectedPropertyValue("shared.key.A", "value A from three");
aggProvider.AssertExpectedPropertyValue("shared.key.B", "value B from two");

#endregion Tests
aggProvider.AssertExpectedPropertyValue("p1.unique.key.1", "p1 unique value 1");
aggProvider.AssertExpectedPropertyValue("p2.unique.key.1", "p2 unique value 1");
aggProvider.AssertExpectedPropertyValue("p3.unique.key.1", "p3 unique value 1");
}

#endregion Tests
}
Loading

0 comments on commit 072d62c

Please sign in to comment.