From 07e1d8a32b5275789f1758e04d7d481b54f1c085 Mon Sep 17 00:00:00 2001 From: czf Date: Mon, 17 Feb 2020 14:48:39 -0800 Subject: [PATCH 1/6] Update unit tests project. (#223) - Set .net core xunit test - remove tests for more functionaly from master - fix test for subredditimage --- RedditSharp.sln | 32 +++- UnitTesting/AdvancedSearchTest.cs | 60 ++++--- UnitTesting/MoreUnitTest.cs | 115 ------------ UnitTesting/Properties/AssemblyInfo.cs | 36 ---- .../SubredditImageTests.cs | 35 ++-- UnitTesting/TestData/JsonGetComments.cs | 167 ------------------ UnitTesting/TestData/More-3-4-5.cs | 83 --------- UnitTesting/TestData/comments.json | 141 --------------- UnitTesting/TestData/more3-4-5.json | 66 ------- UnitTesting/UnitTest1.cs | 18 -- UnitTesting/UnitTesting.csproj | 116 ++---------- UnitTesting/packages.config | 5 - 12 files changed, 97 insertions(+), 777 deletions(-) delete mode 100644 UnitTesting/MoreUnitTest.cs delete mode 100644 UnitTesting/Properties/AssemblyInfo.cs delete mode 100644 UnitTesting/TestData/JsonGetComments.cs delete mode 100644 UnitTesting/TestData/More-3-4-5.cs delete mode 100644 UnitTesting/TestData/comments.json delete mode 100644 UnitTesting/TestData/more3-4-5.json delete mode 100644 UnitTesting/UnitTest1.cs delete mode 100644 UnitTesting/packages.config diff --git a/RedditSharp.sln b/RedditSharp.sln index 6f955576..0bd09e04 100644 --- a/RedditSharp.sln +++ b/RedditSharp.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2010 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29728.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{46584E90-4894-4EB7-A0B9-FDAF29B4AF8B}" ProjectSection(SolutionItems) = preProject @@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedditSharp", "RedditSharp\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedditSharpTests", "RedditSharpTests\RedditSharpTests.csproj", "{BE04B672-0F15-4507-8029-6A861061DED5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "UnitTesting\UnitTesting.csproj", "{D164656E-D0E6-41A0-ADEA-37C55E34531B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting_old", "UnitTesting_old\UnitTesting_old.csproj", "{A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +51,30 @@ Global {BE04B672-0F15-4507-8029-6A861061DED5}.Release|Mixed Platforms.Build.0 = Release|Any CPU {BE04B672-0F15-4507-8029-6A861061DED5}.Release|x86.ActiveCfg = Release|Any CPU {BE04B672-0F15-4507-8029-6A861061DED5}.Release|x86.Build.0 = Release|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Debug|x86.ActiveCfg = Debug|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Debug|x86.Build.0 = Debug|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|Any CPU.Build.0 = Release|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|x86.ActiveCfg = Release|Any CPU + {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|x86.Build.0 = Release|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|x86.ActiveCfg = Debug|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|x86.Build.0 = Debug|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Any CPU.Build.0 = Release|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|x86.ActiveCfg = Release|Any CPU + {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UnitTesting/AdvancedSearchTest.cs b/UnitTesting/AdvancedSearchTest.cs index 5419e25d..15bbbc76 100644 --- a/UnitTesting/AdvancedSearchTest.cs +++ b/UnitTesting/AdvancedSearchTest.cs @@ -1,14 +1,18 @@ using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using RedditSharp.Things; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Xunit; using System.Linq.Expressions; using RedditSharp.Search; -namespace UnitTesting +namespace RedditSharp.UnitTesting { - [TestClass] + public class AdvancedSearchTest { - [TestCategory("AdvancedSearch"),TestMethod] + [Fact] public void BoolPropertyTest() { //Arrange @@ -22,10 +26,10 @@ public void BoolPropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void NOT_BoolPropertyTest() { //Arrange @@ -39,10 +43,10 @@ public void NOT_BoolPropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void StringPropertyTest() { //Arrange @@ -56,10 +60,10 @@ public void StringPropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void Flipped_StringPropertyTest() { //Arrange @@ -73,10 +77,10 @@ public void Flipped_StringPropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void Not_StringPropertyTest() { //Arrange @@ -90,10 +94,10 @@ public void Not_StringPropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void AndAlsoTest() { //Arrange @@ -107,10 +111,10 @@ public void AndAlsoTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void TwoString_AndAlsoTest() { //Arrange @@ -124,10 +128,10 @@ public void TwoString_AndAlsoTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void TwoString_OrElseTest() { //Arrange @@ -141,10 +145,10 @@ public void TwoString_OrElseTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void NotOrElseTest() { //Arrange @@ -158,10 +162,10 @@ public void NotOrElseTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void AndNotOrElseTest() { //Arrange @@ -175,10 +179,10 @@ public void AndNotOrElseTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void StringVariablePropertyTest() { //Arrange @@ -193,10 +197,10 @@ public void StringVariablePropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } - [TestCategory("AdvancedSearch"), TestMethod] + [Fact] public void ClassVariablePropertyTest() { //Arrange @@ -212,7 +216,7 @@ public void ClassVariablePropertyTest() string actual = searchFormatter.Format(expression); //Assert - Assert.AreEqual(expected, actual); + Assert.Equal(expected, actual); } //[TestMethod] @@ -230,7 +234,7 @@ public void ClassVariablePropertyTest() // string actual = searchFormatter.Format(expression); // //Assert - // Assert.AreEqual(expected, actual); + // Assert.Equal(expected, actual); //} private class Test diff --git a/UnitTesting/MoreUnitTest.cs b/UnitTesting/MoreUnitTest.cs deleted file mode 100644 index 069dd810..00000000 --- a/UnitTesting/MoreUnitTest.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using RedditSharp.Things; -using RedditSharp; -using System.Net; -using UnitTesting.TestData; -using System.IO; -using Newtonsoft.Json.Linq; -using System.Linq; -namespace UnitTesting -{ - /// - /// Summary description for MoreUnitTest - /// - [TestClass] - public class MoreUnitTest - { - - private TestContext testContextInstance; - - /// - ///Gets or sets the test context which provides - ///information about and functionality for the current test run. - /// - public TestContext TestContext - { - get - { - return testContextInstance; - } - set - { - testContextInstance = value; - } - } - - #region Additional test attributes - // - // You can use the following additional attributes as you write your tests: - // - // Use ClassInitialize to run code before running the first test in the class - // [ClassInitialize()] - // public static void MyClassInitialize(TestContext testContext) { } - // - // Use ClassCleanup to run code after all tests in a class have run - // [ClassCleanup()] - // public static void MyClassCleanup() { } - // - // Use TestInitialize to run code before running each test - // [TestInitialize()] - // public void MyTestInitialize() { } - // - // Use TestCleanup to run code after each test has run - // [TestCleanup()] - // public void MyTestCleanup() { } - // - #endregion - - [TestMethod] - public void EnumerateComments() - { - Mock mockWebAgent = new Mock(MockBehavior.Strict); - Mock mockRequest = new Mock(MockBehavior.Strict); - Mock mockRequestMore1 = new Mock(MockBehavior.Strict); - - Mock mockResponse = new Mock(MockBehavior.Strict); - Mock mockResponseMore1 = new Mock(MockBehavior.Strict); - - mockRequest.Setup(mr => - mr.GetResponse() - ).Returns(mockResponse.Object); - - mockRequestMore1.Setup(mr => - mr.GetResponse() - ).Returns(mockResponseMore1.Object); - - - MemoryStream ms1 = new MemoryStream(); - MemoryStream ms2 = new MemoryStream(); - - mockResponse.Setup(mr => mr.GetResponseStream()).Returns(ms1); - mockResponseMore1.Setup(mr => mr.GetResponseStream()).Returns(ms2); - - mockWebAgent.Setup(wa => wa.CreateGet("/comments/post.json")).Returns(mockRequest.Object); - mockWebAgent.Setup(wa => wa.CreateGet("/api/morechildren.json?link_id=post&children=3,3-1,3-1-more,4,5,5-1,5-1-1,5-1-more&api_type=json")).Returns(mockRequestMore1.Object); - - - mockWebAgent.Setup(wa => wa.GetResponseString(It.Is(x => x == ms1))).Returns(JsonGetComments.JsonComments()); - mockWebAgent.Setup(wa => wa.GetResponseString(It.Is(x => x == ms2))).Returns(More_3_4_5.GetMore_3_4_5()); - - Mock mockReddit = new Mock(MockBehavior.Strict); - JToken jObject = JsonGetComments.GetComments()[0]["data"]["children"].First; - - Reddit r = mockReddit.Object; - WebAgent waz = mockWebAgent.Object; - - - Post p = new Post().Init(mockReddit.Object, jObject, mockWebAgent.Object); - - string[] fullNames = { "t1_1", "t1_2", "t1_3", "t1_4", "t1_5" }; - Comment[] comments = p.EnumerateComments().ToArray(); - Assert.AreEqual(fullNames.Count(), comments.Count()); - - foreach (var element in - comments.Zip(fullNames, - (c, fn) => new { comment = c, fullName = fn })) - { - Assert.AreEqual(element.comment.FullName, element.fullName); - } - - Assert.AreEqual(comments[0].Comments.Count, 1); - } - } -} diff --git a/UnitTesting/Properties/AssemblyInfo.cs b/UnitTesting/Properties/AssemblyInfo.cs deleted file mode 100644 index ceb1697f..00000000 --- a/UnitTesting/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("UnitTesting")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("UnitTesting")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("a4640fc9-f8a5-4b11-a9fe-8feb626b2080")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTesting/Subreddit Information/SubredditImageTests.cs b/UnitTesting/Subreddit Information/SubredditImageTests.cs index 1a4b2228..866d03b5 100644 --- a/UnitTesting/Subreddit Information/SubredditImageTests.cs +++ b/UnitTesting/Subreddit Information/SubredditImageTests.cs @@ -1,31 +1,36 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; +using System; using RedditSharp; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; +using Xunit; +using System.Linq.Expressions; +using Moq; +using System.Net; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; -namespace RedditSharp.Tests +namespace RedditSharp.UnitTesting { - [TestClass()] + public class SubredditImageTests { - [TestMethod()] + [Fact] public void SubredditImageTest() { - //var sub = new Mock(); - Things.Subreddit sub = new Things.Subreddit(); - sub.FullName = "TestSub"; + Mock mockWebAgent = new Mock(MockBehavior.Strict); + JObject json = JObject.FromObject(new { data= new { name = "TestSub" }, kind = "t5" }); + + Things.Subreddit sub = new Things.Subreddit(mockWebAgent.Object,json); - var subStyle = new SubredditStyle(null, sub ,null); + var subStyle = new SubredditStyle(sub ); - SubredditImage img = new SubredditImage(null, subStyle, "link", "imagename", "12345", null); - Assert.IsTrue(img.Url.ToString() == "http://thumbs.reddit.com/TestSub_12345.png"); + + SubredditImage img = new SubredditImage( subStyle, "link", "imagename", "12345"); + Assert.Equal( "http://thumbs.reddit.com/TestSub_12345.png", img.Url.ToString()); - img = new SubredditImage(null, subStyle, "link", "imagename", "https://testuri.uri/", null); - Assert.IsTrue(img.Url.ToString() == "https://testuri.uri/"); + img = new SubredditImage( subStyle, "link", "imagename", "https://testuri.uri/"); + Assert.Equal("https://testuri.uri/", img.Url.ToString()); } } } \ No newline at end of file diff --git a/UnitTesting/TestData/JsonGetComments.cs b/UnitTesting/TestData/JsonGetComments.cs deleted file mode 100644 index b6f3a199..00000000 --- a/UnitTesting/TestData/JsonGetComments.cs +++ /dev/null @@ -1,167 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json.Linq; - -namespace UnitTesting.TestData -{ - public static class JsonGetComments - { - public static JArray GetComments() - { - - return JArray.Parse(JsonComments()); - } - public static String JsonComments() - { - #region return - return @" -[ - { - - ""kind"": ""Listing"", - ""data"": { - ""modhash"": """", - ""children"": [ - { - ""kind"": ""t3"", - ""data"": { - ""author"": ""anauthor"", - ""name"": ""t3_post"", - ""id"": ""post"" - } -} - ], - ""after"": null, - ""before"": null - } - }, - { - - ""kind"": ""Listing"", - ""data"": { - - ""modhash"": """", - - ""children"": [ - - { - ""kind"": ""t1"", - ""data"": { - ""author"": ""somone"", - ""id"": ""1"", - ""name"": ""t1_1"", - ""link_id"": ""0"", - ""replies"": { - ""kind"": ""Listing"", - ""data"": { - ""modhash"": """", - ""children"": [ - { - ""kind"": ""t1"", - ""data"": { - ""author"": ""someperson"", - ""id"": ""1-1"", - ""name"": ""t1_1-1"", - ""link_id"": ""0"", - ""replies"": { - ""kind"": ""Listing"", - ""data"": { - ""modhash"": """", - ""children"": [ - { - ""kind"": ""t1"", - ""data"":{ - ""author"": ""someotherperson"", - ""id"": ""1-1-1"", - ""name"": ""t1_1-1-1"", - ""link_id"": ""0"", - ""replies"": { - ""kind"": ""Listing"", - ""data"": { - ""modhash"": """", - ""children"": [ - { - ""kind"": ""more"", - ""data"": { - ""count"": ""4"", - ""parent_id"": ""post"", - ""children"": [ ""1-1-1-1"", ""1-1-1-1-1"", ""1-1-1-2"", ""1-1-1-2-more"" ], - ""id"": ""1-1-1-more"", - ""name"": ""t1_1-1-1-more"" - } - } - ] - } - } - } - } - ] - } - } - } - } - ] - } - } - } - }, - - { - ""kind"": ""t1"", - ""data"": { - ""author"": ""user"", - ""id"": ""2"", - ""name"": ""t1_2"", - ""link_id"": ""0"", - ""replies"": { - ""kind"": ""Listing"", - ""data"": { - ""modhash"": """", - ""children"": [ - { - ""kind"": ""more"", - ""data"": { - ""count"": 1, - ""parent_id"": ""t1_2"", - ""children"": [ ""2-1"" ] - }, - ""id"": ""2-more"", - ""name"": ""t1_2-more"" - } - ] - } - } - - } - }, - { - ""kind"": ""more"", - ""data"": { - ""count"": 3, - ""parent_id"": ""post"", - ""children"": [ - ""3"",""3-1"",""3-1-more"", - ""4"", - ""5"",""5-1"",""5-1-1"",""5-1-more"" - ] - }, - ""id"": ""1-more"", - ""name"": ""t1_1-more"" - } - ] - - } - } - - - ] - -"; -#endregion - } - - } -} diff --git a/UnitTesting/TestData/More-3-4-5.cs b/UnitTesting/TestData/More-3-4-5.cs deleted file mode 100644 index 229fd613..00000000 --- a/UnitTesting/TestData/More-3-4-5.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UnitTesting.TestData -{ - public static class More_3_4_5 - { - public static string GetMore_3_4_5() - { - return @" -{ - ""json"": { - ""errors"": [], - ""data"": { - ""things"": [ - { - ""kind"": ""t1"", - ""data"": { - ""id"": ""3"", - ""name"": ""t1_3"", - ""parent_id"": ""t3_post"" - } -}, - { - ""kind"": ""t1"", - ""data"": { - ""id"": ""3-1"", - ""name"": ""t1_3-1"", - ""parent_id"": ""t1_3"" - } - }, - { - ""kind"": ""more"", - ""data"": { - ""id"": ""3-more"", - ""name"": ""t1_3-more"", - ""children"": [ ""3-2"" ], - ""parent_id"": ""t1_3"" - } - }, - { - ""kind"": ""t1"", - ""data"": { - ""id"": ""4"", - ""name"": ""t1_4"", - ""parent_id"": ""t3_post"" - } - }, - { - ""kind"": ""t1"", - ""data"": { - ""id"": ""5"", - ""name"": ""t1_5"", - ""parent_id"": ""t3_post"" - } - }, - { - ""kind"": ""t1"", - ""data"": { - ""id"": ""5-1"", - ""name"": ""t1_5-1"", ""parent_id"": ""t1_5"" - } - }, - { - ""kind"": ""t1"", - ""data"": {""id"": ""5-1-1"",""name"": ""t1_5-1-1"",""parent_id"": ""t1_5-1""} - }, - { - ""kind"": ""more"", - ""data"": {""id"": ""5-1-more"", ""name"": ""5-1-more"",""parent_id"": ""t1_5-1"" ,""children"": [""5-1-2""]} - } - - ] - } - } -} -"; - } - } -} diff --git a/UnitTesting/TestData/comments.json b/UnitTesting/TestData/comments.json deleted file mode 100644 index 34d40994..00000000 --- a/UnitTesting/TestData/comments.json +++ /dev/null @@ -1,141 +0,0 @@ -[ - { - - "kind": "Listing", - "data": { - "modhash": "", - "children": [ - { - "kind": "t3", - "data": { - "author": "anauthor", - "name": "t3_post", - "id": "post" - } - } - ], - "after": null, - "before": null - } - }, - { - - "kind": "Listing", - "data": { - - "modhash": "", - - "children": [ - - { - "kind": "t1", - "data": { - "author": "somone", - "id": "1", - "name": "t1_1", - "link_id": "0", - "replies": { - "kind": "Listing", - "data": { - "modhash": "", - "children": [ - { - "kind": "t1", - "data": { - "author": "someperson", - "id": "1-1", - "name": "t1_1-1", - "link_id": "0", - "replies": { - "kind": "Listing", - "data": { - "modhash": "", - "children": [ - { - "kind": "t1", - "data": { - "author": "someotherperson", - "id": "1-1-1", - "name": "t1_1-1-1", - "link_id": "0", - "replies": { - "kind": "Listing", - "data": { - "modhash": "", - "children": [ - { - "kind": "more", - "data": { - "count": "4", - "parent_id": "post", - "children": [ "1-1-1-1", "1-1-1-1-1", "1-1-1-2", "1-1-1-2-more" ], - "id": "1-1-1-more", - "name": "t1_1-1-1-more" - } - } - ] - } - } - } - } - ] - } - } - } - } - ] - } - } - } - }, - - { - "kind": "t1", - "data": { - "author": "user", - "id": "2", - "name": "t1_2", - "link_id": "0", - "replies": { - "kind": "Listing", - "data": { - "modhash": "", - "children": [ - { - "kind": "more", - "data": { - "count": 1, - "parent_id": "t1_2", - "children": [ "2-1" ] - }, - "id": "2-more", - "name": "t1_2-more" - } - ] - } - } - - } - }, - { - "kind": "more", - "data": { - "count": 3, - "parent_id": "post", - "children": [ - "3","3-1","3-1-more", - "4", - "5","5-1","5-1-1","5-1-more" - ] - }, - "id": "1-more", - "name": "t1_1-more" - } - ] - - } - } - - - ] -- \ No newline at end of file diff --git a/UnitTesting/TestData/more3-4-5.json b/UnitTesting/TestData/more3-4-5.json deleted file mode 100644 index 39a00d2d..00000000 --- a/UnitTesting/TestData/more3-4-5.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "json": { - "errors": [], - "data": { - "things": [ - { - "kind": "t1", - "data": { - "id": "3", - "name": "t1_3", - "parent_id": "t3_post" - } - }, - { - "kind": "t1", - "data": { - "id": "3-1", - "name": "t1_3-1", - "parent_id": "t1_3" - } - }, - { - "kind": "more", - "data": { - "id": "3-more", - "name": "t1_3-more", - "children": [ "3-2" ], - "parent_id": "t1_3" - } - }, - { - "kind": "t1", - "data": { - "id": "4", - "name": "t1_4", - "parent_id": "t3_post" - } - }, - { - "kind": "t1", - "data": { - "id": "5", - "name": "t1_5", - "parent_id": "t3_post" - } - }, - { - "kind": "t1", - "data": { - "id": "5-1", - "name": "t1_5-1", "parent_id": "t1_5" - } - }, - { - "kind": "t1", - "data": {"id": "5-1-1","name": "t1_5-1-1","parent_id": "t1_5-1"} - }, - { - "kind": "more", - "data": {"id": "5-1-more", "name": "t1_5-1-more","parent_id": "t1_5-1" ,"children": ["5-1-2"]} - } - - ] - } - } -} \ No newline at end of file diff --git a/UnitTesting/UnitTest1.cs b/UnitTesting/UnitTest1.cs deleted file mode 100644 index 26a3b53c..00000000 --- a/UnitTesting/UnitTest1.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using RedditSharp; -using RedditSharp.Things; - -namespace UnitTesting -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void GetSubreddit() - { //Discovered a bug where reddit.getSubreddit() will produce a 403 forbidden if you're not logged in - if (System.Text.RegularExpressions.Regex.Replace("/r/text", "(r/|/)", "") != "text") - throw new Exception("The regexes don't work!"); - } - } -} diff --git a/UnitTesting/UnitTesting.csproj b/UnitTesting/UnitTesting.csproj index a3b171aa..1fc913d4 100644 --- a/UnitTesting/UnitTesting.csproj +++ b/UnitTesting/UnitTesting.csproj @@ -1,107 +1,21 @@ - - + + - Debug - AnyCPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080} - Library - Properties - UnitTesting - UnitTesting - v4.6.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - + netcoreapp3.1 + + false - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll - True - - - ..\packages\Moq.4.5.23\lib\net45\Moq.dll - True - - - ..\Newtonsoft.Json.dll - - - - - - - - - - - - - False - - - - + - - - - - - - + + + + + + - - - + - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file + + diff --git a/UnitTesting/packages.config b/UnitTesting/packages.config deleted file mode 100644 index 8166f306..00000000 --- a/UnitTesting/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file From 7463d86b62e8a00630895b38c8f1666997ceb763 Mon Sep 17 00:00:00 2001 From: czf Date: Mon, 17 Feb 2020 14:49:45 -0800 Subject: [PATCH 2/6] #219 - update to account for "more" in comment response. (#224) --- RedditSharp/Things/Comment.cs | 12 +++++++++++- RedditSharp/Things/Post.cs | 7 ++++++- RedditSharpTests/Things/PostTests.cs | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/RedditSharp/Things/Comment.cs b/RedditSharp/Things/Comment.cs index 438282b2..4b4c6569 100644 --- a/RedditSharp/Things/Comment.cs +++ b/RedditSharp/Things/Comment.cs @@ -102,7 +102,17 @@ private void ParseComments(JToken data, Thing sender) if (replies != null && replies.Count() > 0) { foreach (var comment in replies["data"]["children"]) - subComments.Add(new Comment(WebAgent, comment, sender)); + { + if (comment.Value("kind") != "more") + { + subComments.Add(new Comment(WebAgent, comment, sender)); + } + else + { + More = (new More(WebAgent, comment)); + } + + } } Comments = subComments.ToArray(); } diff --git a/RedditSharp/Things/Post.cs b/RedditSharp/Things/Post.cs index 252fd893..a15ef9e3 100644 --- a/RedditSharp/Things/Post.cs +++ b/RedditSharp/Things/Post.cs @@ -288,7 +288,7 @@ public async Task> GetCommentsAsync(int limit = 0, CommentSort sor /// /// Maximum number of comments to return. Returned list may be larger than this number though due to /// - public async Task> GetCommentsWithMoresAsync(int limit = 0, CommentSort sort = CommentSort.Best) + public async Task> GetCommentsWithMoresAsync(int limit = 0, CommentSort sort = CommentSort.Best, int depth=0) { var url = string.Format(GetCommentsUrl, Id); @@ -307,6 +307,11 @@ public async Task> GetCommentsWithMoresAsync(int limit = 0, CommentS url = $"{url}&limit={limit}"; } + if(depth > 0) + { + url = $"{url}&depth={depth}"; + } + var json = await WebAgent.Get(url).ConfigureAwait(false); var postJson = json.Last()["data"]["children"]; diff --git a/RedditSharpTests/Things/PostTests.cs b/RedditSharpTests/Things/PostTests.cs index 82c0d523..2248c07e 100644 --- a/RedditSharpTests/Things/PostTests.cs +++ b/RedditSharpTests/Things/PostTests.cs @@ -42,6 +42,22 @@ public async Task GetCommentsMore() Assert.Equal(10, comments.Count); } + [Fact] + public async Task GetCommentsWithMoresAsync() + { + RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken); + RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent); + var post = (Post)await reddit.GetThingByFullnameAsync("t3_f1bo6u"); + + var things = await post.GetCommentsWithMoresAsync(limit: 9, depth: 2); + Assert.NotEmpty(things); + Assert.Equal(typeof(More), things.Last().GetType()); + Assert.NotNull(((Comment)things[0]).More); + Assert.NotNull(((Comment)things[0]).Comments[0].More); + + } + + [Fact] public async Task EnumerateAllComments() @@ -59,5 +75,7 @@ public async Task EnumerateAllComments() Assert.Equal(25, commentsList.Count); } + + } } From 0cff99f40c88d3c8d9f4d8bb3760790009d4d560 Mon Sep 17 00:00:00 2001 From: czf Date: Mon, 17 Feb 2020 14:51:12 -0800 Subject: [PATCH 3/6] #217 Adding Crosspost _list (#225) * Adding Crosspost _list can still add is_crosspostable crosspost_parent num_crossposts * adding more crosspost properties --- RedditSharp/RedditSharp.csproj | 1 + RedditSharp/Things/Post.cs | 34 ++++++++++++++++++++++++++++ RedditSharpTests/Things/PostTests.cs | 14 +++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/RedditSharp/RedditSharp.csproj b/RedditSharp/RedditSharp.csproj index fbbed94c..17e8b279 100755 --- a/RedditSharp/RedditSharp.csproj +++ b/RedditSharp/RedditSharp.csproj @@ -14,6 +14,7 @@ + diff --git a/RedditSharp/Things/Post.cs b/RedditSharp/Things/Post.cs index a15ef9e3..bdaed870 100644 --- a/RedditSharp/Things/Post.cs +++ b/RedditSharp/Things/Post.cs @@ -7,6 +7,7 @@ using System.Reactive.Linq; using System.Threading.Tasks; using System.Text.RegularExpressions; +using System.Collections.Immutable; namespace RedditSharp.Things { @@ -54,6 +55,30 @@ public Post(IWebAgent agent, JToken json) : base(agent, json) [JsonProperty("is_self")] public bool IsSelfPost { get; private set; } + public IReadOnlyList CrossPostParents + { + get + { + if(_crossPostParents == null) + { + var builder = ImmutableList.CreateBuilder(); + if (RawJson["crosspost_parent_list"] != null) + { + foreach (JToken token in RawJson["crosspost_parent_list"]) + { + Post post = new Post(WebAgent, token); + builder.Add(post); + } + } + _crossPostParents = builder.ToImmutable(); + } + return _crossPostParents; + } + + } + + private ImmutableList _crossPostParents; + /// /// Css class of the link flair. /// @@ -128,6 +153,15 @@ public Post(IWebAgent agent, JToken json) : base(agent, json) [JsonConverter(typeof(UrlParser))] public Uri Url { get; private set; } + [JsonProperty("is_crosspostable")] + public bool IsCrossPostable { get; private set; } + + [JsonProperty("num_crossposts")] + public int NumberOfCrossposts { get; private set; } + + [JsonProperty("crosspost_parent")] + public string CrosspostParent { get; private set; } + /// /// Returns the parent for this post /// diff --git a/RedditSharpTests/Things/PostTests.cs b/RedditSharpTests/Things/PostTests.cs index 2248c07e..78cf9f7a 100644 --- a/RedditSharpTests/Things/PostTests.cs +++ b/RedditSharpTests/Things/PostTests.cs @@ -75,7 +75,19 @@ public async Task EnumerateAllComments() Assert.Equal(25, commentsList.Count); } + [Fact] + public async Task CrosspostParentList() + { + RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken); + RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent); + var post = (Post)await reddit.GetThingByFullnameAsync("t3_f1e0jg"); + + + Assert.NotNull(post.CrossPostParents); + Assert.True(post.CrossPostParents.Count > 0); + Assert.True(post.CrossPostParents[0].CrossPostParents.Count == 0); + + } - } } From 1c45db702a42f965dfa246fef0eab1a11d0664b8 Mon Sep 17 00:00:00 2001 From: Maxime Faye Date: Thu, 27 Feb 2020 04:43:40 +0100 Subject: [PATCH 4/6] Updated the README.md for the ListingStream and have a working example (#229) * Updated ListingStream example. * Added example with ListingStream --- README.md | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a20ba4d6..d896958d 100644 --- a/README.md +++ b/README.md @@ -105,29 +105,39 @@ await reddit.RSlashAll.New.Take(2).ForEachAsync(page => { **Using ListingStreams** -Use ListingStreams to infinitely yeild new Things posted to reddit +Use `ListingStreams` to infinitely yield new `Things` posted to reddit Example: ```csharp -// get all new comments as they are posted. -var comments = subreddit.Comments.GetListingStream(); +// Create the stream +ListingStream postStream = subreddit.GetPosts(Subreddit.Sort.New).Stream(); +// Note: Don't set the max in the GetPosts() method, otherwise the stream will +// stop working as soon as you reach this value. +// The handling method that will be call on each new post +postStream.Subscribe(post => logger.LogDebug($"Post : [{post.Title} at {post.CreatedUTC}]")); +// Start listening +await postStream.Enumerate(cancellationToken); +``` -await comments.Execute(); -foreach (var comment in subreddit.CommentStream) -{ - Console.WriteLine(DateTime.Now + " New Comment posted to /r/example: " + comment.ShortLink); -} +```csharp +// Any properties that returns a Listing has its stream version, another example, new modmail. +ListingStream modMailStream = reddit.User.GetModMail().Stream(); +modMailStream.Subscribe(message => logger.LogDebug($"ModMail : {message.Subject}")); +await modMailStream.Enumerate(cancellationToken); ``` ```csharp -// get new modmail -var newModmail = user.ModMail.GetListingStream(); -foreach (var message in newModmail) -{ - if (message.FirstMessageName == "") - message.Reply("Thanks for the message - we will get back to you soon."); -} +// Need more than one stream at a time ? +ListingStream postStream = subreddit.GetPosts(Subreddit.Sort.New).Stream(); +postStream.Subscribe(post => logger.LogDebug($"Post : [{post.Title} at {post.CreatedUTC}]")); +ListingStream modMailStream = reddit.User.GetModMail().Stream(); +modMailStream.Subscribe(message => logger.LogDebug($"ModMail : {message.Subject}")); + +await Task.WhenAll({ + postStream.Enumerate(cancellationToken), + modMailStream.Enumerate(cancellationToken) +}); ``` ## Development From b87b2486d5ae46910464fac3d9ed60a6378a5ca3 Mon Sep 17 00:00:00 2001 From: HoundThe Date: Thu, 11 Feb 2021 05:01:15 +0100 Subject: [PATCH 5/6] Update to .NET Core 3.1 and apply all necessary changes to IAsyncEnumerable implementations that comes with this update. (#239) --- RedditSharp.sln | 14 ------------ RedditSharp/CommentsEnumerable.cs | 8 +++---- RedditSharp/Listing.cs | 26 +++++++++++------------ RedditSharp/RedditSharp.csproj | 5 ++--- RedditSharp/Things/PrivateMessage.cs | 4 ++-- RedditSharpTests/RedditSharpTests.csproj | 2 +- RedditSharpTests/Things/SubredditTests.cs | 10 ++++----- 7 files changed, 26 insertions(+), 43 deletions(-) diff --git a/RedditSharp.sln b/RedditSharp.sln index 0bd09e04..f11dc970 100644 --- a/RedditSharp.sln +++ b/RedditSharp.sln @@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedditSharpTests", "RedditS EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "UnitTesting\UnitTesting.csproj", "{D164656E-D0E6-41A0-ADEA-37C55E34531B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting_old", "UnitTesting_old\UnitTesting_old.csproj", "{A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,18 +61,6 @@ Global {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|Mixed Platforms.Build.0 = Release|Any CPU {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|x86.ActiveCfg = Release|Any CPU {D164656E-D0E6-41A0-ADEA-37C55E34531B}.Release|x86.Build.0 = Release|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|x86.ActiveCfg = Debug|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Debug|x86.Build.0 = Debug|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Any CPU.Build.0 = Release|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|x86.ActiveCfg = Release|Any CPU - {A4640FC9-F8A5-4B11-A9FE-8FEB626B2080}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RedditSharp/CommentsEnumerable.cs b/RedditSharp/CommentsEnumerable.cs index c280d218..0073f53d 100644 --- a/RedditSharp/CommentsEnumerable.cs +++ b/RedditSharp/CommentsEnumerable.cs @@ -34,7 +34,7 @@ public CommentsEnumarable(IWebAgent agent, Post post, int limitPerRequest = 0) /// Returns for the comments on the > /// /// - public IAsyncEnumerator GetEnumerator() + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { return new CommentsEnumerator(agent, post, limit); } @@ -67,7 +67,7 @@ public Comment Current } } - public async Task MoveNext(CancellationToken cancellationToken) + public async ValueTask MoveNextAsync() { if (currentIndex == -1) @@ -139,9 +139,9 @@ private async Task GetBaseComments() currentBranch = retrieved; } - public void Dispose() + public ValueTask DisposeAsync() { - + return new ValueTask(); } } } diff --git a/RedditSharp/Listing.cs b/RedditSharp/Listing.cs index 477517a5..0140e28a 100644 --- a/RedditSharp/Listing.cs +++ b/RedditSharp/Listing.cs @@ -173,7 +173,7 @@ public IAsyncEnumerator GetEnumerator(int limitPerRequest, int maximumLimit = } /// - public IAsyncEnumerator GetEnumerator() + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { return GetEnumerator(LimitPerRequest, MaximumLimit, IsStream); } @@ -365,26 +365,25 @@ private void Parse(JToken json) Before = json["data"]["before"].Value(); } - public void Dispose() + public ValueTask DisposeAsync() { - // ... + return default; } - public async Task MoveNext(CancellationToken cancellationToken) + public async ValueTask MoveNextAsync() { if (stream) { - return await MoveNextForwardAsync(cancellationToken).ConfigureAwait(false); + return await MoveNextForwardAsync().ConfigureAwait(false); } else { - return await MoveNextBackAsync(cancellationToken).ConfigureAwait(false); + return await MoveNextBackAsync().ConfigureAwait(false); } } - private async Task MoveNextBackAsync(CancellationToken cancellationToken) + private async Task MoveNextBackAsync() { - cancellationToken.ThrowIfCancellationRequested(); if (CurrentIndex == -1) { //first call, get a page and set CurrentIndex @@ -421,7 +420,7 @@ private async Task MoveNextBackAsync(CancellationToken cancellationToken) return true; } - private async Task MoveNextForwardAsync(CancellationToken cancellationToken) + private async Task MoveNextForwardAsync() { CurrentIndex++; @@ -435,7 +434,6 @@ private async Task MoveNextForwardAsync(CancellationToken cancellationToke int tries = 0; while (true) { - cancellationToken.ThrowIfCancellationRequested(); tries++; try @@ -446,7 +444,7 @@ private async Task MoveNextForwardAsync(CancellationToken cancellationToke catch (Exception ex) { // sleep for a while to see if we can recover - await Sleep(tries, cancellationToken, ex).ConfigureAwait(false); + await Sleep(tries, ex).ConfigureAwait(false); } // the page is only populated if there are *new* items to yielded from the listing. @@ -456,14 +454,14 @@ private async Task MoveNextForwardAsync(CancellationToken cancellationToke } // No listings were returned in the page. - await Sleep(tries, cancellationToken).ConfigureAwait(false); + await Sleep(tries).ConfigureAwait(false); } } Count++; return true; } - private async Task Sleep(int tries, CancellationToken cancellationToken, Exception ex = null) + private async Task Sleep(int tries, Exception ex = null) { // wait up to 3 minutes between tries // TODO: Make this configurable @@ -481,7 +479,7 @@ private async Task Sleep(int tries, CancellationToken cancellationToken, Excepti { seconds = tries * 5; } - await Task.Delay(seconds * 1000, cancellationToken).ConfigureAwait(false); + await Task.Delay(seconds * 1000).ConfigureAwait(false); } } #pragma warning restore diff --git a/RedditSharp/RedditSharp.csproj b/RedditSharp/RedditSharp.csproj index 17e8b279..222cad9b 100755 --- a/RedditSharp/RedditSharp.csproj +++ b/RedditSharp/RedditSharp.csproj @@ -3,8 +3,7 @@ RedditSharp 2.0.0 - net462;netstandard1.3;netstandard2.0; - $(LibraryFrameworks) + netcoreapp3.1 RedditSharp RedditSharp https://github.com/CrustyJew/RedditSharp @@ -21,7 +20,7 @@ - + diff --git a/RedditSharp/Things/PrivateMessage.cs b/RedditSharp/Things/PrivateMessage.cs index 1c3cbb35..4502bf36 100644 --- a/RedditSharp/Things/PrivateMessage.cs +++ b/RedditSharp/Things/PrivateMessage.cs @@ -131,8 +131,8 @@ public PrivateMessage GetParent() return null; } //TODO: Convert this into an async function - var firstPage = thread.First(); - firstPage.Wait(); + var firstPage = thread.FirstAsync(); + firstPage.GetAwaiter(); var firstMessage = firstPage.Result; if (firstMessage?.FullName == ParentID) return firstMessage; diff --git a/RedditSharpTests/RedditSharpTests.csproj b/RedditSharpTests/RedditSharpTests.csproj index 62dc03fd..59f183f8 100644 --- a/RedditSharpTests/RedditSharpTests.csproj +++ b/RedditSharpTests/RedditSharpTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.1 RedditSharpTests RedditSharpTests true diff --git a/RedditSharpTests/Things/SubredditTests.cs b/RedditSharpTests/Things/SubredditTests.cs index 3c7969c9..c17a5215 100644 --- a/RedditSharpTests/Things/SubredditTests.cs +++ b/RedditSharpTests/Things/SubredditTests.cs @@ -20,7 +20,7 @@ public async Task GetContributors() RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken); RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent); var sub = await reddit.GetSubredditAsync(authFixture.Config["TestSubreddit"]); - var contribs = await sub.GetContributors().ToList(); + var contribs = await sub.GetContributors().ToListAsync(); Assert.NotEmpty(contribs); Assert.Contains(authFixture.TestUserName.ToLower(), contribs.Select(c => c.Name.ToLower())); @@ -56,8 +56,8 @@ public async Task GetRALLComments() RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken); RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent, true); - var comments = reddit.RSlashAll.GetComments(5); - Assert.Equal(5, await comments.Count()); + var comments = await reddit.RSlashAll.GetComments().Take(5).CountAsync(); + Assert.Equal(5, comments); } [Fact] @@ -66,7 +66,7 @@ public async Task PageComments() RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken); RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent, true); - var comments = await reddit.RSlashAll.GetComments().Take(55).ToList(); + var comments = await reddit.RSlashAll.GetComments().Take(55).ToListAsync(); Assert.Equal(55, comments.Count); @@ -80,7 +80,7 @@ public async Task StreamComments() var count = 0; var comments = reddit.RSlashAll.GetComments().GetEnumerator(50, 100, true); - while (await comments.MoveNext(CancellationToken.None)) + while (await comments.MoveNextAsync()) { count++; } From ec17ece1fe630b1137787c392ba848136e354995 Mon Sep 17 00:00:00 2001 From: CrustyJew Date: Wed, 25 Aug 2021 19:36:35 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d896958d..616427ab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ [![redditsharp MyGet Build Status](https://www.myget.org/BuildSource/Badge/redditsharp?identifier=0871c1e1-0ab6-489d-9a7f-ce6c2485cfe5)](https://www.myget.org/) [![NuGet version](https://badge.fury.io/nu/redditsharp.svg)](https://badge.fury.io/nu/redditsharp) -**This is a hard fork and IS maintained**. +# DEPRECATED +Due to my own motivation and recent occurences at Reddit, I'm not longer going to be maintaining this repository. If someone has interest in taking this over, feel free to contact me (snoonotes@gmail.com) + + + +________ + +**This is a hard fork**. Due to the project being abandoned and the previous owner's refusal to transfer the repository to someone else to maintain it, I've created this fork to continue on support for the project.