2020-01-21 03:53:33 +00:00
|
|
|
using NUnit.Framework;
|
2020-02-02 21:49:01 +00:00
|
|
|
using Aurora.Proto.Party;
|
2020-01-21 03:53:33 +00:00
|
|
|
using Aurora.Services.Server;
|
|
|
|
using Grpc.Core;
|
|
|
|
using System.Threading.Tasks;
|
2020-01-21 04:22:58 +00:00
|
|
|
using System.Linq;
|
2020-02-02 15:26:47 +00:00
|
|
|
using Autofac;
|
2020-01-21 03:53:33 +00:00
|
|
|
|
|
|
|
namespace Aurora.test.ControllerTests
|
|
|
|
{
|
|
|
|
public class MemberControllerTests
|
|
|
|
{
|
|
|
|
private RemotePartyService.RemotePartyServiceClient _remotePartyService;
|
|
|
|
private Channel _channel;
|
2020-02-02 15:26:47 +00:00
|
|
|
|
|
|
|
private IContainer _container;
|
|
|
|
private IServerService _serverService;
|
|
|
|
|
2020-02-02 18:05:14 +00:00
|
|
|
#region Setup
|
2020-02-02 15:26:47 +00:00
|
|
|
[OneTimeSetUp]
|
|
|
|
public void SetupOneTime()
|
|
|
|
{
|
2020-02-02 18:05:14 +00:00
|
|
|
_container = SetupUtil.SetupOneTime();
|
2020-02-02 15:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[OneTimeTearDown]
|
|
|
|
public void TearDownOneTime()
|
|
|
|
{
|
|
|
|
_container.Dispose();
|
|
|
|
}
|
|
|
|
|
2020-01-21 03:53:33 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2020-02-02 18:05:14 +00:00
|
|
|
_remotePartyService = SetupUtil.Setup(ref _container, ref _serverService, ref _channel);
|
2020-01-21 03:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public async Task TearDown()
|
|
|
|
{
|
2020-02-02 15:26:47 +00:00
|
|
|
await _serverService.Stop();
|
2020-01-21 03:53:33 +00:00
|
|
|
await _channel.ShutdownAsync();
|
|
|
|
}
|
2020-02-02 18:05:14 +00:00
|
|
|
#endregion Setup
|
|
|
|
|
2020-01-21 03:53:33 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DefaultTest()
|
|
|
|
{
|
|
|
|
ListMembersResponse resp = _remotePartyService.ListMembers(new ListMembersRequest()
|
|
|
|
{
|
|
|
|
Parent = "party1",
|
|
|
|
PageSize = 10,
|
|
|
|
});
|
|
|
|
Assert.NotNull(resp);
|
|
|
|
Assert.GreaterOrEqual(resp.Members.Count, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[TestCase("Alex")]
|
|
|
|
[TestCase("Alex Goldberg")]
|
|
|
|
[TestCase("Alex/goldberg")]
|
|
|
|
[TestCase("alex@welcome.com")]
|
|
|
|
public void CreateMemberTest(string value)
|
|
|
|
{
|
|
|
|
Member member = _remotePartyService.CreateMember(new CreateMemberRequest()
|
|
|
|
{
|
|
|
|
Parent = "party1",
|
|
|
|
Member = new Member()
|
|
|
|
{
|
|
|
|
UserName = value,
|
|
|
|
IpAddress = ServerService.GetLocalIPAddress(),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.NotNull(member);
|
|
|
|
}
|
2020-01-21 04:22:58 +00:00
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
2020-02-01 01:41:45 +00:00
|
|
|
|
|
|
|
static object[] PagingCases =
|
|
|
|
{
|
|
|
|
new object[] {"Tupac", "Aubrey Grahm", "Beyonce Knowls", "Ke$ha", "A$ap Ferg", "asdf", "sdfa", "dfas", "fasd"},
|
|
|
|
};
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[TestCaseSource("PagingCases")]
|
|
|
|
public void MemberPagingTest(object[] members)
|
|
|
|
{
|
|
|
|
foreach (string name in members)
|
|
|
|
{
|
|
|
|
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 = 2,
|
|
|
|
});
|
|
|
|
|
|
|
|
string nextPageToken = resp.NextPageToken;
|
|
|
|
|
|
|
|
Assert.AreEqual(resp.Members.Count, 2);
|
|
|
|
|
|
|
|
//List members
|
|
|
|
resp = _remotePartyService.ListMembers(new ListMembersRequest()
|
|
|
|
{
|
|
|
|
Parent = "party1",
|
|
|
|
PageSize = 2,
|
|
|
|
PageToken = nextPageToken,
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.AreEqual(resp.Members.Count, 2);
|
|
|
|
}
|
2020-01-21 03:53:33 +00:00
|
|
|
}
|
|
|
|
}
|