Skip to content

Commit 5344e46

Browse files
prashantchoudharyPrashant Choudhary
andauthored
Added dotnet core 2.2 as Targeting framework (#25)
Co-authored-by: Prashant Choudhary <[email protected]>
1 parent 6d98f09 commit 5344e46

File tree

5 files changed

+69
-13
lines changed

5 files changed

+69
-13
lines changed

src/stream-net-tests/IntegrationTests.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,12 +2299,49 @@ public async Task TestEnrich_OwnReaction()
22992299

23002300
var enrichedAct = enriched.Results.First();
23012301

2302-
Assert.True(enrichedAct.OwnReactions.ContainsKey(reaction.Kind));
2302+
Assert.True(enrichedAct.OwnReactions.ContainsKey(reaction.Kind));
2303+
23032304
Assert.AreEqual(reaction.ID, enrichedAct.OwnReactions[reaction.Kind].FirstOrDefault().ID);
23042305
Assert.AreEqual(reaction.Kind, enrichedAct.OwnReactions[reaction.Kind].FirstOrDefault().Kind);
2305-
Assert.AreEqual(reaction.UserID, enrichedAct.OwnReactions[reaction.Kind].FirstOrDefault().UserID);
2306+
Assert.AreEqual(reaction.UserID, enrichedAct.OwnReactions[reaction.Kind].FirstOrDefault().UserID);
23062307
}
23072308

2309+
[Test]
2310+
public async Task TestEnrich_User_InReaction()
2311+
{
2312+
var userData = new Dictionary<string, object>()
2313+
{
2314+
{"is_admin", true},
2315+
{"nickname","bobby"}
2316+
};
2317+
var u = await this._client.Users.Add(Guid.NewGuid().ToString(), userData);
2318+
var uRef = u.Ref();
2319+
2320+
var a = new Stream.Activity(uRef, "add", "post");
2321+
var act = await this._user1.AddActivity(a);
2322+
2323+
var reaction = await this._client.Reactions.Add("like", act.Id, u.ID);
2324+
2325+
var enriched = await this._user1.GetEnrichedFlatActivities(GetOptions.Default.WithReaction(ReactionOption.With().Own()));
2326+
2327+
Assert.AreEqual(1, enriched.Results.Count());
2328+
2329+
var enrichedAct = enriched.Results.First();
2330+
2331+
Assert.True(enrichedAct.OwnReactions.ContainsKey(reaction.Kind));
2332+
var ownReaction = enrichedAct.OwnReactions[reaction.Kind].FirstOrDefault();
2333+
2334+
Assert.AreEqual(reaction.ID, ownReaction.ID);
2335+
Assert.AreEqual(reaction.Kind, ownReaction.Kind);
2336+
Assert.AreEqual(reaction.UserID, ownReaction.UserID);
2337+
Assert.AreEqual(reaction.UserID, ownReaction.User.Enriched?.GetData<string>("id"));
2338+
Assert.AreEqual("bobby", ownReaction.User.Enriched?.GetData<Dictionary<string, object>>("data")["nickname"] as string);
2339+
Assert.AreEqual(true, (bool)ownReaction.User.Enriched?.GetData<Dictionary<string, object>>("data")["is_admin"]);
2340+
}
2341+
2342+
2343+
2344+
23082345
[Test]
23092346
public async Task TestEnrich_LatestReactions()
23102347
{
@@ -2383,7 +2420,8 @@ public async Task TestEnrich()
23832420

23842421
var enrichedAct = enriched.Results.First();
23852422

2386-
Assert.True(enrichedAct.LatestReactions.ContainsKey(reaction.Kind));
2423+
Assert.True(enrichedAct.LatestReactions.ContainsKey(reaction.Kind));
2424+
23872425
Assert.AreEqual(reaction.ID, enrichedAct.LatestReactions[reaction.Kind].FirstOrDefault().ID);
23882426
Assert.AreEqual(reaction.Kind, enrichedAct.LatestReactions[reaction.Kind].FirstOrDefault().Kind);
23892427
Assert.AreEqual(reaction.UserID, enrichedAct.LatestReactions[reaction.Kind].FirstOrDefault().UserID);

src/stream-net-tests/stream-net-tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
<ItemGroup>
1010
<PackageReference Include="coveralls.io" Version="1.4.2" />
1111
<PackageReference Include="Microsoft.IdentityModel.Tokens.JWT" Version="0.1.0" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
13-
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
14-
<PackageReference Include="NUnit" Version="3.9.0" />
15-
<PackageReference Include="NUnit.Console" Version="3.7.0" />
16-
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
17-
<PackageReference Include="OpenCover" Version="4.6.519" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
13+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
14+
<PackageReference Include="NUnit" Version="3.12.0" />
15+
<PackageReference Include="NUnit.Console" Version="3.10.0" />
16+
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
17+
<PackageReference Include="OpenCover" Version="4.7.922" />
1818
<ProjectReference Include="..\stream-net\stream-net.csproj">
1919
<Name>stream-net</Name>
2020
</ProjectReference>

src/stream-net/EnrichableField.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public bool IsEnriched
2323
{
2424
get
2525
{
26-
var tst = _data as GenericData;
27-
return tst != null;
26+
return _data is GenericData;
2827
}
2928
set { }
3029
}
@@ -56,4 +55,19 @@ internal static EnrichableField FromJSON(JToken token)
5655

5756

5857
};
58+
59+
60+
public class EnrichableFieldConverter : JsonConverter
61+
{
62+
public override bool CanConvert(Type objectType) => false;
63+
public override bool CanWrite => false;
64+
public override bool CanRead => true;
65+
66+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
67+
68+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
69+
{
70+
return EnrichableField.FromJSON(JToken.Load(reader));
71+
}
72+
}
5973
}

src/stream-net/Reactions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Stream.Rest;
44
using System;
55
using System.Collections.Generic;
6+
using System.Runtime.Serialization;
67
using System.Threading.Tasks;
78

89
namespace Stream
@@ -37,6 +38,9 @@ public class Reaction
3738
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "user_id")]
3839
public string UserID { get; internal set; }
3940

41+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "user"), JsonConverter(typeof(EnrichableFieldConverter))]
42+
public EnrichableField User { get; internal set; }
43+
4044
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "data")]
4145
public IDictionary<string, object> Data { get; internal set; }
4246

src/stream-net/stream-net.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<DefineConstants>TRACE;DEBUG;NETCORE</DefineConstants>
44
</PropertyGroup>
55
<PropertyGroup>
6-
<TargetFrameworks>net45;net461;netcoreapp1.0;netstandard1.6;netstandard2.0</TargetFrameworks>
6+
<TargetFrameworks>net45;net461;netcoreapp1.0;netcoreapp2.2;netstandard1.6;netstandard2.0</TargetFrameworks>
77
</PropertyGroup>
88
<PropertyGroup>
99
<PackageId>stream-net</PackageId>
@@ -21,7 +21,7 @@
2121
<DefineConstants>NET45</DefineConstants>
2222
</PropertyGroup>
2323
<ItemGroup>
24-
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
24+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
2525
</ItemGroup>
2626
<ItemGroup Condition=" '$(TargetFramework)' == 'net45'">
2727
<Reference Include="System" />

0 commit comments

Comments
 (0)