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

Renamed test to better represent whats tested. Added Delete Player Co… #23

Merged
merged 1 commit into from
Dec 29, 2021
Merged
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
4 changes: 4 additions & 0 deletions src/PlayFabBuddyCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public static async Task<int> Main(string[] args)
var repo = DependencyInjection.Instance.Resolve<IRepository<MasterPlayerAccountEntity>>();
await repo.Save(results.ToList<MasterPlayerAccountEntity>());

Console.ReadKey();

var delete = new DeletePlayersCommand().ExecuteAsync();

//If there is no predifined User List to use, create random users!
if (config["input"] == null)
{
Expand Down
61 changes: 61 additions & 0 deletions src/PlayFabHelpers/Commands/Player/DeletePlayersCommand.cs
Original file line number Diff line number Diff line change
@@ -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<bool>
{
private IRepository<MasterPlayerAccountEntity> Repository;
private List<MasterPlayerAccountEntity> AccountList;

/**
* Default behavior when creating this command is to load players from repository.
*/
public DeletePlayersCommand()
{
Repository = DependencyInjection.Instance.Resolve<IRepository<MasterPlayerAccountEntity>>();
AccountList = Repository.Get();
}

public DeletePlayersCommand(List<MasterPlayerAccountEntity> accountList)
{
Repository = DependencyInjection.Instance.Resolve<IRepository<MasterPlayerAccountEntity>>();
AccountList = accountList;
}

public DeletePlayersCommand(IRepository<MasterPlayerAccountEntity> repo)
{
Repository = repo;
AccountList = Repository.Get();
}

public DeletePlayersCommand(IRepository<MasterPlayerAccountEntity> repo, List<MasterPlayerAccountEntity> accounts)
{
Repository = repo;
AccountList = accounts;
}

public Task<bool> ExecuteAsync()
{
foreach (var account in AccountList)
{
var request = new DeleteMasterPlayerAccountRequest
{
PlayFabId = account.Id
};

PlayFabAdminAPI.DeleteMasterPlayerAccountAsync(request);


}

Repository.Save(new List<MasterPlayerAccountEntity>());

return Task.FromResult(true);
}
}
}
15 changes: 15 additions & 0 deletions src/PlayFabHelpers/Proxy/Accounts/MasterPlayerAccountProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
9 changes: 9 additions & 0 deletions src/PlayFabHelpers/Proxy/Accounts/TitlePlayerAccountProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public TitlePlayerAccountProxy(string id)
Id = id
};
}
public TitlePlayerAccountProxy(TitlePlayerAccountEntity account)
{
PlayerAccount = account;
}

public TitlePlayerAccountProxy(string id, MasterPlayerAccountEntity account)
{
Expand All @@ -38,5 +42,10 @@ public void AssignMasterAccount(MasterPlayerAccountEntity account)
PlayerAccount.MasterAccount = account;
proxy.AddTitlePlayerAccount(PlayerAccount);
}

public void RemoveMasterAccount()
{
PlayerAccount.MasterAccount = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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<TitlePlayerAccountEntity> { 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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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()
Expand Down