Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V6 #90

Merged
merged 7 commits into from
May 31, 2024
Merged

V6 #90

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Reference Include="Newtonsoft.Json">
<HintPath>..\DLLs\net35\Newtonsoft.Json.dll</HintPath>
<HintPath>..\DLLs\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net472' AND '$(Configuration)' == 'Debug'">
Expand All @@ -52,7 +52,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net47'">
<Reference Include="Newtonsoft.Json">
<HintPath>..\DLLs\net35\Newtonsoft.Json.dll</HintPath>
<HintPath>..\DLLs\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net47' AND '$(Configuration)' == 'Debug'">
Expand Down
50 changes: 45 additions & 5 deletions Archipelago.MultiClient.Net.Tests/ArchipelagoSessionFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Archipelago.MultiClient.Net.Cache;
using Archipelago.MultiClient.Net.DataPackage;
using Archipelago.MultiClient.Net.Enums;
using Archipelago.MultiClient.Net.Helpers;
using Archipelago.MultiClient.Net.Models;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void Should_send_connect_after_retrieving_data_package()

var session = CreateTestSession(socket, fileSystemDataPackageProvider);

SetupRoomInfoPacket(socket, new RoomInfoPacket { Games = Array.Empty<string>() });
SetupRoomInfoPacket(socket, new RoomInfoPacket { Games = new []{ "Game1" } });
SetupLoginResultPacket(socket, new ConnectionRefusedPacket());

var result = session.TryConnectAndLogin("", "", ItemsHandlingFlags.NoItems);
Expand Down Expand Up @@ -142,17 +142,57 @@ public void Should_add_correct_properties_to_login_successful()
Assert.That(successful.Team, Is.EqualTo(3));
}

[Test]
public void Should_say_text()
{
var socket = Substitute.For<IArchipelagoSocketHelper>();
var fileSystemDataPackageProvider = Substitute.For<IFileSystemDataPackageProvider>();

var session = CreateTestSession(socket, fileSystemDataPackageProvider);

session.Say("!message for server");

socket.Received().SendPacket(Arg.Is<SayPacket>(p => p.Text == "!message for server"));
}

[Test]
public void Should_update_client_status()
{
var socket = Substitute.For<IArchipelagoSocketHelper>();
var fileSystemDataPackageProvider = Substitute.For<IFileSystemDataPackageProvider>();

var session = CreateTestSession(socket, fileSystemDataPackageProvider);

session.SetClientState(ArchipelagoClientState.ClientReady);

socket.Received().SendPacket(Arg.Is<StatusUpdatePacket>(p => p.Status == ArchipelagoClientState.ClientReady));
}

[Test]
public void Should_update_client_goal()
{
var socket = Substitute.For<IArchipelagoSocketHelper>();
var fileSystemDataPackageProvider = Substitute.For<IFileSystemDataPackageProvider>();

var session = CreateTestSession(socket, fileSystemDataPackageProvider);

session.SetGoalAchieved();

socket.Received().SendPacket(Arg.Is<StatusUpdatePacket>(p => p.Status == ArchipelagoClientState.ClientGoal));
}

static ArchipelagoSession CreateTestSession(IArchipelagoSocketHelper socket,
IFileSystemDataPackageProvider fileSystemDataPackageProvider)
{
var dataPackageCache = new DataPackageCache(socket, fileSystemDataPackageProvider);
var locations = new LocationCheckHelper(socket, dataPackageCache);
var items = new ReceivedItemsHelper(socket, locations, dataPackageCache);
var connectionInfo = new ConnectionInfoHelper(socket);
var itemInfoResolver = new ItemInfoResolver(dataPackageCache, connectionInfo);
var players = new PlayerHelper(socket, connectionInfo);
var locations = new LocationCheckHelper(socket, itemInfoResolver, connectionInfo, players);
var items = new ReceivedItemsHelper(socket, locations, itemInfoResolver, connectionInfo, players);
var roomState = new RoomStateHelper(socket, locations);
var dataStorage = new DataStorageHelper(socket, connectionInfo);
var messageLog = new MessageLogHelper(socket, items, locations, players, connectionInfo);
var messageLog = new MessageLogHelper(socket, itemInfoResolver, players, connectionInfo);

return new ArchipelagoSession(socket, items, locations, players, roomState, connectionInfo, dataStorage, messageLog);
}
Expand Down
109 changes: 95 additions & 14 deletions Archipelago.MultiClient.Net.Tests/DataPackageFileSystemCacheFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Archipelago.MultiClient.Net.Cache;
using Archipelago.MultiClient.Net.DataPackage;
using Archipelago.MultiClient.Net.Helpers;
using Archipelago.MultiClient.Net.Models;
using Archipelago.MultiClient.Net.Packets;
Expand All @@ -11,8 +11,7 @@ namespace Archipelago.MultiClient.Net.Tests
{
//use Directory C:\Users\<current_user>\AppData\Local\Archipelago\Cache\<game>\<checksum>.json
//retention 1 month since last modified, update File.SetLastWriteTime(file, modifiedTime) in use



[TestFixture]
public class DataPackageFileSystemCacheFixture
{
Expand Down Expand Up @@ -58,7 +57,7 @@ public void Should_request_data_package_when_no_local_cache_is_available()
[Test]
public void Should_not_request_data_when_local_contains_a_file_with_same_checksum()
{
var localDataPackage = new DataPackage {
var localDataPackage = new Models.DataPackage {
Games = new Dictionary<string, GameData> {
{ "One", new TestGameData("3") },
{ "Two", new TestGameData("4") },
Expand Down Expand Up @@ -94,7 +93,7 @@ public void Should_not_request_data_when_local_contains_a_file_with_same_checksu
[Test]
public void Should_only_request_data_for_games_that_a_have_different_checksum_then_cached()
{
var localDataPackage = new DataPackage
var localDataPackage = new Models.DataPackage
{
Games = new Dictionary<string, GameData> {
{ "One", new TestGameData("3") },
Expand Down Expand Up @@ -137,7 +136,7 @@ public void Should_only_request_data_for_games_that_a_have_different_checksum_th
public void Should_save_received_datapackage_contents()
{
var serverDataPackage = new DataPackagePacket {
DataPackage = new DataPackage {
DataPackage = new Models.DataPackage {
Games = new Dictionary<string, GameData> {
{
"One", new GameData {
Expand Down Expand Up @@ -175,7 +174,7 @@ public void Should_save_received_datapackage_contents()
[Test]
public void Should_merge_received_datapackage_with_cached_version()
{
var localDataPackage = new DataPackage
var localDataPackage = new Models.DataPackage
{
Games = new Dictionary<string, GameData> {
{ "One", new TestGameData("1") },
Expand All @@ -197,7 +196,7 @@ public void Should_merge_received_datapackage_with_cached_version()

var serverDataPackage = new DataPackagePacket
{
DataPackage = new DataPackage
DataPackage = new Models.DataPackage
{
Games = new Dictionary<string, GameData> {
{ "Two", new TestGameData("6") }
Expand All @@ -220,16 +219,16 @@ public void Should_merge_received_datapackage_with_cached_version()

sut.TryGetDataPackageFromCache(out var inMemoryDataPackage);

Assert.IsTrue(inMemoryDataPackage.Games.Count == 3
&& inMemoryDataPackage.Games["One"].Checksum == "1"
&& inMemoryDataPackage.Games["Two"].Checksum == "6"
&& inMemoryDataPackage.Games["Archipelago"].Checksum == "3");
Assert.IsTrue(inMemoryDataPackage.Count == 3
&& inMemoryDataPackage["One"].Checksum == "1"
&& inMemoryDataPackage["Two"].Checksum == "6"
&& inMemoryDataPackage["Archipelago"].Checksum == "3");
}

[Test]
public void Should_request_data_package_for_games_the_server_fails_to_send_the_version_for()
{
var localDataPackage = new DataPackage
var localDataPackage = new Models.DataPackage
{
Games = new Dictionary<string, GameData> {
{ "One", new TestGameData("1") },
Expand Down Expand Up @@ -263,7 +262,89 @@ public void Should_request_data_package_for_games_the_server_fails_to_send_the_v
));
}

class TestGameData : GameData

[Test]
public void Should_allow_overlapping_ids()
{
var localDataPackage = new Models.DataPackage
{
Games = new Dictionary<string, GameData> {
{ "One", new TestGameData("1") },
{ "Two", new TestGameData("3") },
{ "Archipelago", new TestGameData("3") },
}
};

var roomInfo = new RoomInfoPacket
{
Version = new NetworkVersion(0, 4, 0),
Games = new[] { "One", "Two", "Archipelago" },
DataPackageChecksums = new Dictionary<string, string> {
{ "One", "2" },
{ "Two", "1" },
{ "Archipelago", "3" }
}
};

var serverDataPackage = new DataPackagePacket
{
DataPackage = new Models.DataPackage
{
Games = new Dictionary<string, GameData> {
{ "One", new TestGameData("2") {
ItemLookup = new Dictionary<string, long> {
{ "GameOneItem", 20 },
{ "DuplicatedName", 15 }
},
LocationLookup = new Dictionary<string, long> {
{ "GameOneLocation", 20 },
{ "DuplicatedName", 15 }
}
}},
{ "Two", new TestGameData("1") {
ItemLookup = new Dictionary<string, long> {
{ "GameTwoItem", 20 },
{ "DuplicatedName", 30 }
},
LocationLookup = new Dictionary<string, long> {
{ "GameTwoLocation", 20 },
{ "DuplicatedName", 15 }
}
}}
}
}
};

var socket = Substitute.For<IArchipelagoSocketHelper>();
var fileSystemDataPackageProvider = Substitute.For<IFileSystemDataPackageProvider>();
fileSystemDataPackageProvider.TryGetDataPackage("", "", out _)
.ReturnsForAnyArgs(x => {
x[2] = localDataPackage.Games[x.ArgAt<string>(0)];
return true;
});

var sut = new DataPackageCache(socket, fileSystemDataPackageProvider);

socket.PacketReceived += Raise.Event<ArchipelagoSocketHelperDelagates.PacketReceivedHandler>(roomInfo);
socket.PacketReceived += Raise.Event<ArchipelagoSocketHelperDelagates.PacketReceivedHandler>(serverDataPackage);

sut.TryGetDataPackageFromCache(out var inMemoryDataPackage);

Assert.IsTrue(inMemoryDataPackage.Count == 3
&& inMemoryDataPackage["One"].Checksum == "2"
&& inMemoryDataPackage["One"].Items["GameOneItem"] == 20
&& inMemoryDataPackage["One"].Items["DuplicatedName"] == 15
&& inMemoryDataPackage["One"].Locations["GameOneLocation"] == 20
&& inMemoryDataPackage["One"].Locations["DuplicatedName"] == 15
&& inMemoryDataPackage["Two"].Checksum == "1"
&& inMemoryDataPackage["Two"].Items["GameTwoItem"] == 20
&& inMemoryDataPackage["Two"].Items["DuplicatedName"] == 30
&& inMemoryDataPackage["Two"].Locations["GameTwoLocation"] == 20
&& inMemoryDataPackage["Two"].Locations["DuplicatedName"] == 15
&& inMemoryDataPackage["Archipelago"].Checksum == "3");
}

class TestGameData : GameData
{
public TestGameData(string checksum)
{
Expand Down
Loading
Loading