From: Matt Kotsenas Date: Wed, 16 Sep 2020 23:41:45 +0000 (-0700) Subject: Remove unused locals and fix tests in System.ServiceModel.Syndication (#39639) X-Git-Tag: submit/tizen/20210909.063632~5456 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=783913897623ed0af0d5e750b0657d923fac9a2c;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove unused locals and fix tests in System.ServiceModel.Syndication (#39639) * Remove unused locals and fix tests in System.ServiceModel.Syndication Remove unused locals in System.ServiceModel.Syndication. While refactoring I found two places where unit tests appear to have a copy/paste error and were asserting the wrong value. * Add back `thirdDocument` and correct tests * Add back `sixthDocument` and correct tests * Add back item and correct tests * Add back `genericFormatter` and correct test * Add back `elementExtensions` and add assert --- diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatterTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatterTests.cs index 21a21d8..db1f33b 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatterTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatterTests.cs @@ -49,7 +49,6 @@ namespace System.ServiceModel.Syndication.Tests [InlineData(typeof(InlineCategoriesDocumentSubclass), typeof(ReferencedCategoriesDocumentSubclass))] public void Ctor_Type_Type(Type inlineDocumentType, Type referencedDocumentType) { - var document = new InlineCategoriesDocument(); var formatter = new AtomPub10CategoriesDocumentFormatter(inlineDocumentType, referencedDocumentType); Assert.Null(formatter.Document); Assert.Equal("http://www.w3.org/2007/app", formatter.Version); diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10ServiceDocumentFormatterTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10ServiceDocumentFormatterTests.cs index 3aac563..55fca75 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10ServiceDocumentFormatterTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/AtomPub10ServiceDocumentFormatterTests.cs @@ -255,7 +255,6 @@ namespace System.ServiceModel.Syndication.Tests writer.WriteEndElement(); }); - var genericFormatter = new AtomPub10ServiceDocumentFormatter(document); CompareHelper.AssertEqualWriteOutput(expected, writer => formatter.WriteTo(writer)); CompareHelper.AssertEqualWriteOutput(expected, writer => document.Save(writer)); CompareHelper.AssertEqualWriteOutput(expected, writer => @@ -491,11 +490,13 @@ namespace System.ServiceModel.Syndication.Tests Assert.Equal("category_label", secondDocumentSecondCategory.Label); InlineCategoriesDocument thirdDocument = Assert.IsType(secondCollection.Categories[2]); - Assert.Empty(secondDocumentFirstCategory.AttributeExtensions); - Assert.Empty(secondDocumentFirstCategory.ElementExtensions); - Assert.Empty(secondDocumentFirstCategory.Name); - Assert.Equal("inlinecategories_scheme", secondDocumentFirstCategory.Scheme); - Assert.Null(secondDocumentFirstCategory.Label); + Assert.Empty(thirdDocument.AttributeExtensions); + Assert.Equal(new Uri("http://resourcecollectioninfo_url.com/"), thirdDocument.BaseUri); + Assert.Empty(thirdDocument.Categories); + Assert.Empty(thirdDocument.ElementExtensions); + Assert.False(thirdDocument.IsFixed); + Assert.Null(thirdDocument.Language); + Assert.Null(thirdDocument.Scheme); ReferencedCategoriesDocument fourthDocument = Assert.IsType(secondCollection.Categories[3]); Assert.Equal(4, fourthDocument.AttributeExtensions.Count); @@ -517,11 +518,11 @@ namespace System.ServiceModel.Syndication.Tests Assert.Equal(new Uri("http://emptyelement_link.com"), fifthDocument.Link); ReferencedCategoriesDocument sixthDocument = Assert.IsType(secondCollection.Categories[5]); - Assert.Empty(fifthDocument.AttributeExtensions); - Assert.Equal(new Uri("http://resourcecollectioninfo_url.com/relative_link"), fifthDocument.BaseUri); - Assert.Empty(fifthDocument.ElementExtensions); - Assert.Null(fifthDocument.Language); - Assert.Equal(new Uri("http://emptyelement_link.com"), fifthDocument.Link); + Assert.Empty(sixthDocument.AttributeExtensions); + Assert.Equal(new Uri("http://resourcecollectioninfo_url.com/relative_link"), sixthDocument.BaseUri); + Assert.Empty(sixthDocument.ElementExtensions); + Assert.Null(sixthDocument.Language); + Assert.Equal(new Uri("http://emptyelement_link.com"), sixthDocument.Link); }); } @@ -667,11 +668,13 @@ namespace System.ServiceModel.Syndication.Tests Assert.Equal("category_label", secondDocumentSecondCategory.Label); InlineCategoriesDocumentTryParseTrueSubclass thirdDocument = Assert.IsType(secondCollection.Categories[2]); - Assert.Empty(secondDocumentFirstCategory.AttributeExtensions); - Assert.Empty(secondDocumentFirstCategory.ElementExtensions); - Assert.Empty(secondDocumentFirstCategory.Name); - Assert.Equal("inlinecategories_scheme", secondDocumentFirstCategory.Scheme); - Assert.Null(secondDocumentFirstCategory.Label); + Assert.Empty(thirdDocument.AttributeExtensions); + Assert.Equal(new Uri("http://resourcecollectioninfo_url.com/"), thirdDocument.BaseUri); + Assert.Empty(thirdDocument.Categories); + Assert.Empty(thirdDocument.ElementExtensions); + Assert.False(thirdDocument.IsFixed); + Assert.Null(thirdDocument.Language); + Assert.Null(thirdDocument.Scheme); ReferencedCategoriesDocumentTryParseTrueSubclass fourthDocument = Assert.IsType(secondCollection.Categories[3]); Assert.Empty(fourthDocument.AttributeExtensions); @@ -688,11 +691,11 @@ namespace System.ServiceModel.Syndication.Tests Assert.Equal(new Uri("http://emptyelement_link.com"), fifthDocument.Link); ReferencedCategoriesDocumentTryParseTrueSubclass sixthDocument = Assert.IsType(secondCollection.Categories[5]); - Assert.Empty(fifthDocument.AttributeExtensions); - Assert.Equal(new Uri("http://resourcecollectioninfo_url.com/relative_link"), fifthDocument.BaseUri); - Assert.Empty(fifthDocument.ElementExtensions); - Assert.Null(fifthDocument.Language); - Assert.Equal(new Uri("http://emptyelement_link.com"), fifthDocument.Link); + Assert.Empty(sixthDocument.AttributeExtensions); + Assert.Equal(new Uri("http://resourcecollectioninfo_url.com/relative_link"), sixthDocument.BaseUri); + Assert.Empty(sixthDocument.ElementExtensions); + Assert.Null(sixthDocument.Language); + Assert.Equal(new Uri("http://emptyelement_link.com"), sixthDocument.Link); } } @@ -945,11 +948,11 @@ namespace System.ServiceModel.Syndication.Tests var typedFormatter = new GenericFormatter(); ServiceDocumentSubclass item = Assert.IsType(typedFormatter.CreateDocumentInstanceEntryPoint()); - Assert.Empty(document.AttributeExtensions); - Assert.Null(document.BaseUri); - Assert.Empty(document.ElementExtensions); - Assert.Null(document.Language); - Assert.Empty(document.Workspaces); + Assert.Empty(item.AttributeExtensions); + Assert.Null(item.BaseUri); + Assert.Empty(item.ElementExtensions); + Assert.Null(item.Language); + Assert.Empty(item.Workspaces); } public class ServiceDocumentSubclass : ServiceDocument { } diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20FeedFormatterTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20FeedFormatterTests.cs index e087e22..0b64efe 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20FeedFormatterTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20FeedFormatterTests.cs @@ -450,7 +450,7 @@ namespace System.ServiceModel.Syndication.Tests }); var genericFormatter = new Rss20FeedFormatter(feed); - CompareHelper.AssertEqualWriteOutput(expectedFull, writer => formatter.WriteTo(writer)); + CompareHelper.AssertEqualWriteOutput(expectedFull, writer => genericFormatter.WriteTo(writer)); CompareHelper.AssertEqualWriteOutput(expectedFull, writer => feed.SaveAsRss20(writer)); } diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20ItemFormatterTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20ItemFormatterTests.cs index d7d0424..ea59527 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20ItemFormatterTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/Rss20ItemFormatterTests.cs @@ -746,11 +746,11 @@ namespace System.ServiceModel.Syndication.Tests Assert.Equal("author_uri", thirdAuthor.Uri); SyndicationPerson fourthAuthor = item.Authors[3]; - Assert.Empty(firstAuthor.AttributeExtensions); - Assert.Empty(firstAuthor.ElementExtensions); - Assert.Null(firstAuthor.Email); - Assert.Null(firstAuthor.Name); - Assert.Null(firstAuthor.Uri); + Assert.Empty(fourthAuthor.AttributeExtensions); + Assert.Empty(fourthAuthor.ElementExtensions); + Assert.Null(fourthAuthor.Email); + Assert.Null(fourthAuthor.Name); + Assert.Null(fourthAuthor.Uri); SyndicationPerson fifthAuthor = item.Authors[4]; Assert.Empty(fifthAuthor.AttributeExtensions); @@ -1150,11 +1150,11 @@ namespace System.ServiceModel.Syndication.Tests Assert.Equal("author_uri", thirdAuthor.Uri); SyndicationPerson fourthAuthor = item.Authors[3]; - Assert.Empty(firstAuthor.AttributeExtensions); - Assert.Empty(firstAuthor.ElementExtensions); - Assert.Null(firstAuthor.Email); - Assert.Null(firstAuthor.Name); - Assert.Null(firstAuthor.Uri); + Assert.Empty(fourthAuthor.AttributeExtensions); + Assert.Empty(fourthAuthor.ElementExtensions); + Assert.Null(fourthAuthor.Email); + Assert.Null(fourthAuthor.Name); + Assert.Null(fourthAuthor.Uri); SyndicationPerson fifthAuthor = item.Authors[4]; Assert.Empty(fifthAuthor.AttributeExtensions); diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionCollectionTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionCollectionTests.cs index 1072996..a8b3528 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionCollectionTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionCollectionTests.cs @@ -108,7 +108,6 @@ namespace System.ServiceModel.Syndication.Tests [Fact] public void ItemSet_Null_ThrowsArgumentNullException() { - var extension = new SyndicationElementExtension(new ExtensionObject { Value = 10 }); SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions; elementExtensions.Add(new ExtensionObject { Value = 9 }); @@ -206,7 +205,9 @@ namespace System.ServiceModel.Syndication.Tests public void Clone_NoExtensions_ReturnsExpected() { var category = new SyndicationCategory(); + SyndicationElementExtensionCollection elementExtensions = category.ElementExtensions; + Assert.Empty(elementExtensions); SyndicationElementExtensionCollection clone = category.Clone().ElementExtensions; Assert.Empty(clone); diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionTests.cs index b7030d4..e7d57bb 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationElementExtensionTests.cs @@ -17,7 +17,6 @@ namespace System.ServiceModel.Syndication.Tests [Fact] public void Ctor_Reader() { - var extensionObject = new ExtensionObject { Value = 10 }; var extension = new SyndicationElementExtension(new XElement("ExtensionObject", new XElement("Value", 10)).CreateReader()); Assert.Equal("ExtensionObject", extension.OuterName); Assert.Empty(extension.OuterNamespace); @@ -215,7 +214,6 @@ namespace System.ServiceModel.Syndication.Tests [Fact] public void GetReader_WithReader_ReturnsExpected() { - var extensionObject = new ExtensionObject { Value = 10 }; var extension = new SyndicationElementExtension(new XElement("ExtensionObject", new XElement("Value", 10)).CreateReader()); XmlReader reader = extension.GetReader(); Assert.Equal(@"10", reader.ReadOuterXml()); diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.cs index 535159f..280929d 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.cs @@ -209,7 +209,6 @@ namespace System.ServiceModel.Syndication.Tests [Fact] public void Ctor_NullSource_ThrowsArgumentNullException() { - var feed = new SyndicationFeed(); AssertExtensions.Throws("source", () => new SyndicationFeedSubclass(null, true)); } @@ -470,8 +469,6 @@ namespace System.ServiceModel.Syndication.Tests public SyndicationCategory CreateCategoryEntryPoint() => CreateCategory(); - public SyndicationItem CreateItemEntryPoint() => CreateItem(); - public SyndicationLink CreateLinkEntryPoint() => CreateLink(); public SyndicationPerson CreatePersonEntryPoint() => CreatePerson(); diff --git a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.netcoreapp.cs b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.netcoreapp.cs index d76d7c8..66a7226 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.netcoreapp.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/System/ServiceModel/Syndication/SyndicationFeedTests.netcoreapp.cs @@ -96,7 +96,6 @@ namespace System.ServiceModel.Syndication.Tests [Fact] public void Ctor_NoNetcoreappProperties_Success() { - var input = new SyndicationTextInput(); var feed = new SyndicationFeed(); var clone = new SyndicationFeedSubclass(feed, cloneItems: false); Assert.Null(clone.Documentation); diff --git a/src/libraries/System.ServiceModel.Syndication/tests/Utils/XmlDiffDocument.cs b/src/libraries/System.ServiceModel.Syndication/tests/Utils/XmlDiffDocument.cs index 2951233..c35a297 100644 --- a/src/libraries/System.ServiceModel.Syndication/tests/Utils/XmlDiffDocument.cs +++ b/src/libraries/System.ServiceModel.Syndication/tests/Utils/XmlDiffDocument.cs @@ -667,7 +667,6 @@ namespace System.ServiceModel.Syndication.Tests { if (elem.FirstChild != null) { - XmlDiffNode _first = elem.FirstChild; XmlDiffNode _current = elem.FirstChild; XmlDiffNode _last = elem.LastChild; elem._firstChild = null;