Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Language Support: Add UI Warning #2112

Merged
merged 7 commits into from
Jul 30, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* SonarScanner for .NET
* Copyright (C) 2016-2024 SonarSource SA
* mailto: info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using SonarScanner.MSBuild.Common;
using TestUtilities;

using static FluentAssertions.FluentActions;

namespace SonarScanner.MSBuild.PostProcessor.Test;

[TestClass]
public class AnalysisWarningProcessorTests
{
private readonly IFileWrapper fileWrapper = Substitute.For<IFileWrapper>();
private readonly TestLogger logger = new();

[TestMethod]
public void AnalysisWarningProcessor_Constructor()
{
Invoking(() => AnalysisWarningProcessor.Process(null, null, null, null)).Should()
.ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("warnings");

Invoking(() => AnalysisWarningProcessor.Process([], null, null, null)).Should()
.ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("outputPath");

Invoking(() => AnalysisWarningProcessor.Process([], string.Empty, null, null)).Should()
.ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("fileWrapper");

Invoking(() => AnalysisWarningProcessor.Process([], string.Empty, Substitute.For<IFileWrapper>(), null)).Should()
.ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("logger");
}

[TestMethod]
public void AnalysisWarningProcessor_Process_EmptyWarnings()
{
AnalysisWarningProcessor.Process([], string.Empty, fileWrapper, logger);

logger.AssertNoWarningsLogged();
fileWrapper.DidNotReceiveWithAnyArgs().WriteAllText(default, default);
}

[TestMethod]
public void AnalysisWarningProcessor_Process_MultipleWarnings()
{
AnalysisWarningProcessor.Process(["exploding", "whale"], string.Empty, fileWrapper, logger);

logger.Warnings.Should().BeEquivalentTo("exploding", "whale");
fileWrapper.Received(1).WriteAllText(string.Empty, """
[
{
"Text": "exploding"
},
{
"Text": "whale"
}
]
""");
}
}
Loading
Loading