-
Notifications
You must be signed in to change notification settings - Fork 0
Added play action #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2373823
Renamed GamingSession to ServerSession
SparrowBrain 17ef34f
Added client session
SparrowBrain c39737b
Fixed client launch
SparrowBrain c03c2b6
Fixed session used for server
SparrowBrain f7aeab6
Fixed client arguments not being read from config
SparrowBrain 4296c31
Fixed config example
SparrowBrain b193ce9
PR fixes
SparrowBrain 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
This file contains hidden or 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,79 @@ | ||
using AutoFixture.Xunit2; | ||
using BuddySave.Core; | ||
using BuddySave.Core.Models; | ||
using BuddySave.System; | ||
using BuddySave.TestTools; | ||
using Moq; | ||
using System; | ||
using System.Diagnostics; | ||
using Xunit; | ||
|
||
namespace BuddySave.UnitTests.Core; | ||
|
||
public class ClientSessionTests | ||
{ | ||
[Theory] | ||
[InlineAutoMoqData("")] | ||
[InlineAutoMoqData((string)null)] | ||
public void StartClient_ThrowsArgumentException_WhenClientPathIsNull( | ||
string path, | ||
Session session, | ||
ClientParameters clientParameters, | ||
ClientSession sut) | ||
{ | ||
// Arrange | ||
clientParameters.Path = path; | ||
|
||
// Act | ||
var exception = Record.Exception(() => sut.StartClient(session, clientParameters)); | ||
|
||
// Assert | ||
Assert.NotNull(exception); | ||
Assert.IsType<ArgumentException>(exception); | ||
Assert.Equal("No client path provided. Cannot start a client session.", exception.Message); | ||
} | ||
|
||
[Theory] | ||
[InlineAutoMoqData("")] | ||
[InlineAutoMoqData((string)null)] | ||
public void StartClient_ThrowsArgumentException_WhenClientArgumentsIsNull( | ||
string arguments, | ||
Session session, | ||
ClientParameters clientParameters, | ||
ClientSession sut) | ||
{ | ||
// Arrange | ||
clientParameters.Arguments = arguments; | ||
|
||
// Act | ||
var exception = Record.Exception(() => sut.StartClient(session, clientParameters)); | ||
|
||
// Assert | ||
Assert.NotNull(exception); | ||
Assert.IsType<ArgumentException>(exception); | ||
Assert.Equal("No launch arguments provided for client. Cannot start a client session.", exception.Message); | ||
} | ||
|
||
[Theory] | ||
[AutoMoqData] | ||
public void StartClient_StartsClient( | ||
[Frozen] Mock<IProcessProvider> processProviderMock, | ||
Session session, | ||
ClientParameters clientParameters, | ||
ClientSession sut) | ||
{ | ||
// Arrange | ||
clientParameters.Arguments = "+connect {{Ip}}:{{Port}}"; | ||
var expectedArguments = $"+connect {session.Ip}:{session.Port}"; | ||
|
||
// Act | ||
sut.StartClient(session, clientParameters); | ||
|
||
// Assert | ||
processProviderMock.Verify( | ||
x => x.Start(It.Is<ProcessStartInfo>(x => | ||
x.FileName == $"{clientParameters.Path} {expectedArguments}" | ||
&& x.UseShellExecute == true)), | ||
Times.Once()); | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,190 +1,64 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using AutoFixture.Xunit2; | ||
using AutoFixture.Xunit2; | ||
using BuddySave.Core; | ||
using BuddySave.Core.Models; | ||
using BuddySave.System; | ||
using BuddySave.TestTools; | ||
using Moq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace BuddySave.UnitTests.Core; | ||
|
||
public class GamingSessionTests | ||
{ | ||
[Theory] | ||
[InlineAutoMoqData((string)null)] | ||
[InlineAutoMoqData("")] | ||
public async Task Run_ThrowsException_WhenNoServerPathIsEmpty( | ||
string serverPath, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
serverParameters.Path = serverPath; | ||
|
||
// Act | ||
var act = new Func<Task>(() => sut.RunServerWithAutoSave(gameSave, session, serverParameters)); | ||
|
||
// Assert | ||
await Assert.ThrowsAsync<ArgumentException>(act); | ||
} | ||
|
||
[Theory] | ||
[AutoMoqData] | ||
public async Task Run_DoesNotStartTheServer_WhenLoadingSaveFails( | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
[Frozen] Mock<IProcessProvider> processProviderMock, | ||
Exception exception, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())).Throws(exception); | ||
|
||
// Act | ||
var act = new Func<Task>(() => sut.RunServerWithAutoSave(gameSave, session, serverParameters)); | ||
|
||
// Assert | ||
await Assert.ThrowsAnyAsync<Exception>(act); | ||
processProviderMock.Verify(x => x.Start(It.IsAny<ProcessStartInfo>()), Times.Never()); | ||
} | ||
|
||
[Theory] | ||
[InlineAutoMoqData(OrchestratorResult.SaveLocked)] | ||
[InlineAutoMoqData(OrchestratorResult.Failed)] | ||
public async Task Run_DoesNotStartTheServer_WhenGameSaveIsNotLoaded( | ||
OrchestratorResult orchestratorResult, | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
[Frozen] Mock<IProcessProvider> processProviderMock, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())).ReturnsAsync(orchestratorResult); | ||
|
||
// Act | ||
await sut.RunServerWithAutoSave(gameSave, session, serverParameters); | ||
|
||
// Assert | ||
processProviderMock.Verify(x => x.Start(It.IsAny<ProcessStartInfo>()), Times.Never()); | ||
} | ||
|
||
[Theory] | ||
[InlineAutoMoqData(OrchestratorResult.SaveLocked)] | ||
[InlineAutoMoqData(OrchestratorResult.Failed)] | ||
public async Task Run_DoesWaitForServerToStop_WhenGameSaveIsNotLoaded( | ||
OrchestratorResult orchestratorResult, | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
[Frozen] Mock<IProcessProvider> processProviderMock, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())).ReturnsAsync(orchestratorResult); | ||
|
||
// Act | ||
await sut.RunServerWithAutoSave(gameSave, session, serverParameters); | ||
|
||
// Assert | ||
processProviderMock.Verify(x => x.WaitForExitAsync(It.IsAny<Process>()), Times.Never()); | ||
} | ||
|
||
[Theory] | ||
[InlineAutoMoqData(OrchestratorResult.SaveLocked)] | ||
[InlineAutoMoqData(OrchestratorResult.Failed)] | ||
public async Task Run_DoesNotCallSave_WhenGameSaveIsNotLoaded( | ||
OrchestratorResult orchestratorResult, | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())).ReturnsAsync(orchestratorResult); | ||
|
||
// Act | ||
await sut.RunServerWithAutoSave(gameSave, session, serverParameters); | ||
|
||
// Assert | ||
sharedSaveOrchestratorMock.Verify(x => x.Save(It.IsAny<GameSave>(), It.IsAny<Session>()), Times.Never()); | ||
} | ||
|
||
[Theory] | ||
[AutoMoqData] | ||
public async Task Run_DoesNotSave_WhenStartingServerFails( | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
[Frozen] Mock<IProcessProvider> processProviderMock, | ||
Exception exception, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock | ||
.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())) | ||
.ReturnsAsync(OrchestratorResult.Loaded); | ||
processProviderMock.Setup(x => x.Start(It.IsAny<ProcessStartInfo>())).Throws(exception); | ||
|
||
// Act | ||
var act = new Func<Task>(() => sut.RunServerWithAutoSave(gameSave, session, serverParameters)); | ||
|
||
// Assert | ||
await Assert.ThrowsAnyAsync<Exception>(act); | ||
sharedSaveOrchestratorMock.Verify(x => x.Save(It.IsAny<GameSave>(), It.IsAny<Session>()), Times.Never()); | ||
} | ||
|
||
[Theory] | ||
[AutoMoqData] | ||
public async Task Run_WaitsForServerStop_WhenServerStarts( | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
[Frozen] Mock<IProcessProvider> processProviderMock, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock | ||
.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())) | ||
.ReturnsAsync(OrchestratorResult.Loaded); | ||
|
||
// Act | ||
await sut.RunServerWithAutoSave(gameSave, session, serverParameters); | ||
|
||
// Assert | ||
processProviderMock.Verify(x => x.WaitForExitAsync(It.IsAny<Process>())); | ||
} | ||
|
||
[Theory] | ||
[AutoMoqData] | ||
public async Task Run_Saves_WhenServerStops( | ||
[Frozen] Mock<ISharedSaveOrchestrator> sharedSaveOrchestratorMock, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
sharedSaveOrchestratorMock | ||
.Setup(x => x.Load(It.IsAny<GameSave>(), It.IsAny<Session>())) | ||
.ReturnsAsync(OrchestratorResult.Loaded); | ||
|
||
// Act | ||
await sut.RunServerWithAutoSave(gameSave, session, serverParameters); | ||
|
||
// Assert | ||
sharedSaveOrchestratorMock.Verify(x => x.Save(It.IsAny<GameSave>(), It.IsAny<Session>())); | ||
} | ||
[Theory] | ||
[AutoMoqData] | ||
public async Task Play_StartsClient_WhenLockExists( | ||
[Frozen] Mock<ILockManager> lockManagerMock, | ||
[Frozen] Mock<IClientSession> clientSessionMock, | ||
[Frozen] Mock<IServerSession> serverSessionMock, | ||
GameSave gameSave, | ||
Session ourSession, | ||
Session lockSession, | ||
ServerParameters serverParameters, | ||
ClientParameters clientParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
lockManagerMock.Setup(x => x.LockExists(gameSave)).Returns(true); | ||
lockManagerMock.Setup(x => x.GetLockedSession(gameSave)).ReturnsAsync(lockSession); | ||
|
||
// Act | ||
await sut.Play(gameSave, ourSession, serverParameters, clientParameters); | ||
|
||
// Assert | ||
clientSessionMock.Verify(x => x.StartClient(lockSession, clientParameters), Times.Once()); | ||
serverSessionMock.Verify( | ||
x => x.RunServerWithAutoSave(It.IsAny<GameSave>(), It.IsAny<Session>(), It.IsAny<ServerParameters>()), | ||
Times.Never); | ||
} | ||
|
||
[Theory] | ||
[AutoMoqData] | ||
public async Task Play_StartsServerAndClient_WhenLockDoesNotExist( | ||
[Frozen] Mock<ILockManager> lockManagerMock, | ||
[Frozen] Mock<IClientSession> clientSessionMock, | ||
[Frozen] Mock<IServerSession> serverSessionMock, | ||
GameSave gameSave, | ||
Session session, | ||
ServerParameters serverParameters, | ||
ClientParameters clientParameters, | ||
GamingSession sut) | ||
{ | ||
// Arrange | ||
lockManagerMock.Setup(x => x.LockExists(gameSave)).Returns(false); | ||
|
||
// Act | ||
await sut.Play(gameSave, session, serverParameters, clientParameters); | ||
|
||
// Assert | ||
serverSessionMock.Verify(x => x.RunServerWithAutoSave(gameSave, session, serverParameters), Times.Once()); | ||
clientSessionMock.Verify( | ||
x => x.StartClient(It.Is<Session>(s => s.Ip == "127.0.0.1" && s.Port == session.Port), clientParameters), | ||
Times.Once()); | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.