-
Notifications
You must be signed in to change notification settings - Fork 51
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
Sync SiegeEvent fields/props #1027
Open
brodrigz
wants to merge
6
commits into
development
Choose a base branch
from
916-sync-siegeevent
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cd108cb
Run CLI scaffolding command
brodrigz 3fd178c
Restore SiegeEvent RegisterAll
brodrigz 879093d
Restore disabled methods
brodrigz 1d89d0c
Remove old files
brodrigz e699bf6
Refactor settlement registry
brodrigz cf2e2a9
Add CampaignTime surrogate
brodrigz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
source/E2E.Tests/Services/SiegeEvents/SiegeEventFieldTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,159 @@ | ||||||
using TaleWorlds.CampaignSystem.Siege; | ||||||
using TaleWorlds.CampaignSystem.Settlements; | ||||||
using System; | ||||||
using E2E.Tests.Environment; | ||||||
using E2E.Tests.Environment.Instance; | ||||||
using E2E.Tests.Util; | ||||||
using HarmonyLib; | ||||||
using System.Reflection; | ||||||
using Xunit.Abstractions; | ||||||
using static Common.Extensions.ReflectionExtensions; | ||||||
using Common.Util; | ||||||
using TaleWorlds.CampaignSystem.Party; | ||||||
|
||||||
namespace E2E.Tests.Services.SiegeEvents; | ||||||
|
||||||
public class SiegeEventFieldTests : IDisposable | ||||||
{ | ||||||
private readonly List<MethodBase> disabledMethods; | ||||||
private E2ETestEnvironment TestEnvironment { get; } | ||||||
private EnvironmentInstance Server => TestEnvironment.Server; | ||||||
private IEnumerable<EnvironmentInstance> Clients => TestEnvironment.Clients; | ||||||
private IEnumerable<EnvironmentInstance> AllEnvironmentInstances => Clients.Append(Server); | ||||||
|
||||||
private readonly string siegeEventId; | ||||||
|
||||||
public SiegeEventFieldTests(ITestOutputHelper output) | ||||||
{ | ||||||
TestEnvironment = new E2ETestEnvironment(output); | ||||||
|
||||||
disabledMethods = new List<MethodBase> | ||||||
{ | ||||||
AccessTools.Method(typeof(MobileParty), nameof(MobileParty.OnPartyJoinedSiegeInternal)), | ||||||
}; | ||||||
|
||||||
disabledMethods.AddRange(AccessTools.GetDeclaredConstructors(typeof(SiegeEvent))); | ||||||
|
||||||
// Create SiegeEvent on the server | ||||||
siegeEventId = TestEnvironment.CreateRegisteredObject<SiegeEvent>(disabledMethods); | ||||||
} | ||||||
|
||||||
public void Dispose() | ||||||
{ | ||||||
TestEnvironment.Dispose(); | ||||||
} | ||||||
|
||||||
|
||||||
[Fact] | ||||||
public void ServerChangeSiegeEventBesiegedSettlement_SyncAllClients() | ||||||
{ | ||||||
// Arrange | ||||||
var field = AccessTools.Field(typeof(SiegeEvent), nameof(SiegeEvent.BesiegedSettlement)); | ||||||
var intercept = TestEnvironment.GetIntercept(field); | ||||||
|
||||||
/// Create instances on server | ||||||
Assert.True(Server.ObjectManager.AddNewObject(ObjectHelper.SkipConstructor<Settlement>(), out var besiegedSettlementId)); | ||||||
|
||||||
/// Create instances on all clients | ||||||
foreach (var client in Clients) | ||||||
{ | ||||||
var clientBesiegedSettlement = ObjectHelper.SkipConstructor<Settlement>(); | ||||||
Assert.True(client.ObjectManager.AddExisting(besiegedSettlementId, clientBesiegedSettlement)); | ||||||
} | ||||||
|
||||||
// Act | ||||||
Server.Call(() => | ||||||
{ | ||||||
Assert.True(Server.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var SiegeEvent)); | ||||||
Assert.True(Server.ObjectManager.TryGetObject<Settlement>(besiegedSettlementId, out var serverBesiegedSettlement)); | ||||||
|
||||||
Assert.Null(SiegeEvent.BesiegedSettlement); | ||||||
|
||||||
/// Simulate the field changing | ||||||
intercept.Invoke(null, new object[] { SiegeEvent, serverBesiegedSettlement}); | ||||||
|
||||||
Assert.Same(serverBesiegedSettlement, SiegeEvent.BesiegedSettlement); | ||||||
}); | ||||||
|
||||||
// Assert | ||||||
foreach (var client in Clients) | ||||||
{ | ||||||
Assert.True(client.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var SiegeEvent)); | ||||||
|
||||||
Assert.True(client.ObjectManager.TryGetObject<Settlement>(besiegedSettlementId, out var clientBesiegedSettlement)); | ||||||
|
||||||
Assert.True(clientBesiegedSettlement == SiegeEvent.BesiegedSettlement); | ||||||
} | ||||||
} | ||||||
|
||||||
[Fact] | ||||||
public void ServerChangeSiegeEventBesiegerCamp_SyncAllClients() | ||||||
{ | ||||||
// Arrange | ||||||
var field = AccessTools.Field(typeof(SiegeEvent), nameof(SiegeEvent.BesiegerCamp)); | ||||||
var intercept = TestEnvironment.GetIntercept(field); | ||||||
|
||||||
/// Create instances on server | ||||||
Assert.True(Server.ObjectManager.AddNewObject(ObjectHelper.SkipConstructor<BesiegerCamp>(), out var besiegerCampId)); | ||||||
|
||||||
/// Create instances on all clients | ||||||
foreach (var client in Clients) | ||||||
{ | ||||||
var clientBesiegerCamp = ObjectHelper.SkipConstructor<BesiegerCamp>(); | ||||||
Assert.True(client.ObjectManager.AddExisting(besiegerCampId, clientBesiegerCamp)); | ||||||
} | ||||||
|
||||||
// Act | ||||||
Server.Call(() => | ||||||
{ | ||||||
Assert.True(Server.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var SiegeEvent)); | ||||||
Assert.True(Server.ObjectManager.TryGetObject<BesiegerCamp>(besiegerCampId, out var serverBesiegerCamp)); | ||||||
|
||||||
Assert.Null(SiegeEvent.BesiegerCamp); | ||||||
|
||||||
/// Simulate the field changing | ||||||
intercept.Invoke(null, new object[] { SiegeEvent, serverBesiegerCamp}); | ||||||
|
||||||
Assert.Same(serverBesiegerCamp, SiegeEvent.BesiegerCamp); | ||||||
}); | ||||||
|
||||||
// Assert | ||||||
foreach (var client in Clients) | ||||||
{ | ||||||
Assert.True(client.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var SiegeEvent)); | ||||||
|
||||||
Assert.True(client.ObjectManager.TryGetObject<BesiegerCamp>(besiegerCampId, out var clientBesiegerCamp)); | ||||||
|
||||||
Assert.True(clientBesiegerCamp == SiegeEvent.BesiegerCamp); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
|
||||||
[Fact] | ||||||
public void ServerChangeSiegeEventIsBesiegerDefeated_SyncAllClients() | ||||||
{ | ||||||
// Arrange | ||||||
var field = AccessTools.Field(typeof(SiegeEvent), nameof(SiegeEvent._isBesiegerDefeated)); | ||||||
var intercept = TestEnvironment.GetIntercept(field); | ||||||
Assert.True(Server.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var serverSiegeEvent)); | ||||||
var newValue=Random<Boolean>(); | ||||||
|
||||||
// Act | ||||||
Server.Call(() => | ||||||
{ | ||||||
/// Simulate the field changing | ||||||
intercept.Invoke(null, new object[] { serverSiegeEvent, newValue }); | ||||||
|
||||||
Assert.Equal(newValue, serverSiegeEvent._isBesiegerDefeated); | ||||||
}); | ||||||
|
||||||
// Assert | ||||||
foreach (var client in TestEnvironment.Clients) | ||||||
{ | ||||||
Assert.True(client.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var clientSiegeEvent)); | ||||||
Assert.Equal(serverSiegeEvent._isBesiegerDefeated, clientSiegeEvent._isBesiegerDefeated); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
source/E2E.Tests/Services/SiegeEvents/SiegeEventPropertyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using TaleWorlds.CampaignSystem.Siege; | ||
using TaleWorlds.CampaignSystem; | ||
using E2E.Tests.Environment; | ||
using E2E.Tests.Environment.Instance; | ||
using E2E.Tests.Util; | ||
using HarmonyLib; | ||
using System.Reflection; | ||
using Xunit.Abstractions; | ||
using Common.Util; | ||
using static Common.Extensions.ReflectionExtensions; | ||
using TaleWorlds.CampaignSystem.Party; | ||
|
||
namespace E2E.Tests.Services.SiegeEvents; | ||
|
||
public class SiegeEventPropertyTests : IDisposable | ||
{ | ||
private readonly List<MethodBase> disabledMethods; | ||
private E2ETestEnvironment TestEnvironment { get; } | ||
private EnvironmentInstance Server => TestEnvironment.Server; | ||
private IEnumerable<EnvironmentInstance> Clients => TestEnvironment.Clients; | ||
private IEnumerable<EnvironmentInstance> AllEnvironmentInstances => Clients.Append(Server); | ||
|
||
private readonly string siegeEventId; | ||
|
||
public SiegeEventPropertyTests(ITestOutputHelper output) | ||
{ | ||
TestEnvironment = new E2ETestEnvironment(output); | ||
|
||
disabledMethods = new List<MethodBase> | ||
{ | ||
AccessTools.Method(typeof(MobileParty), nameof(MobileParty.OnPartyJoinedSiegeInternal)), | ||
}; | ||
|
||
disabledMethods.AddRange(AccessTools.GetDeclaredConstructors(typeof(SiegeEvent))); | ||
|
||
// Create SiegeEvent on the server | ||
siegeEventId = TestEnvironment.CreateRegisteredObject<SiegeEvent>(disabledMethods); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
TestEnvironment.Dispose(); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ServerChangeSiegeEventSiegeStartTime_SyncAllClients() | ||
{ | ||
// Arrange | ||
Assert.True(Server.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var serverSiegeEvent)); | ||
var newValue=Random<CampaignTime>(); | ||
|
||
// Act | ||
Server.Call(() => | ||
{ | ||
serverSiegeEvent.SiegeStartTime = newValue; | ||
}); | ||
|
||
// Assert | ||
foreach (var client in TestEnvironment.Clients) | ||
{ | ||
Assert.True(client.ObjectManager.TryGetObject<SiegeEvent>(siegeEventId, out var clientSiegeEvent)); | ||
Assert.Equal(serverSiegeEvent.SiegeStartTime, clientSiegeEvent.SiegeStartTime); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.