diff --git a/Client/ViewModels/ViewModelGame.cs b/Client/ViewModels/ViewModelGame.cs
index 37f3508..bc4238e 100644
--- a/Client/ViewModels/ViewModelGame.cs
+++ b/Client/ViewModels/ViewModelGame.cs
@@ -8,7 +8,7 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Timers;
using System.Windows;
-using System.Windows.Input;
+using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
diff --git a/Eindproject/Eindproject.sln b/Eindproject/Eindproject.sln
index d1522f0..ff5a59a 100644
--- a/Eindproject/Eindproject.sln
+++ b/Eindproject/Eindproject.sln
@@ -9,11 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "..\Client\Client.
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedClientServer", "..\SharedClientServer\SharedClientServer.shproj", "{6D26F969-9CB1-414F-AC3E-7253D449AC5A}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{4CB2CD76-07D9-44D0-A559-A7A301621D30}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{4CB2CD76-07D9-44D0-A559-A7A301621D30}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
- ..\SharedClientServer\SharedClientServer.projitems*{4cb2cd76-07d9-44d0-a559-a7a301621d30}*SharedItemsImports = 5
..\SharedClientServer\SharedClientServer.projitems*{67a9bf1a-d317-47ca-9f07-c3480d1360ff}*SharedItemsImports = 5
..\SharedClientServer\SharedClientServer.projitems*{6d26f969-9cb1-414f-ac3e-7253d449ac5a}*SharedItemsImports = 13
..\SharedClientServer\SharedClientServer.projitems*{83768edb-097e-4089-a5de-208cb252d1a0}*SharedItemsImports = 5
diff --git a/Eindproject/TestHelper/Helper.cs b/Eindproject/TestHelper/Helper.cs
new file mode 100644
index 0000000..7da9c38
--- /dev/null
+++ b/Eindproject/TestHelper/Helper.cs
@@ -0,0 +1,10 @@
+using SharedClientServer;
+using System;
+
+namespace TestHelper
+{
+ public class Helper
+ {
+ public static JSONConvert JSONConvert;
+ }
+}
diff --git a/Eindproject/TestHelper/TestHelper.csproj b/Eindproject/TestHelper/TestHelper.csproj
new file mode 100644
index 0000000..4101597
--- /dev/null
+++ b/Eindproject/TestHelper/TestHelper.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
diff --git a/Eindproject/Tests/JSONConvertTest.cs b/Eindproject/Tests/JSONConvertTest.cs
index cd4d178..2650f43 100644
--- a/Eindproject/Tests/JSONConvertTest.cs
+++ b/Eindproject/Tests/JSONConvertTest.cs
@@ -6,12 +6,15 @@ using Xunit.Sdk;
namespace Tests
{
+
[TestClass]
public class JSONConvertTest
{
+
[TestMethod]
public void TestGetMessageToSendLength()
{
+
byte identifier = 0x01;
dynamic payload = new
{
@@ -22,9 +25,9 @@ namespace Tests
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
Assert.AreEqual(payloadToBytes.Length + 5, result.Length);
- Assert.AreEqual(0x01, result[4]);
}
+ [TestMethod]
public void TestGetMessageToSendIdentifier()
{
byte identifier = 0x01;
@@ -32,8 +35,6 @@ namespace Tests
{
value = "test"
};
- string payloadToJson = JsonConvert.SerializeObject(payload);
- byte[] payloadToBytes = Encoding.UTF8.GetBytes(payloadToJson);
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
Assert.AreEqual(0x01, result[4]);
diff --git a/Eindproject/Tests/Tests.csproj b/Eindproject/Tests/Tests.csproj
index 676c0ac..b27b157 100644
--- a/Eindproject/Tests/Tests.csproj
+++ b/Eindproject/Tests/Tests.csproj
@@ -7,13 +7,19 @@
-
-
-
-
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
-
+
+
+
diff --git a/SharedClientServer/JSONConvert.cs b/SharedClientServer/JSONConvert.cs
index 82755e3..cd3d6e7 100644
--- a/SharedClientServer/JSONConvert.cs
+++ b/SharedClientServer/JSONConvert.cs
@@ -1,17 +1,15 @@
using Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
+using System;
+using System.Diagnostics;
using System.IO;
-using System.Linq;
-using System.Text;
-using System.Windows.Media;
-
+using System.Text;
+using System.Windows.Media;
+
namespace SharedClientServer
{
- class JSONConvert
+ public class JSONConvert
{
public const byte LOGIN = 0x01;
public const byte MESSAGE = 0x02;
@@ -23,7 +21,6 @@ namespace SharedClientServer
public const int CANVAS_WRITING = 0;
public const int CANVAS_RESET = 1;
-
public enum LobbyIdentifier
{
@@ -42,11 +39,11 @@ namespace SharedClientServer
NEXT_ROUND
}
- public static (string,string) GetUsernameAndMessage(byte[] json)
+ public static (string, string) GetUsernameAndMessage(byte[] json)
{
string msg = Encoding.UTF8.GetString(json);
- dynamic payload = JsonConvert.DeserializeObject(msg);
-
+ dynamic payload = JsonConvert.DeserializeObject(msg);
+
return (payload.username, payload.message);
}
@@ -88,7 +85,7 @@ namespace SharedClientServer
{
identifier = LobbyIdentifier.HOST,
id = lobbyID
- }) ;
+ });
}
public static byte[] ConstructLobbyRequestMessage()
@@ -102,13 +99,12 @@ namespace SharedClientServer
public static byte[] ConstructLobbyListMessage(Lobby[] lobbiesList)
{
return GetMessageToSend(LOBBY, new
- {
+ {
identifier = LobbyIdentifier.LIST,
lobbies = lobbiesList
});
}
-
public static byte[] ConstructLobbyJoinMessage(int lobbyID)
{
return GetMessageToSend(LOBBY, new
@@ -125,7 +121,8 @@ namespace SharedClientServer
identifier = LobbyIdentifier.LEAVE,
id = lobbyID
});
- }
+ }
+
public static LobbyIdentifier GetLobbyIdentifier(byte[] json)
{
dynamic payload = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(json));
@@ -161,8 +158,11 @@ namespace SharedClientServer
public static byte[] ConstructLobbyJoinSuccessMessage(bool isHost)
{
- return GetMessageToSend(LOBBY, new { identifier = LobbyIdentifier.JOIN_SUCCESS,
- host = isHost});
+ return GetMessageToSend(LOBBY, new
+ {
+ identifier = LobbyIdentifier.JOIN_SUCCESS,
+ host = isHost
+ });
}
public static bool GetLobbyJoinIsHost(byte[] json)
@@ -171,11 +171,10 @@ namespace SharedClientServer
return payload.host;
}
- #endregion
+ #endregion lobby messages
public static byte[] ConstructCanvasDataSend(int typeToSend, double[][] buffer, Color colorToSend)
{
-
return GetMessageToSend(CANVAS, new
{
canvasType = typeToSend,
@@ -192,8 +191,8 @@ namespace SharedClientServer
coords = buffer,
color = colorToSend
});
- }
-
+ }
+
public static byte[] ConstructCanvasReset()
{
dynamic payload = new
@@ -229,7 +228,6 @@ namespace SharedClientServer
public static byte[] ConstructGameStartData(int lobbyID)
{
-
return GetMessageToSend(GAME, new
{
command = GameCommand.START_GAME,
@@ -276,13 +274,14 @@ namespace SharedClientServer
// put the identifier at the start of the payload part
res[4] = identifier;
// put the length of the payload at the start of the res array
- Array.Copy(BitConverter.GetBytes(payloadBytes.Length+5),0,res,0,4);
+ Array.Copy(BitConverter.GetBytes(payloadBytes.Length + 5), 0, res, 0, 4);
return res;
- }
-
- /*
- * This method sends a random word from the json file, this happens when the client joins a lobby.
- */
+ }
+
+ /*
+ * This method sends a random word from the json file, this happens when the client joins a lobby.
+ */
+
public static string SendRandomWord(string filename)
{
dynamic words;
@@ -291,29 +290,27 @@ namespace SharedClientServer
string projDir = Directory.GetParent(workingDir).Parent.Parent.FullName;
string filePath = projDir += $@"\resources\{filename}";
- using(StreamReader reader = new StreamReader(filePath))
+ using (StreamReader reader = new StreamReader(filePath))
{
string json = reader.ReadToEnd();
words = JsonConvert.DeserializeObject(json);
}
-
int index = random.Next(0, 24);
Debug.WriteLine($"[SERVERCLIENT] Sending random words {words}");
return words.words[index];
- }
-
+ }
+
/*
* Client gets the payload and retrieves the word from the payload
- */
+ */
+
public static string GetRandomWord(byte[] json)
{
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
return payload.word;
}
-
-
}
-}
+}
\ No newline at end of file
diff --git a/SharedClientServer/Lobby.cs b/SharedClientServer/Lobby.cs
index fa4f2c6..1b3baff 100644
--- a/SharedClientServer/Lobby.cs
+++ b/SharedClientServer/Lobby.cs
@@ -6,7 +6,7 @@ using System.Text;
namespace Client
{
- internal class Lobby : INotifyPropertyChanged
+ public class Lobby : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
diff --git a/SharedClientServer/SharedClientServer.shproj b/SharedClientServer/SharedClientServer.shproj
index 68327bb..0da03ce 100644
--- a/SharedClientServer/SharedClientServer.shproj
+++ b/SharedClientServer/SharedClientServer.shproj
@@ -10,4 +10,4 @@
-
+
\ No newline at end of file
diff --git a/SharedClientServer/User.cs b/SharedClientServer/User.cs
index 7b9770a..7fa0fce 100644
--- a/SharedClientServer/User.cs
+++ b/SharedClientServer/User.cs
@@ -6,7 +6,7 @@ using System.Text;
namespace SharedClientServer
{
- class User : IEquatable
+ public class User : IEquatable
{
private string _username;
private int _score;