From f8ad2f459e1dbfaed6671bae32ff4b954b453b16 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Mon, 20 Jan 2020 23:22:58 -0500 Subject: [PATCH] Added more unit tests for members resource --- .../ControllerTests/MembersControllerTest.cs | 83 +++++++++++++++++++ .../Server/EventManager/EventManager.cs | 5 +- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/Aurora.test/ControllerTests/MembersControllerTest.cs b/Aurora.test/ControllerTests/MembersControllerTest.cs index 9be17eb..d9122d5 100644 --- a/Aurora.test/ControllerTests/MembersControllerTest.cs +++ b/Aurora.test/ControllerTests/MembersControllerTest.cs @@ -3,6 +3,7 @@ using Aurora.Proto.PartyV2; using Aurora.Services.Server; using Grpc.Core; using System.Threading.Tasks; +using System.Linq; namespace Aurora.test.ControllerTests { @@ -56,5 +57,87 @@ namespace Aurora.test.ControllerTests Assert.NotNull(member); } + + static object[] MultipleMembersCases = + { + new object[] {"Tupac", "Aubrey Grahm", "Beyonce Knowls", "Ke$ha", "A$ap Ferg"}, + }; + + [Test] + [TestCaseSource("MultipleMembersCases")] + public void CreateMultiplMembersTest(object[] memberNames) + { + //Add members + foreach (string name in memberNames) + { + Member member = _remotePartyService.CreateMember(new CreateMemberRequest() + { + Parent = "party1", + Member = new Member() + { + UserName = name + } + }); + + Assert.NotNull(member); + } + + //List members + ListMembersResponse resp = _remotePartyService.ListMembers(new ListMembersRequest() + { + Parent = "party1", + PageSize = 10, + }); + Assert.NotNull(resp); + Assert.AreEqual(resp.Members.Count, 6); + } + + [Test] + [TestCaseSource("MultipleMembersCases")] + public void DeleteMemberTest(object[] memberNames) + { + //Add members + foreach (string name in memberNames) + { + Member member = _remotePartyService.CreateMember(new CreateMemberRequest() + { + Parent = "party1", + Member = new Member() + { + UserName = name + } + }); + + Assert.NotNull(member); + } + + //List members + ListMembersResponse resp = _remotePartyService.ListMembers(new ListMembersRequest() + { + Parent = "party1", + PageSize = 10, + }); + Assert.NotNull(resp); + Assert.AreEqual(resp.Members.Count, 6); + + string keshaResourceName = resp.Members.First(member => member.UserName == "Ke$ha").Name; + + //Delete member + + _remotePartyService.DeleteMember(new DeleteMemberRequest() + { + Name = keshaResourceName + }); + + //List members + resp = _remotePartyService.ListMembers(new ListMembersRequest() + { + Parent = "party1", + PageSize = 10, + }); + Assert.NotNull(resp); + Assert.AreEqual(resp.Members.Count, 5); + Assert.False(resp.Members.Any(member => member.UserName == "Ke$sha")); + } } } \ No newline at end of file diff --git a/Aurora/Services/Server/EventManager/EventManager.cs b/Aurora/Services/Server/EventManager/EventManager.cs index 732b41b..b6e56f1 100644 --- a/Aurora/Services/Server/EventManager/EventManager.cs +++ b/Aurora/Services/Server/EventManager/EventManager.cs @@ -163,7 +163,10 @@ namespace Aurora.Services.Server.EventManager public void CancelEventStream(string sessionIdentifierId) { _actionList.TryGetValue(sessionIdentifierId, out EventAction value); - value.Cancel(); + if (value != null) + { + value.Cancel(); + } RemoveEventHandler(sessionIdentifierId); }