diff --git a/test/Directory.Build.props b/test/Directory.Build.props index a0b1fcf254b..aa2bdcea6c3 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -7,7 +7,7 @@ false @@ -30,8 +30,9 @@ - - - + + + + diff --git a/test/Directory.Packages.props b/test/Directory.Packages.props index b6dd29a5e18..8cabbad86e7 100644 --- a/test/Directory.Packages.props +++ b/test/Directory.Packages.props @@ -4,11 +4,9 @@ - - - - + + diff --git a/test/Docfx.Build.Common.Tests/FileLinkInfoTest.cs b/test/Docfx.Build.Common.Tests/FileLinkInfoTest.cs index 07c66c3714b..3f7022cc11e 100644 --- a/test/Docfx.Build.Common.Tests/FileLinkInfoTest.cs +++ b/test/Docfx.Build.Common.Tests/FileLinkInfoTest.cs @@ -3,13 +3,13 @@ using Docfx.Common; using FluentAssertions; -using Xunit; namespace Docfx.MarkdigEngine.Tests; +[TestClass] public class FileLinkInfoTest { - [Fact] + [TestMethod] public void TestFileLinkInfo_EncodedWorkspaceCharacter() { string fromFileInSource = "articles/vpn-gateway/vpn-gateway-verify-connection-resource-manager.md"; diff --git a/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs b/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs index 5e5da0a699e..a2a79775c31 100644 --- a/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs +++ b/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs @@ -6,13 +6,13 @@ using Docfx.Build.Engine; using Docfx.MarkdigEngine; using Docfx.Plugins; -using Xunit; namespace Docfx.Build.Common.Tests; +[TestClass] public class MarkdownReaderTest { - [Fact] + [TestMethod] public void TestReadMarkdownAsOverwrite() { var content = @"--- @@ -34,11 +34,11 @@ public void TestReadMarkdownAsOverwrite() var ft = new FileAndType(baseDir, fileName, DocumentType.Overwrite); var results = MarkdownReader.ReadMarkdownAsOverwrite(host, ft).ToList(); - Assert.NotNull(results); - Assert.Single(results); - Assert.Equal("Test", results[0].Uid); - Assert.Equal("Hello", results[0].Metadata["remarks"]); - Assert.Equal("\n

This is unit test!

\n", results[0].Conceptual); + Assert.IsNotNull(results); + Assert.ContainsSingle(results); + Assert.AreEqual("Test", results[0].Uid); + Assert.AreEqual("Hello", results[0].Metadata["remarks"]); + Assert.AreEqual("\n

This is unit test!

\n", results[0].Conceptual); File.Delete(fileName); // Test conceptual content between two yamlheader @@ -55,13 +55,13 @@ This is unit test! content = Regex.Replace(content, "\r?\n", "\r\n"); File.WriteAllText(fileName, content); results = MarkdownReader.ReadMarkdownAsOverwrite(host, ft).ToList(); - Assert.NotNull(results); - Assert.Equal(2, results.Count); - Assert.Equal("Test1", results[0].Uid); - Assert.Equal("Test2", results[1].Uid); - Assert.Equal("Hello", results[0].Metadata["remarks"]); - Assert.Equal("\n

This is unit test!

\n", results[0].Conceptual); - Assert.Equal(string.Empty, results[1].Conceptual); + Assert.IsNotNull(results); + Assert.AreEqual(2, results.Count); + Assert.AreEqual("Test1", results[0].Uid); + Assert.AreEqual("Test2", results[1].Uid); + Assert.AreEqual("Hello", results[0].Metadata["remarks"]); + Assert.AreEqual("\n

This is unit test!

\n", results[0].Conceptual); + Assert.AreEqual(string.Empty, results[1].Conceptual); File.Delete(fileName); content = @"--- @@ -76,13 +76,13 @@ This is unit test! content = Regex.Replace(content, "\r?\n", "\r\n"); File.WriteAllText(fileName, content); results = MarkdownReader.ReadMarkdownAsOverwrite(host, ft).ToList(); - Assert.NotNull(results); - Assert.Equal(2, results.Count); - Assert.Equal("Test1", results[0].Uid); - Assert.Equal("Hello", results[0].Metadata["remarks"]); - Assert.Equal("\n

This is unit test!

\n", results[0].Conceptual); - Assert.Equal("Test2", results[1].Uid); - Assert.Equal("", results[1].Conceptual); + Assert.IsNotNull(results); + Assert.AreEqual(2, results.Count); + Assert.AreEqual("Test1", results[0].Uid); + Assert.AreEqual("Hello", results[0].Metadata["remarks"]); + Assert.AreEqual("\n

This is unit test!

\n", results[0].Conceptual); + Assert.AreEqual("Test2", results[1].Uid); + Assert.AreEqual("", results[1].Conceptual); File.Delete(fileName); // Test conceptual content with extra empty line between two yamlheader @@ -102,24 +102,24 @@ This is unit test! content = Regex.Replace(content, "\r?\n", "\r\n"); File.WriteAllText(fileName, content); results = MarkdownReader.ReadMarkdownAsOverwrite(host, ft).ToList(); - Assert.NotNull(results); - Assert.Equal(2, results.Count); - Assert.Equal("Test1", results[0].Uid); - Assert.Equal("Test2", results[1].Uid); - Assert.Equal("Hello", results[0].Metadata["remarks"]); - Assert.Equal("\n

This is unit test!

\n", results[0].Conceptual); - Assert.Equal(string.Empty, results[1].Conceptual); + Assert.IsNotNull(results); + Assert.AreEqual(2, results.Count); + Assert.AreEqual("Test1", results[0].Uid); + Assert.AreEqual("Test2", results[1].Uid); + Assert.AreEqual("Hello", results[0].Metadata["remarks"]); + Assert.AreEqual("\n

This is unit test!

\n", results[0].Conceptual); + Assert.AreEqual(string.Empty, results[1].Conceptual); File.Delete(fileName); // Test different line ending content = "---\nuid: Test\nremarks: Hello\n---\nThis is unit test!\n"; File.WriteAllText(fileName, content); results = MarkdownReader.ReadMarkdownAsOverwrite(host, ft).ToList(); - Assert.NotNull(results); - Assert.Single(results); - Assert.Equal("Test", results[0].Uid); - Assert.Equal("Hello", results[0].Metadata["remarks"]); - Assert.Equal("\n

This is unit test!

\n", results[0].Conceptual); + Assert.IsNotNull(results); + Assert.ContainsSingle(results); + Assert.AreEqual("Test", results[0].Uid); + Assert.AreEqual("Hello", results[0].Metadata["remarks"]); + Assert.AreEqual("\n

This is unit test!

\n", results[0].Conceptual); File.Delete(fileName); // Test link to files and Uids in overwrite document @@ -136,47 +136,46 @@ [Not exist link2](link2.md) content = Regex.Replace(content, "\r?\n", "\r\n"); File.WriteAllText(fileName, content); results = MarkdownReader.ReadMarkdownAsOverwrite(host, ft).ToList(); - Assert.NotNull(results); - Assert.Single(results); - Assert.Equal("Test", results[0].Uid); - Assert.Equal("Hello", results[0].Metadata["remarks"]); - Assert.Equal(2, results[0].LinkToFiles.Count); - Assert.True(results[0].LinkToFiles.OrderBy(f => f).SequenceEqual(new[] { "~/link.md", "~/link2.md", })); - Assert.Single(results[0].LinkToUids); - Assert.Equal("NotExistUid", results[0].LinkToUids.ElementAt(0)); - Assert.Equal(2, results[0].FileLinkSources.Count); + Assert.IsNotNull(results); + Assert.ContainsSingle(results); + Assert.AreEqual("Test", results[0].Uid); + Assert.AreEqual("Hello", results[0].Metadata["remarks"]); + Assert.AreEqual(2, results[0].LinkToFiles.Count); + Assert.IsTrue(results[0].LinkToFiles.OrderBy(f => f).SequenceEqual(new[] { "~/link.md", "~/link2.md", })); + Assert.ContainsSingle(results[0].LinkToUids); + Assert.AreEqual("NotExistUid", results[0].LinkToUids.ElementAt(0)); + Assert.AreEqual(2, results[0].FileLinkSources.Count); var fileLinkSource0 = results[0].FileLinkSources["~/link.md"]; - Assert.NotNull(fileLinkSource0); - Assert.Single(fileLinkSource0); - Assert.Null(fileLinkSource0[0].Anchor); - Assert.Equal(7, fileLinkSource0[0].LineNumber); - Assert.Equal(fileName, fileLinkSource0[0].SourceFile); - Assert.Equal("~/link.md", fileLinkSource0[0].Target); - Assert.Single(results[0].UidLinkSources); + Assert.IsNotNull(fileLinkSource0); + Assert.ContainsSingle(fileLinkSource0); + Assert.IsNull(fileLinkSource0[0].Anchor); + Assert.AreEqual(7, fileLinkSource0[0].LineNumber); + Assert.AreEqual(fileName, fileLinkSource0[0].SourceFile); + Assert.AreEqual("~/link.md", fileLinkSource0[0].Target); + Assert.ContainsSingle(results[0].UidLinkSources); var fileLinkSource1 = results[0].FileLinkSources["~/link2.md"]; - Assert.NotNull(fileLinkSource1); - Assert.Single(fileLinkSource1); - Assert.Null(fileLinkSource1[0].Anchor); - Assert.Equal(8, fileLinkSource1[0].LineNumber); - Assert.Equal(fileName, fileLinkSource1[0].SourceFile); - Assert.Equal("~/link2.md", fileLinkSource1[0].Target); - Assert.Single(results[0].UidLinkSources); + Assert.IsNotNull(fileLinkSource1); + Assert.ContainsSingle(fileLinkSource1); + Assert.IsNull(fileLinkSource1[0].Anchor); + Assert.AreEqual(8, fileLinkSource1[0].LineNumber); + Assert.AreEqual(fileName, fileLinkSource1[0].SourceFile); + Assert.AreEqual("~/link2.md", fileLinkSource1[0].Target); + Assert.ContainsSingle(results[0].UidLinkSources); var uidLinkSource = results[0].UidLinkSources["NotExistUid"]; - Assert.NotNull(uidLinkSource); - Assert.Single(uidLinkSource); - Assert.Null(uidLinkSource[0].Anchor); - Assert.Equal(5, uidLinkSource[0].LineNumber); - Assert.Equal(fileName, uidLinkSource[0].SourceFile); - Assert.Equal("NotExistUid", uidLinkSource[0].Target); - Assert.Equal( + Assert.IsNotNull(uidLinkSource); + Assert.ContainsSingle(uidLinkSource); + Assert.IsNull(uidLinkSource[0].Anchor); + Assert.AreEqual(5, uidLinkSource[0].LineNumber); + Assert.AreEqual(fileName, uidLinkSource[0].SourceFile); + Assert.AreEqual("NotExistUid", uidLinkSource[0].Target); + Assert.AreEqual( """

Not exist link Not exist link2

This is unit test!

- """, - results[0].Conceptual.Trim(), - ignoreLineEndingDifferences: true); + """.ReplaceLineEndings(), + results[0].Conceptual.Trim().ReplaceLineEndings()); File.Delete(fileName); } } diff --git a/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs b/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs index 79047dc6bb0..276fe344be8 100644 --- a/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs +++ b/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs @@ -6,15 +6,15 @@ using Docfx.DataContracts.Common; using Docfx.MarkdigEngine; using Docfx.Plugins; -using Xunit; namespace Docfx.Build.Common.Tests; +[TestClass] public class ModelAttributeHandlerTest { #region UniqueIdentityAttribute - [Fact] + [TestMethod] public void TestSimpleModelWithUniqueIdentityReferenceAttributeShouldSucceed() { var model = new SimpleModel @@ -25,12 +25,12 @@ public void TestSimpleModelWithUniqueIdentityReferenceAttributeShouldSucceed() var context = Handle(model); - Assert.Equal(2, context.LinkToUids.Count); + Assert.AreEqual(2, context.LinkToUids.Count); Assert.Contains(model.Identity, context.LinkToUids); Assert.Contains(model.Identities[0], context.LinkToUids); } - [Fact] + [TestMethod] public void TestModelWithLoopShouldSucceed() { var model = new LoopModel @@ -40,10 +40,10 @@ public void TestModelWithLoopShouldSucceed() }; model.Reference = model; var context = Handle(model); - Assert.Single(context.LinkToUids); + Assert.ContainsSingle(context.LinkToUids); } - [Fact] + [TestMethod] public void TestModelWithInvalidTypeShouldThrow() { var model = new InvalidModel @@ -56,7 +56,7 @@ public void TestModelWithInvalidTypeShouldThrow() ); } - [Fact] + [TestMethod] public void TestModelWithInvalidItemTypeShouldThrow() { var model = new InvalidModel2 @@ -68,7 +68,7 @@ public void TestModelWithInvalidItemTypeShouldThrow() ); } - [Fact] + [TestMethod] public void TestComplexModelWithUniqueIdentityReferenceAttributeShouldSucceed() { var model = new ComplexModel @@ -104,17 +104,17 @@ public void TestComplexModelWithUniqueIdentityReferenceAttributeShouldSucceed() }; var context = Handle(model); - Assert.Equal(12, context.LinkToUids.Count); - Assert.Equal(new List { + Assert.AreEqual(12, context.LinkToUids.Count); + CollectionAssert.AreEqual(new string[] { "0", "0.0", "0.0.0", "1", "1.1", "1.1.1","1.1.2", "1.2", "1.3","2", "2.2", "3", - }, context.LinkToUids.OrderBy(x => x)); + }, context.LinkToUids.OrderBy(x => x).ToArray()); } #endregion #region MarkdownContentAttribute - [Fact] + [TestMethod] public void TestSimpleModelWithMarkdownContentAttributeShouldSucceed() { var model = new MarkdownModel1 @@ -130,17 +130,17 @@ public void TestSimpleModelWithMarkdownContentAttributeShouldSucceed() var context = Handle(model); - Assert.Single(context.LinkToUids); - Assert.Single(context.LinkToFiles); - Assert.Single(context.FileLinkSources); - Assert.Single(context.UidLinkSources); - Assert.Equal( + Assert.ContainsSingle(context.LinkToUids); + Assert.ContainsSingle(context.LinkToFiles); + Assert.ContainsSingle(context.FileLinkSources); + Assert.ContainsSingle(context.UidLinkSources); + Assert.AreEqual( @"

Hello world, , link

".Replace("\r\n", "\n"), model.Content); } - [Fact] + [TestMethod] public void TestMarkdownContentAttributeWithContentPlaceholderShouldSucceed() { var model = new MarkdownModel1 @@ -171,22 +171,22 @@ public void TestMarkdownContentAttributeWithContentPlaceholderShouldSucceed() context.PlaceholderContent = "placeholder"; context = Handle(model, context); - Assert.Single(context.LinkToUids); - Assert.Single(context.LinkToFiles); - Assert.Single(context.FileLinkSources); - Assert.Single(context.UidLinkSources); + Assert.ContainsSingle(context.LinkToUids); + Assert.ContainsSingle(context.LinkToFiles); + Assert.ContainsSingle(context.FileLinkSources); + Assert.ContainsSingle(context.UidLinkSources); var expected = @"

Hello world, , link

".Replace("\r\n", "\n"); - Assert.Equal(expected, model.Content); - Assert.Equal(context.PlaceholderContent, model.Content2); - Assert.Equal(context.PlaceholderContent, model.Inner.Content); - Assert.Equal(context.PlaceholderContent, model.Inner.Content2); - Assert.Equal(context.PlaceholderContent, model.Inner.Content3[0]); - Assert.Equal(context.PlaceholderContent, model.Inner.Content4["key1"]); - Assert.Equal(context.PlaceholderContent, model.Inner.Content5["key1"]); + Assert.AreEqual(expected, model.Content); + Assert.AreEqual(context.PlaceholderContent, model.Content2); + Assert.AreEqual(context.PlaceholderContent, model.Inner.Content); + Assert.AreEqual(context.PlaceholderContent, model.Inner.Content2); + Assert.AreEqual(context.PlaceholderContent, model.Inner.Content3[0]); + Assert.AreEqual(context.PlaceholderContent, model.Inner.Content4["key1"]); + Assert.AreEqual(context.PlaceholderContent, model.Inner.Content5["key1"]); } - [Fact] + [TestMethod] public void TestMarkdownContentIgnoreAttributeShouldSucceed() { var model = new MarkdownModelWithIgnore @@ -218,22 +218,22 @@ public void TestMarkdownContentIgnoreAttributeShouldSucceed() context.PlaceholderContent = "placeholder"; context = Handle(model, context); - Assert.Equal(3, context.LinkToUids.Count); - Assert.Single(context.LinkToFiles); - Assert.Single(context.FileLinkSources); - Assert.Single(context.UidLinkSources); + Assert.AreEqual(3, context.LinkToUids.Count); + Assert.ContainsSingle(context.LinkToFiles); + Assert.ContainsSingle(context.FileLinkSources); + Assert.ContainsSingle(context.UidLinkSources); var expected = @"

Hello world, , link

".Replace("\r\n", "\n"); - Assert.Equal(expected, model.Content); - Assert.Equal(context.PlaceholderContent, model.Content2); - Assert.Equal("*content", model.Inner.Content); - Assert.Equal("*content", model.Inner.Content2); - Assert.Equal("Identity1", model.Inner.Content3[0]); - Assert.Equal("*content", model.Inner.Content4["key1"]); - Assert.Equal("*content", model.Inner.Content5["key1"]); + Assert.AreEqual(expected, model.Content); + Assert.AreEqual(context.PlaceholderContent, model.Content2); + Assert.AreEqual("*content", model.Inner.Content); + Assert.AreEqual("*content", model.Inner.Content2); + Assert.AreEqual("Identity1", model.Inner.Content3[0]); + Assert.AreEqual("*content", model.Inner.Content4["key1"]); + Assert.AreEqual("*content", model.Inner.Content5["key1"]); } - [Fact] + [TestMethod] public void TesteModelWithIListMarkdownContentAttributeShouldSucceed() { var model = new MarkdownModelWithIList @@ -247,20 +247,20 @@ public void TesteModelWithIListMarkdownContentAttributeShouldSucceed() context.PlaceholderContent = "placeholder"; context = Handle(model, context); - Assert.Single(context.LinkToUids); - Assert.Empty(context.LinkToFiles); - Assert.Empty(context.FileLinkSources); - Assert.Single(context.UidLinkSources); - Assert.Equal("

list

\n", model.ListContent[0]); - Assert.Equal("

\n", model.ArrayContent[0]); - Assert.Equal("placeholder", model.ArrayContent[1]); + Assert.ContainsSingle(context.LinkToUids); + Assert.IsEmpty(context.LinkToFiles); + Assert.IsEmpty(context.FileLinkSources); + Assert.ContainsSingle(context.UidLinkSources); + Assert.AreEqual("

list

\n", model.ListContent[0]); + Assert.AreEqual("

\n", model.ArrayContent[0]); + Assert.AreEqual("placeholder", model.ArrayContent[1]); } #endregion #region UrlContentAttribute - [Fact] + [TestMethod] public void TestSimpleModelWithUrlContentAttributeShouldSucceed() { var model = new SimpleModel @@ -270,11 +270,11 @@ public void TestSimpleModelWithUrlContentAttributeShouldSucceed() var context = Handle(model); - Assert.Empty(context.LinkToUids); - Assert.Empty(context.UidLinkSources); - Assert.Single(context.LinkToFiles); - Assert.Single(context.FileLinkSources); - Assert.Equal("~/linkTarget", model.Href); + Assert.IsEmpty(context.LinkToUids); + Assert.IsEmpty(context.UidLinkSources); + Assert.ContainsSingle(context.LinkToFiles); + Assert.ContainsSingle(context.FileLinkSources); + Assert.AreEqual("~/linkTarget", model.Href); } #endregion diff --git a/test/Docfx.Build.Common.Tests/ReflectionHelperTest.cs b/test/Docfx.Build.Common.Tests/ReflectionHelperTest.cs index 70dcd04bf18..4dcbedd8eaf 100644 --- a/test/Docfx.Build.Common.Tests/ReflectionHelperTest.cs +++ b/test/Docfx.Build.Common.Tests/ReflectionHelperTest.cs @@ -1,13 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Docfx.Build.Common.Tests; +[TestClass] public class ReflectionHelperTest { - [Fact] + [TestMethod] public void TestGetPropertyValueForClass() { var obj = new MyClass @@ -16,12 +15,12 @@ public void TestGetPropertyValueForClass() MyProperty2 = 100, MyProperty3 = null, }; - Assert.Equal("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty1)))); - Assert.Equal(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty2)))); - Assert.Null(ReflectionHelper.GetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty3)))); + Assert.AreEqual("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty1)))); + Assert.AreEqual(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty2)))); + Assert.IsNull(ReflectionHelper.GetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty3)))); } - [Fact] + [TestMethod] public void TestGetPropertyValueForStructure() { var obj = new MyStruct @@ -30,12 +29,12 @@ public void TestGetPropertyValueForStructure() MyProperty2 = 100, MyProperty3 = null, }; - Assert.Equal("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty1)))); - Assert.Equal(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty2)))); - Assert.Null(ReflectionHelper.GetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty3)))); + Assert.AreEqual("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty1)))); + Assert.AreEqual(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty2)))); + Assert.IsNull(ReflectionHelper.GetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty3)))); } - [Fact] + [TestMethod] public void TestGetPropertyValueForClassByInterface() { var obj = new MyClass @@ -44,12 +43,12 @@ public void TestGetPropertyValueForClassByInterface() MyProperty2 = 100, MyProperty3 = null, }; - Assert.Equal("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)))); - Assert.Equal(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty2)))); - Assert.Null(ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)))); + Assert.AreEqual("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)))); + Assert.AreEqual(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty2)))); + Assert.IsNull(ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)))); } - [Fact] + [TestMethod] public void TestGetPropertyValueForStructureByInterface() { var obj = new MyStruct @@ -58,73 +57,73 @@ public void TestGetPropertyValueForStructureByInterface() MyProperty2 = 100, MyProperty3 = null, }; - Assert.Equal("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)))); - Assert.Equal(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty2)))); - Assert.Null(ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)))); + Assert.AreEqual("Hello", ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)))); + Assert.AreEqual(100, ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty2)))); + Assert.IsNull(ReflectionHelper.GetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)))); } - [Fact] + [TestMethod] public void TestSetPropertyValueForClass() { var obj = new MyClass(); ReflectionHelper.SetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty1)), "Hello"); - Assert.Equal("Hello", obj.MyProperty1); + Assert.AreEqual("Hello", obj.MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty1)), null); - Assert.Null(obj.MyProperty1); + Assert.IsNull(obj.MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty2)), 100); - Assert.Equal(100, obj.MyProperty2); + Assert.AreEqual(100, obj.MyProperty2); ReflectionHelper.SetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty3)), true); - Assert.True(obj.MyProperty3); + Assert.IsTrue(obj.MyProperty3); ReflectionHelper.SetPropertyValue(obj, typeof(MyClass).GetProperty(nameof(MyClass.MyProperty3)), null); - Assert.Null(obj.MyProperty3); + Assert.IsNull(obj.MyProperty3); } - [Fact] + [TestMethod] public void TestSetPropertyValueForStructure() { object obj = new MyStruct(); ReflectionHelper.SetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty1)), "Hello"); - Assert.Equal("Hello", ((MyStruct)obj).MyProperty1); + Assert.AreEqual("Hello", ((MyStruct)obj).MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty1)), null); - Assert.Null(((MyStruct)obj).MyProperty1); + Assert.IsNull(((MyStruct)obj).MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty2)), 100); - Assert.Equal(100, ((MyStruct)obj).MyProperty2); + Assert.AreEqual(100, ((MyStruct)obj).MyProperty2); ReflectionHelper.SetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty3)), true); - Assert.True(((MyStruct)obj).MyProperty3); + Assert.IsTrue(((MyStruct)obj).MyProperty3); ReflectionHelper.SetPropertyValue(obj, typeof(MyStruct).GetProperty(nameof(MyStruct.MyProperty3)), null); - Assert.Null(((MyStruct)obj).MyProperty3); + Assert.IsNull(((MyStruct)obj).MyProperty3); } - [Fact] + [TestMethod] public void TestSetPropertyValueForClassByInterface() { var obj = new MyClass(); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)), "Hello"); - Assert.Equal("Hello", obj.MyProperty1); + Assert.AreEqual("Hello", obj.MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)), null); - Assert.Null(obj.MyProperty1); + Assert.IsNull(obj.MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty2)), 100); - Assert.Equal(100, obj.MyProperty2); + Assert.AreEqual(100, obj.MyProperty2); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)), true); - Assert.True(obj.MyProperty3); + Assert.IsTrue(obj.MyProperty3); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)), null); - Assert.Null(obj.MyProperty3); + Assert.IsNull(obj.MyProperty3); } - [Fact] + [TestMethod] public void TestSetPropertyValueForStructureByInterface() { MyInterface obj = new MyStruct(); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)), "Hello"); - Assert.Equal("Hello", obj.MyProperty1); + Assert.AreEqual("Hello", obj.MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty1)), null); - Assert.Null(obj.MyProperty1); + Assert.IsNull(obj.MyProperty1); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty2)), 100); - Assert.Equal(100, obj.MyProperty2); + Assert.AreEqual(100, obj.MyProperty2); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)), true); - Assert.True(obj.MyProperty3); + Assert.IsTrue(obj.MyProperty3); ReflectionHelper.SetPropertyValue(obj, typeof(MyInterface).GetProperty(nameof(MyInterface.MyProperty3)), null); - Assert.Null(obj.MyProperty3); + Assert.IsNull(obj.MyProperty3); } public class MyClass : MyInterface diff --git a/test/Docfx.Build.ManagedReference.Tests/ManagedReferenceDocumentProcessorTest.cs b/test/Docfx.Build.ManagedReference.Tests/ManagedReferenceDocumentProcessorTest.cs index 1c46adc1a98..6e5e5528142 100644 --- a/test/Docfx.Build.ManagedReference.Tests/ManagedReferenceDocumentProcessorTest.cs +++ b/test/Docfx.Build.ManagedReference.Tests/ManagedReferenceDocumentProcessorTest.cs @@ -11,10 +11,10 @@ using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.ManagedReference.Tests; +[TestClass] public class ManagedReferenceDocumentProcessorTest : TestBase { private readonly string _outputFolder; @@ -40,55 +40,55 @@ public ManagedReferenceDocumentProcessorTest() _templateManager = new TemplateManager(["template"], null, "TestData/"); } - [Fact] + [TestMethod] public void ProcessMrefShouldSucceed() { FileCollection files = new(_defaultFiles); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); + Assert.IsNotNull(model); - Assert.Equal("Hello world!", model.Metadata["meta"]); - Assert.Equal("item level metadata should overwrite page level metadata.", model.Metadata["anotherMeta"]); - Assert.Single(model.Attributes); - Assert.Equal("System.SerializableAttribute.#ctor", model.Attributes[0].Constructor); - Assert.Empty(model.Attributes[0].Arguments); - Assert.Equal("System.SerializableAttribute", model.Attributes[0].Type); + Assert.AreEqual("Hello world!", model.Metadata["meta"]); + Assert.AreEqual("item level metadata should overwrite page level metadata.", model.Metadata["anotherMeta"]); + Assert.ContainsSingle(model.Attributes); + Assert.AreEqual("System.SerializableAttribute.#ctor", model.Attributes[0].Constructor); + Assert.IsEmpty(model.Attributes[0].Arguments); + Assert.AreEqual("System.SerializableAttribute", model.Attributes[0].Type); - Assert.Equal(2, model.Implements.Count); + Assert.AreEqual(2, model.Implements.Count); - Assert.Single(model.Inheritance); + Assert.ContainsSingle(model.Inheritance); - Assert.Equal(6, model.InheritedMembers.Count); + Assert.AreEqual(6, model.InheritedMembers.Count); - Assert.Equal(2, model.Syntax.Content.Count); - Assert.Equal("csharp", model.Syntax.Content[0].Language); - Assert.Equal("

[A](http://A/).

\n", model.AdditionalNotes.Implementer); - Assert.Equal("[Serializable]\npublic class Cat : ICat, IAnimal where T : class, new ()where K : struct", model.Syntax.Content[0].Value); - Assert.Equal("vb", model.Syntax.Content[1].Language); - Assert.Equal("\nPublic Class Cat(Of T As {Class, New}, K As Structure)\n Implements ICat, IAnimal", model.Syntax.Content[1].Value); + Assert.AreEqual(2, model.Syntax.Content.Count); + Assert.AreEqual("csharp", model.Syntax.Content[0].Language); + Assert.AreEqual("

[A](http://A/).

\n", model.AdditionalNotes.Implementer); + Assert.AreEqual("[Serializable]\npublic class Cat : ICat, IAnimal where T : class, new ()where K : struct", model.Syntax.Content[0].Value); + Assert.AreEqual("vb", model.Syntax.Content[1].Language); + Assert.AreEqual("\nPublic Class Cat(Of T As {Class, New}, K As Structure)\n Implements ICat, IAnimal", model.Syntax.Content[1].Value); - Assert.Equal(2, model.Syntax.TypeParameters.Count); - Assert.Equal("T", model.Syntax.TypeParameters[0].Name); - Assert.Equal("

This type should be class and can new instance.

\n", model.Syntax.TypeParameters[0].Description); - Assert.Equal("K", model.Syntax.TypeParameters[1].Name); - Assert.Equal("

This type is a struct type, class type can't be used for this parameter.

\n", model.Syntax.TypeParameters[1].Description); + Assert.AreEqual(2, model.Syntax.TypeParameters.Count); + Assert.AreEqual("T", model.Syntax.TypeParameters[0].Name); + Assert.AreEqual("

This type should be class and can new instance.

\n", model.Syntax.TypeParameters[0].Description); + Assert.AreEqual("K", model.Syntax.TypeParameters[1].Name); + Assert.AreEqual("

This type is a struct type, class type can't be used for this parameter.

\n", model.Syntax.TypeParameters[1].Description); - Assert.Single(model.Examples); - Assert.Equal("

Here's example of how to create an instance of **Cat** class. As T is limited with class and K is limited with struct.

\n
    var a = new Cat(object, int)();\n    int catNumber = new int();\n    unsafe\n    {\n        a.GetFeetLength(catNumber);\n    }
\n

As you see, here we bring in pointer so we need to add unsafe keyword.

\n", model.Examples[0]); + Assert.ContainsSingle(model.Examples); + Assert.AreEqual("

Here's example of how to create an instance of **Cat** class. As T is limited with class and K is limited with struct.

\n
    var a = new Cat(object, int)();\n    int catNumber = new int();\n    unsafe\n    {\n        a.GetFeetLength(catNumber);\n    }
\n

As you see, here we bring in pointer so we need to add unsafe keyword.

\n", model.Examples[0]); - Assert.Equal(20, model.Children.Count); + Assert.AreEqual(20, model.Children.Count); var cm = model.Children[1]; - Assert.Equal("

[A](http://A/).

\n", cm.AdditionalNotes.Implementer); - Assert.Equal("

[B](http://B/).

\n", cm.AdditionalNotes.Inheritor); - Assert.Equal("

[C](http://C/).

\n", cm.AdditionalNotes.Caller); + Assert.AreEqual("

[A](http://A/).

\n", cm.AdditionalNotes.Implementer); + Assert.AreEqual("

[B](http://B/).

\n", cm.AdditionalNotes.Inheritor); + Assert.AreEqual("

[C](http://C/).

\n", cm.AdditionalNotes.Caller); } - [Fact] + [TestMethod] public void ProcessMrefWithComplexFileNameShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -97,35 +97,35 @@ public void ProcessMrefWithComplexFileNameShouldSucceed() BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("Namespace1.Class1`2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); + Assert.IsNotNull(model); outputRawModelPath = GetRawModelFilePath("Namespace1.Class1`2.#ctor.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); + Assert.IsNotNull(model); var outputHtml = GetOutputFilePath("mref/Namespace1.Class1`2.html"); - Assert.True(File.Exists(outputHtml)); + Assert.IsTrue(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); - Assert.Equal("

Constructor

\n", content); + Assert.AreEqual("

Constructor

\n", content); } - [Fact] + [TestMethod] public void ProcessMrefWithXRefMapShouldSucceed() { var files = new FileCollection(_defaultFiles); BuildDocument(files); var xrefMapPath = Path.Combine(Directory.GetCurrentDirectory(), _outputFolder, XRefArchive.MajorFileName); - Assert.True(File.Exists(xrefMapPath)); + Assert.IsTrue(File.Exists(xrefMapPath)); var xrefMap = YamlUtility.Deserialize(xrefMapPath); - Assert.NotNull(xrefMap.References); - Assert.Equal(34, xrefMap.References.Count); + Assert.IsNotNull(xrefMap.References); + Assert.AreEqual(34, xrefMap.References.Count); } - [Fact] + [TestMethod] public void ProcessMrefWithDefaultOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -133,46 +133,46 @@ public void ProcessMrefWithDefaultOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("

Overwrite summary

", model.Children[0].Metadata["summary"].ToString().Trim()); - Assert.Equal("

Overwrite content

", model.Children[0].Conceptual.Trim()); + Assert.AreEqual("

Overwrite summary

", model.Children[0].Metadata["summary"].ToString().Trim()); + Assert.AreEqual("

Overwrite content

", model.Children[0].Conceptual.Trim()); } } - [Fact] + [TestMethod] public void ProcessMrefWithSimpleOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.simple.md"]); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("\n

Overwrite content

\n", model.Summary); - Assert.Null(model.Conceptual); + Assert.AreEqual("\n

Overwrite content

\n", model.Summary); + Assert.IsNull(model.Conceptual); } - [Fact] + [TestMethod] public void ProcessMrefWithParametersOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.parameters.md"]); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); var method = model.Children.First(s => s.Uid == "CatLibrary.Cat`2.CatLibrary#IAnimal#Eat``1(``0)"); // Verify overwrite parameters - Assert.Equal("

The overwritten description for a

\n", method.Syntax.Parameters[0].Description); - Assert.NotNull(method.Syntax.Parameters[0].Type); - Assert.Equal("\n

This is overwritten type parameters

\n", method.Syntax.TypeParameters[0].Description); - Assert.Null(model.Conceptual); + Assert.AreEqual("

The overwritten description for a

\n", method.Syntax.Parameters[0].Description); + Assert.IsNotNull(method.Syntax.Parameters[0].Type); + Assert.AreEqual("\n

This is overwritten type parameters

\n", method.Syntax.TypeParameters[0].Description); + Assert.IsNull(model.Conceptual); } - [Fact] + [TestMethod] public void ProcessMrefWithNotPredefinedOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -180,15 +180,15 @@ public void ProcessMrefWithNotPredefinedOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("\n

Overwrite content

\n" + Assert.AreEqual("\n

Overwrite content

\n" , model.Metadata["not_defined_property"]); } } - [Fact] + [TestMethod] public void ProcessMrefWithDynamicDevLangsShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -198,19 +198,19 @@ public void ProcessMrefWithDynamicDevLangsShouldSucceed() BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("System.String.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.NotNull(model.Syntax); - Assert.NotNull(model.Syntax.Content); - Assert.Equal(4, model.Syntax.Content.Count); - Assert.Equal("public ref class String sealed", model.Syntax.Content.First(c => c.Language == "cpp").Value); - Assert.Equal("public sealed class String", model.Syntax.Content.First(c => c.Language == "csharp").Value); - Assert.Equal("type String", model.Syntax.Content.First(c => c.Language == "fsharp").Value); - Assert.Equal("Public NotInheritable Class String", model.Syntax.Content.First(c => c.Language == "vb").Value); + Assert.IsNotNull(model); + Assert.IsNotNull(model.Syntax); + Assert.IsNotNull(model.Syntax.Content); + Assert.AreEqual(4, model.Syntax.Content.Count); + Assert.AreEqual("public ref class String sealed", model.Syntax.Content.First(c => c.Language == "cpp").Value); + Assert.AreEqual("public sealed class String", model.Syntax.Content.First(c => c.Language == "csharp").Value); + Assert.AreEqual("type String", model.Syntax.Content.First(c => c.Language == "fsharp").Value); + Assert.AreEqual("Public NotInheritable Class String", model.Syntax.Content.First(c => c.Language == "vb").Value); } - [Fact] + [TestMethod] public void ProcessMrefWithInvalidCrossReferenceShouldWarn() { var files = new FileCollection(Directory.GetCurrentDirectory()); @@ -222,19 +222,19 @@ public void ProcessMrefWithInvalidCrossReferenceShouldWarn() BuildDocument(files); var warnings = listener.GetItemsByLogLevel(LogLevel.Warning); - Assert.Single(warnings); + Assert.ContainsSingle(warnings); var warning = warnings.Single(); - Assert.Equal("2 invalid cross reference(s) \"\", \"\".", warning.Message); - Assert.Equal("TestData/mref/System.String.yml", warning.File); + Assert.AreEqual("2 invalid cross reference(s) \"\", \"\".", warning.Message); + Assert.AreEqual("TestData/mref/System.String.yml", warning.File); var infos = listener.GetItemsByLogLevel(LogLevel.Info).Where(i => i.Message.Contains("Details for invalid cross reference(s)")).ToList(); - Assert.Single(infos); - Assert.Equal("Details for invalid cross reference(s): \"\" in line 6, \"\" in line 8", infos[0].Message); - Assert.Equal("TestData/overwrite/mref.overwrite.invalid.ref.md", infos[0].File); - Assert.Null(infos[0].Line); + Assert.ContainsSingle(infos); + Assert.AreEqual("Details for invalid cross reference(s): \"\" in line 6, \"\" in line 8", infos[0].Message); + Assert.AreEqual("TestData/overwrite/mref.overwrite.invalid.ref.md", infos[0].File); + Assert.IsNull(infos[0].Line); } - [Fact] + [TestMethod] public void ProcessMrefWithInvalidOverwriteShouldFail() { FileCollection files = new(_defaultFiles); @@ -242,7 +242,7 @@ public void ProcessMrefWithInvalidOverwriteShouldFail() Assert.Throws(() => BuildDocument(files)); } - [Fact] + [TestMethod] public void ProcessMrefWithRemarksOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -250,14 +250,14 @@ public void ProcessMrefWithRemarksOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); var method = model.Children.First(s => s.Uid == "CatLibrary.Cat`2.#ctor(`0)"); - Assert.Equal("\n

Remarks content

\n", method.Remarks); + Assert.AreEqual("\n

Remarks content

\n", method.Remarks); } } - [Fact] + [TestMethod] public void ProcessMrefWithMultiUidOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -265,31 +265,31 @@ public void ProcessMrefWithMultiUidOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("\n

Overwrite content1

\n", model.Conceptual); - Assert.Equal("\n

Overwrite "content2"

\n", model.Summary); - Assert.Equal("\n

Overwrite 'content3'

\n", model.Metadata["not_defined_property"]); + Assert.AreEqual("\n

Overwrite content1

\n", model.Conceptual); + Assert.AreEqual("\n

Overwrite "content2"

\n", model.Summary); + Assert.AreEqual("\n

Overwrite 'content3'

\n", model.Metadata["not_defined_property"]); } } - [Fact] + [TestMethod] public void SystemKeysListShouldBeComplete() { var files = new FileCollection(_defaultFiles); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); var systemKeys = ToList(model[Constants.PropertyName.SystemKeys]); - Assert.NotEmpty(systemKeys); + Assert.IsNotEmpty(systemKeys); foreach (var key in model.Keys.Where(key => key[0] != '_' && key != "meta" && key != "anotherMeta")) { Assert.Contains(key, systemKeys); } } - [Fact] + [TestMethod] public void LoadArticleWithEmptyFileShouldWarnAndReturnNull() { var fileWithNoContent = "TestData/mref/FileWithNoContent.yml"; @@ -301,12 +301,12 @@ public void LoadArticleWithEmptyFileShouldWarnAndReturnNull() var actualFileModel = processor.Load(file, null); var warnings = listener.GetItemsByLogLevel(LogLevel.Warning); - Assert.Single(warnings); + Assert.ContainsSingle(warnings); var warning = warnings.Single(); - Assert.Equal("Please add `YamlMime` as the first line of file, e.g.: `### YamlMime:ManagedReference`, otherwise the file will be not treated as ManagedReference source file in near future.", warning.Message); - Assert.Equal(fileWithNoContent, warning.File); + Assert.AreEqual("Please add `YamlMime` as the first line of file, e.g.: `### YamlMime:ManagedReference`, otherwise the file will be not treated as ManagedReference source file in near future.", warning.Message); + Assert.AreEqual(fileWithNoContent, warning.File); - Assert.Null(actualFileModel); + Assert.IsNull(actualFileModel); } private void BuildDocument(FileCollection files) diff --git a/test/Docfx.Build.OverwriteDocuments.Tests/MarkdownFragmentsCreatorTest.cs b/test/Docfx.Build.OverwriteDocuments.Tests/MarkdownFragmentsCreatorTest.cs index f08c2c55d73..45c76af44d6 100644 --- a/test/Docfx.Build.OverwriteDocuments.Tests/MarkdownFragmentsCreatorTest.cs +++ b/test/Docfx.Build.OverwriteDocuments.Tests/MarkdownFragmentsCreatorTest.cs @@ -3,35 +3,35 @@ using Markdig; using Markdig.Syntax; -using Xunit; namespace Docfx.Build.OverwriteDocuments.Tests; +[TestClass] public class MarkdownFragmentsCreatorTest { - [Fact] + [TestMethod] public void BaseTest() { var markdown = File.ReadAllText("TestData/System.String.yml.md"); var ast = Markdown.Parse(markdown); var model = new MarkdownFragmentsCreator().Create(ast).ToList(); - Assert.Equal(2, model.Count); - Assert.Equal("System.String", model[0].Uid); - Assert.NotNull(model[0].UidSource); - Assert.Equal("author: rpetrusha\nms.author: ronpet\nmanager: wpickett", model[0].YamlCodeBlock.Replace("\r", "")); - Assert.NotNull(model[0].YamlCodeBlockSource); - Assert.Equal(4, model[0].Contents.Count); - Assert.Equal("summary", model[0].Contents[0].PropertyName); - Assert.NotNull(model[0].Contents[0].PropertyNameSource); - Assert.Single(model[0].Contents[0].PropertyValue); - Assert.IsType(model[0].Contents[0].PropertyValue[0]); - Assert.Equal("remarks", model[0].Contents[1].PropertyName); - Assert.Equal(6, model[0].Contents[1].PropertyValue.Count); - Assert.Equal("System.String.#ctor(System.Char*)", model[1].Uid); + Assert.AreEqual(2, model.Count); + Assert.AreEqual("System.String", model[0].Uid); + Assert.IsNotNull(model[0].UidSource); + Assert.AreEqual("author: rpetrusha\nms.author: ronpet\nmanager: wpickett", model[0].YamlCodeBlock.Replace("\r", "")); + Assert.IsNotNull(model[0].YamlCodeBlockSource); + Assert.AreEqual(4, model[0].Contents.Count); + Assert.AreEqual("summary", model[0].Contents[0].PropertyName); + Assert.IsNotNull(model[0].Contents[0].PropertyNameSource); + Assert.ContainsSingle(model[0].Contents[0].PropertyValue); + Assert.IsInstanceOfType(model[0].Contents[0].PropertyValue[0]); + Assert.AreEqual("remarks", model[0].Contents[1].PropertyName); + Assert.AreEqual(6, model[0].Contents[1].PropertyValue.Count); + Assert.AreEqual("System.String.#ctor(System.Char*)", model[1].Uid); } - [Fact] + [TestMethod] public void MissingStartingH1CodeHeadingShouldFail() { var markdown = @"## `summary` @@ -42,11 +42,11 @@ markdown content var ast = Markdown.Parse(markdown); var ex = Assert.Throws(() => new MarkdownFragmentsCreator().Create(ast).ToList()); - Assert.Equal("Expect L1InlineCodeHeading", ex.Message); - Assert.Equal(0, ex.Position); + Assert.AreEqual("Expect L1InlineCodeHeading", ex.Message); + Assert.AreEqual(0, ex.Position); } - [Fact] + [TestMethod] public void MarkdownContentAfterL1CodeHeadingShouldFail() { var markdown = @"# `Lesson_1` @@ -62,11 +62,11 @@ markdown content var ast = Markdown.Parse(markdown); var ex = Assert.Throws(() => new MarkdownFragmentsCreator().Create(ast).ToList()); - Assert.Equal("Expect L1InlineCodeHeading", ex.Message); - Assert.Equal(8, ex.Position); + Assert.AreEqual("Expect L1InlineCodeHeading", ex.Message); + Assert.AreEqual(8, ex.Position); } - [Fact] + [TestMethod] public void YamlCodeBlockShouldBeNextToL1CodeHeading() { var markdown = @"# `YAML` @@ -82,8 +82,8 @@ public void YamlCodeBlockShouldBeNextToL1CodeHeading() var ast = Markdown.Parse(markdown); var model = new MarkdownFragmentsCreator().Create(ast).ToList(); - Assert.Null(model[0].YamlCodeBlock); - Assert.Null(model[0].YamlCodeBlockSource); - Assert.IsType(model[0].Contents[0].PropertyValue[1]); + Assert.IsNull(model[0].YamlCodeBlock); + Assert.IsNull(model[0].YamlCodeBlockSource); + Assert.IsInstanceOfType(model[0].Contents[0].PropertyValue[1]); } } diff --git a/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs b/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs index 01dbcbe25ee..182329d177e 100644 --- a/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs +++ b/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs @@ -6,15 +6,15 @@ using Markdig; using Markdig.Syntax; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.OverwriteDocuments.Tests; +[TestClass] public class OverwriteDocumentModelCreatorTest { private readonly TestLoggerListener _listener = new(); - [Fact] + [TestMethod] public void YamlCodeBlockTest() { var yamlCodeBlockString = @"name: name overwrite @@ -27,13 +27,13 @@ public void YamlCodeBlockTest() description: overwrite in yaml block"; var testYamlCodeBlock = Markdown.Parse($"```\n{yamlCodeBlockString}\n```")[0]; var actual = JObject.FromObject(OverwriteDocumentModelCreator.ConvertYamlCodeBlock(yamlCodeBlockString, testYamlCodeBlock)); - Assert.Equal("name overwrite", actual["name"].ToString()); - Assert.Equal("Application 1", actual["definitions"][0]["name"].ToString()); - Assert.Equal("id", actual["definitions"][0]["properties"][0]["name"].ToString()); - Assert.Equal("overwrite in yaml block", actual["definitions"][0]["properties"][1]["description"].ToString()); + Assert.AreEqual("name overwrite", actual["name"].ToString()); + Assert.AreEqual("Application 1", actual["definitions"][0]["name"].ToString()); + Assert.AreEqual("id", actual["definitions"][0]["properties"][0]["name"].ToString()); + Assert.AreEqual("overwrite in yaml block", actual["definitions"][0]["properties"][1]["description"].ToString()); } - [Fact] + [TestMethod] public void ContentConvertTest() { var testBlockList = Markdown.Parse("Test").ToList(); @@ -59,23 +59,23 @@ public void ContentConvertTest() } var contentsMetadata = new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents); - Assert.Equal(3, contentsMetadata.Count); - Assert.Equal("summary,return,function", ExtractDictionaryKeys(contentsMetadata)); - Assert.Equal(2, ((Dictionary)contentsMetadata["return"]).Count); - Assert.Equal("description,type", + Assert.AreEqual(3, contentsMetadata.Count); + Assert.AreEqual("summary,return,function", ExtractDictionaryKeys(contentsMetadata)); + Assert.AreEqual(2, ((Dictionary)contentsMetadata["return"]).Count); + Assert.AreEqual("description,type", ExtractDictionaryKeys((Dictionary)contentsMetadata["return"])); - Assert.Single((Dictionary)contentsMetadata["function"]); - Assert.Equal(2, + Assert.ContainsSingle((Dictionary)contentsMetadata["function"]); + Assert.AreEqual(2, ((List)((Dictionary)contentsMetadata["function"])["parameters"]).Count); - Assert.Equal("id,description,type", + Assert.AreEqual("id,description,type", ExtractDictionaryKeys( (Dictionary)((List)((Dictionary)contentsMetadata["function"])["parameters"])[0])); - Assert.Equal("id,description", + Assert.AreEqual("id,description", ExtractDictionaryKeys( (Dictionary)((List)((Dictionary)contentsMetadata["function"])["parameters"])[1])); } - [Fact] + [TestMethod] public void DuplicateOPathInMarkdownSectionTest() { var testOPath = "function/parameters"; @@ -107,13 +107,13 @@ public void DuplicateOPathInMarkdownSectionTest() } var logs = _listener.Items; - Assert.Single(logs, l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments); - Assert.Single(contentsMetadata); - Assert.Equal("test2", + Assert.ContainsSingle(logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments)); + Assert.ContainsSingle(contentsMetadata); + Assert.AreEqual("test2", ((ParagraphBlock)((MarkdownDocument)((Dictionary)contentsMetadata["function"])["parameters"])[0]).Inline.FirstChild.ToString()); } - [Fact] + [TestMethod] public void DuplicateOPathsInYamlCodeBlockAndContentsBlockTest() { // Yaml section @@ -161,15 +161,15 @@ public void DuplicateOPathsInYamlCodeBlockAndContentsBlockTest() var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments).ToList(); - Assert.Single(warningLogs); - Assert.Equal("Two duplicate OPaths `definitions[name=\"Application 1\"]/properties[name=\"displayName\"]/description` in yaml code block and contents block", warningLogs[0].Message); - Assert.Equal("name overwrite", metadata["name"].ToString()); - Assert.Equal(typeof(MarkdownDocument), metadata["summary"].GetType()); - Assert.Equal(typeof(MarkdownDocument), ((Dictionary)((List)((Dictionary)((List)metadata["definitions"])[0])["properties"])[1])["description"].GetType()); - Assert.Equal(typeof(MarkdownDocument), ((Dictionary)((List)((Dictionary)((List)metadata["definitions"])[0])["properties"])[2])["description"].GetType()); + Assert.ContainsSingle(warningLogs); + Assert.AreEqual("Two duplicate OPaths `definitions[name=\"Application 1\"]/properties[name=\"displayName\"]/description` in yaml code block and contents block", warningLogs[0].Message); + Assert.AreEqual("name overwrite", metadata["name"].ToString()); + Assert.AreEqual(typeof(MarkdownDocument), metadata["summary"].GetType()); + Assert.AreEqual(typeof(MarkdownDocument), ((Dictionary)((List)((Dictionary)((List)metadata["definitions"])[0])["properties"])[1])["description"].GetType()); + Assert.AreEqual(typeof(MarkdownDocument), ((Dictionary)((List)((Dictionary)((List)metadata["definitions"])[0])["properties"])[2])["description"].GetType()); } - [Fact] + [TestMethod] public void InvalidOPathsTest1() { var testBlockList = Markdown.Parse("Test").ToList(); @@ -190,13 +190,13 @@ public void InvalidOPathsTest1() } var ex = Assert.Throws(() => new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents)); - Assert.Equal( + Assert.AreEqual( "A(parameters) is not expected to be an array like \"A[c=d]/B\", however it is used as an array in line 0 with `parameters[id=\"para1\"]/...`", ex.Message); - Assert.Equal(0, ex.Position); + Assert.AreEqual(0, ex.Position); } - [Fact] + [TestMethod] public void InvalidOPathsTest2() { var testBlockList = Markdown.Parse("Test").ToList(); @@ -217,10 +217,10 @@ public void InvalidOPathsTest2() } var ex = Assert.Throws(() => new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents)); - Assert.Equal( + Assert.AreEqual( "A(parameters) is not expected to be an object like \"A/B\", however it is used as an object in line 0 with `parameters/...`", ex.Message); - Assert.Equal(0, ex.Position); + Assert.AreEqual(0, ex.Position); } private static string ExtractDictionaryKeys(Dictionary dict) diff --git a/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteUtilityTest.cs b/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteUtilityTest.cs index e7e5513b21a..f177348fe62 100644 --- a/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteUtilityTest.cs +++ b/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteUtilityTest.cs @@ -1,37 +1,36 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Docfx.Build.OverwriteDocuments.Tests; +[TestClass] public class OverwriteUtilityTest { - [Fact] + [TestMethod] public void ParseOPathTest() { var OPathString = "a/f[c= \"d\"]/g/b[c =\"d/d_d d\"]/e"; var OPathSegments = OverwriteUtility.ParseOPath(OPathString); - Assert.Equal(5, OPathSegments.Count); - Assert.Equal("a,f,g,b,e", OPathSegments.Select(o => o.SegmentName).Aggregate((a, b) => a + "," + b)); - Assert.Equal("c", OPathSegments[1].Key); - Assert.Equal("d", OPathSegments[1].Value); - Assert.Equal("d/d_d d", OPathSegments[3].Value); + Assert.AreEqual(5, OPathSegments.Count); + Assert.AreEqual("a,f,g,b,e", OPathSegments.Select(o => o.SegmentName).Aggregate((a, b) => a + "," + b)); + Assert.AreEqual("c", OPathSegments[1].Key); + Assert.AreEqual("d", OPathSegments[1].Value); + Assert.AreEqual("d/d_d d", OPathSegments[3].Value); } - [Theory] - [InlineData("abc[]d=\"e\"/g]")] - [InlineData("abc[d='e']/g")] - [InlineData("abc[d=\"e\"]/g/")] - [InlineData("abc[d=2]/g/")] - [InlineData("abc[d=true]/g/")] - [InlineData("abc[a=\"b]\b")] - [InlineData("abc/efg[a=\"b\"]")] - [InlineData("abc/efg[a=\"b\"]e/g")] - [InlineData("abc/[efg=\"hij\"]/e")] + [TestMethod] + [DataRow("abc[]d=\"e\"/g]")] + [DataRow("abc[d='e']/g")] + [DataRow("abc[d=\"e\"]/g/")] + [DataRow("abc[d=2]/g/")] + [DataRow("abc[d=true]/g/")] + [DataRow("abc[a=\"b]\b")] + [DataRow("abc/efg[a=\"b\"]")] + [DataRow("abc/efg[a=\"b\"]e/g")] + [DataRow("abc/[efg=\"hij\"]/e")] public void ParseInvalidOPathsTest(string OPathString) { var ex = Assert.Throws(() => OverwriteUtility.ParseOPath(OPathString)); - Assert.Equal($"{OPathString} is not a valid OPath", ex.Message); + Assert.AreEqual($"{OPathString} is not a valid OPath", ex.Message); } } diff --git a/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs b/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs index e2dcb241d03..e3ba51723fc 100644 --- a/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs +++ b/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs @@ -11,11 +11,11 @@ using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.RestApi.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class RestApiDocumentProcessorTest : TestBase { private readonly string _outputFolder; @@ -37,120 +37,120 @@ public RestApiDocumentProcessorTest() }; } - [Fact] + [TestMethod] public void ProcessSwaggerShouldSucceed() { FileCollection files = new(_defaultFiles); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("graph.windows.net/myorganization/Contacts/1.0", model.Uid); - Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); - Assert.Equal(10, model.Children.Count); - Assert.Equal("Hello world!", model.Metadata["meta"]); + Assert.AreEqual("graph.windows.net/myorganization/Contacts/1.0", model.Uid); + Assert.AreEqual("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); + Assert.AreEqual(10, model.Children.Count); + Assert.AreEqual("Hello world!", model.Metadata["meta"]); // Verify $ref in path var item0 = model.Children[0]; - Assert.Equal("graph.windows.net/myorganization/Contacts/1.0/get contacts", item0.Uid); - Assert.Equal("

You can get a collection of contacts from your tenant.

\n", item0.Summary); - Assert.Single(item0.Parameters); - Assert.Equal("1.6", item0.Parameters[0].Metadata["default"]); - Assert.Single(item0.Responses); - Assert.Equal("200", item0.Responses[0].HttpStatusCode); + Assert.AreEqual("graph.windows.net/myorganization/Contacts/1.0/get contacts", item0.Uid); + Assert.AreEqual("

You can get a collection of contacts from your tenant.

\n", item0.Summary); + Assert.ContainsSingle(item0.Parameters); + Assert.AreEqual("1.6", item0.Parameters[0].Metadata["default"]); + Assert.ContainsSingle(item0.Responses); + Assert.AreEqual("200", item0.Responses[0].HttpStatusCode); // Verify tags of child - Assert.Equal("contacts", item0.Tags[0]); + Assert.AreEqual("contacts", item0.Tags[0]); var item1 = model.Children[1]; - Assert.Equal("contacts", item1.Tags[0]); - Assert.Equal("pet store", item1.Tags[1]); + Assert.AreEqual("contacts", item1.Tags[0]); + Assert.AreEqual("pet store", item1.Tags[1]); // Verify tags of root - Assert.Equal(3, model.Tags.Count); + Assert.AreEqual(3, model.Tags.Count); var tag0 = model.Tags[0]; - Assert.Equal("contact", tag0.Name); - Assert.Equal("

Everything about the contacts

\n", tag0.Description); - Assert.Equal("contact-bookmark", tag0.HtmlId); - Assert.Single(tag0.Metadata); + Assert.AreEqual("contact", tag0.Name); + Assert.AreEqual("

Everything about the contacts

\n", tag0.Description); + Assert.AreEqual("contact-bookmark", tag0.HtmlId); + Assert.ContainsSingle(tag0.Metadata); var externalDocs = (JObject)tag0.Metadata["externalDocs"]; - Assert.NotNull(externalDocs); - Assert.Equal("Find out more", externalDocs["description"]); - Assert.Equal("http://swagger.io", externalDocs["url"]); + Assert.IsNotNull(externalDocs); + Assert.AreEqual("Find out more", externalDocs["description"]); + Assert.AreEqual("http://swagger.io", externalDocs["url"]); var tag1 = model.Tags[1]; - Assert.Equal("pet_store", tag1.HtmlId); + Assert.AreEqual("pet_store", tag1.HtmlId); // Verify path parameters // Path parameter applicable for get operation - Assert.Equal(2, item1.Parameters.Count); - Assert.Equal("object_id", item1.Parameters[0].Name); - Assert.Equal("api-version", item1.Parameters[1].Name); - Assert.Equal(true, item1.Parameters[1].Metadata["required"]); + Assert.AreEqual(2, item1.Parameters.Count); + Assert.AreEqual("object_id", item1.Parameters[0].Name); + Assert.AreEqual("api-version", item1.Parameters[1].Name); + Assert.AreEqual(true, item1.Parameters[1].Metadata["required"]); // Override ""api-version" parameters by $ref for patch operation var item2 = model.Children[2]; - Assert.Equal(3, item2.Parameters.Count); - Assert.Equal("object_id", item2.Parameters[0].Name); - Assert.Equal("api-version", item2.Parameters[1].Name); - Assert.Equal(false, item2.Parameters[1].Metadata["required"]); + Assert.AreEqual(3, item2.Parameters.Count); + Assert.AreEqual("object_id", item2.Parameters[0].Name); + Assert.AreEqual("api-version", item2.Parameters[1].Name); + Assert.AreEqual(false, item2.Parameters[1].Metadata["required"]); // Override ""api-version" parameters by self definition for delete operation var item3 = model.Children[3]; - Assert.Equal(2, item3.Parameters.Count); - Assert.Equal("object_id", item3.Parameters[0].Name); - Assert.Equal("api-version", item3.Parameters[1].Name); - Assert.Equal(false, item3.Parameters[1].Metadata["required"]); + Assert.AreEqual(2, item3.Parameters.Count); + Assert.AreEqual("object_id", item3.Parameters[0].Name); + Assert.AreEqual("api-version", item3.Parameters[1].Name); + Assert.AreEqual(false, item3.Parameters[1].Metadata["required"]); // When operation parameters is not set, inherit from th parameters for post operation var item4 = model.Children[4]; - Assert.Single(item4.Parameters); - Assert.Equal("api-version", item4.Parameters[0].Name); - Assert.Equal(true, item4.Parameters[0].Metadata["required"]); + Assert.ContainsSingle(item4.Parameters); + Assert.AreEqual("api-version", item4.Parameters[0].Name); + Assert.AreEqual(true, item4.Parameters[0].Metadata["required"]); // When 'definitions' has direct child with $ref defined, should resolve it var item5 = model.Children[6]; var parameter2 = (JObject)item5.Parameters[2].Metadata["schema"]; - Assert.Equal("string", parameter2["type"]); - Assert.Equal("uri", parameter2["format"]); + Assert.AreEqual("string", parameter2["type"]); + Assert.AreEqual("uri", parameter2["format"]); // Verify markup result of parameters - Assert.Equal("

The request body contains a single property that specifies the URL of the user or contact to add as manager.

\n", + Assert.AreEqual("

The request body contains a single property that specifies the URL of the user or contact to add as manager.

\n", item5.Parameters[2].Description); - Assert.Equal("

uri description.

\n", + Assert.AreEqual("

uri description.

\n", (string)parameter2["description"]); - Assert.Equal("

No Content. Indicates success. No response body is returned.

\n", + Assert.AreEqual("

No Content. Indicates success. No response body is returned.

\n", item5.Responses[0].Description); // Verify for markup result of securityDefinitions var securityDefinitions = (JObject)model.Metadata.Single(m => m.Key == "securityDefinitions").Value; var auth = (JObject)securityDefinitions["auth"]; - Assert.Equal("

securityDefinitions description.

\n", + Assert.AreEqual("

securityDefinitions description.

\n", auth["description"].ToString()); } - [Fact] + [TestMethod] public void ProcessSwaggerWithExternalReferenceShouldSucceed() { FileCollection files = new(_defaultFiles); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); var operation = model.Children.Single(c => c.OperationId == "get contact direct reports links"); var externalSchema = operation.Parameters[2].Metadata["schema"]; var externalParameters = ((JObject)externalSchema)["parameters"]; - Assert.Equal("cache1", externalParameters["name"]); + Assert.AreEqual("cache1", externalParameters["name"]); var scheduleEntries = externalParameters["parameters"]["properties"]["scheduleEntries"]; - Assert.Equal(JTokenType.Array, scheduleEntries.Type); - Assert.Equal(2, ((JArray)scheduleEntries).Count); - Assert.Equal("Monday", ((JArray)scheduleEntries)[0]["dayOfWeek"]); + Assert.AreEqual(JTokenType.Array, scheduleEntries.Type); + Assert.AreEqual(2, ((JArray)scheduleEntries).Count); + Assert.AreEqual("Monday", ((JArray)scheduleEntries)[0]["dayOfWeek"]); var responses = ((JObject)externalSchema)["responses"]; - Assert.Equal("fake metadata", responses["200"]["examples"]["application/json"]["odata.metadata"]); + Assert.AreEqual("fake metadata", responses["200"]["examples"]["application/json"]["odata.metadata"]); } - [Fact] + [TestMethod] public void ProcessSwaggerWithExternalEmbeddedReferenceShouldSucceed() { var files = new FileCollection(Directory.GetCurrentDirectory()); @@ -158,18 +158,18 @@ public void ProcessSwaggerWithExternalEmbeddedReferenceShouldSucceed() BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contactsForExternalRef.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); var operation = model.Children.Single(c => c.OperationId == "update_contact_manager"); var externalSchema = (JObject)operation.Parameters[2].Metadata["schema"]; - Assert.Equal("

uri description.

\n", externalSchema["description"].ToString()); - Assert.Equal("string", externalSchema["type"]); - Assert.Equal("uri", externalSchema["format"]); - Assert.Equal("refUrl", externalSchema["x-internal-ref-name"]); + Assert.AreEqual("

uri description.

\n", externalSchema["description"].ToString()); + Assert.AreEqual("string", externalSchema["type"]); + Assert.AreEqual("uri", externalSchema["format"]); + Assert.AreEqual("refUrl", externalSchema["x-internal-ref-name"]); } - [Fact] + [TestMethod] public void ProcessSwaggerWithNotExistedExternalReferenceShouldFail() { var files = new FileCollection(Directory.GetCurrentDirectory()); @@ -179,12 +179,12 @@ public void ProcessSwaggerWithNotExistedExternalReferenceShouldFail() BuildDocument(files); - Assert.NotNull(listener.Items); - Assert.Single(listener.Items); + Assert.IsNotNull(listener.Items); + Assert.ContainsSingle(listener.Items); Assert.Contains("External swagger path not exist", listener.Items[0].Message); } - [Fact] + [TestMethod] public void ProcessSwaggerWithExternalReferenceHasRefInsideShouldFail() { var files = new FileCollection(Directory.GetCurrentDirectory()); @@ -194,12 +194,12 @@ public void ProcessSwaggerWithExternalReferenceHasRefInsideShouldFail() BuildDocument(files); - Assert.NotNull(listener.Items); - Assert.Single(listener.Items); + Assert.IsNotNull(listener.Items); + Assert.ContainsSingle(listener.Items); Assert.Contains("$ref in refWithRefInside.json is not supported in external reference currently.", listener.Items[0].Message); } - [Fact] + [TestMethod] public void ProcessSwaggerWithXRefMapShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -208,22 +208,22 @@ public void ProcessSwaggerWithXRefMapShouldSucceed() var xrefMapPath = Path.Combine(Directory.GetCurrentDirectory(), _outputFolder, XRefArchive.MajorFileName); var xrefMap = YamlUtility.Deserialize(xrefMapPath); - Assert.NotNull(xrefMap.References); + Assert.IsNotNull(xrefMap.References); var rootItem = xrefMap.References[0]; - Assert.Equal("graph.windows.net/myorganization/Contacts/1.0", rootItem.Uid); - Assert.Equal("Contacts", rootItem.Name); - Assert.Equal("swagger/contacts.json", rootItem.Href); + Assert.AreEqual("graph.windows.net/myorganization/Contacts/1.0", rootItem.Uid); + Assert.AreEqual("Contacts", rootItem.Name); + Assert.AreEqual("swagger/contacts.json", rootItem.Href); var childItem1 = xrefMap.References[1]; - Assert.Equal("graph.windows.net/myorganization/Contacts/1.0/delete contact", childItem1.Uid); - Assert.Equal("delete contact", childItem1.Name); - Assert.Equal("swagger/contacts.json", childItem1.Href); + Assert.AreEqual("graph.windows.net/myorganization/Contacts/1.0/delete contact", childItem1.Uid); + Assert.AreEqual("delete contact", childItem1.Name); + Assert.AreEqual("swagger/contacts.json", childItem1.Href); var tagItem1 = xrefMap.References[9]; - Assert.Equal("graph.windows.net/myorganization/Contacts/1.0/tag/contact", tagItem1.Uid); - Assert.Equal("contact", tagItem1.Name); - Assert.Equal("swagger/contacts.json", tagItem1.Href); + Assert.AreEqual("graph.windows.net/myorganization/Contacts/1.0/tag/contact", tagItem1.Uid); + Assert.AreEqual("contact", tagItem1.Name); + Assert.AreEqual("swagger/contacts.json", tagItem1.Href); } - [Fact] + [TestMethod] public void ProcessSwaggerWithTagsOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -232,18 +232,18 @@ public void ProcessSwaggerWithTagsOverwriteShouldSucceed() { var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); var tag1 = model.Tags[0]; - Assert.Equal("

Overwrite description content

\n", tag1.Description); - Assert.Null(tag1.Conceptual); + Assert.AreEqual("

Overwrite description content

\n", tag1.Description); + Assert.IsNull(tag1.Conceptual); var tag2 = model.Tags[1]; - Assert.Equal("

Access to Petstore orders

\n", tag2.Description); - Assert.Equal("

Overwrite conceptual content

\n", tag2.Conceptual); + Assert.AreEqual("

Access to Petstore orders

\n", tag2.Description); + Assert.AreEqual("

Overwrite conceptual content

\n", tag2.Conceptual); } } - [Fact] + [TestMethod] public void ProcessSwaggerWithDefaultOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -252,27 +252,27 @@ public void ProcessSwaggerWithDefaultOverwriteShouldSucceed() { var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("

Overwrite summary

\n", model.Summary); - Assert.Equal("\n

Overwrite content

\n", model.Conceptual); + Assert.AreEqual("

Overwrite summary

\n", model.Summary); + Assert.AreEqual("\n

Overwrite content

\n", model.Conceptual); } } - [Fact] + [TestMethod] public void ProcessSwaggerWithSimpleOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.simple.md" }); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("\n

Overwrite content

\n", model.Summary); - Assert.Null(model.Conceptual); + Assert.AreEqual("\n

Overwrite content

\n", model.Summary); + Assert.IsNull(model.Conceptual); } - [Fact] + [TestMethod] public void ProcessSwaggerWithInvalidLinksOverwriteShouldSucceedWithWarning() { using var listener = new TestListenerScope(); @@ -283,84 +283,84 @@ public void ProcessSwaggerWithInvalidLinksOverwriteShouldSucceedWithWarning() files.Add(DocumentType.Overwrite, ["TestData/overwrite/rest.overwrite.invalid.links.second.md"]); BuildDocument(files); - Assert.Equal(7, listener.Items.Count); // Additional warning for "There is no template processing document type(s): RestApi" + Assert.AreEqual(7, listener.Items.Count); // Additional warning for "There is no template processing document type(s): RestApi" var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); var warningsForLinkA = listener.Items.Where(i => i.Message == "Invalid file link:(~/TestData/overwrite/a.md).").ToList(); - Assert.Equal( + Assert.AreEqual( "

Remarks content remarks

", model.Remarks.Trim()); - Assert.Equal("6", warningsForLinkA.Single(i => i.File == "TestData/overwrite/rest.overwrite.invalid.links.first.md").Line); + Assert.AreEqual("6", warningsForLinkA.Single(i => i.File == "TestData/overwrite/rest.overwrite.invalid.links.first.md").Line); - Assert.Equal( + Assert.AreEqual( "

Summary content summary

", model.Summary.Trim()); var summaryLink = listener.Items.Single(i => i.Message == "Invalid file link:(~/TestData/overwrite/b.md)."); - Assert.Equal("TestData/overwrite/rest.overwrite.invalid.links.first.md", summaryLink.File); + Assert.AreEqual("TestData/overwrite/rest.overwrite.invalid.links.first.md", summaryLink.File); var warningsForLinkAForSecond = warningsForLinkA.Where(i => i.File == "TestData/overwrite/rest.overwrite.invalid.links.second.md").ToList(); - Assert.Equal( + Assert.AreEqual( "

Conceptual content Conceptual

\n

Conceptual

", model.Conceptual.Trim()); - Assert.Equal(1, warningsForLinkAForSecond.Count(i => i.Line == "5")); - Assert.Equal(1, warningsForLinkAForSecond.Count(i => i.Line == "7")); + Assert.AreEqual(1, warningsForLinkAForSecond.Count(i => i.Line == "5")); + Assert.AreEqual(1, warningsForLinkAForSecond.Count(i => i.Line == "7")); var outputTagRawModelPath = GetRawModelFilePath("tag.json"); - Assert.True(File.Exists(outputTagRawModelPath)); + Assert.IsTrue(File.Exists(outputTagRawModelPath)); var tagModel = JsonUtility.Deserialize(outputTagRawModelPath); - Assert.Equal( + Assert.AreEqual( "

Another uid content Another

", tagModel.Conceptual.Trim()); - Assert.Equal(1, warningsForLinkAForSecond.Count(i => i.Line == "13")); + Assert.AreEqual(1, warningsForLinkAForSecond.Count(i => i.Line == "13")); } - [Fact] + [TestMethod] public void ProcessSwaggerWithParametersOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); files.Add(DocumentType.Overwrite, ["TestData/overwrite/rest.overwrite.parameters.md"]); BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); // Verify overwrite parameters var parametersForUpdate = model.Children.Single(c => c.OperationId == "update contact").Parameters; - Assert.Equal("

The new object_id description

\n", + Assert.AreEqual("

The new object_id description

\n", parametersForUpdate.Single(p => p.Name == "object_id").Description); var bodyparam = parametersForUpdate.Single(p => p.Name == "bodyparam"); - Assert.Equal("

The new bodyparam description

\n", + Assert.AreEqual("

The new bodyparam description

\n", bodyparam.Description); var properties = (JObject)((JObject)bodyparam.Metadata["schema"])["properties"]; var objectType = properties["objectType"]; - Assert.Equal("string", objectType["type"]); - Assert.Equal("this is overwrite objectType description", objectType["description"]); + Assert.AreEqual("string", objectType["type"]); + Assert.AreEqual("this is overwrite objectType description", objectType["description"]); var errorDetail = properties["provisioningErrors"]["items"]["schema"]["properties"]["errorDetail"]; - Assert.Equal(JTokenType.Boolean, errorDetail["readOnly"].Type); - Assert.Equal("false", errorDetail["readOnly"].ToString().ToLower()); - Assert.Equal("this is overwrite errorDetail description", errorDetail["description"]); + Assert.AreEqual(JTokenType.Boolean, errorDetail["readOnly"].Type); + Assert.AreEqual("false", errorDetail["readOnly"].ToString().ToLower()); + Assert.AreEqual("this is overwrite errorDetail description", errorDetail["description"]); var paramForUpdateManager = model.Children.Single(c => c.OperationId == "get contact memberOf links").Parameters.Single(p => p.Name == "bodyparam"); var paramForAllOf = ((JObject)paramForUpdateManager.Metadata["schema"])["allOf"]; // First allOf item is not overwritten - Assert.Equal("

original first allOf description

\n", paramForAllOf[0]["description"]); + Assert.AreEqual("

original first allOf description

\n", paramForAllOf[0]["description"]); // Second allOf item is overwritten - Assert.Equal("this is second overwrite allOf description", paramForAllOf[1]["description"]); - Assert.Equal("this is overwrite location description", paramForAllOf[1]["properties"]["location"]["description"]); + Assert.AreEqual("this is second overwrite allOf description", paramForAllOf[1]["description"]); + Assert.AreEqual("this is overwrite location description", paramForAllOf[1]["properties"]["location"]["description"]); // Third allOf item's enum value is overwritten var paramForLevel = paramForAllOf[2]["properties"]["level"]; - Assert.Equal("this is overwrite level description", paramForLevel["description"]); - Assert.Equal(3, paramForLevel["enum"].Count()); - Assert.Equal("Verbose", paramForLevel["enum"][0].ToString()); - Assert.Equal("Info", paramForLevel["enum"][1].ToString()); - Assert.Equal("Warning", paramForLevel["enum"][2].ToString()); + Assert.AreEqual("this is overwrite level description", paramForLevel["description"]); + Assert.AreEqual(3, paramForLevel["enum"].Count()); + Assert.AreEqual("Verbose", paramForLevel["enum"][0].ToString()); + Assert.AreEqual("Info", paramForLevel["enum"][1].ToString()); + Assert.AreEqual("Warning", paramForLevel["enum"][2].ToString()); } - [Fact] + [TestMethod] public void ProcessSwaggerWithNotPredefinedOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -368,14 +368,14 @@ public void ProcessSwaggerWithNotPredefinedOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("\n

Overwrite content

\n", model.Metadata["not_defined_property"]); - Assert.Null(model.Conceptual); + Assert.AreEqual("\n

Overwrite content

\n", model.Metadata["not_defined_property"]); + Assert.IsNull(model.Conceptual); } } - [Fact] + [TestMethod] public void ProcessSwaggerWithInvalidOverwriteShouldFail() { FileCollection files = new(_defaultFiles); @@ -383,7 +383,7 @@ public void ProcessSwaggerWithInvalidOverwriteShouldFail() Assert.Throws(() => BuildDocument(files)); } - [Fact] + [TestMethod] public void ProcessSwaggerWithUnmergeableOverwriteShouldSucceed() { FileCollection files = new(_defaultFiles); @@ -391,13 +391,13 @@ public void ProcessSwaggerWithUnmergeableOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); + Assert.AreEqual("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); } } - [Fact] + [TestMethod] public void ProcessSwaggerWithRemarksOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -405,13 +405,13 @@ public void ProcessSwaggerWithRemarksOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("\n

Remarks content

\n", model.Remarks); + Assert.AreEqual("\n

Remarks content

\n", model.Remarks); } } - [Fact] + [TestMethod] public void ProcessSwaggerWithMultiUidOverwriteShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -420,16 +420,16 @@ public void ProcessSwaggerWithMultiUidOverwriteShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); - Assert.Equal("\n

Overwrite content1

\n", model.Conceptual); - Assert.Equal("\n

Overwrite "content2"

\n", model.Summary); - Assert.Equal("\n

Overwrite 'content3'

\n", model.Metadata["not_defined_property"]); + Assert.AreEqual("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId); + Assert.AreEqual("\n

Overwrite content1

\n", model.Conceptual); + Assert.AreEqual("\n

Overwrite "content2"

\n", model.Summary); + Assert.AreEqual("\n

Overwrite 'content3'

\n", model.Metadata["not_defined_property"]); } } - [Fact] + [TestMethod] public void SystemKeysListShouldBeComplete() { var userKeys = new[] { "meta", "swagger", "securityDefinitions", "schemes" }; @@ -437,10 +437,10 @@ public void SystemKeysListShouldBeComplete() BuildDocument(files); var outputRawModelPath = GetRawModelFilePath("contacts.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); var systemKeys = ToList(model[Constants.PropertyName.SystemKeys]); - Assert.NotEmpty(systemKeys); + Assert.IsNotEmpty(systemKeys); foreach (var key in model.Keys.Where(key => key[0] != '_' && !userKeys.Contains(key))) { Assert.Contains(key, systemKeys); diff --git a/test/Docfx.Build.RestApi.Tests/SwaggerJsonParserTest.cs b/test/Docfx.Build.RestApi.Tests/SwaggerJsonParserTest.cs index 8444caf7e37..3e4bef6f649 100644 --- a/test/Docfx.Build.RestApi.Tests/SwaggerJsonParserTest.cs +++ b/test/Docfx.Build.RestApi.Tests/SwaggerJsonParserTest.cs @@ -5,122 +5,122 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.RestApi.Tests; +[TestClass] public class SwaggerJsonParserTest { - [Fact] + [TestMethod] public void ParseSimpleSwaggerJsonShouldSucceed() { var swaggerFile = "TestData/swagger/simple_swagger2.json"; var swagger = SwaggerJsonParser.Parse(swaggerFile); - Assert.Single(swagger.Paths.Values); + Assert.ContainsSingle(swagger.Paths.Values); var actionJObject = swagger.Paths["/contacts"].Metadata["get"] as JObject; - Assert.NotNull(actionJObject); + Assert.IsNotNull(actionJObject); var action = actionJObject.ToObject(); var parameters = action.Parameters; - Assert.Single(parameters); - Assert.Equal("query", parameters[0].Metadata["in"]); - Assert.Single(action.Responses); + Assert.ContainsSingle(parameters); + Assert.AreEqual("query", parameters[0].Metadata["in"]); + Assert.ContainsSingle(action.Responses); var response = action.Responses["200"]; - Assert.Single(response.Examples); + Assert.ContainsSingle(response.Examples); var example = response.Examples["application/json"]; - Assert.NotNull(example); + Assert.IsNotNull(example); } - [Fact] + [TestMethod] public void ParseSwaggerJsonWithReferenceShouldSucceed() { var swaggerFile = "TestData/swagger/ref_swagger2.json"; var swagger = SwaggerJsonParser.Parse(swaggerFile); - Assert.Single(swagger.Paths); - Assert.Single(swagger.Paths["/contacts"].Metadata); + Assert.ContainsSingle(swagger.Paths); + Assert.ContainsSingle(swagger.Paths["/contacts"].Metadata); var actionJObject = swagger.Paths["/contacts"].Metadata["patch"] as JObject; - Assert.NotNull(actionJObject); + Assert.IsNotNull(actionJObject); var action = actionJObject.ToObject(); var parameters = action.Parameters; var schema = parameters[0].Metadata["schema"] as JObject; - Assert.NotNull(schema); - Assert.Equal("Sales", schema["example"]["department"].ToString()); + Assert.IsNotNull(schema); + Assert.AreEqual("Sales", schema["example"]["department"].ToString()); // Reference object var properties = schema["properties"] as JObject; - Assert.NotNull(properties); - Assert.Equal(2, properties.Count); - Assert.Equal("string", properties["objectType"]["type"]); - Assert.Equal("array", properties["provisioningErrors"]["type"]); + Assert.IsNotNull(properties); + Assert.AreEqual(2, properties.Count); + Assert.AreEqual("string", properties["objectType"]["type"]); + Assert.AreEqual("array", properties["provisioningErrors"]["type"]); var refProperty = properties["provisioningErrors"]["items"]["schema"] as JObject; - Assert.NotNull(refProperty); - Assert.Equal("string", refProperty["properties"]["errorDetail"]["type"]); + Assert.IsNotNull(refProperty); + Assert.AreEqual("string", refProperty["properties"]["errorDetail"]["type"]); schema = parameters[1].Metadata["schema"] as JObject; properties = schema["properties"] as JObject; var message = properties["message"]; - Assert.Equal("A message describing the error, intended to be suitable for display in a user interface.", message["description"]); + Assert.AreEqual("A message describing the error, intended to be suitable for display in a user interface.", message["description"]); - Assert.Single(action.Responses); + Assert.ContainsSingle(action.Responses); var response = action.Responses["204"]; - Assert.Single(response.Examples); + Assert.ContainsSingle(response.Examples); var example = response.Examples["application/json"]; - Assert.NotNull(example); + Assert.IsNotNull(example); } - [Fact] + [TestMethod] public void ParseSwaggerJsonWithTagShouldSucceed() { const string swaggerFile = "TestData/swagger/tag_swagger2.json"; var swagger = SwaggerJsonParser.Parse(swaggerFile); - Assert.Equal(3, swagger.Tags.Count); + Assert.AreEqual(3, swagger.Tags.Count); var tag0 = swagger.Tags[0]; - Assert.Equal("contact", tag0.Name); - Assert.Equal("Everything about the **contacts**", tag0.Description); - Assert.Equal("contact-bookmark", tag0.BookmarkId); - Assert.Single(tag0.Metadata); + Assert.AreEqual("contact", tag0.Name); + Assert.AreEqual("Everything about the **contacts**", tag0.Description); + Assert.AreEqual("contact-bookmark", tag0.BookmarkId); + Assert.ContainsSingle(tag0.Metadata); var externalDocs = (JObject)tag0.Metadata["externalDocs"]; - Assert.NotNull(externalDocs); - Assert.Equal("Find out more", externalDocs["description"]); - Assert.Equal("http://swagger.io", externalDocs["url"]); + Assert.IsNotNull(externalDocs); + Assert.AreEqual("Find out more", externalDocs["description"]); + Assert.AreEqual("http://swagger.io", externalDocs["url"]); } - [Fact] + [TestMethod] public void ParseSwaggerJsonWithPathParametersShouldSucceed() { const string swaggerFile = "TestData/swagger/pathParameters_swagger2.json"; var swagger = SwaggerJsonParser.Parse(swaggerFile); - Assert.Single(swagger.Paths.Values); + Assert.ContainsSingle(swagger.Paths.Values); var parameters = swagger.Paths["/contacts"].Parameters; - Assert.Equal(2, parameters.Count); + Assert.AreEqual(2, parameters.Count); // $ref parameter - Assert.Equal("api-version", parameters[0].Name); - Assert.Equal(false, parameters[0].Metadata["required"]); - Assert.Equal("api version description", parameters[0].Description); + Assert.AreEqual("api-version", parameters[0].Name); + Assert.AreEqual(false, parameters[0].Metadata["required"]); + Assert.AreEqual("api version description", parameters[0].Description); // self defined parameter - Assert.Equal("subscriptionId", parameters[1].Name); - Assert.Equal(true, parameters[1].Metadata["required"]); - Assert.Equal("subscription id", parameters[1].Description); + Assert.AreEqual("subscriptionId", parameters[1].Name); + Assert.AreEqual(true, parameters[1].Metadata["required"]); + Assert.AreEqual("subscription id", parameters[1].Description); } - [Fact] + [TestMethod] public void ParseSwaggerJsonWithLoopReferenceShouldSucceed() { const string swaggerFile = "TestData/swagger/loopref_swagger2.json"; var swagger = SwaggerJsonParser.Parse(swaggerFile); - Assert.Single(swagger.Paths.Values); + Assert.ContainsSingle(swagger.Paths.Values); var actionJObject = swagger.Paths["/contacts"].Metadata["patch"] as JObject; - Assert.NotNull(actionJObject); + Assert.IsNotNull(actionJObject); var action = actionJObject.ToObject(); var schemaJObject = (JObject)action.Parameters[0].Metadata["schema"]; var schemaObj = schemaJObject.ToString(Formatting.Indented); - Assert.Equal(@"{ + Assert.AreEqual(@"{ ""properties"": { ""provisioningErrors"": { ""type"": ""array"", @@ -147,19 +147,19 @@ public void ParseSwaggerJsonWithLoopReferenceShouldSucceed() }".Replace("\r\n", "\n"), schemaObj.Replace("\r\n", "\n")); } - [Fact] + [TestMethod] public void ParseSwaggerJsonWithExternalLoopReferenceShouldSucceed() { const string swaggerFile = "TestData/swagger/externalLoopRef_A.json"; var swagger = SwaggerJsonParser.Parse(swaggerFile); - Assert.Single(swagger.Paths.Values); + Assert.ContainsSingle(swagger.Paths.Values); var actionJObject = swagger.Paths["/contacts"].Metadata["patch"] as JObject; - Assert.NotNull(actionJObject); + Assert.IsNotNull(actionJObject); var action = actionJObject.ToObject(); var schemaJObject = (JObject)action.Parameters[0].Metadata["schema"]; var schemaObj = schemaJObject.ToString(Formatting.Indented); - Assert.Equal(@"{ + Assert.AreEqual(@"{ ""properties"": { ""provisioningErrors"": { ""type"": ""array"", @@ -185,7 +185,7 @@ public void ParseSwaggerJsonWithExternalLoopReferenceShouldSucceed() } }".Replace("\r\n", "\n"), schemaObj.Replace("\r\n", "\n")); } - [Fact] + [TestMethod] public void ParseKeyWordSwaggerJsonShouldSucceed() { var swaggerFile = "TestData/swagger/resolveKeywordWithRefInside.json"; @@ -193,7 +193,7 @@ public void ParseKeyWordSwaggerJsonShouldSucceed() ///test x-ms-examples: unresolved. var xmsexamples = swagger.Metadata["x-ms-examples"] as JObject; - Assert.NotNull(xmsexamples["$ref"]); + Assert.IsNotNull(xmsexamples["$ref"]); var get = swagger.Paths["/{resourceUri}/providers/microsoft.insights/metrics"].Metadata["get"] as JObject; var responses = get["responses"] as JObject; @@ -201,35 +201,35 @@ public void ParseKeyWordSwaggerJsonShouldSucceed() ///test responses/../examples: unresolved. var response200 = responses["200"] as JObject; var examplesOfResponse200 = response200["examples"] as JObject; - Assert.NotNull(examplesOfResponse200["$ref"]); + Assert.IsNotNull(examplesOfResponse200["$ref"]); ///test responses/examples: resolved. var examplesOfResponse = responses["examples"] as JObject; - Assert.Null(examplesOfResponse["$ref"]); + Assert.IsNull(examplesOfResponse["$ref"]); ///test parameters/examples: resolved. var parameters = get["parameters"] as JObject; var examplesOfParameters = parameters["examples"] as JObject; - Assert.Null(examplesOfParameters["$ref"]); + Assert.IsNull(examplesOfParameters["$ref"]); ///test definitions/../example: unresolved. var definitions = swagger.Definitions as JObject; var tag = definitions["Tag"] as JObject; var examplesOfTag = tag["example"] as JObject; - Assert.NotNull(examplesOfTag["$ref"]); + Assert.IsNotNull(examplesOfTag["$ref"]); ///test definitions/example: resolved. var examplesOfDefinitions = definitions["example"] as JObject; - Assert.Null(examplesOfDefinitions["$ref"]); + Assert.IsNull(examplesOfDefinitions["$ref"]); ///test properties/../example: unresolved. var propertiesOfTag = tag["properties"] as JObject; var unresolvedOfTag = propertiesOfTag["unresolved"] as JObject; var examplesOfUnresolved = unresolvedOfTag["example"] as JObject; - Assert.NotNull(examplesOfUnresolved["$ref"]); + Assert.IsNotNull(examplesOfUnresolved["$ref"]); ///test properties/example: resolved. var examplesOfResolved = propertiesOfTag["example"] as JObject; - Assert.Null(examplesOfResolved["$ref"]); + Assert.IsNull(examplesOfResolved["$ref"]); } } diff --git a/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs b/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs index db65cfef4c8..3ecba3c0eae 100644 --- a/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs +++ b/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs @@ -11,11 +11,11 @@ using Docfx.Plugins; using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.RestApi.WithPlugins.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class SplitRestApiToOperationLevelTest : TestBase { private readonly string _outputFolder; @@ -39,7 +39,7 @@ public SplitRestApiToOperationLevelTest() _templateManager = new TemplateManager(["template"], null, "TestData/"); } - [Fact] + [TestMethod] public void SplitRestApiToOperationLevelShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -48,45 +48,45 @@ public void SplitRestApiToOperationLevelShouldSucceed() { // Verify original petstore page var outputRawModelPath = GetRawModelFilePath("petstore.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); - Assert.Empty(model.Children); - Assert.True((bool)model.Metadata["_isSplittedByOperation"]); - Assert.Empty(model.Tags); - Assert.Equal("

Find out more about Swagger

\n", ((JObject)model.Metadata["externalDocs"])["description"]); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); + Assert.IsEmpty(model.Children); + Assert.IsTrue((bool)model.Metadata["_isSplittedByOperation"]); + Assert.IsEmpty(model.Tags); + Assert.AreEqual("

Find out more about Swagger

\n", ((JObject)model.Metadata["externalDocs"])["description"]); } { // Verify splitted operation page var outputRawModelPath = GetRawModelFilePath("petstore/addPet.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", model.Uid); - Assert.Null(model.HtmlId); - Assert.Equal("addPet", model.Name); - Assert.Equal("

Add a new pet to the store

\n", model.Summary); - Assert.Empty(model.Tags); - Assert.Equal("swagger/petstore/addPet.html", model.Metadata["_path"]); - Assert.Equal("TestData/swagger/petstore/addPet.json", model.Metadata["_key"]); - Assert.True(model.Metadata.ContainsKey("externalDocs")); - Assert.True((bool)model.Metadata["_isSplittedToOperation"]); - Assert.Single(model.Children); - Assert.Empty(model.Tags); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", model.Uid); + Assert.IsNull(model.HtmlId); + Assert.AreEqual("addPet", model.Name); + Assert.AreEqual("

Add a new pet to the store

\n", model.Summary); + Assert.IsEmpty(model.Tags); + Assert.AreEqual("swagger/petstore/addPet.html", model.Metadata["_path"]); + Assert.AreEqual("TestData/swagger/petstore/addPet.json", model.Metadata["_key"]); + Assert.IsTrue(model.Metadata.ContainsKey("externalDocs")); + Assert.IsTrue((bool)model.Metadata["_isSplittedToOperation"]); + Assert.ContainsSingle(model.Children); + Assert.IsEmpty(model.Tags); // Test overwritten metadata - Assert.Equal("

Find out more about addPet

\n", ((JObject)model.Metadata["externalDocs"])["description"]); + Assert.AreEqual("

Find out more about addPet

\n", ((JObject)model.Metadata["externalDocs"])["description"]); var child = model.Children[0]; - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet/operation", child.Uid); - Assert.Null(child.HtmlId); - Assert.Null(child.Summary); // Summary is popped to operation page - Assert.Empty(child.Tags); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet/operation", child.Uid); + Assert.IsNull(child.HtmlId); + Assert.IsNull(child.Summary); // Summary is popped to operation page + Assert.IsEmpty(child.Tags); } } - [Fact] + [TestMethod] public void SplitRestApiToOperationLevelWithTocShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -96,55 +96,55 @@ public void SplitRestApiToOperationLevelWithTocShouldSucceed() { // Verify original petstore page var outputRawModelPath = GetRawModelFilePath("petstore.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); - Assert.Empty(model.Children); - Assert.Empty(model.Tags); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); + Assert.IsEmpty(model.Children); + Assert.IsEmpty(model.Tags); } { // Verify splitted operation page var outputRawModelPath = GetRawModelFilePath("petstore/addPet.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", model.Uid); - Assert.Null(model.HtmlId); - Assert.Equal("addPet", model.Name); - Assert.Equal("

Add a new pet to the store

\n", model.Summary); - Assert.Empty(model.Tags); - Assert.Equal("swagger/petstore/addPet.html", model.Metadata["_path"]); - Assert.Equal("TestData/swagger/petstore/addPet.json", model.Metadata["_key"]); - Assert.Equal("../toc.yml", model.Metadata["_tocRel"]); - Assert.True(model.Metadata.ContainsKey("externalDocs")); - Assert.Single(model.Children); - Assert.Empty(model.Tags); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", model.Uid); + Assert.IsNull(model.HtmlId); + Assert.AreEqual("addPet", model.Name); + Assert.AreEqual("

Add a new pet to the store

\n", model.Summary); + Assert.IsEmpty(model.Tags); + Assert.AreEqual("swagger/petstore/addPet.html", model.Metadata["_path"]); + Assert.AreEqual("TestData/swagger/petstore/addPet.json", model.Metadata["_key"]); + Assert.AreEqual("../toc.yml", model.Metadata["_tocRel"]); + Assert.IsTrue(model.Metadata.ContainsKey("externalDocs")); + Assert.ContainsSingle(model.Children); + Assert.IsEmpty(model.Tags); var child = model.Children[0]; - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet/operation", child.Uid); - Assert.Null(child.HtmlId); - Assert.Null(child.Summary); // Summary has been popped to operation page - Assert.Empty(child.Tags); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet/operation", child.Uid); + Assert.IsNull(child.HtmlId); + Assert.IsNull(child.Summary); // Summary has been popped to operation page + Assert.IsEmpty(child.Tags); } { // Verify toc page var outputRawModelPath = GetRawModelFilePath("toc.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Single(model.Items); + Assert.IsNotNull(model); + Assert.ContainsSingle(model.Items); var rootModel = model.Items[0]; - Assert.Equal("petstore.html", rootModel.TopicHref); - Assert.Equal(20, rootModel.Items.Count); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", rootModel.Items[0].TopicUid); - Assert.Equal("petstore/addPet.html", rootModel.Items[0].TopicHref); - Assert.Equal("petstore/addPet.html", rootModel.Items[0].Href); - Assert.Equal("addPet", rootModel.Items[0].Name); + Assert.AreEqual("petstore.html", rootModel.TopicHref); + Assert.AreEqual(20, rootModel.Items.Count); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", rootModel.Items[0].TopicUid); + Assert.AreEqual("petstore/addPet.html", rootModel.Items[0].TopicHref); + Assert.AreEqual("petstore/addPet.html", rootModel.Items[0].Href); + Assert.AreEqual("addPet", rootModel.Items[0].Name); } } - [Fact] + [TestMethod] public void SplitRestApiToTagAndOperationLevelWithTocShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -154,77 +154,77 @@ public void SplitRestApiToTagAndOperationLevelWithTocShouldSucceed() { // Verify original petstore page var outputRawModelPath = GetRawModelFilePath("petstore.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); - Assert.Empty(model.Children); - Assert.Empty(model.Tags); - Assert.True((bool)model.Metadata["_isSplittedByTag"]); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); + Assert.IsEmpty(model.Children); + Assert.IsEmpty(model.Tags); + Assert.IsTrue((bool)model.Metadata["_isSplittedByTag"]); } { // Verify splitted tag page var outputRawModelPath = GetRawModelFilePath("petstore/pet.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", model.Uid); - Assert.Equal("pet", model.Name); - Assert.Equal("

Everything about your Pets

\n", model.Description); - Assert.Empty(model.Children); - Assert.Empty(model.Tags); - Assert.Equal("swagger/petstore/pet.html", model.Metadata["_path"]); - Assert.Equal("TestData/swagger/petstore/pet.json", model.Metadata["_key"]); - Assert.True(model.Metadata.ContainsKey("externalDocs")); - Assert.True((bool)model.Metadata["_isSplittedToTag"]); - Assert.True((bool)model.Metadata["_isSplittedByOperation"]); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", model.Uid); + Assert.AreEqual("pet", model.Name); + Assert.AreEqual("

Everything about your Pets

\n", model.Description); + Assert.IsEmpty(model.Children); + Assert.IsEmpty(model.Tags); + Assert.AreEqual("swagger/petstore/pet.html", model.Metadata["_path"]); + Assert.AreEqual("TestData/swagger/petstore/pet.json", model.Metadata["_key"]); + Assert.IsTrue(model.Metadata.ContainsKey("externalDocs")); + Assert.IsTrue((bool)model.Metadata["_isSplittedToTag"]); + Assert.IsTrue((bool)model.Metadata["_isSplittedByOperation"]); } { // Verify splitted operation page var outputRawModelPath = GetRawModelFilePath("petstore/pet/addPet.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", model.Uid); - Assert.Null(model.HtmlId); - Assert.Equal("addPet", model.Name); - Assert.Equal("

Add a new pet to the store

\n", model.Summary); - Assert.Empty(model.Tags); - Assert.Equal("swagger/petstore/pet/addPet.html", model.Metadata["_path"]); - Assert.Equal("TestData/swagger/petstore/pet/addPet.json", model.Metadata["_key"]); - Assert.Equal("../../toc.yml", model.Metadata["_tocRel"]); - Assert.True(model.Metadata.ContainsKey("externalDocs")); - Assert.Single(model.Children); - Assert.True((bool)model.Metadata["_isSplittedToOperation"]); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", model.Uid); + Assert.IsNull(model.HtmlId); + Assert.AreEqual("addPet", model.Name); + Assert.AreEqual("

Add a new pet to the store

\n", model.Summary); + Assert.IsEmpty(model.Tags); + Assert.AreEqual("swagger/petstore/pet/addPet.html", model.Metadata["_path"]); + Assert.AreEqual("TestData/swagger/petstore/pet/addPet.json", model.Metadata["_key"]); + Assert.AreEqual("../../toc.yml", model.Metadata["_tocRel"]); + Assert.IsTrue(model.Metadata.ContainsKey("externalDocs")); + Assert.ContainsSingle(model.Children); + Assert.IsTrue((bool)model.Metadata["_isSplittedToOperation"]); var child = model.Children[0]; - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet/operation", child.Uid); - Assert.Null(child.HtmlId); - Assert.Null(child.Summary); // Summary has been popped to operation page - Assert.Empty(child.Tags); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet/operation", child.Uid); + Assert.IsNull(child.HtmlId); + Assert.IsNull(child.Summary); // Summary has been popped to operation page + Assert.IsEmpty(child.Tags); } { // Verify toc page var outputRawModelPath = GetRawModelFilePath("toc.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Single(model.Items); + Assert.IsNotNull(model); + Assert.ContainsSingle(model.Items); var rootModel = model.Items[0]; - Assert.Equal("petstore.html", rootModel.TopicHref); - Assert.Equal(3, rootModel.Items.Count); + Assert.AreEqual("petstore.html", rootModel.TopicHref); + Assert.AreEqual(3, rootModel.Items.Count); var firstTagToc = rootModel.Items[0]; - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", firstTagToc.TopicUid); - Assert.Equal("petstore/pet.html", firstTagToc.TopicHref); - Assert.Equal("petstore/pet.html", firstTagToc.Href); - Assert.Equal("pet", firstTagToc.Name); - Assert.Equal(8, firstTagToc.Items.Count); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", firstTagToc.TopicUid); + Assert.AreEqual("petstore/pet.html", firstTagToc.TopicHref); + Assert.AreEqual("petstore/pet.html", firstTagToc.Href); + Assert.AreEqual("pet", firstTagToc.Name); + Assert.AreEqual(8, firstTagToc.Items.Count); var firstOperationToc = firstTagToc.Items[0]; - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", firstOperationToc.TopicUid); - Assert.Equal("petstore/pet/addPet.html", firstOperationToc.TopicHref); - Assert.Equal("petstore/pet/addPet.html", firstOperationToc.Href); - Assert.Equal("addPet", firstOperationToc.Name); - Assert.Null(firstOperationToc.Items); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/addPet", firstOperationToc.TopicUid); + Assert.AreEqual("petstore/pet/addPet.html", firstOperationToc.TopicHref); + Assert.AreEqual("petstore/pet/addPet.html", firstOperationToc.Href); + Assert.AreEqual("addPet", firstOperationToc.Name); + Assert.IsNull(firstOperationToc.Items); } } diff --git a/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToTagLevelTest.cs b/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToTagLevelTest.cs index 22a06714040..1260b4aff49 100644 --- a/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToTagLevelTest.cs +++ b/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToTagLevelTest.cs @@ -12,11 +12,11 @@ using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.RestApi.WithPlugins.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class SplitRestApiToTagLevelTest : TestBase { private readonly string _outputFolder; @@ -40,7 +40,7 @@ public SplitRestApiToTagLevelTest() _templateManager = new TemplateManager(["template"], null, "TestData/"); } - [Fact] + [TestMethod] public void ProcessRestApiShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -49,38 +49,38 @@ public void ProcessRestApiShouldSucceed() { // Verify original petstore page var outputRawModelPath = GetRawModelFilePath("petstore.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); - Assert.Empty(model.Children); - Assert.Empty(model.Tags); - Assert.True((bool)model.Metadata["_isSplittedByTag"]); - Assert.Equal("

Find out more about Swagger

\n", ((JObject)model.Metadata["externalDocs"])["description"]); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); + Assert.IsEmpty(model.Children); + Assert.IsEmpty(model.Tags); + Assert.IsTrue((bool)model.Metadata["_isSplittedByTag"]); + Assert.AreEqual("

Find out more about Swagger

\n", ((JObject)model.Metadata["externalDocs"])["description"]); } { // Verify splitted tag page var outputRawModelPath = GetRawModelFilePath("petstore/pet.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", model.Uid); - Assert.Equal("pet", model.Name); - Assert.Equal("

Everything about your Pets

\n", model.Description); - Assert.Equal(8, model.Children.Count); - Assert.Empty(model.Tags); - Assert.Empty(model.Children[0].Tags); - Assert.Equal("swagger/petstore/pet.html", model.Metadata["_path"]); - Assert.Equal("TestData/swagger/petstore/pet.json", model.Metadata["_key"]); - Assert.True(model.Metadata.ContainsKey("externalDocs")); - Assert.True((bool)model.Metadata["_isSplittedToTag"]); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", model.Uid); + Assert.AreEqual("pet", model.Name); + Assert.AreEqual("

Everything about your Pets

\n", model.Description); + Assert.AreEqual(8, model.Children.Count); + Assert.IsEmpty(model.Tags); + Assert.IsEmpty(model.Children[0].Tags); + Assert.AreEqual("swagger/petstore/pet.html", model.Metadata["_path"]); + Assert.AreEqual("TestData/swagger/petstore/pet.json", model.Metadata["_key"]); + Assert.IsTrue(model.Metadata.ContainsKey("externalDocs")); + Assert.IsTrue((bool)model.Metadata["_isSplittedToTag"]); // Test overwritten metadata - Assert.Equal("

Find out more about pets

\n", ((JObject)model.Metadata["externalDocs"])["description"]); + Assert.AreEqual("

Find out more about pets

\n", ((JObject)model.Metadata["externalDocs"])["description"]); } } - [Fact] + [TestMethod] public void ProcessRestApiWithTocShouldSucceed() { var files = new FileCollection(_defaultFiles); @@ -90,41 +90,41 @@ public void ProcessRestApiWithTocShouldSucceed() { // Verify original petstore page var outputRawModelPath = GetRawModelFilePath("petstore.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); - Assert.Empty(model.Children); - Assert.Empty(model.Tags); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0", model.Uid); + Assert.IsEmpty(model.Children); + Assert.IsEmpty(model.Tags); } { // Verify splitted tag page var outputRawModelPath = GetRawModelFilePath("petstore/pet.json"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", model.Uid); - Assert.Equal("pet", model.Name); - Assert.Equal("

Everything about your Pets

\n", model.Description); - Assert.Equal(8, model.Children.Count); - Assert.Empty(model.Tags); - Assert.Empty(model.Children[0].Tags); - Assert.Equal("swagger/petstore/pet.html", model.Metadata["_path"]); - Assert.Equal("TestData/swagger/petstore/pet.json", model.Metadata["_key"]); - Assert.True(model.Metadata.ContainsKey("externalDocs")); + Assert.IsNotNull(model); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", model.Uid); + Assert.AreEqual("pet", model.Name); + Assert.AreEqual("

Everything about your Pets

\n", model.Description); + Assert.AreEqual(8, model.Children.Count); + Assert.IsEmpty(model.Tags); + Assert.IsEmpty(model.Children[0].Tags); + Assert.AreEqual("swagger/petstore/pet.html", model.Metadata["_path"]); + Assert.AreEqual("TestData/swagger/petstore/pet.json", model.Metadata["_key"]); + Assert.IsTrue(model.Metadata.ContainsKey("externalDocs")); } { // Verify toc page var outputRawModelPath = GetRawModelFilePath("toc.yml"); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize(outputRawModelPath); - Assert.NotNull(model); - Assert.Single(model.Items); + Assert.IsNotNull(model); + Assert.ContainsSingle(model.Items); var rootModel = model.Items[0]; - Assert.Equal("petstore.html", rootModel.TopicHref); - Assert.Equal(3, rootModel.Items.Count); - Assert.Equal("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", rootModel.Items[0].TopicUid); - Assert.Equal("pet", rootModel.Items[0].Name); + Assert.AreEqual("petstore.html", rootModel.TopicHref); + Assert.AreEqual(3, rootModel.Items.Count); + Assert.AreEqual("petstore.swagger.io/v2/Swagger Petstore/1.0.0/tag/pet", rootModel.Items[0].TopicUid); + Assert.AreEqual("pet", rootModel.Items[0].Name); } } diff --git a/test/Docfx.Build.SchemaDriven.Tests/JsonPointerTest.cs b/test/Docfx.Build.SchemaDriven.Tests/JsonPointerTest.cs index 381e10fa736..754604ef5c0 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/JsonPointerTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/JsonPointerTest.cs @@ -5,12 +5,13 @@ using Docfx.Exceptions; using Docfx.Tests.Common; using FluentAssertions; -using Xunit; namespace Docfx.Build.SchemaDriven.Tests; + +[TestClass] public class JsonPointerTest : TestBase { - [Fact] + [TestMethod] public void TestJsonPointerSpec() { var root = ConvertToObjectHelper.ConvertToDynamic(ConvertToObjectHelper.ConvertJObjectToObject(JsonUtility.FromJsonString( @@ -43,7 +44,7 @@ public void TestJsonPointerSpec() new JsonPointer("/m~0n").GetValue(root).Should().Be(8); } - [Fact] + [TestMethod] public void TestJsonPointerWithComplexObject() { var root = ConvertToObjectHelper.ConvertToDynamic(ConvertToObjectHelper.ConvertJObjectToObject(JsonUtility.FromJsonString(@" @@ -67,26 +68,26 @@ public void TestJsonPointerWithComplexObject() } "))); - Assert.Equal(root, new JsonPointer("").GetValue(root)); - Assert.Equal("value1", new JsonPointer("/dict/key1").GetValue(root)); - Assert.Equal("arr2", new JsonPointer("/dict/key2/1").GetValue(root)); - Assert.Equal("value1", new JsonPointer("/dict/key3/key3/key3/key1").GetValue(root)); - Assert.Null(new JsonPointer("/dict/key4").GetValue(root)); - Assert.Null(new JsonPointer("/dict/key4/key1").GetValue(root)); - Assert.Null(new JsonPointer("/dict/key2/2").GetValue(root)); + Assert.AreEqual(root, new JsonPointer("").GetValue(root)); + Assert.AreEqual("value1", new JsonPointer("/dict/key1").GetValue(root)); + Assert.AreEqual("arr2", new JsonPointer("/dict/key2/1").GetValue(root)); + Assert.AreEqual("value1", new JsonPointer("/dict/key3/key3/key3/key1").GetValue(root)); + Assert.IsNull(new JsonPointer("/dict/key4").GetValue(root)); + Assert.IsNull(new JsonPointer("/dict/key4/key1").GetValue(root)); + Assert.IsNull(new JsonPointer("/dict/key2/2").GetValue(root)); var jp = new JsonPointer("/dict/key1"); jp.SetValue(ref root, 1); - Assert.Equal(1, jp.GetValue(root)); + Assert.AreEqual(1, jp.GetValue(root)); jp = new JsonPointer("/dict/key3/key2/1"); jp.SetValue(ref root, 2); - Assert.Equal(2, jp.GetValue(root)); + Assert.AreEqual(2, jp.GetValue(root)); jp = new JsonPointer(""); jp.SetValue(ref root, 3); - Assert.Equal(3, root); - Assert.Equal(3, jp.GetValue(root)); + Assert.AreEqual(3, root); + Assert.AreEqual(3, jp.GetValue(root)); Assert.Throws(() => new JsonPointer("/dict/key2/2").SetValue(ref root, 1)); } diff --git a/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs b/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs index 814cdd70777..b4639582534 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/MarkdownFragmentsValidationTest.cs @@ -6,11 +6,10 @@ using Docfx.Plugins; using Docfx.Tests.Common; -using Xunit; - namespace Docfx.Build.SchemaDriven.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class MarkdownFragmentsValidationTest : TestBase { private string _outputFolder; @@ -26,7 +25,7 @@ public class MarkdownFragmentsValidationTest : TestBase private const string RawModelFileExtension = ".raw.json"; - [Fact] + [TestMethod] public void OverwriteUnEditableTest() { _outputFolder = GetRandomFolder(); @@ -58,18 +57,17 @@ public void OverwriteUnEditableTest() var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments).ToList(); - Assert.True(File.Exists(_rawModelFilePath)); - Assert.Equal(5, warningLogs.Count); - Assert.Equal( + Assert.IsTrue(File.Exists(_rawModelFilePath)); + Assert.AreEqual(5, warningLogs.Count); + Assert.AreEqual( @"Markdown property `depot_name` is not allowed inside a YAML code block You cannot overwrite a readonly property: `site_name`, please add an `editable` tag on this property or mark its contentType as `markdown` in schema if you want to overwrite this property There is an invalid H2: `name`: the contentType of this property in schema must be `markdown` There is an invalid H2: `operations[id=""management.azure.com.advisor.fragmentsValidation.create""]/summary`: the contentType of this property in schema must be `markdown` -""/operations/1"" in overwrite object fails to overwrite ""/operations"" for ""management.azure.com.advisor.fragmentsValidation"" because it does not match any existing item.", - string.Join(Environment.NewLine, warningLogs.Select(x => x.Message)), - ignoreLineEndingDifferences: true); - Assert.Equal("14", warningLogs[2].Line); - Assert.Equal("17", warningLogs[3].Line); +""/operations/1"" in overwrite object fails to overwrite ""/operations"" for ""management.azure.com.advisor.fragmentsValidation"" because it does not match any existing item.".ReplaceLineEndings(), + string.Join(Environment.NewLine, warningLogs.Select(x => x.Message))); + Assert.AreEqual("14", warningLogs[2].Line); + Assert.AreEqual("17", warningLogs[3].Line); } private void BuildDocument(FileCollection files) diff --git a/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs b/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs index 15909a250f9..254d1e50422 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/MergeMarkdownFragmentsTest.cs @@ -7,11 +7,11 @@ using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.SchemaDriven.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class MergeMarkdownFragmentsTest : TestBase { private readonly string _outputFolder; @@ -43,7 +43,7 @@ public MergeMarkdownFragmentsTest() _files.Add(DocumentType.Article, [yamlFile], _inputFolder); } - [Fact] + [TestMethod] public void TestMergeMarkdownFragments() { // Arrange @@ -53,15 +53,15 @@ public void TestMergeMarkdownFragments() BuildDocument(_files); // Assert - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Equal("bob", rawModel["author"]); + Assert.AreEqual("bob", rawModel["author"]); Assert.Contains("Enables the snoozed or dismissed attribute", rawModel["operations"][0]["summary"].ToString()); Assert.Contains("Some empty lines between H2 and this paragraph is tolerant", rawModel["definitions"][0]["properties"][0]["description"].ToString()); Assert.Contains("This is a summary at YAML's", rawModel["summary"].ToString()); } - [Fact] + [TestMethod] public void TestMissingStartingH1CodeHeading() { // Arrange @@ -85,15 +85,15 @@ markdown content var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Single(warningLogs); - Assert.Equal("Unable to parse markdown fragments: Expect L1InlineCodeHeading", warningLogs.First().Message); - Assert.Equal("1", warningLogs.First().Line); - Assert.Null(rawModel["summary"]); + Assert.ContainsSingle(warningLogs); + Assert.AreEqual("Unable to parse markdown fragments: Expect L1InlineCodeHeading", warningLogs.First().Message); + Assert.AreEqual("1", warningLogs.First().Line); + Assert.IsNull(rawModel["summary"]); } - [Fact] + [TestMethod] public void TestInvalidSpaceMissing() { // Arrange @@ -119,15 +119,15 @@ markdown content var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Single(warningLogs); - Assert.Equal("Unable to parse markdown fragments: Expect L1InlineCodeHeading", warningLogs.First().Message); - Assert.Equal("1", warningLogs.First().Line); - Assert.Null(rawModel["summary"]); + Assert.ContainsSingle(warningLogs); + Assert.AreEqual("Unable to parse markdown fragments: Expect L1InlineCodeHeading", warningLogs.First().Message); + Assert.AreEqual("1", warningLogs.First().Line); + Assert.IsNull(rawModel["summary"]); } - [Fact] + [TestMethod] public void TestValidSpaceMissing() { // Arrange @@ -146,12 +146,12 @@ markdown content // Act BuildDocument(_files); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); Assert.Contains("##head_3_without_space", rawModel["summary"].ToString()); } - [Fact] + [TestMethod] public void TestInvalidYaml() { // Arrange @@ -180,15 +180,15 @@ markdown content var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Single(warningLogs); - Assert.Equal("Unable to parse markdown fragments: Encountered an invalid YAML code block: (Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 28, Idx: 27): Exception during deserialization", warningLogs.First().Message); - Assert.Equal("2", warningLogs.First().Line); - Assert.Null(rawModel["summary"]); + Assert.ContainsSingle(warningLogs); + Assert.AreEqual("Unable to parse markdown fragments: Encountered an invalid YAML code block: (Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 28, Idx: 27): Exception during deserialization", warningLogs.First().Message); + Assert.AreEqual("2", warningLogs.First().Line); + Assert.IsNull(rawModel["summary"]); } - [Fact] + [TestMethod] public void TestInvalidOPath() { // Arrange @@ -218,15 +218,15 @@ markdown content var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Single(warningLogs); - Assert.Equal("Unable to parse markdown fragments: operations[id=]/summary is not a valid OPath", warningLogs.First().Message); - Assert.Equal("3", warningLogs.First().Line); - Assert.Null(rawModel["summary"]); + Assert.ContainsSingle(warningLogs); + Assert.AreEqual("Unable to parse markdown fragments: operations[id=]/summary is not a valid OPath", warningLogs.First().Message); + Assert.AreEqual("3", warningLogs.First().Line); + Assert.IsNull(rawModel["summary"]); } - [Fact] + [TestMethod] public void TestNotExistedUid() { // Arrange @@ -275,14 +275,14 @@ Some empty lines between H2 and this paragraph is tolerant var logs = _listener.Items; var warningLogs = logs.Where(l => l.Code == WarningCodes.Overwrite.InvalidMarkdownFragments); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Single(warningLogs); - Assert.Equal("Unable to find UidDefinition for Uid: uid_not_exist", warningLogs.First().Message); - Assert.Empty(rawModel["summary"]); + Assert.ContainsSingle(warningLogs); + Assert.AreEqual("Unable to find UidDefinition for Uid: uid_not_exist", warningLogs.First().Message); + Assert.IsEmpty(rawModel["summary"]); } - [Fact] + [TestMethod] public void TestDuplicateOPathsInYamlCodeBlockAndContentsBlock() { // Arrange @@ -308,24 +308,24 @@ overwrite in contents block // Act BuildDocument(_files); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Equal("name overwrite", rawModel["name"]); - Assert.Equal($"

overwrite in yaml block

\n", rawModel["definitions"][0]["properties"][0]["description"].ToString()); - Assert.Equal($"

overwrite in contents block

\n", rawModel["definitions"][0]["properties"][1]["description"].ToString()); + Assert.AreEqual("name overwrite", rawModel["name"]); + Assert.AreEqual($"

overwrite in yaml block

\n", rawModel["definitions"][0]["properties"][0]["description"].ToString()); + Assert.AreEqual($"

overwrite in contents block

\n", rawModel["definitions"][0]["properties"][1]["description"].ToString()); } - [Fact] + [TestMethod] public void TestFragmentsWithIncremental() { using var listener = new TestListenerScope(); // first build BuildDocument(_files); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); var rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.Null(rawModel["summary"]); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); + Assert.IsNull(rawModel["summary"]); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); ClearLog(listener.Items); // add fragments @@ -339,12 +339,12 @@ I add a summary. BuildDocument(_files); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.NotNull(rawModel["summary"]); + Assert.IsNotNull(rawModel["summary"]); Assert.Contains("I add a summary", rawModel["summary"].ToString()); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.Contains("Cannot resolve") && s.Message.Contains("invalid.md"))); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.Contains("Cannot resolve") && s.Message.Contains("invalid.md"))); List lastMessages; var messages = ClearLog(listener.Items); @@ -361,28 +361,28 @@ I add a summary. BuildDocument(_files); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.NotNull(rawModel["summary"]); + Assert.IsNotNull(rawModel["summary"]); Assert.Contains("I update a summary", rawModel["summary"].ToString()); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.Contains("Cannot resolve") && s.Message.Contains("invalid.md"))); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.Contains("Cannot resolve") && s.Message.Contains("invalid.md"))); lastMessages = messages; messages = ClearLog(listener.Items); - Assert.True(messages.SequenceEqual(lastMessages)); + Assert.IsTrue(messages.SequenceEqual(lastMessages)); // rebuild BuildDocument(_files); - Assert.True(File.Exists(_rawModelFilePath)); + Assert.IsTrue(File.Exists(_rawModelFilePath)); rawModel = JsonUtility.Deserialize(_rawModelFilePath); - Assert.NotNull(rawModel["summary"]); + Assert.IsNotNull(rawModel["summary"]); Assert.Contains("I update a summary", rawModel["summary"].ToString()); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.Contains("Cannot resolve") && s.Message.Contains("invalid.md"))); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): RESTMixedTest"))); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.Contains("Cannot resolve") && s.Message.Contains("invalid.md"))); lastMessages = messages; messages = ClearLog(listener.Items); - Assert.True(messages.SequenceEqual(lastMessages)); + Assert.IsTrue(messages.SequenceEqual(lastMessages)); } private static List ClearLog(List items) diff --git a/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs b/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs index 0337e095193..43a61d1222f 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs @@ -11,11 +11,11 @@ using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.SchemaDriven.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class SchemaDrivenProcessorTest : TestBase { private readonly string _outputFolder; @@ -42,7 +42,7 @@ public SchemaDrivenProcessorTest() _templateManager = new TemplateManager(["template"], null, _templateFolder); } - [Fact] + [TestMethod] public void TestRef() { using var listener = new TestListenerScope(); @@ -86,18 +86,18 @@ public void TestRef() files.Add(DocumentType.Article, [inputFile], _inputFolder); BuildDocument(files); - Assert.Single(listener.Items); + Assert.ContainsSingle(listener.Items); var xrefspec = Path.Combine(_outputFolder, "xrefmap.yml"); var xrefmap = YamlUtility.Deserialize(xrefspec); - Assert.Empty(xrefmap.References); + Assert.IsEmpty(xrefmap.References); var outputFileName = Path.ChangeExtension(inputFileName, ".html"); var outputFilePath = Path.Combine(_outputFolder, outputFileName); - Assert.True(File.Exists(outputFilePath)); + Assert.IsTrue(File.Exists(outputFilePath)); - Assert.Equal(@" + CollectionAssert.AreEqual(@"

Hello

1Hello

1.1Hello

@@ -114,7 +114,7 @@ public void TestRef() File.ReadAllLines(outputFilePath).Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToArray()); } - [Fact] + [TestMethod] public void TestXrefResolver() { using var listener = new TestListenerScope(); @@ -139,32 +139,32 @@ public void TestXrefResolver() BuildDocument(files); // assert - Assert.Single(listener.Items); + Assert.ContainsSingle(listener.Items); listener.Items.Clear(); var xrefspec = Path.Combine(_outputFolder, "xrefmap.yml"); var xrefmap = YamlUtility.Deserialize(xrefspec); - Assert.Equal(2, xrefmap.References.Count); - Assert.Equal(8, xrefmap.References[0].Keys.Count); - Assert.Equal(10, xrefmap.References[1].Keys.Count); + Assert.AreEqual(2, xrefmap.References.Count); + Assert.AreEqual(8, xrefmap.References[0].Keys.Count); + Assert.AreEqual(10, xrefmap.References[1].Keys.Count); - Assert.Equal("ICat", xrefmap.References[0].Name); - Assert.Equal("CatLibrary.ICat.CatLibrary.ICatExtension.Sleep(System.Int64)", xrefmap.References[0]["extensionMethods/0"]); + Assert.AreEqual("ICat", xrefmap.References[0].Name); + Assert.AreEqual("CatLibrary.ICat.CatLibrary.ICatExtension.Sleep(System.Int64)", xrefmap.References[0]["extensionMethods/0"]); var outputFileName = Path.ChangeExtension(inputFileName, ".html"); - Assert.Equal(outputFileName, xrefmap.References[0].Href); - Assert.NotNull(xrefmap.References[0]["summary"]); + Assert.AreEqual(outputFileName, xrefmap.References[0].Href); + Assert.IsNotNull(xrefmap.References[0]["summary"]); var outputFilePath = Path.Combine(_outputFolder, outputFileName); - Assert.True(File.Exists(outputFilePath)); + Assert.IsTrue(File.Exists(outputFilePath)); var outputFileContent = File.ReadAllLines(outputFilePath); - Assert.Equal(@" + CollectionAssert.AreEqual(@" eat:

eat event of cat. Every cat must implement this event. This method is within ICat

|666|net472netstandard2_0".Split(["\r\n", "\n"], StringSplitOptions.None), outputFileContent); } - [Fact] + [TestMethod] public void TestXrefResolverShouldWarnWithEmptyUidReference() { using var listener = new TestListenerScope(); @@ -179,11 +179,11 @@ public void TestXrefResolverShouldWarnWithEmptyUidReference() BuildDocument(files); // assert - Assert.NotEmpty(listener.Items); - Assert.Contains(listener.Items, i => i.Code == WarningCodes.Build.UidNotFound); + Assert.IsNotEmpty(listener.Items); + Assert.Contains(i => i.Code == WarningCodes.Build.UidNotFound, listener.Items); } - [Fact] + [TestMethod] public void TestValidMetadataReferenceWithIncremental() { using var listener = new TestListenerScope(); @@ -235,26 +235,26 @@ public void TestValidMetadataReferenceWithIncremental() BuildDocument(files); - Assert.Equal(4, listener.Items.Count); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): MetadataReferenceTest,Toc"))); + Assert.AreEqual(4, listener.Items.Count); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): MetadataReferenceTest,Toc"))); listener.Items.Clear(); var rawModelFilePath = GetRawModelFilePath(inputFileName1); - Assert.True(File.Exists(rawModelFilePath)); + Assert.IsTrue(File.Exists(rawModelFilePath)); var rawModel = JsonUtility.Deserialize(rawModelFilePath); - Assert.Equal("overwritten", rawModel["metadata"]["meta"].ToString()); - Assert.Equal("postbuild1", rawModel["metadata"]["postMeta"].ToString()); - Assert.Equal("1", rawModel["metadata"]["another"].ToString()); - Assert.Equal("app-service", rawModel["metadata"]["ms.service"].ToString()); + Assert.AreEqual("overwritten", rawModel["metadata"]["meta"].ToString()); + Assert.AreEqual("postbuild1", rawModel["metadata"]["postMeta"].ToString()); + Assert.AreEqual("1", rawModel["metadata"]["another"].ToString()); + Assert.AreEqual("app-service", rawModel["metadata"]["ms.service"].ToString()); var rawModelFilePath2 = GetRawModelFilePath(inputFileName2); - Assert.True(File.Exists(rawModelFilePath2)); + Assert.IsTrue(File.Exists(rawModelFilePath2)); var rawModel2 = JsonUtility.Deserialize(rawModelFilePath2); - Assert.Equal("Hello world!", rawModel2["metadata"]["meta"].ToString()); - Assert.Equal("2", rawModel2["metadata"]["another"].ToString()); - Assert.Equal("postbuild2", rawModel2["metadata"]["postMeta"].ToString()); + Assert.AreEqual("Hello world!", rawModel2["metadata"]["meta"].ToString()); + Assert.AreEqual("2", rawModel2["metadata"]["another"].ToString()); + Assert.AreEqual("postbuild2", rawModel2["metadata"]["postMeta"].ToString()); // change dependent markdown UpdateFile("toc.md", ["# Updated"], _inputFolder); @@ -262,19 +262,19 @@ public void TestValidMetadataReferenceWithIncremental() rawModel = JsonUtility.Deserialize(rawModelFilePath); - Assert.Equal("overwritten", rawModel["metadata"]["meta"].ToString()); - Assert.Equal("1", rawModel["metadata"]["another"].ToString()); - Assert.Equal("app-service", rawModel["metadata"]["ms.service"].ToString()); - Assert.Equal("postbuild1", rawModel["metadata"]["postMeta"].ToString()); + Assert.AreEqual("overwritten", rawModel["metadata"]["meta"].ToString()); + Assert.AreEqual("1", rawModel["metadata"]["another"].ToString()); + Assert.AreEqual("app-service", rawModel["metadata"]["ms.service"].ToString()); + Assert.AreEqual("postbuild1", rawModel["metadata"]["postMeta"].ToString()); rawModel2 = JsonUtility.Deserialize(rawModelFilePath2); - Assert.Equal("Hello world!", rawModel2["metadata"]["meta"].ToString()); - Assert.Equal("2", rawModel2["metadata"]["another"].ToString()); - Assert.Equal("postbuild2", rawModel2["metadata"]["postMeta"].ToString()); + Assert.AreEqual("Hello world!", rawModel2["metadata"]["meta"].ToString()); + Assert.AreEqual("2", rawModel2["metadata"]["another"].ToString()); + Assert.AreEqual("postbuild2", rawModel2["metadata"]["postMeta"].ToString()); } - [Fact] + [TestMethod] public void TestInvalidSchemaDefinition() { // Json.NET schema has limitation of 1000 calls per hour @@ -306,7 +306,7 @@ public void TestInvalidSchemaDefinition() Assert.Throws(() => BuildDocument(files)); } - [Fact] + [TestMethod] public void TestInvalidObjectAgainstSchema() { using var listener = new TestListenerScope(); @@ -335,10 +335,10 @@ public void TestInvalidObjectAgainstSchema() files.Add(DocumentType.Article, [inputFile], _inputFolder); BuildDocument(files); var errors = listener.Items.Where(s => s.Code == "ViolateSchema").ToList(); - Assert.Single(errors); + Assert.ContainsSingle(errors); } - [Fact] + [TestMethod] public void TestInvalidMetadataReference() { using var listener = new TestListenerScope(); diff --git a/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs b/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs index a0d6cbcb63b..61439cbdf7c 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs @@ -3,14 +3,14 @@ using Docfx.Build.OverwriteDocuments; -using Xunit; using YamlDotNet.RepresentationModel; namespace Docfx.Build.SchemaDriven.Tests; +[TestClass] public class SchemaFragmentsIteratorTest { - [Fact] + [TestMethod] public void TestSchemaFragmentsIterator() { // arrange @@ -27,11 +27,11 @@ public void TestSchemaFragmentsIterator() iterator.Traverse(yamlStream.Documents[0].RootNode, [], schema); // assert - Assert.Single(counter.ExistingUids); - Assert.Equal("management.azure.com.advisor.suppressions", counter.ExistingUids[0]); - Assert.Single(counter.ExistingMarkdownProperties); - Assert.Equal("definitions[name=\"Application 1\"]/properties[name=\"id\"]/description", counter.ExistingMarkdownProperties[0]); - Assert.Equal(6, counter.MissingMarkdownProperties.Count); + Assert.ContainsSingle(counter.ExistingUids); + Assert.AreEqual("management.azure.com.advisor.suppressions", counter.ExistingUids[0]); + Assert.ContainsSingle(counter.ExistingMarkdownProperties); + Assert.AreEqual("definitions[name=\"Application 1\"]/properties[name=\"id\"]/description", counter.ExistingMarkdownProperties[0]); + Assert.AreEqual(6, counter.MissingMarkdownProperties.Count); } private class UidPropertyCounter : ISchemaFragmentsHandler diff --git a/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs b/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs index 9ede2aedd41..66a96d563a0 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs @@ -8,11 +8,11 @@ using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.SchemaDriven.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class SchemaMergerTest : TestBase { private readonly string _outputFolder; @@ -39,7 +39,7 @@ public SchemaMergerTest() _templateManager = new TemplateManager(["template"], null, _templateFolder); } - [Fact] + [TestMethod] public void TestSchemaOverwriteWithGeneralMergeTypes() { using var listener = new TestListenerScope(); @@ -221,72 +221,72 @@ Overwrite with content BuildDocument(files); // One plugin warning for yml and one plugin warning for overwrite file - Assert.Equal(7, listener.Items.Count); - Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): testmerger"))); - Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/stringArrayValue/0\" in overwrite object fails to overwrite \"/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); - Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/intArrayValue/0\" in overwrite object fails to overwrite \"/intArrayValue\" for \"uid1\" because it does not match any existing item."))); - Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/emptyArray/0\" in overwrite object fails to overwrite \"/emptyArray\" for \"uid1\" because it does not match any existing item."))); - Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/array/0/stringArrayValue/0\" in overwrite object fails to overwrite \"/array/0/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); - Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/dict/stringArrayValue/0\" in overwrite object fails to overwrite \"/dict/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); + Assert.AreEqual(7, listener.Items.Count); + Assert.IsNotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): testmerger"))); + Assert.AreEqual(1, listener.Items.Count(s => s.Message.StartsWith("\"/stringArrayValue/0\" in overwrite object fails to overwrite \"/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); + Assert.AreEqual(1, listener.Items.Count(s => s.Message.StartsWith("\"/intArrayValue/0\" in overwrite object fails to overwrite \"/intArrayValue\" for \"uid1\" because it does not match any existing item."))); + Assert.AreEqual(1, listener.Items.Count(s => s.Message.StartsWith("\"/emptyArray/0\" in overwrite object fails to overwrite \"/emptyArray\" for \"uid1\" because it does not match any existing item."))); + Assert.AreEqual(1, listener.Items.Count(s => s.Message.StartsWith("\"/array/0/stringArrayValue/0\" in overwrite object fails to overwrite \"/array/0/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); + Assert.AreEqual(1, listener.Items.Count(s => s.Message.StartsWith("\"/dict/stringArrayValue/0\" in overwrite object fails to overwrite \"/dict/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); listener.Items.Clear(); var rawModelFilePath = GetRawModelFilePath(inputFileName); - Assert.True(File.Exists(rawModelFilePath)); + Assert.IsTrue(File.Exists(rawModelFilePath)); var rawModel = JsonUtility.Deserialize(rawModelFilePath); - Assert.Equal("Hello world!", rawModel["meta"].Value()); - Assert.Equal(2, rawModel["intValue"].Value()); - Assert.Equal("string1", rawModel["stringValue"].Value()); - Assert.Equal("abc", rawModel["ignoreValue"].Value()); - Assert.True(rawModel["boolValue"].Value()); - Assert.Equal("notEmpty", rawModel["empty"].Value()); + Assert.AreEqual("Hello world!", rawModel["meta"].Value()); + Assert.AreEqual(2, rawModel["intValue"].Value()); + Assert.AreEqual("string1", rawModel["stringValue"].Value()); + Assert.AreEqual("abc", rawModel["ignoreValue"].Value()); + Assert.IsTrue(rawModel["boolValue"].Value()); + Assert.AreEqual("notEmpty", rawModel["empty"].Value()); - Assert.Single(rawModel["stringArrayValue"]); - Assert.Equal(".NET", rawModel["stringArrayValue"][0].Value()); + Assert.ContainsSingle(rawModel["stringArrayValue"]); + Assert.AreEqual(".NET", rawModel["stringArrayValue"][0].Value()); - Assert.Equal(2, rawModel["intArrayValue"].Count()); - Assert.Equal(1, rawModel["intArrayValue"][0].Value()); - Assert.Equal(2, rawModel["intArrayValue"][1].Value()); + Assert.AreEqual(2, rawModel["intArrayValue"].Count()); + Assert.AreEqual(1, rawModel["intArrayValue"][0].Value()); + Assert.AreEqual(2, rawModel["intArrayValue"][1].Value()); - Assert.Empty(rawModel["emptyArray"]); + Assert.IsEmpty(rawModel["emptyArray"]); var array1 = rawModel["array"][0]; - Assert.Equal(2, array1["intValue"].Value()); - Assert.Equal($"\n

Nice

\n", array1["stringValue"].Value()); - Assert.Equal("abcdef", array1["ignoreValue"].Value()); - Assert.False(array1["boolValue"].Value()); - Assert.Equal(3, array1["empty"].Value()); + Assert.AreEqual(2, array1["intValue"].Value()); + Assert.AreEqual($"\n

Nice

\n", array1["stringValue"].Value()); + Assert.AreEqual("abcdef", array1["ignoreValue"].Value()); + Assert.IsFalse(array1["boolValue"].Value()); + Assert.AreEqual(3, array1["empty"].Value()); - Assert.Single(array1["stringArrayValue"]); - Assert.Equal(".NET", array1["stringArrayValue"][0].Value()); + Assert.ContainsSingle(array1["stringArrayValue"]); + Assert.AreEqual(".NET", array1["stringArrayValue"][0].Value()); - Assert.Equal(2, array1["intArrayValue"].Count()); - Assert.Equal(1, array1["intArrayValue"][0].Value()); - Assert.Equal(2, array1["intArrayValue"][1].Value()); + Assert.AreEqual(2, array1["intArrayValue"].Count()); + Assert.AreEqual(1, array1["intArrayValue"][0].Value()); + Assert.AreEqual(2, array1["intArrayValue"][1].Value()); - Assert.Empty(array1["emptyArray"]); + Assert.IsEmpty(array1["emptyArray"]); var dict = rawModel["dict"]; - Assert.Equal(3, dict["intValue"].Value()); - Assert.Equal($"\n

Nice

\n", dict["stringValue"].Value()); - Assert.False(dict["boolValue"].Value()); - Assert.Equal(4, dict["empty"].Value()); + Assert.AreEqual(3, dict["intValue"].Value()); + Assert.AreEqual($"\n

Nice

\n", dict["stringValue"].Value()); + Assert.IsFalse(dict["boolValue"].Value()); + Assert.AreEqual(4, dict["empty"].Value()); - Assert.Single(dict["stringArrayValue"]); - Assert.Equal(".NET", dict["stringArrayValue"][0].Value()); + Assert.ContainsSingle(dict["stringArrayValue"]); + Assert.AreEqual(".NET", dict["stringArrayValue"][0].Value()); - Assert.Single(dict["intArrayValue"]); - Assert.Equal(4, dict["intArrayValue"][0].Value()); + Assert.ContainsSingle(dict["intArrayValue"]); + Assert.AreEqual(4, dict["intArrayValue"][0].Value()); - Assert.Empty(dict["emptyArray"]); - Assert.Equal($"\n

Cool

\n", dict["another"].Value()); - Assert.Equal($"\n

Overwrite with content

\n", dict["summary"].Value()); + Assert.IsEmpty(dict["emptyArray"]); + Assert.AreEqual($"\n

Cool

\n", dict["another"].Value()); + Assert.AreEqual($"\n

Overwrite with content

\n", dict["summary"].Value()); } - [Fact] + [TestMethod] public void TestSchemaOverwriteWithGeneralSchemaOptions() { using var listener = new TestListenerScope(); @@ -348,20 +348,20 @@ public void TestSchemaOverwriteWithGeneralSchemaOptions() BuildDocument(files); // One plugin warning for yml and one plugin warning for overwrite file - Assert.True(listener.Items.Count == 0, listener.Items.Select(s => s.Message).ToDelimitedString()); + Assert.IsTrue(listener.Items.Count == 0, listener.Items.Select(s => s.Message).ToDelimitedString()); var rawModelFilePath = GetRawModelFilePath(inputFileName); - Assert.True(File.Exists(rawModelFilePath)); + Assert.IsTrue(File.Exists(rawModelFilePath)); var rawModel = JsonUtility.Deserialize(rawModelFilePath); - Assert.Equal("Hello world!", rawModel["meta"].Value()); - Assert.Equal($"\n

Nice

\n", rawModel["summary"].Value()); - Assert.Equal("src.html", rawModel["href"].Value()); - Assert.Equal("uid1", rawModel["xref"].Value()); - Assert.Equal($"

overwrite

\n", rawModel["reference"].Value()); + Assert.AreEqual("Hello world!", rawModel["meta"].Value()); + Assert.AreEqual($"\n

Nice

\n", rawModel["summary"].Value()); + Assert.AreEqual("src.html", rawModel["href"].Value()); + Assert.AreEqual("uid1", rawModel["xref"].Value()); + Assert.AreEqual($"

overwrite

\n", rawModel["reference"].Value()); var outputFile = GetOutputFilePath(inputFileName); - Assert.Equal("uid1", File.ReadAllText(outputFile)); + Assert.AreEqual("uid1", File.ReadAllText(outputFile)); } private void BuildDocument(FileCollection files) diff --git a/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs b/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs index c7a5f1eeae3..2651182ab5d 100644 --- a/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs +++ b/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs @@ -9,11 +9,11 @@ using Docfx.Plugins; using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.ManagedReference.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class ConceptualDocumentProcessorTest : TestBase { private readonly string _outputFolder; @@ -52,9 +52,9 @@ public override void Dispose() base.Dispose(); } - [Theory] - [InlineData(@"

", "~/docs/csharp/language-reference/keywords/select-clause.md")] - [InlineData(@"

", "~/../samples/readme.md")] + [TestMethod] + [DataRow(@"

", "~/docs/csharp/language-reference/keywords/select-clause.md")] + [DataRow(@"

", "~/../samples/readme.md")] public void ProcessMarkdownResultWithEncodedUrlShouldSucceed(string htmlContent, string expectedFileLink) { var markdownResult = new MarkupResult @@ -63,10 +63,10 @@ public void ProcessMarkdownResultWithEncodedUrlShouldSucceed(string htmlContent, }; markdownResult = MarkupUtility.Parse(markdownResult, "docs/framework/data/wcf/how-to-project-query-results-wcf-data-services.md", ImmutableDictionary.Create()); - Assert.Equal(expectedFileLink, markdownResult.LinkToFiles.First()); + Assert.AreEqual(expectedFileLink, markdownResult.LinkToFiles.First()); } - [Fact] + [TestMethod] public void ProcessMarkdownFileWithComplexCharsShouldSucceed() { var fileName1 = "A#ctor.md"; @@ -82,16 +82,16 @@ public void ProcessMarkdownFileWithComplexCharsShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file2); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var outputHtml = GetOutputFilePath(file2); - Assert.True(File.Exists(outputHtml)); + Assert.IsTrue(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); - Assert.Equal("

Constructor

\n", + Assert.AreEqual("

Constructor

\n", content); } } - [Fact] + [TestMethod] public void ProcessMarkdownFileWithBreakLinkShouldSucceed() { var fileName = "normal.md"; @@ -101,15 +101,15 @@ public void ProcessMarkdownFileWithBreakLinkShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var outputHtml = GetOutputFilePath(file); - Assert.True(File.Exists(outputHtml)); + Assert.IsTrue(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); - Assert.Equal("

Main

\n", content); + Assert.AreEqual("

Main

\n", content); } } - [Fact] + [TestMethod] public void ProcessMarkdownFileWithBreakLinkInTokenShouldSucceed() { var fileName = "normal.md"; @@ -121,17 +121,17 @@ public void ProcessMarkdownFileWithBreakLinkInTokenShouldSucceed() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var outputHtml = GetOutputFilePath(file); - Assert.True(File.Exists(outputHtml)); + Assert.IsTrue(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); - Assert.Equal(@"

Main

+ Assert.AreEqual(@"

Main

".Replace("\r\n", "\n"), content); } } - [Fact] + [TestMethod] public void SystemKeysListShouldBeComplete() { var fileName = "test.md"; @@ -141,10 +141,10 @@ public void SystemKeysListShouldBeComplete() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); var systemKeys = ToList(model[Constants.PropertyName.SystemKeys]); - Assert.NotEmpty(systemKeys); + Assert.IsNotEmpty(systemKeys); foreach (var key in model.Keys.Where(key => key[0] != '_' && key != "meta")) { Assert.Contains(key, systemKeys); @@ -152,7 +152,7 @@ public void SystemKeysListShouldBeComplete() } } - [Fact] + [TestMethod] public void ProcessMarkdownFileWithRenameOutputFileName() { var fileName1 = "a.md"; @@ -176,16 +176,16 @@ public void ProcessMarkdownFileWithRenameOutputFileName() BuildDocument(files); { var outputRawModelPath = GetRawModelFilePath(renameFile2); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var outputHtml = GetOutputFilePath(renameFile2); - Assert.True(File.Exists(outputHtml)); + Assert.IsTrue(File.Exists(outputHtml)); var content = File.ReadAllText(outputHtml); - Assert.Equal($"\n

Constructor

\n", + Assert.AreEqual($"\n

Constructor

\n", content); } } - [Fact] + [TestMethod] public void ExtractTitle() { // arrange @@ -202,17 +202,17 @@ public void ExtractTitle() // assert var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue("title", out var title)); - Assert.Equal("This is title", title); - Assert.True(model.TryGetValue("rawTitle", out var rawTitle)); - Assert.Equal( + Assert.IsTrue(model.TryGetValue("title", out var title)); + Assert.AreEqual("This is title", title); + Assert.IsTrue(model.TryGetValue("rawTitle", out var rawTitle)); + Assert.AreEqual( "

This is title

", rawTitle); } - [Fact] + [TestMethod] public void ExtractTitleFromYamlHeader() { // arrange @@ -233,13 +233,13 @@ public void ExtractTitleFromYamlHeader() // assert var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue("title", out var title)); - Assert.Equal("Overwrite title", title); + Assert.IsTrue(model.TryGetValue("title", out var title)); + Assert.AreEqual("Overwrite title", title); } - [Fact] + [TestMethod] public void ExtractTitleFromH1IfItIsNullInYamlHeader() { // arrange @@ -260,13 +260,13 @@ public void ExtractTitleFromH1IfItIsNullInYamlHeader() // assert var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue("title", out var title)); - Assert.Equal("This is title", title); + Assert.IsTrue(model.TryGetValue("title", out var title)); + Assert.AreEqual("This is title", title); } - [Fact] + [TestMethod] public void ExtractTitleFromH1IfItIsEmptyInYamlHeader() { // arrange @@ -287,13 +287,13 @@ public void ExtractTitleFromH1IfItIsEmptyInYamlHeader() // assert var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue("title", out var title)); - Assert.Equal("This is title", title); + Assert.IsTrue(model.TryGetValue("title", out var title)); + Assert.AreEqual("This is title", title); } - [Fact] + [TestMethod] public void TitleOverwriteH1InMetadataCanOverwriteTitleFromH1() { // arrange @@ -312,13 +312,13 @@ public void TitleOverwriteH1InMetadataCanOverwriteTitleFromH1() // assert var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue("title", out var title)); - Assert.Equal("this title overwrites title from H1", title); + Assert.IsTrue(model.TryGetValue("title", out var title)); + Assert.AreEqual("this title overwrites title from H1", title); } - [Fact] + [TestMethod] public void TitleOverwriteH1InMetadataCannotOverwriteTitleFromYamlHeader() { // arrange @@ -340,13 +340,13 @@ public void TitleOverwriteH1InMetadataCannotOverwriteTitleFromYamlHeader() // assert var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue("title", out var title)); - Assert.Equal("This is title from YAML header", title); + Assert.IsTrue(model.TryGetValue("title", out var title)); + Assert.AreEqual("This is title from YAML header", title); } - [Fact] + [TestMethod] public void ProcessMarkdownFileWithRedirectUrl() { // arrange @@ -377,15 +377,15 @@ Some content // Test `redirection.raw.json` content. var outputRawModelPath = GetRawModelFilePath(file); - Assert.True(File.Exists(outputRawModelPath)); + Assert.IsTrue(File.Exists(outputRawModelPath)); var model = JsonUtility.Deserialize>(outputRawModelPath); - Assert.True(model.TryGetValue(Constants.PropertyName.RedirectUrl, out var redirectUrl)); - Assert.Equal(RedirectUrl, redirectUrl); + Assert.IsTrue(model.TryGetValue(Constants.PropertyName.RedirectUrl, out var redirectUrl)); + Assert.AreEqual(RedirectUrl, redirectUrl); // Test `manifest.json` content var manifest = GetOutputManifest(); - Assert.Single(manifest.Files); - Assert.True(manifest.Files[0].Type == Constants.DocumentType.Redirection); + Assert.ContainsSingle(manifest.Files); + Assert.IsTrue(manifest.Files[0].Type == Constants.DocumentType.Redirection); } #region Private Helpers diff --git a/test/Docfx.Build.Tests/DocumentBuilderTest.cs b/test/Docfx.Build.Tests/DocumentBuilderTest.cs index 98a7478e338..c09ea507150 100644 --- a/test/Docfx.Build.Tests/DocumentBuilderTest.cs +++ b/test/Docfx.Build.Tests/DocumentBuilderTest.cs @@ -10,11 +10,11 @@ using Docfx.Plugins; using Docfx.Tests.Common; using Newtonsoft.Json.Linq; -using Xunit; namespace Docfx.Build.Engine.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class DocumentBuilderTest : TestBase { private const string RawModelFileExtension = ".raw.json"; @@ -39,7 +39,7 @@ public override void Dispose() base.Dispose(); } - [Fact] + [TestMethod] public void TestBuild() { #region Prepare test data @@ -160,35 +160,35 @@ public void TestBuild() { // check toc. - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))).Items; - Assert.NotNull(model); - Assert.Equal("test1", model[0].Name); - Assert.Equal("test.html#bookmark", model[0].Href); - Assert.NotNull(model[0].Items); - Assert.Equal("test2", model[0].Items[0].Name); - Assert.Equal("test/test.html", model[0].Items[0].Href); - Assert.Equal("GitHub", model[0].Items[1].Name); - Assert.Equal("GH.md?isAbbreviated=true&shouldBeAbbreviated=true#test", model[0].Items[1].Href); - Assert.Equal("Api", model[1].Name); - Assert.Null(model[1].Href); - Assert.NotNull(model[1].Items); - Assert.Equal("Console", model[1].Items[0].Name); - Assert.Equal("../System.Console.csyml", model[1].Items[0].Href); - Assert.Equal("ConsoleColor", model[1].Items[1].Name); - Assert.Equal("../System.ConsoleColor.csyml", model[1].Items[1].Href); + Assert.IsNotNull(model); + Assert.AreEqual("test1", model[0].Name); + Assert.AreEqual("test.html#bookmark", model[0].Href); + Assert.IsNotNull(model[0].Items); + Assert.AreEqual("test2", model[0].Items[0].Name); + Assert.AreEqual("test/test.html", model[0].Items[0].Href); + Assert.AreEqual("GitHub", model[0].Items[1].Name); + Assert.AreEqual("GH.md?isAbbreviated=true&shouldBeAbbreviated=true#test", model[0].Items[1].Href); + Assert.AreEqual("Api", model[1].Name); + Assert.IsNull(model[1].Href); + Assert.IsNotNull(model[1].Items); + Assert.AreEqual("Console", model[1].Items[0].Name); + Assert.AreEqual("../System.Console.csyml", model[1].Items[0].Href); + Assert.AreEqual("ConsoleColor", model[1].Items[1].Name); + Assert.AreEqual("../System.ConsoleColor.csyml", model[1].Items[1].Href); } { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); - Assert.True(File.Exists(conceptualOutputPath)); - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); + Assert.IsTrue(File.Exists(conceptualOutputPath)); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize>(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); - Assert.Equal( + Assert.AreEqual( $"

Hello World

", model["rawTitle"]); - Assert.Equal( + Assert.AreEqual( string.Join( "\n", "", @@ -222,7 +222,7 @@ public void TestBuild() "test", "

"), model["conceptual"]); - Assert.Equal( + Assert.AreEqual( string.Join( "\n", "", @@ -256,39 +256,39 @@ public void TestBuild() "test", "

"), File.ReadAllText(conceptualOutputPath)); - Assert.Equal("Conceptual", model["type"]); - Assert.Equal("Hello world!", model["meta"]); - Assert.Equal("b", model["a"]); + Assert.AreEqual("Conceptual", model["type"]); + Assert.AreEqual("Hello world!", model["meta"]); + Assert.AreEqual("b", model["a"]); } { // check mref. - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.Console.csyml", RawModelFileExtension)))); - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.ConsoleColor.csyml", RawModelFileExtension)))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.Console.csyml", RawModelFileExtension)))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("System.ConsoleColor.csyml", RawModelFileExtension)))); } { // check resource. - Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile))); - Assert.True(File.Exists(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, resourceFile))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension))); var meta = JsonUtility.Deserialize>(Path.Combine(_outputFolder, resourceFile + RawModelFileExtension)); - Assert.Single(meta); - Assert.False(meta.ContainsKey("meta")); + Assert.ContainsSingle(meta); + Assert.IsFalse(meta.ContainsKey("meta")); } { // check xrefmap - Assert.True(File.Exists(Path.Combine(_outputFolder, "xrefmap.yml"))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, "xrefmap.yml"))); var xrefMap = YamlUtility.Deserialize(Path.Combine(_outputFolder, "xrefmap.yml")); - Assert.Equal(71, xrefMap.References.Count); + Assert.AreEqual(71, xrefMap.References.Count); var xref1 = xrefMap.References.Where(xref => xref.Uid.Equals("XRef1")).ToList(); - Assert.Single(xref1); - Assert.Equal(Path.ChangeExtension(conceptualFile3, "html").ToNormalizedPath(), xref1[0]?.Href); + Assert.ContainsSingle(xref1); + Assert.AreEqual(Path.ChangeExtension(conceptualFile3, "html").ToNormalizedPath(), xref1[0]?.Href); var xref2 = xrefMap.References.Where(xref => xref.Uid.Equals("XRef2")).ToList(); - Assert.Single(xref2); - Assert.Equal(Path.ChangeExtension(conceptualFile2, "html").ToNormalizedPath(), xref2[0]?.Href); + Assert.ContainsSingle(xref2); + Assert.AreEqual(Path.ChangeExtension(conceptualFile2, "html").ToNormalizedPath(), xref2[0]?.Href); } } finally @@ -297,7 +297,7 @@ public void TestBuild() } } - [Fact] + [TestMethod] public void TestBuildConceptualWithTemplateShouldSucceed() { CreateFile("conceptual.html.js", @" @@ -354,7 +354,7 @@ public void TestBuildConceptualWithTemplateShouldSucceed() { // check toc. - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize>(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))); var expected = new Dictionary { @@ -422,8 +422,8 @@ public void TestBuildConceptualWithTemplateShouldSucceed() { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); - Assert.True(File.Exists(conceptualOutputPath)); - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); + Assert.IsTrue(File.Exists(conceptualOutputPath)); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize>(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); var expected = new Dictionary { @@ -500,7 +500,7 @@ public void TestBuildConceptualWithTemplateShouldSucceed() } } - [Fact] + [TestMethod] public void TestBuildWithInvalidPath() { #region Prepare test data @@ -553,26 +553,26 @@ public void TestBuildWithInvalidPath() { // check toc. - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize(Path.Combine(_outputFolder, Path.ChangeExtension(tocFile, RawModelFileExtension))).Items; - Assert.NotNull(model); - Assert.Equal("test1", model[0].Name); - Assert.Equal("test.html", model[0].Href); - Assert.NotNull(model[0].Items); - Assert.Equal("test2", model[0].Items[0].Name); - Assert.Equal("test/test.html", model[0].Items[0].Href); + Assert.IsNotNull(model); + Assert.AreEqual("test1", model[0].Name); + Assert.AreEqual("test.html", model[0].Href); + Assert.IsNotNull(model[0].Items); + Assert.AreEqual("test2", model[0].Items[0].Name); + Assert.AreEqual("test/test.html", model[0].Items[0].Href); } { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, ".html")); - Assert.True(File.Exists(conceptualOutputPath)); - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); + Assert.IsTrue(File.Exists(conceptualOutputPath)); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension)))); var model = JsonUtility.Deserialize>(Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile, RawModelFileExtension))); - Assert.Equal( + Assert.AreEqual( $"

Hello World

", model["rawTitle"]); - Assert.Equal( + Assert.AreEqual( string.Join( "\n", "", @@ -588,7 +588,7 @@ public void TestBuildWithInvalidPath() $"Test link: link 10

", ""), model["conceptual"].ToString().Replace("\r", "")); - Assert.Equal( + Assert.AreEqual( string.Join( "\n", "", @@ -604,8 +604,8 @@ public void TestBuildWithInvalidPath() "Test link: link 10

", ""), File.ReadAllText(conceptualOutputPath)); - Assert.Equal("Conceptual", model["type"]); - Assert.Equal("Hello world!", model["meta"]); + Assert.AreEqual("Conceptual", model["type"]); + Assert.AreEqual("Hello world!", model["meta"]); } } finally @@ -613,7 +613,7 @@ public void TestBuildWithInvalidPath() } } - [Fact] + [TestMethod] public void TestBuildWithInvalidPathWithTokenAndMapping() { #region Prepare test data @@ -645,9 +645,9 @@ public void TestBuildWithInvalidPathWithTokenAndMapping() { // check conceptual. var conceptualOutputPath = Path.Combine(_outputFolder, "a.html"); - Assert.True(File.Exists(conceptualOutputPath)); - Assert.True(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("a.md", RawModelFileExtension)))); - Assert.Equal( + Assert.IsTrue(File.Exists(conceptualOutputPath)); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, Path.ChangeExtension("a.md", RawModelFileExtension)))); + Assert.AreEqual( string.Join( "\n", "

link a", @@ -675,7 +675,7 @@ protected override Task SendAsync(HttpRequestMessage reques } } - [Fact] + [TestMethod] public void TestBuildWithMultipleVersion() { #region Prepare test data @@ -696,9 +696,9 @@ public void TestBuildWithMultipleVersion() versionDir: versionDir); var conceptualOutputPath = Path.Combine(_outputFolder, versionDir, Path.ChangeExtension("a.md", RawModelFileExtension)); - Assert.True(File.Exists(conceptualOutputPath)); + Assert.IsTrue(File.Exists(conceptualOutputPath)); var conceptualWithFileMappingOutputPath = Path.Combine(_outputFolder, versionDir, subDir, Path.ChangeExtension("b.md", RawModelFileExtension)); - Assert.True(File.Exists(conceptualWithFileMappingOutputPath)); + Assert.IsTrue(File.Exists(conceptualWithFileMappingOutputPath)); } private static void AssertMetadataEqual(object expected, object actual) @@ -706,7 +706,7 @@ private static void AssertMetadataEqual(object expected, object actual) var expectedJObject = JObject.FromObject(expected); var actualJObject = JObject.FromObject(actual); var equal = JObject.DeepEquals(expectedJObject, actualJObject); - Assert.True(equal, $"Expected: {expectedJObject.ToJsonString()};{Environment.NewLine}Actual: {actualJObject.ToJsonString()}."); + Assert.IsTrue(equal, $"Expected: {expectedJObject.ToJsonString()};{Environment.NewLine}Actual: {actualJObject.ToJsonString()}."); } private void BuildDocument( diff --git a/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs b/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs index 478ce955538..1ba27c603a4 100644 --- a/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs +++ b/test/Docfx.Build.Tests/ExtractSearchIndexFromHtmlTest.cs @@ -4,16 +4,16 @@ using System.Text; using Docfx.Plugins; using HtmlAgilityPack; -using Xunit; namespace Docfx.Build.Engine.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class ExtractSearchIndexFromHtmlTest { private static readonly ExtractSearchIndex _extractor = new(); - [Fact] + [TestMethod] public void TestBasicFeature() { var rawHtml = @" @@ -39,10 +39,10 @@ This is article title html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Equal(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Hello World, Microsoft This is article title docfx can do anything..." }, item); + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Hello World, Microsoft This is article title docfx can do anything..." }, item); } - [Fact] + [TestMethod] public void TestMRefMetadata() { var rawHtml = @" @@ -75,7 +75,7 @@ This is article title ["Title"] = "ManagedReferenceExample", ["Summary"] = "Lorem Ipsum", }); - Assert.Equal(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Hello World, Microsoft This is article title docfx can do anything..." }, itemNoMetadata); + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Hello World, Microsoft This is article title docfx can do anything..." }, itemNoMetadata); _extractor.UseMetadata = true; _extractor.UseMetadataTitle = true; var itemWithMetadata = _extractor.ExtractItem(html, href, new() @@ -84,7 +84,7 @@ This is article title ["Title"] = "ManagedReferenceExample", ["Summary"] = "Lorem Ipsum", }); - Assert.Equal(new SearchIndexItem + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "ManagedReferenceExample", @@ -98,7 +98,7 @@ This is article title ["Title"] = "ManagedReferenceExample", ["Summary"] = "Lorem Ipsum", }); - Assert.Equal(new SearchIndexItem + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "This is title in head metadata", @@ -107,7 +107,7 @@ This is article title }, itemWithMetadataNoTitle); } - [Fact] + [TestMethod] public void TestSearchableClass() { var rawHtml = @" @@ -124,10 +124,10 @@ public void TestSearchableClass() html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Equal(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Cooooooool!" }, item); + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Cooooooool!" }, item); } - [Fact] + [TestMethod] public void TestSearchDisableClass() { var rawHtml = @" @@ -150,10 +150,10 @@ This is article title html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Null(item); + Assert.IsNull(item); } - [Fact] + [TestMethod] public void TestArticleTagWithSearchableClass() { var rawHtml = @" @@ -172,10 +172,10 @@ Only index once. html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Equal(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Only index once." }, item); + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = "Only index once." }, item); } - [Fact] + [TestMethod] public void TestDisableTagWithSearchableClass() { var rawHtml = @" @@ -196,10 +196,10 @@ Only index once. html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Null(item); + Assert.IsNull(item); } - [Fact] + [TestMethod] public void TestEmptyItem() { var rawHtml = @" @@ -215,10 +215,10 @@ public void TestEmptyItem() html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Equal(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = string.Empty }, item); + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "This is title in head metadata", Summary = string.Empty }, item); } - [Fact] + [TestMethod] public void TestBlockTagsVsInlineTags() { var rawHtml = @" @@ -235,10 +235,10 @@ public void TestBlockTagsVsInlineTags() html.LoadHtml(rawHtml); var href = "http://dotnet.github.io/docfx"; var item = _extractor.ExtractItem(html, href); - Assert.Equal(new SearchIndexItem { Href = href, Title = "", Summary = "Insert space in block level html tags Donotinsertspaceininlinehtmltags" }, item); + Assert.AreEqual(new SearchIndexItem { Href = href, Title = "", Summary = "Insert space in block level html tags Donotinsertspaceininlinehtmltags" }, item); } - [Fact] + [TestMethod] public void TestIndexDotJsonWithNonEnglishCharacters() { var rawHtml = @" @@ -294,6 +294,6 @@ This is article title } }"; var actualIndexJSON = File.ReadAllText(Path.Combine(tempTestFolder, "index.json"), Encoding.UTF8); - Assert.Equal(expectedIndexJSON, actualIndexJSON, ignoreLineEndingDifferences: true); + Assert.AreEqual(expectedIndexJSON.ReplaceLineEndings(), actualIndexJSON.ReplaceLineEndings()); } } diff --git a/test/Docfx.Build.Tests/FileMetadataHelperTest.cs b/test/Docfx.Build.Tests/FileMetadataHelperTest.cs index 72d6703db72..b8f6e01b16e 100644 --- a/test/Docfx.Build.Tests/FileMetadataHelperTest.cs +++ b/test/Docfx.Build.Tests/FileMetadataHelperTest.cs @@ -3,13 +3,13 @@ using System.Collections.Immutable; using Docfx.Glob; -using Xunit; namespace Docfx.Build.Engine.Tests; +[TestClass] public class FileMetadataHelperTest { - [Fact] + [TestMethod] public void TestGetChangedGlobs_AllTheSame() { var baseDir = "inputFolder"; @@ -38,11 +38,11 @@ public void TestGetChangedGlobs_AllTheSame() }); var actual = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actual); - Assert.Empty(actual); + Assert.IsNotNull(actual); + Assert.IsEmpty(actual); } - [Fact] + [TestMethod] public void TestGetChangedGlobs_AllChanged_With_DifferentBaseDir() { var patterns = new string[] { "*md", "*.m", "abc", "/[]\\*.cs", "*/*.cs", "**" }; @@ -71,11 +71,11 @@ public void TestGetChangedGlobs_AllChanged_With_DifferentBaseDir() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Empty(actualResults); + Assert.IsNotNull(actualResults); + Assert.IsEmpty(actualResults); } - [Fact] + [TestMethod] public void TestGetChangedGlobs_AllChanged_With_DifferentPattern() { var baseDir = "inputFolder"; @@ -106,16 +106,16 @@ public void TestGetChangedGlobs_AllChanged_With_DifferentPattern() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Equal(12, actualResults.Count); + Assert.IsNotNull(actualResults); + Assert.AreEqual(12, actualResults.Count); var patterns = patternsA.Concat(patternsB).ToList(); for (var index = 0; index < patterns.Count; index++) { - Assert.Equal(patterns[index], actualResults[index].Raw); + Assert.AreEqual(patterns[index], actualResults[index].Raw); } } - [Fact] + [TestMethod] public void TestGetChangedGlobs_CrossGlobsChanged() { var baseDir = "inputFolder"; @@ -143,13 +143,13 @@ public void TestGetChangedGlobs_CrossGlobsChanged() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Equal(2, actualResults.Count); - Assert.Equal(patterns[0], actualResults[0].Raw); - Assert.Equal(patterns[2], actualResults[1].Raw); + Assert.IsNotNull(actualResults); + Assert.AreEqual(2, actualResults.Count); + Assert.AreEqual(patterns[0], actualResults[0].Raw); + Assert.AreEqual(patterns[2], actualResults[1].Raw); } - [Fact] + [TestMethod] public void TestGetChangedGlobs_ReduceGlobsChanged() { var baseDir = "inputFolder"; @@ -171,12 +171,12 @@ public void TestGetChangedGlobs_ReduceGlobsChanged() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Single(actualResults); - Assert.Equal(patterns[1], actualResults[0].Raw); + Assert.IsNotNull(actualResults); + Assert.ContainsSingle(actualResults); + Assert.AreEqual(patterns[1], actualResults[0].Raw); } - [Fact] + [TestMethod] public void TestGetChangedGlobs_IncreaseGlobsChanged() { var baseDir = "inputFolder"; @@ -205,12 +205,12 @@ public void TestGetChangedGlobs_IncreaseGlobsChanged() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Single(actualResults); - Assert.Equal(patterns[2], actualResults[0].Raw); + Assert.IsNotNull(actualResults); + Assert.ContainsSingle(actualResults); + Assert.AreEqual(patterns[2], actualResults[0].Raw); } - [Fact] + [TestMethod] public void TestGetChangedGlobs_Changed() { var baseDir = "inputFolder"; @@ -240,14 +240,14 @@ public void TestGetChangedGlobs_Changed() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Equal(3, actualResults.Count); - Assert.Equal(patterns[5], actualResults[0].Raw); - Assert.Equal(patterns[2], actualResults[1].Raw); - Assert.Equal(patterns[4], actualResults[2].Raw); + Assert.IsNotNull(actualResults); + Assert.AreEqual(3, actualResults.Count); + Assert.AreEqual(patterns[5], actualResults[0].Raw); + Assert.AreEqual(patterns[2], actualResults[1].Raw); + Assert.AreEqual(patterns[4], actualResults[2].Raw); } - [Fact] + [TestMethod] public void TestGetChangedGlobs_Changed_Reverse() { var baseDir = "inputFolder"; @@ -271,8 +271,8 @@ public void TestGetChangedGlobs_Changed_Reverse() }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); - Assert.NotNull(actualResults); - Assert.Single(actualResults); - Assert.Equal(patterns[1], actualResults[0].Raw); + Assert.IsNotNull(actualResults); + Assert.ContainsSingle(actualResults); + Assert.AreEqual(patterns[1], actualResults[0].Raw); } } diff --git a/test/Docfx.Build.Tests/HtmlTemplateTest.cs b/test/Docfx.Build.Tests/HtmlTemplateTest.cs index 83b2709b393..6050f76f834 100644 --- a/test/Docfx.Build.Tests/HtmlTemplateTest.cs +++ b/test/Docfx.Build.Tests/HtmlTemplateTest.cs @@ -1,33 +1,32 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - using static Docfx.Build.HtmlTemplate; namespace Docfx.Build.Engine.Tests; +[TestClass] public class HtmlTemplateTest { - [Fact] + [TestMethod] public void HtmlTemplate_HtmlTest() { - Assert.Equal("ab", Html($"a{null}b").ToString()); - Assert.Equal("a1b", Html($"a{1}b").ToString()); - Assert.Equal("a<br/>b", Html($"a{"
"}b").ToString()); - Assert.Equal("a
b", Html($"a{UnsafeHtml("
")}b").ToString()); - Assert.Equal("a

2

b", Html($"a{Html($"

{2}

")}b").ToString()); - Assert.Equal("
  • 0
  • 1
", Html($"
    {new[] { 0, 1 }.Select(i => Html($"
  • {i}
  • "))}
").ToString()); + Assert.AreEqual("ab", Html($"a{null}b").ToString()); + Assert.AreEqual("a1b", Html($"a{1}b").ToString()); + Assert.AreEqual("a<br/>b", Html($"a{"
"}b").ToString()); + Assert.AreEqual("a
b", Html($"a{UnsafeHtml("
")}b").ToString()); + Assert.AreEqual("a

2

b", Html($"a{Html($"

{2}

")}b").ToString()); + Assert.AreEqual("
  • 0
  • 1
", Html($"
    {new[] { 0, 1 }.Select(i => Html($"
  • {i}
  • "))}
").ToString()); } - [Fact] + [TestMethod] public void HtmlTemplate_HtmlAttributesTest() { - Assert.Equal("

", Html($"

").ToString()); - Assert.Equal("

", Html($"

").ToString()); - Assert.Equal("

", Html($"

").ToString()); - Assert.Equal("

", Html($"

").ToString()); - Assert.Equal("

", Html($"

").ToString()); - Assert.Equal("

", Html($"

").ToString()); + Assert.AreEqual("

", Html($"

").ToString()); + Assert.AreEqual("

", Html($"

").ToString()); + Assert.AreEqual("

", Html($"

").ToString()); + Assert.AreEqual("

", Html($"

").ToString()); + Assert.AreEqual("

", Html($"

").ToString()); + Assert.AreEqual("

", Html($"

").ToString()); } } diff --git a/test/Docfx.Build.Tests/JintProcessorHelperTest.cs b/test/Docfx.Build.Tests/JintProcessorHelperTest.cs index ff772e00a34..112281ec003 100644 --- a/test/Docfx.Build.Tests/JintProcessorHelperTest.cs +++ b/test/Docfx.Build.Tests/JintProcessorHelperTest.cs @@ -3,45 +3,45 @@ using Docfx.Common; using Jint; -using Xunit; namespace Docfx.Build.Engine.Tests; +[TestClass] public class JintProcessorHelperTest { - [Trait("Related", "JintProcessor")] - [Fact] + [TestProperty("Related", "JintProcessor")] + [TestMethod] public void TestJObjectConvertWithJToken() { var testData = ConvertToObjectHelper.ConvertStrongTypeToObject(new TestData()); { var engine = new Jint.Engine(); var jsValue = JintProcessorHelper.ConvertObjectToJsValue(engine, testData); - Assert.True(jsValue.IsObject()); + Assert.IsTrue(jsValue.IsObject()); dynamic value = jsValue.ToObject(); - Assert.Equal(2, value.ValueA); - Assert.Equal("ValueB", value.ValueB); + Assert.AreEqual(2, value.ValueA); + Assert.AreEqual("ValueB", value.ValueB); System.Dynamic.ExpandoObject valueDict = value.ValueDict; var dict = (IDictionary)valueDict; - Assert.Equal("Value1", dict["1"]); - Assert.Equal(2.0, dict["key"]); + Assert.AreEqual("Value1", dict["1"]); + Assert.AreEqual(2.0, dict["key"]); object[] array = value.ValueList; - Assert.Equal("ValueA", array[0]); - Assert.Equal("ValueB", array[1]); + Assert.AreEqual("ValueA", array[0]); + Assert.AreEqual("ValueB", array[1]); } } - [Trait("Related", "JintProcessor")] - [Theory] - [InlineData("string", "string")] - [InlineData(1, 1.0)] - [InlineData(true, true)] - [InlineData('a', "a")] + [TestProperty("Related", "JintProcessor")] + [TestMethod] + [DataRow("string", "string")] + [DataRow(1, 1.0)] + [DataRow(true, true)] + [DataRow('a', "a")] public void TestJObjectConvertWithPrimaryType(object input, object expected) { var engine = new Jint.Engine(); var jsValue = JintProcessorHelper.ConvertObjectToJsValue(engine, input); - Assert.Equal(expected, jsValue.ToObject()); + Assert.AreEqual(expected, jsValue.ToObject()); } private sealed class TestData diff --git a/test/Docfx.Build.Tests/MarkdownTocReaderTest.cs b/test/Docfx.Build.Tests/MarkdownTocReaderTest.cs index d59fa4cae26..f5ab0126811 100644 --- a/test/Docfx.Build.Tests/MarkdownTocReaderTest.cs +++ b/test/Docfx.Build.Tests/MarkdownTocReaderTest.cs @@ -2,13 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using Docfx.Plugins; -using Xunit; namespace Docfx.Build.TableOfContents.Tests; +[TestClass] public class MarkdownTocReaderTest { - [Fact] + [TestMethod] public void TestTocMdReader() { var toc = MarkdownTocReader.LoadToc(@" @@ -29,63 +29,63 @@ public void TestTocMdReader() ## ## [Article8](xref:article8) ", "test.md"); - Assert.Equal(3, toc.Count); - Assert.Equal("Article1", toc[0].Name); - Assert.Equal("article1.md", toc[0].Href); + Assert.AreEqual(3, toc.Count); + Assert.AreEqual("Article1", toc[0].Name); + Assert.AreEqual("article1.md", toc[0].Href); { var toc0 = toc[0].Items; - Assert.Equal(3, toc0.Count); - Assert.Equal("Container1", toc0[0].Name); - Assert.Null(toc0[0].Href); + Assert.AreEqual(3, toc0.Count); + Assert.AreEqual("Container1", toc0[0].Name); + Assert.IsNull(toc0[0].Href); { var toc0_0 = toc0[0].Items; - Assert.Equal(2, toc0_0.Count); - Assert.Equal("Article2", toc0_0[0].Name); - Assert.Equal("Article 2", toc0_0[0].DisplayName); - Assert.Equal("article2.md", toc0_0[0].Href); - Assert.Equal("Article3", toc0_0[1].Name); - Assert.Equal("article3.md", toc0_0[1].Href); + Assert.AreEqual(2, toc0_0.Count); + Assert.AreEqual("Article2", toc0_0[0].Name); + Assert.AreEqual("Article 2", toc0_0[0].DisplayName); + Assert.AreEqual("article2.md", toc0_0[0].Href); + Assert.AreEqual("Article3", toc0_0[1].Name); + Assert.AreEqual("article3.md", toc0_0[1].Href); } - Assert.Equal("Container2", toc0[1].Name); - Assert.Null(toc0[1].Href); + Assert.AreEqual("Container2", toc0[1].Name); + Assert.IsNull(toc0[1].Href); { var toc0_1 = toc0[1].Items; - Assert.Single(toc0_1); - Assert.Equal("Article4", toc0_1[0].Name); - Assert.Equal("article4.md", toc0_1[0].Href); + Assert.ContainsSingle(toc0_1); + Assert.AreEqual("Article4", toc0_1[0].Name); + Assert.AreEqual("article4.md", toc0_1[0].Href); { var toc0_1_0 = toc0_1[0].Items; - Assert.Single(toc0_1_0); - Assert.Equal("Article5", toc0_1_0[0].Name); - Assert.Equal("article5.md", toc0_1_0[0].Href); + Assert.ContainsSingle(toc0_1_0); + Assert.AreEqual("Article5", toc0_1_0[0].Name); + Assert.AreEqual("article5.md", toc0_1_0[0].Href); } } - Assert.Equal("Article6", toc0[2].Name); - Assert.Equal("article6.md", toc0[2].Href); + Assert.AreEqual("Article6", toc0[2].Name); + Assert.AreEqual("article6.md", toc0[2].Href); } - Assert.Equal("Article7", toc[1].Name); - Assert.Equal("article7.md", toc[1].Href); + Assert.AreEqual("Article7", toc[1].Name); + Assert.AreEqual("article7.md", toc[1].Href); { var toc1 = toc[1].Items; - Assert.Single(toc1); - Assert.Equal("External", toc1[0].Name); - Assert.Equal("http://www.microsoft.com", toc1[0].Href); + Assert.ContainsSingle(toc1); + Assert.AreEqual("External", toc1[0].Name); + Assert.AreEqual("http://www.microsoft.com", toc1[0].Href); } - Assert.Equal("XrefArticles", toc[2].Name); - Assert.Equal("xref", toc[2].Uid); + Assert.AreEqual("XrefArticles", toc[2].Name); + Assert.AreEqual("xref", toc[2].Uid); { var toc1 = toc[2].Items; - Assert.Equal(3, toc1.Count); - Assert.Null(toc1[0].Name); - Assert.Equal("article8", toc1[0].Uid); - Assert.Null(toc1[1].Name); - Assert.Equal("article8", toc1[1].Uid); - Assert.Equal("Article8", toc1[2].Name); - Assert.Equal("article8", toc1[2].Uid); + Assert.AreEqual(3, toc1.Count); + Assert.IsNull(toc1[0].Name); + Assert.AreEqual("article8", toc1[0].Uid); + Assert.IsNull(toc1[1].Name); + Assert.AreEqual("article8", toc1[1].Uid); + Assert.AreEqual("Article8", toc1[2].Name); + Assert.AreEqual("article8", toc1[2].Uid); } } - [Fact] + [TestMethod] public void TestBadMdToc() { var ex = Assert.Throws(() => @@ -96,9 +96,9 @@ public void TestBadMdToc() >_< >_< ", "test.md")); - Assert.Equal(@"Invalid toc file: test.md, Details: Unknown syntax at line 3: + Assert.AreEqual(@"Invalid toc file: test.md, Details: Unknown syntax at line 3: [bad]() >_< ->_<", ex.Message, ignoreLineEndingDifferences: true); +>_<".ReplaceLineEndings(), ex.Message.ReplaceLineEndings()); } } diff --git a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs index 68860158bfb..a20a7e0cdde 100644 --- a/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs +++ b/test/Docfx.Build.Tests/PostProcessors/SitemapGeneratorTests.cs @@ -4,12 +4,12 @@ using System.Xml.Linq; using Docfx.Plugins; using Docfx.Tests.Common; -using Xunit; using DocumentType = Docfx.DataContracts.Common.Constants.DocumentType; namespace Docfx.Build.Engine.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class SitemapGeneratorTests : TestBase { public override void Dispose() @@ -17,7 +17,7 @@ public override void Dispose() base.Dispose(); } - [Fact] + [TestMethod] public void TestSitemapGenerator() { // Arrange @@ -53,19 +53,19 @@ public void TestSitemapGenerator() manifest = sitemapGenerator.Process(manifest, outputFolder); // Assert - Assert.Equal("https://example.com/", manifest.Sitemap.BaseUrl); - Assert.True(File.Exists(sitemapPath)); + Assert.AreEqual("https://example.com/", manifest.Sitemap.BaseUrl); + Assert.IsTrue(File.Exists(sitemapPath)); var sitemap = XDocument.Load(sitemapPath); var ns = sitemap.Root.Name.Namespace; var urls = sitemap.Root.Elements(ns + "url").ToArray(); - Assert.Equal(4, urls.Length); + Assert.AreEqual(4, urls.Length); // URLs are ordered based on HTML output's RelativePath. - Assert.EndsWith("/Conceptual.html", urls[0].Element(ns + "loc").Value); - Assert.EndsWith("/Dashboard.html", urls[1].Element(ns + "loc").Value); - Assert.EndsWith("/ManagedReference.html", urls[2].Element(ns + "loc").Value); - Assert.EndsWith("/Resource.html", urls[3].Element(ns + "loc").Value); + StringAssert.EndsWith(urls[0].Element(ns + "loc").Value, "/Conceptual.html"); + StringAssert.EndsWith(urls[1].Element(ns + "loc").Value, "/Dashboard.html"); + StringAssert.EndsWith(urls[2].Element(ns + "loc").Value, "/ManagedReference.html"); + StringAssert.EndsWith(urls[3].Element(ns + "loc").Value, "/Resource.html"); } private static ManifestItem GetManifestItem(string documentType, string outputFileExtension = ".html") diff --git a/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs b/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs index 588155d564b..d670105c6db 100644 --- a/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs +++ b/test/Docfx.Build.Tests/RemoveDebugInfoTest.cs @@ -4,11 +4,10 @@ using Docfx.Plugins; using Docfx.Tests.Common; -using Xunit; - namespace Docfx.Build.Engine.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class RemoveDebugInfoTest : TestBase { private readonly string _outputFolder; @@ -26,7 +25,7 @@ public override void Dispose() base.Dispose(); } - [Fact] + [TestMethod] public void TestBasicFeature() { Manifest manifest = new() @@ -46,6 +45,6 @@ public void TestBasicFeature() }.Process(manifest, _outputFolder); var actual = File.ReadAllText(Path.Combine(_outputFolder, "a.html")); - Assert.Equal("

sectionMicrosoft Bing

", actual); + Assert.AreEqual("

sectionMicrosoft Bing

", actual); } } diff --git a/test/Docfx.Build.Tests/TemplateManagerUnitTest.DotnetToolMode.cs b/test/Docfx.Build.Tests/TemplateManagerUnitTest.DotnetToolMode.cs index 838bff1a889..5cc2afb7c91 100644 --- a/test/Docfx.Build.Tests/TemplateManagerUnitTest.DotnetToolMode.cs +++ b/test/Docfx.Build.Tests/TemplateManagerUnitTest.DotnetToolMode.cs @@ -4,7 +4,6 @@ using Docfx.Common; using Docfx.Tests.Common; using FluentAssertions; -using Xunit; using Switches = Docfx.DataContracts.Common.Constants.Switches; namespace Docfx.Build.Engine.Tests; @@ -17,8 +16,8 @@ public partial class TemplateManagerUnitTest /// /// DotnetToolsMode switch is not set or disabled. (it depends on test execution order) /// - [Trait("Related", "TemplateProcessor")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestMethod] public void TestDotnetToolsMode_Default() { // Arrange @@ -35,8 +34,8 @@ public void TestDotnetToolsMode_Default() /// /// DotnetToolsMode switch is enabled /// - [Trait("Related", "TemplateProcessor")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestMethod] public void TestDotnetToolsMode_Enabled() { // Arrange @@ -71,8 +70,8 @@ public void TestDotnetToolsMode_Enabled() /// /// DotnetToolMode is enabled but path is invalid. /// - [Trait("Related", "TemplateProcessor")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestMethod] public void TestDotnetToolsMode_InvalidPath() { // Arrange diff --git a/test/Docfx.Build.Tests/TemplateManagerUnitTest.cs b/test/Docfx.Build.Tests/TemplateManagerUnitTest.cs index 22c766f0612..dc42b97b573 100644 --- a/test/Docfx.Build.Tests/TemplateManagerUnitTest.cs +++ b/test/Docfx.Build.Tests/TemplateManagerUnitTest.cs @@ -4,11 +4,10 @@ using Docfx.Plugins; using Docfx.Tests.Common; -using Xunit; - namespace Docfx.Build.Engine.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public partial class TemplateManagerUnitTest : TestBase { private readonly string _inputFolder; @@ -20,8 +19,8 @@ public TemplateManagerUnitTest() _outputFolder = GetRandomFolder(); } - [Trait("Related", "ResourceFinder")] - [Fact] + [TestProperty("Related", "ResourceFinder")] + [TestMethod] public void TestTemplateManagerWithMultipleThemesShouldWork() { // If the same resource name exists in the override folder, use the overridden one @@ -31,20 +30,20 @@ public void TestTemplateManagerWithMultipleThemesShouldWork() manager.ProcessTheme(outputFolder, true); // 1. Support tmpl1.zip var file1 = Path.Combine(outputFolder, "tmpl1.dot.$"); - Assert.True(File.Exists(file1)); - Assert.Equal("Override: This is file with complex filename characters", File.ReadAllText(file1)); + Assert.IsTrue(File.Exists(file1)); + Assert.AreEqual("Override: This is file with complex filename characters", File.ReadAllText(file1)); // backslash is also supported var file2 = Path.Combine(outputFolder, "sub/file1"); - Assert.True(File.Exists(file2)); - Assert.Equal("Override: This is file inside a subfolder", File.ReadAllText(file2)); + Assert.IsTrue(File.Exists(file2)); + Assert.AreEqual("Override: This is file inside a subfolder", File.ReadAllText(file2)); } #region Mustache template processor test - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateProcessSingleTemplateWithNoScriptShouldWork() { // 1. Prepare template @@ -75,7 +74,7 @@ public void TestMustacheTemplateProcessSingleTemplateWithNoScriptShouldWork() ProcessTemplate(templateName, null, new[] { item }, model, _outputFolder, Tuple.Create("default.tmpl", template)); var outputFile = Path.Combine(_outputFolder, Path.ChangeExtension(modelFileName, null)); - Assert.True(File.Exists(outputFile)); + Assert.IsTrue(File.Exists(outputFile)); AssertEqualIgnoreCrlf(@" name1=test1, name2=; @@ -84,9 +83,9 @@ public void TestMustacheTemplateProcessSingleTemplateWithNoScriptShouldWork() ", File.ReadAllText(outputFile)); } - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateProcessSingleTemplateWithNoScriptWithPartialShouldWork() { // 1. Prepare template @@ -132,7 +131,7 @@ public void TestMustacheTemplateProcessSingleTemplateWithNoScriptWithPartialShou Tuple.Create("partial2.tmpl.partial", partial2)); var outputFile = Path.Combine(_outputFolder, Path.ChangeExtension(modelFileName, null)); - Assert.True(File.Exists(outputFile)); + Assert.IsTrue(File.Exists(outputFile)); AssertEqualIgnoreCrlf(@" test1 test2 @@ -143,9 +142,9 @@ public void TestMustacheTemplateProcessSingleTemplateWithNoScriptWithPartialShou ", File.ReadAllText(outputFile)); } - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateWithMasterPageShouldWork() { // 1. Prepare template @@ -204,8 +203,8 @@ Hello Body Tuple.Create("partial2.tmpl.partial", partial2)); var outputFile = Path.Combine(_outputFolder, Path.ChangeExtension(modelFileName, null)); - Assert.True(File.Exists(Path.Combine(_outputFolder, "reference1.html"))); - Assert.True(File.Exists(outputFile)); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, "reference1.html"))); + Assert.IsTrue(File.Exists(outputFile)); AssertEqualIgnoreCrlf(@" Hello Master @@ -226,9 +225,9 @@ Hello Body ", File.ReadAllText(outputFile)); } - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateProcessInvalidTemplateShouldFail() { var templateName = "InvalidTemplate.html"; @@ -249,9 +248,9 @@ public void TestMustacheTemplateProcessInvalidTemplateShouldFail() ); } - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateProcessSingleTemplateWithIncludesShouldWork() { var templateName = "WithIncludes.html"; @@ -293,17 +292,17 @@ public void TestMustacheTemplateProcessSingleTemplateWithIncludesShouldWork() Tuple.Create("reference2.html", string.Empty) ); var outputFilePath = Path.Combine(_outputFolder, Path.ChangeExtension(modelFileName, "html")); - Assert.True(File.Exists(outputFilePath)); - Assert.True(File.Exists(Path.Combine(_outputFolder, "reference1.html"))); - Assert.True(File.Exists(Path.Combine(_outputFolder, "reference2.html"))); + Assert.IsTrue(File.Exists(outputFilePath)); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, "reference1.html"))); + Assert.IsTrue(File.Exists(Path.Combine(_outputFolder, "reference2.html"))); AssertEqualIgnoreCrlf(@" test1 test2 ", File.ReadAllText(outputFilePath)); } - [Trait("Related", "TemplateProcessor")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestMethod] public void TestMustacheTemplateProcessSingleTemplateWithRequireScriptShouldWork() { var templateName = "WithRequireScript.html"; @@ -353,7 +352,7 @@ function isAbsolutePath(path) { Tuple.Create("util.js", utilScript) ); var outputFilePath = Path.Combine(_outputFolder, Path.ChangeExtension(modelFileName, "html")); - Assert.True(File.Exists(outputFilePath)); + Assert.IsTrue(File.Exists(outputFilePath)); AssertEqualIgnoreCrlf(@" result1 = true result2 = true @@ -361,9 +360,9 @@ function isAbsolutePath(path) { ", File.ReadAllText(outputFilePath)); } - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateProcessTemplateFolderWithDifferentTypeShouldWork() { var templateName = "TemplateFolder.html"; @@ -415,14 +414,14 @@ public void TestMustacheTemplateProcessTemplateFolderWithDifferentTypeShouldWork Tuple.Create("conceptual.md.js", script) ); var outputFilePath1 = Path.Combine(_outputFolder, "TestTemplateProcessor_TemplateFolderWithDifferentType1.md"); - Assert.True(File.Exists(outputFilePath1)); + Assert.IsTrue(File.Exists(outputFilePath1)); AssertEqualIgnoreCrlf(@" conceptual: test1 test2 ", File.ReadAllText(outputFilePath1)); var outputFilePath2 = Path.Combine(_outputFolder, "TestTemplateProcessor_TemplateFolderWithDifferentType2.html"); - Assert.True(File.Exists(outputFilePath2)); + Assert.IsTrue(File.Exists(outputFilePath2)); AssertEqualIgnoreCrlf(@" default: test1 @@ -430,9 +429,9 @@ public void TestMustacheTemplateProcessTemplateFolderWithDifferentTypeShouldWork ", File.ReadAllText(outputFilePath2)); } - [Trait("Related", "TemplateProcessor")] - [Trait("Related", "Mustache")] - [Fact] + [TestProperty("Related", "TemplateProcessor")] + [TestProperty("Related", "Mustache")] + [TestMethod] public void TestMustacheTemplateWithScriptWithLongStringInModelShouldWork() { // https://github.com/sebastienros/jint/issues/357 @@ -469,11 +468,11 @@ public void TestMustacheTemplateWithScriptWithLongStringInModelShouldWork() Tuple.Create("default.html.js", script) ); var outputFilePath1 = Path.Combine(_outputFolder, "TestMustacheTemplateWithScriptWithLongStringInModelShouldWork.html"); - Assert.True(File.Exists(outputFilePath1)); - Assert.Equal($"{{"model":{{"name":"{longName}"}},"__global":{{}}}}", File.ReadAllText(outputFilePath1)); + Assert.IsTrue(File.Exists(outputFilePath1)); + Assert.AreEqual($"{{"model":{{"name":"{longName}"}},"__global":{{}}}}", File.ReadAllText(outputFilePath1)); } - [Fact] + [TestMethod] public void JsRegexShouldNotShareStatusAmongFunctions() { // https://github.com/sebastienros/jint/issues/364 @@ -509,11 +508,11 @@ function isAbsolutePath(path) { Tuple.Create("default.html.js", script) ); var outputFilePath1 = Path.Combine(_outputFolder, "file.html"); - Assert.True(File.Exists(outputFilePath1)); - Assert.Equal("True,True", File.ReadAllText(outputFilePath1)); + Assert.IsTrue(File.Exists(outputFilePath1)); + Assert.AreEqual("True,True", File.ReadAllText(outputFilePath1)); } - [Fact] + [TestMethod] public void JsCreateDateShouldNotThrowError() { var templateName = "TemplateFolder.html"; @@ -538,8 +537,8 @@ public void JsCreateDateShouldNotThrowError() Tuple.Create("default.html.js", script) ); var outputFilePath1 = Path.Combine(_outputFolder, "file.html"); - Assert.True(File.Exists(outputFilePath1)); - Assert.Equal("2019-08-19T05:40:30.463Z", File.ReadAllText(outputFilePath1)); + Assert.IsTrue(File.Exists(outputFilePath1)); + Assert.AreEqual("2019-08-19T05:40:30.463Z", File.ReadAllText(outputFilePath1)); } #endregion @@ -592,6 +591,6 @@ private static void WriteTemplate(string cwd, params Tuple[] fil private static void AssertEqualIgnoreCrlf(string expected, string actual) { - Assert.Equal(expected.Replace("\r\n", "\n"), actual.Replace("\r\n", "\n")); + Assert.AreEqual(expected.Replace("\r\n", "\n"), actual.Replace("\r\n", "\n")); } } diff --git a/test/Docfx.Build.Tests/TemplatePageLoaderUnitTest.cs b/test/Docfx.Build.Tests/TemplatePageLoaderUnitTest.cs index c85c2c72929..9e1978d65d1 100644 --- a/test/Docfx.Build.Tests/TemplatePageLoaderUnitTest.cs +++ b/test/Docfx.Build.Tests/TemplatePageLoaderUnitTest.cs @@ -3,11 +3,10 @@ using Docfx.Tests.Common; -using Xunit; - namespace Docfx.Build.Engine.Tests; -[Collection("docfx STA")] +[DoNotParallelize] +[TestClass] public class TemplatePageLoaderUnitTest : TestBase { private readonly string _inputFolder; @@ -17,32 +16,32 @@ public TemplatePageLoaderUnitTest() _inputFolder = GetRandomFolder(); } - [Fact] + [TestMethod] public void TestLoaderWhenNoFileExists() { using var listener = new TestListenerScope(); var templates = LoadAllTemplates(); - Assert.Empty(listener.Items); - Assert.Empty(templates); + Assert.IsEmpty(listener.Items); + Assert.IsEmpty(templates); CreateFile("a.js", string.Empty, _inputFolder); templates = LoadAllTemplates(); - Assert.Empty(listener.Items); - Assert.Empty(templates); + Assert.IsEmpty(listener.Items); + Assert.IsEmpty(templates); // only allows file under root folder CreateFile("sub/a.tmpl", string.Empty, _inputFolder); templates = LoadAllTemplates(); - Assert.Empty(listener.Items); - Assert.Empty(templates); + Assert.IsEmpty(listener.Items); + Assert.IsEmpty(templates); CreateFile("a.tmpl.js", string.Empty, _inputFolder); templates = LoadAllTemplates(); - Assert.Empty(listener.Items); - Assert.Empty(templates); + Assert.IsEmpty(listener.Items); + Assert.IsEmpty(templates); } - [Fact] + [TestMethod] public void TestLoaderWhenRendererExists() { CreateFile("a.tmpl", string.Empty, _inputFolder); @@ -50,21 +49,21 @@ public void TestLoaderWhenRendererExists() using var listener = new TestListenerScope(); var templates = LoadAllTemplates(); - Assert.Empty(listener.Items); + Assert.IsEmpty(listener.Items); - Assert.Single(templates); + Assert.ContainsSingle(templates); var template = templates[0]; - Assert.NotNull(template.Renderer); - Assert.Equal(TemplateType.Default, template.TemplateType); - Assert.Equal("a", template.Name); - Assert.Equal("a", template.Type); - Assert.Equal(string.Empty, template.Extension); - Assert.Null(template.Preprocessor); - Assert.False(template.ContainsGetOptions); - Assert.False(template.ContainsModelTransformation); + Assert.IsNotNull(template.Renderer); + Assert.AreEqual(TemplateType.Default, template.TemplateType); + Assert.AreEqual("a", template.Name); + Assert.AreEqual("a", template.Type); + Assert.AreEqual(string.Empty, template.Extension); + Assert.IsNull(template.Preprocessor); + Assert.IsFalse(template.ContainsGetOptions); + Assert.IsFalse(template.ContainsModelTransformation); } - [Fact] + [TestMethod] public void TestLoaderWhenPreprocessorExists() { CreateFile("a.primary.tmpl", string.Empty, _inputFolder); @@ -73,24 +72,24 @@ public void TestLoaderWhenPreprocessorExists() using var listener = new TestListenerScope(); var templates = LoadAllTemplates(); - Assert.Empty(listener.Items); + Assert.IsEmpty(listener.Items); - Assert.Single(templates); + Assert.ContainsSingle(templates); var template = templates[0]; - Assert.NotNull(template.Renderer); - Assert.Equal(TemplateType.Primary, template.TemplateType); - Assert.Equal("a.primary", template.Name); - Assert.Equal("a", template.Type); - Assert.Equal(string.Empty, template.Extension); - Assert.NotNull(template.Preprocessor); - Assert.False(template.ContainsGetOptions); - Assert.True(template.ContainsModelTransformation); + Assert.IsNotNull(template.Renderer); + Assert.AreEqual(TemplateType.Primary, template.TemplateType); + Assert.AreEqual("a.primary", template.Name); + Assert.AreEqual("a", template.Type); + Assert.AreEqual(string.Empty, template.Extension); + Assert.IsNotNull(template.Preprocessor); + Assert.IsFalse(template.ContainsGetOptions); + Assert.IsTrue(template.ContainsModelTransformation); var output = template.TransformModel(new { a = 1 }); - Assert.Null(output); + Assert.IsNull(output); } - [Fact] + [TestMethod] public void TestLoaderWhenStandalonePreprocessorExists() { CreateFile("a.ext.TMPL.js", "exports.transform = function(){}", _inputFolder); @@ -98,21 +97,21 @@ public void TestLoaderWhenStandalonePreprocessorExists() using var listener = new TestListenerScope(); var templates = LoadAllTemplates(); - Assert.Empty(listener.Items); + Assert.IsEmpty(listener.Items); - Assert.Single(templates); + Assert.ContainsSingle(templates); var template = templates[0]; - Assert.Null(template.Renderer); - Assert.Equal(TemplateType.Default, template.TemplateType); - Assert.Equal("a.ext", template.Name); - Assert.Equal("a", template.Type); - Assert.Equal(".ext", template.Extension); - Assert.NotNull(template.Preprocessor); - Assert.False(template.ContainsGetOptions); - Assert.True(template.ContainsModelTransformation); + Assert.IsNull(template.Renderer); + Assert.AreEqual(TemplateType.Default, template.TemplateType); + Assert.AreEqual("a.ext", template.Name); + Assert.AreEqual("a", template.Type); + Assert.AreEqual(".ext", template.Extension); + Assert.IsNotNull(template.Preprocessor); + Assert.IsFalse(template.ContainsGetOptions); + Assert.IsTrue(template.ContainsModelTransformation); var output = template.TransformModel(new { a = 1 }); - Assert.Null(output); + Assert.IsNull(output); } private List