From 9cc8fe6f4c4e79110179d0dd24ecbe01db71fb7f Mon Sep 17 00:00:00 2001 From: Artem Pushkin Date: Wed, 27 Nov 2024 14:49:01 +0000 Subject: [PATCH 1/2] Deleted unused unit tests project. --- .../Comparing/XmlComparisonUnitTests.cs | 132 ---------- .../XmlFileGenerationUnitTests.cs | 28 -- ...odeGenerators.SettingsGen.UnitTests.csproj | 14 - .../SettingsFromAttributeParserUnitTests.cs | 244 ------------------ 4 files changed, 418 deletions(-) delete mode 100644 tests/CodeGenerators/SettingsGen.UnitTests/Comparing/XmlComparisonUnitTests.cs delete mode 100644 tests/CodeGenerators/SettingsGen.UnitTests/FileGeneration/XmlFileGenerationUnitTests.cs delete mode 100644 tests/CodeGenerators/SettingsGen.UnitTests/Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.csproj delete mode 100644 tests/CodeGenerators/SettingsGen.UnitTests/Parser/SettingsFromAttributeParserUnitTests.cs diff --git a/tests/CodeGenerators/SettingsGen.UnitTests/Comparing/XmlComparisonUnitTests.cs b/tests/CodeGenerators/SettingsGen.UnitTests/Comparing/XmlComparisonUnitTests.cs deleted file mode 100644 index b09db87e..00000000 --- a/tests/CodeGenerators/SettingsGen.UnitTests/Comparing/XmlComparisonUnitTests.cs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Threading; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Text; -using Microsoft.Omex.CodeGenerators.SettingsGen.Comparing; -using Microsoft.Omex.CodeGenerators.SettingsGen.Models; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.Comparing -{ - /// - /// Unit tests for XmlComparison class - /// - [TestClass] - public sealed class XmlComparisonUnitTests - { - [TestMethod] - public void AreExistingSettingsEqual_TestFalse_NoSourceText() - { - XmlComparison xmlComparison = new XmlComparison(); - AdditionalText additionalText = new MockAdditionalText(string.Empty); - Assert.IsFalse(xmlComparison.AreExistingSettingsEqual(new SettingsXmlModel(), additionalText), "Empty text should be false"); - } - - [TestMethod] - public void AreExistingSettingsEqual_TestEqual_Empty() - { - XmlComparison xmlComparison = new XmlComparison(); - AdditionalText additionalText = new MockAdditionalText(string.Format(SettingElement, string.Empty)); - Assert.IsTrue(xmlComparison.AreExistingSettingsEqual(new SettingsXmlModel(), additionalText), "Empty settings should be equal"); - } - - [TestMethod] - public void AreExistingSettingsEqual_TestEqual_WithParms() - { - XmlComparison xmlComparison = new XmlComparison(); - SettingsXmlModel settingsXmlModel = new(); - settingsXmlModel.Sections.Add(SectionModel); - - AdditionalText additionalText = new MockAdditionalText(string.Format(SettingElement, SectionWithParamXml)); - Assert.IsTrue(xmlComparison.AreExistingSettingsEqual(settingsXmlModel, additionalText), "Empty settings should be equal"); - } - - [TestMethod] - public void AreExistingSettingsEqual_TestNotEqual() - { - XmlComparison xmlComparison = new XmlComparison(); - SettingsXmlModel settingsXmlModel = new(); - settingsXmlModel.Sections.Add(SectionModel); - settingsXmlModel.Sections.Add(new SectionModel - { - Name = "Hello" - }); - - AdditionalText additionalText = new MockAdditionalText(string.Format(SettingElement, SectionWithParamXml)); - Assert.IsFalse(xmlComparison.AreExistingSettingsEqual(settingsXmlModel, additionalText), "Settings should not be equal"); - } - - [TestMethod] - public void AreExistingSettingsEqual_TestInvalidXml() - { - string invalidXml = "hello"; - XmlComparison xmlComparison = new XmlComparison(); - SettingsXmlModel settingsXmlModel = new(); - settingsXmlModel.Sections.Add(SectionModel); - settingsXmlModel.Sections.Add(new SectionModel - { - Name = "Hello" - }); - - AdditionalText additionalText = new MockAdditionalText(invalidXml); - Assert.IsFalse(xmlComparison.AreExistingSettingsEqual(settingsXmlModel, additionalText)); - } - - public readonly SectionModel SectionModel = new SectionModel - { - Name = "NotExample", - Parameters = new List - { - new ParameterModel - { - Name = "Setting1", - Value = "0" - }, - new ParameterModel - { - Name = "Setting2", - Value = "false" - } - } - - }; - - public string SettingElement => "{0}"; - - /// - /// Section with parameters xml string - /// - public const string SectionWithParamXml = "
" + - "\r\n \r\n " + - "
"; - - /// - /// MockAdditional text - /// - public class MockAdditionalText : AdditionalText - { - public string Text { get; private set; } - - public override string Path => string.Empty; - - public MockAdditionalText(string text) - { - Text = text; - } - - /// - /// - /// - /// - /// - public override SourceText? GetText(CancellationToken cancellationToken = default) - { - return string.IsNullOrEmpty(Text) ? null : SourceText.From(Text); - } - } - } -} diff --git a/tests/CodeGenerators/SettingsGen.UnitTests/FileGeneration/XmlFileGenerationUnitTests.cs b/tests/CodeGenerators/SettingsGen.UnitTests/FileGeneration/XmlFileGenerationUnitTests.cs deleted file mode 100644 index fb3b4b64..00000000 --- a/tests/CodeGenerators/SettingsGen.UnitTests/FileGeneration/XmlFileGenerationUnitTests.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using Microsoft.Omex.CodeGenerators.SettingsGen.FileGeneration; -using Microsoft.Omex.CodeGenerators.SettingsGen.Models; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.FileGeneration -{ - public sealed class XmlFileGenerationUnitTests - { - - [TestMethod] - public void XmlFileGeneration_TestWriteToFile_Succeed() - { - XmlFileGeneration generator = new(); - generator.GenerateFile(new SettingsXmlModel(), ".\\text.xml"); - } - - [TestMethod] - public void XmlFileGeneration_TestWriteToFile_Fail() - { - XmlFileGeneration generator = new(); - Assert.ThrowsException(() => generator.GenerateFile(new SettingsXmlModel(), string.Empty)); - } - } -} diff --git a/tests/CodeGenerators/SettingsGen.UnitTests/Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.csproj b/tests/CodeGenerators/SettingsGen.UnitTests/Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.csproj deleted file mode 100644 index d845bc6d..00000000 --- a/tests/CodeGenerators/SettingsGen.UnitTests/Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - $(NetCoreVersions) - - - - - - - - - - diff --git a/tests/CodeGenerators/SettingsGen.UnitTests/Parser/SettingsFromAttributeParserUnitTests.cs b/tests/CodeGenerators/SettingsGen.UnitTests/Parser/SettingsFromAttributeParserUnitTests.cs deleted file mode 100644 index e7f2574c..00000000 --- a/tests/CodeGenerators/SettingsGen.UnitTests/Parser/SettingsFromAttributeParserUnitTests.cs +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.Omex.CodeGenerators.SettingsGen.Models; -using Microsoft.Omex.CodeGenerators.SettingsGen.Models.Attributes; -using Microsoft.Omex.CodeGenerators.SettingsGen.Parser; -using Microsoft.Omex.CodeGenerators.SettingsGen.Wrappers; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Microsoft.Omex.CodeGenerators.SettingsGen.UnitTests.Parser -{ - public sealed class SettingsFromAttributeParserUnitTests - { - private Mock m_contextWrapper = new Mock(); - - [TestMethod] - public void Constructor_TestEmptySet() - { - Assert.ThrowsException(() => new SettingsFromAttributeParser(new HashSet { }, m_contextWrapper.Object)); - } - - [TestMethod] - public void OnVisitSyntax_TestNoSection() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - - m_contextWrapper.Setup(x => x.GetAttributes(It.IsAny())).Returns( - (new List(), mock.Object)); - - SettingsFromAttributeParser parser = new SettingsFromAttributeParser(new HashSet { - "Testing" - }, m_contextWrapper.Object); - - parser.OnVisitSyntaxNode(new GeneratorSyntaxContext()); - Assert.AreEqual(0, parser.Classes.Count); - } - - [TestMethod] - public void OnVisitSyntax_TestHasSections_WithNameAttribute() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - - Mock mockAttr = new Mock(); - mockAttr.Setup(x => x.Name).Returns("Testing"); - mockAttr.Setup(x => x.Arguments).Returns(new Dictionary { {"Name", "Override" } }); - - m_contextWrapper.Setup(x => x.GetAttributes(It.IsAny())).Returns( - (new List { mockAttr.Object }, mock.Object)); - - SettingsFromAttributeParser parser = new SettingsFromAttributeParser(new HashSet { - "Testing" - }, m_contextWrapper.Object); - parser.OnVisitSyntaxNode(new GeneratorSyntaxContext()); - - Assert.AreEqual(1, parser.Classes.Count); - Assert.AreEqual("Override", parser.Classes.First().sectionName); - } - - [TestMethod] - public void OnVisitSyntax_TestHasSections_WithNoNameAttribute() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - - Mock mockAttr = new Mock(); - mockAttr.Setup(x => x.Name).Returns("Testing"); - mockAttr.Setup(x => x.Arguments).Returns(new Dictionary { }); - - m_contextWrapper.Setup(x => x.GetAttributes(It.IsAny())).Returns( - (new List { mockAttr.Object }, mock.Object)); - - SettingsFromAttributeParser parser = new SettingsFromAttributeParser(new HashSet { - "Testing" - }, m_contextWrapper.Object); - parser.OnVisitSyntaxNode(new GeneratorSyntaxContext()); - - Assert.AreEqual(1, parser.Classes.Count); - Assert.AreEqual("Hello", parser.Classes.First().sectionName); - } - - [TestMethod] - public void GetSettings_TestHasSections_WithNoNameAttribute() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - mock.Setup(x => x.GetMembers()).Returns(PropertySymbols()); - - m_contextWrapper.Setup(x => x.GetAttributes(It.IsAny())).Returns( - CreateNoNameWrappers()); - - SettingsFromAttributeParser parser = new SettingsFromAttributeParser(new HashSet { - "Testing" - }, m_contextWrapper.Object); - parser.Classes.Add(("Something", mock.Object)); - SettingsXmlModel settings = parser.GetSettings(); - - SettingsXmlModel expected = new SettingsXmlModel - { - Sections = new List { - new SectionModel - { - Name = "Something", - Parameters = new List - { - new ParameterModel - { - Name ="Hello", - Value = "Mocking" - } - } - } - } - }; - - Assert.AreEqual(expected, settings); - } - - - [TestMethod] - public void GetSettings_TestHasSections_WithNameAttribute() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - mock.Setup(x => x.GetMembers()).Returns(PropertySymbols()); - - m_contextWrapper.Setup(x => x.GetAttributes(It.IsAny())).Returns( - CreateNameWrappers()); - - SettingsFromAttributeParser parser = new SettingsFromAttributeParser(new HashSet { - "Testing" - }, m_contextWrapper.Object); - parser.Classes.Add(("Something", mock.Object)); - SettingsXmlModel settings = parser.GetSettings(); - - SettingsXmlModel expected = new SettingsXmlModel - { - Sections = new List { - new SectionModel - { - Name = "Something", - Parameters = new List - { - new ParameterModel - { - Name ="Override", - Value = "Mocking" - } - } - } - } - }; - - Assert.AreEqual(expected, settings); - } - - [TestMethod] - public void GetSettings_TestHasSections_WithIgnoreAttribute() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - mock.Setup(x => x.GetMembers()).Returns(PropertySymbols()); - - m_contextWrapper.Setup(x => x.GetAttributes(It.IsAny())).Returns( - CreateIgnoreWrappers()); - - SettingsFromAttributeParser parser = new SettingsFromAttributeParser(new HashSet { - "Testing" - }, m_contextWrapper.Object); - parser.Classes.Add(("Something", mock.Object)); - SettingsXmlModel settings = parser.GetSettings(); - - SettingsXmlModel expected = new SettingsXmlModel - { - Sections = new List { - new SectionModel - { - Name = "Something", - Parameters = new List - { - } - } - } - }; - - Assert.AreEqual(expected, settings); - } - - private static ImmutableArray PropertySymbols() - { - Mock mock = new Mock(); - mock.Setup(x => x.Name).Returns("Hello"); - mock.Setup(x => x.Kind).Returns(SymbolKind.Property); - - return new List - { - mock.Object - }.ToImmutableArray(); - } - - private IList CreateNoNameWrappers() - { - IList attributeWrappers = new List(); - Mock mockWrapper = new Mock(); - mockWrapper.Setup(x => x.Name).Returns(AttributeNames.Parameter); - mockWrapper.Setup(x => x.Arguments).Returns(new Dictionary - { { "Value", "Mocking" } }); - - attributeWrappers.Add(mockWrapper.Object); - return attributeWrappers; - } - - private IList CreateNameWrappers() - { - IList attributeWrappers = new List(); - Mock mockWrapper = new Mock(); - mockWrapper.Setup(x => x.Name).Returns(AttributeNames.Parameter); - mockWrapper.Setup(x => x.Arguments).Returns(new Dictionary - { { "Value", "Mocking" }, { "Name", "Override" } }); - - attributeWrappers.Add(mockWrapper.Object); - return attributeWrappers; - } - - private IList CreateIgnoreWrappers() - { - IList attributeWrappers = new List(); - Mock mockWrapper = new Mock(); - mockWrapper.Setup(x => x.Name).Returns(AttributeNames.Ignore); - mockWrapper.Setup(x => x.Arguments).Returns(new Dictionary - { { "Value", "Mocking" }, { "Name", "Override" } }); - - attributeWrappers.Add(mockWrapper.Object); - return attributeWrappers; - } - } -} From d06da07f6d86449c3ed21e65198ebdcfd2a4447f Mon Sep 17 00:00:00 2001 From: Artem Pushkin Date: Wed, 27 Nov 2024 16:41:16 +0000 Subject: [PATCH 2/2] Allow latest .NET patch version from 8.0 channel. --- .github/pipelines/dotnet-initialize.yml | 2 +- .github/pipelines/github-semmle.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pipelines/dotnet-initialize.yml b/.github/pipelines/dotnet-initialize.yml index c166fcb2..11acef79 100644 --- a/.github/pipelines/dotnet-initialize.yml +++ b/.github/pipelines/dotnet-initialize.yml @@ -13,7 +13,7 @@ steps: - task: UseDotNet@2 displayName: Temporarily install .NET 8 SDK while dual targeting inputs: - version: "8.0.404" + version: "8.0.x" - task: UseDotNet@2 displayName: Use .NET SDK from global.json inputs: diff --git a/.github/pipelines/github-semmle.yml b/.github/pipelines/github-semmle.yml index 69f5a103..e004e57a 100644 --- a/.github/pipelines/github-semmle.yml +++ b/.github/pipelines/github-semmle.yml @@ -40,7 +40,7 @@ extends: - task: UseDotNet@2 displayName: Temporarily install .NET 8 SDK while dual targeting inputs: - version: "8.0.404" + version: "8.0.x" - task: UseDotNet@2 displayName: Use .NET SDK from global.json inputs: