From 769ce6e91200106d823e1101141c7d828b929b2d Mon Sep 17 00:00:00 2001 From: Annonator Date: Wed, 29 Dec 2021 16:32:54 +0100 Subject: [PATCH] Renamed test to better represent whats tested. Added Delete Player Command to resolve #6 --- src/PlayFabBuddyCli/Program.cs | 4 ++ .../Commands/Player/DeletePlayersCommand.cs | 61 +++++++++++++++++++ .../Accounts/MasterPlayerAccountProxy.cs | 15 +++++ .../Proxy/Accounts/TitlePlayerAccountProxy.cs | 9 +++ .../MasterPlayerAccountProxyTests.cs} | 25 +++++++- .../Accounts/TitlePlayerAccountProxyTests.cs} | 6 +- 6 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 src/PlayFabHelpers/Commands/Player/DeletePlayersCommand.cs rename src/PlayFabHelpersTests/{Entities/Accounts/MasterPlayerAccountEntityTests.cs => Proxy/Accounts/MasterPlayerAccountProxyTests.cs} (72%) rename src/PlayFabHelpersTests/{Entities/Accounts/TitlePlayerAccountEntityTests.cs => Proxy/Accounts/TitlePlayerAccountProxyTests.cs} (91%) diff --git a/src/PlayFabBuddyCli/Program.cs b/src/PlayFabBuddyCli/Program.cs index 6c4875a..de7387b 100644 --- a/src/PlayFabBuddyCli/Program.cs +++ b/src/PlayFabBuddyCli/Program.cs @@ -78,6 +78,10 @@ public static async Task Main(string[] args) var repo = DependencyInjection.Instance.Resolve>(); await repo.Save(results.ToList()); + Console.ReadKey(); + + var delete = new DeletePlayersCommand().ExecuteAsync(); + //If there is no predifined User List to use, create random users! if (config["input"] == null) { diff --git a/src/PlayFabHelpers/Commands/Player/DeletePlayersCommand.cs b/src/PlayFabHelpers/Commands/Player/DeletePlayersCommand.cs new file mode 100644 index 0000000..6089cfc --- /dev/null +++ b/src/PlayFabHelpers/Commands/Player/DeletePlayersCommand.cs @@ -0,0 +1,61 @@ +using PlayFab; +using PlayFab.AdminModels; +using PlayFabBuddy.PlayFabHelpers.Entities.Accounts; +using PlayFabBuddy.PlayFabHelpers.Proxy.Accounts; +using PlayFabBuddy.PlayFabHelpers.Util.IoC; +using PlayFabBuddy.PlayFabHelpers.Util.Repository; + +namespace PlayFabBuddy.PlayFabHelpers.Commands.Player +{ + public class DeletePlayersCommand : ICommand + { + private IRepository Repository; + private List AccountList; + + /** + * Default behavior when creating this command is to load players from repository. + */ + public DeletePlayersCommand() + { + Repository = DependencyInjection.Instance.Resolve>(); + AccountList = Repository.Get(); + } + + public DeletePlayersCommand(List accountList) + { + Repository = DependencyInjection.Instance.Resolve>(); + AccountList = accountList; + } + + public DeletePlayersCommand(IRepository repo) + { + Repository = repo; + AccountList = Repository.Get(); + } + + public DeletePlayersCommand(IRepository repo, List accounts) + { + Repository = repo; + AccountList = accounts; + } + + public Task ExecuteAsync() + { + foreach (var account in AccountList) + { + var request = new DeleteMasterPlayerAccountRequest + { + PlayFabId = account.Id + }; + + PlayFabAdminAPI.DeleteMasterPlayerAccountAsync(request); + + + } + + Repository.Save(new List()); + + return Task.FromResult(true); + } + } +} diff --git a/src/PlayFabHelpers/Proxy/Accounts/MasterPlayerAccountProxy.cs b/src/PlayFabHelpers/Proxy/Accounts/MasterPlayerAccountProxy.cs index 1e75f35..a07a135 100644 --- a/src/PlayFabHelpers/Proxy/Accounts/MasterPlayerAccountProxy.cs +++ b/src/PlayFabHelpers/Proxy/Accounts/MasterPlayerAccountProxy.cs @@ -56,5 +56,20 @@ public void AddTitlePlayerAccount(TitlePlayerAccountEntity account) MainAccount.PlayerAccounts.Add(account); } + + public void RemoveAllTitlePlayerAccounts() + { + if (MainAccount.PlayerAccounts != null) + { + foreach (var account in MainAccount.PlayerAccounts) + { + var proxy = new TitlePlayerAccountProxy(account); + + proxy.RemoveMasterAccount(); + } + + MainAccount.PlayerAccounts.Clear(); + } + } } } diff --git a/src/PlayFabHelpers/Proxy/Accounts/TitlePlayerAccountProxy.cs b/src/PlayFabHelpers/Proxy/Accounts/TitlePlayerAccountProxy.cs index b250be0..ea0094f 100644 --- a/src/PlayFabHelpers/Proxy/Accounts/TitlePlayerAccountProxy.cs +++ b/src/PlayFabHelpers/Proxy/Accounts/TitlePlayerAccountProxy.cs @@ -13,6 +13,10 @@ public TitlePlayerAccountProxy(string id) Id = id }; } + public TitlePlayerAccountProxy(TitlePlayerAccountEntity account) + { + PlayerAccount = account; + } public TitlePlayerAccountProxy(string id, MasterPlayerAccountEntity account) { @@ -38,5 +42,10 @@ public void AssignMasterAccount(MasterPlayerAccountEntity account) PlayerAccount.MasterAccount = account; proxy.AddTitlePlayerAccount(PlayerAccount); } + + public void RemoveMasterAccount() + { + PlayerAccount.MasterAccount = null; + } } } diff --git a/src/PlayFabHelpersTests/Entities/Accounts/MasterPlayerAccountEntityTests.cs b/src/PlayFabHelpersTests/Proxy/Accounts/MasterPlayerAccountProxyTests.cs similarity index 72% rename from src/PlayFabHelpersTests/Entities/Accounts/MasterPlayerAccountEntityTests.cs rename to src/PlayFabHelpersTests/Proxy/Accounts/MasterPlayerAccountProxyTests.cs index 379ccc5..3f0344b 100644 --- a/src/PlayFabHelpersTests/Entities/Accounts/MasterPlayerAccountEntityTests.cs +++ b/src/PlayFabHelpersTests/Proxy/Accounts/MasterPlayerAccountProxyTests.cs @@ -1,12 +1,12 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using PlayFabBuddy.PlayFabHelpers.Proxy.Accounts; +using PlayFabBuddy.PlayFabHelpers.Entities.Accounts; using System; using System.Collections.Generic; -namespace PlayFabBuddy.PlayFabHelpers.Entities.Accounts.Tests +namespace PlayFabBuddy.PlayFabHelpers.Proxy.Accounts.Tests { [TestClass()] - public class MasterPlayerAccountEntityTests + public class MasterPlayerAccountProxyTests { [TestMethod()] public void MasterPlayerAccountEntityTestEmptyConstructor() @@ -76,5 +76,24 @@ public void AddTitlePlayerAccountTest() Assert.IsNotNull(account.MainAccount.PlayerAccounts); Assert.IsTrue(account.MainAccount.PlayerAccounts.Contains(entity)); } + + [TestMethod()] + public void RemoveAllTitlePlayerAccountsTest() + { + var guid = Guid.NewGuid().ToString(); + + var entity = new TitlePlayerAccountProxy(Guid.NewGuid().ToString()).PlayerAccount; + var entity2 = new TitlePlayerAccountProxy(Guid.NewGuid().ToString()).PlayerAccount; + + var filledList = new List { entity, entity2 }; + + var account = new MasterPlayerAccountProxy(guid, filledList); + + account.RemoveAllTitlePlayerAccounts(); + + Assert.IsNotNull(account.MainAccount.PlayerAccounts); + Assert.IsFalse(account.MainAccount.PlayerAccounts.Contains(entity)); + Assert.IsFalse(account.MainAccount.PlayerAccounts.Contains(entity2)); + } } } \ No newline at end of file diff --git a/src/PlayFabHelpersTests/Entities/Accounts/TitlePlayerAccountEntityTests.cs b/src/PlayFabHelpersTests/Proxy/Accounts/TitlePlayerAccountProxyTests.cs similarity index 91% rename from src/PlayFabHelpersTests/Entities/Accounts/TitlePlayerAccountEntityTests.cs rename to src/PlayFabHelpersTests/Proxy/Accounts/TitlePlayerAccountProxyTests.cs index 84b17f3..b3886c9 100644 --- a/src/PlayFabHelpersTests/Entities/Accounts/TitlePlayerAccountEntityTests.cs +++ b/src/PlayFabHelpersTests/Proxy/Accounts/TitlePlayerAccountProxyTests.cs @@ -1,12 +1,12 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using PlayFabBuddy.PlayFabHelpers.Proxy.Accounts; +using PlayFabBuddy.PlayFabHelpers.Entities.Accounts; using System; using System.Linq; -namespace PlayFabBuddy.PlayFabHelpers.Entities.Accounts.Tests +namespace PlayFabBuddy.PlayFabHelpers.Proxy.Accounts.Tests { [TestClass()] - public class TitlePlayerAccountEntityTests + public class TitlePlayerAccountProxyTests { [TestMethod()] public void TitlePlayerAccountEntityTest()