Skip to content

Commit

Permalink
Updated tests to work in VS2022
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Zhu committed Dec 14, 2022
1 parent a02cdcc commit 0a51e8d
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 35 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/Rocket.Chat.Net.Example/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion src/Rocket.Chat.Net.Example/GiphyResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public IEnumerable<IMessageResponse> GetResponse(ResponseContext context, Rocket

private string GetGiphy(string search)
{
var request = new RestRequest("/v1/gifs/translate", Method.GET);
var request = new RestRequest("/v1/gifs/translate", Method.Get);
request.AddQueryParameter("s", search);
request.AddQueryParameter("rating", Rating);
request.AddQueryParameter("api_key", GiphyApiKey);
Expand Down
33 changes: 30 additions & 3 deletions src/Rocket.Chat.Net.Example/Rocket.Chat.Net.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,25 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\packages\NLog.5.1.0\lib\net46\NLog.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath>
<Private>True</Private>
<Reference Include="RestSharp, Version=108.0.3.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\..\packages\RestSharp.108.0.3\lib\netstandard2.0\RestSharp.dll</HintPath>
</Reference>
<Reference Include="SuperSocket.ClientEngine, Version=0.10.0.0, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>..\..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Specialized, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Collections.Specialized.4.3.0\lib\net46\System.Collections.Specialized.dll</HintPath>
<Private>True</Private>
Expand All @@ -81,6 +86,9 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.NameResolution, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Net.NameResolution.4.3.0\lib\net46\System.Net.NameResolution.dll</HintPath>
<Private>True</Private>
Expand All @@ -96,11 +104,18 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -131,11 +146,23 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.Encodings.Web.5.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.Json.5.0.1\lib\net461\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Text.RegularExpressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
11 changes: 10 additions & 1 deletion src/Rocket.Chat.Net.Example/packages.config
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net48" />
<package id="Microsoft.Net.Compilers" version="1.2.2" targetFramework="net45" developmentDependency="true" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net48" />
<package id="NLog" version="5.1.0" targetFramework="net48" />
<package id="RestSharp" version="105.2.3" targetFramework="net45" />
<package id="RestSharp" version="108.0.3" targetFramework="net48" />
<package id="SuperSocket.ClientEngine.Core" version="0.10.0" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Collections.Specialized" version="4.3.0" targetFramework="net48" />
<package id="System.IO" version="4.3.0" targetFramework="net48" />
<package id="System.Linq" version="4.3.0" targetFramework="net48" />
<package id="System.Memory" version="4.5.4" targetFramework="net48" />
<package id="System.Net.NameResolution" version="4.3.0" targetFramework="net48" />
<package id="System.Net.Security" version="4.3.0" targetFramework="net48" />
<package id="System.Net.Sockets" version="4.3.0" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime" version="4.3.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net48" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net48" />
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net48" />
<package id="System.Text.Encodings.Web" version="5.0.0" targetFramework="net48" />
<package id="System.Text.Json" version="5.0.1" targetFramework="net48" />
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net48" />
<package id="System.Threading" version="4.3.0" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net48" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
<package id="WebSocket4Net" version="0.15.2" targetFramework="net48" />
</packages>
13 changes: 9 additions & 4 deletions src/Rocket.Chat.Net/Driver/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using WebSocketSharp;
using RestSharp.Authenticators;
using NLog.LayoutRenderers.Wrappers;
using Rocket.Chat.Net.Models.RestResults;

namespace Rocket.Chat.Net.Driver
{
Expand Down Expand Up @@ -87,13 +88,17 @@ public void Dispose()

public async Task LoginAsync(object args)
{
JObject response = await CallAsync("POST", "login", CancellationToken.None, args).ConfigureAwait(false);
if (response["status"].ToObject<String>() == "success")
var response = await CallAsync("POST", "login", CancellationToken.None, args).ConfigureAwait(false);
var result = response.ToObject<RestResult<RestLoginResult>>();
if (result.Success)
{
string authToken = response["status"]["authToken"].ToObject<String>();
string userId = response["status"]["userId"].ToObject<String>();
string authToken = result.Data.AuthToken;
string userId = result.Data.UserId;
_client.Authenticator = new RocketAuthenticator(userId, authToken);
_isLoggedIn = true;
} else
{
_logger.Error($"Login Error: {result.Error}");
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Rocket.Chat.Net/Driver/RocketChatDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Rocket.Chat.Net.Models.Collections;
using Rocket.Chat.Net.Models.LoginOptions;
using Rocket.Chat.Net.Models.MethodResults;
using Rocket.Chat.Net.Models.RestResults;
using Rocket.Chat.Net.Models.SubscriptionResults;

public class RocketChatDriver : IRocketChatDriver
Expand Down Expand Up @@ -497,6 +498,13 @@ public async Task<MethodResult<RocketMessage>> SendCustomMessageAsync(Attachment
return result.ToObject<MethodResult<RocketMessage>>(JsonSerializer);
}

public async Task<RestResult> UploadFileToRoomAsync(string roomId, params object[] args)
{
var data = await _restClient.CallAsync("POST", $"rooms.upload/{roomId}", CancellationToken.None, args).ConfigureAwait(false);
return data.ToObject<RestResult>(JsonSerializer);

}

public async Task<MethodResult> UpdateMessageAsync(string messageId, string roomId, string newMessage)
{
_logger.Info($"Updating message {messageId}");
Expand Down
39 changes: 39 additions & 0 deletions src/Rocket.Chat.Net/JsonConverters/RestApiConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Rocket.Chat.Net.JsonConverters
{
public class RestApiConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
if (objectType == typeof(string))
return true;
else
return false;
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var value = reader.Value;
if (value == null || String.IsNullOrWhiteSpace(value.ToString()))
{
return false;
}

if ("success".Equals(value.ToString(), StringComparison.OrdinalIgnoreCase))
{
return true;
}

return false;
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
}
17 changes: 17 additions & 0 deletions src/Rocket.Chat.Net/Models/RestResults/RestLoginResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Rocket.Chat.Net.Models.RestResults
{
public class RestLoginResult
{

public string UserId { get; set; }

public string AuthToken { get; set; }

public User Me { get; set; }

}
}
26 changes: 26 additions & 0 deletions src/Rocket.Chat.Net/Models/RestResults/RestResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Newtonsoft.Json;
using Rocket.Chat.Net.JsonConverters;

namespace Rocket.Chat.Net.Models.RestResults
{
public class RestResult
{
[JsonProperty(PropertyName = "_id")]
public string Id { get; set; }

[JsonConverter(typeof(RestApiConverter))]
public bool Success { get; set; }

public string Error { get; set; }
}

public class RestResult<T> : RestResult
{
public T Data { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Rocket.Chat.Net/Rocket.Chat.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog" Version="5.1.0" />
<PackageReference Include="Otp.NET" Version="1.2.2" />
Expand Down
Loading

0 comments on commit 0a51e8d

Please sign in to comment.