2020-02-02 18:05:14 +00:00
|
|
|
|
|
|
|
using NUnit.Framework;
|
2020-02-02 21:49:01 +00:00
|
|
|
using Aurora.Proto.Party;
|
2020-02-02 18:05:14 +00:00
|
|
|
using Aurora.Services.Server;
|
2020-02-02 21:49:01 +00:00
|
|
|
using Aurora.Services.EventManager;
|
2020-02-02 18:05:14 +00:00
|
|
|
using Grpc.Core;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading;
|
|
|
|
using Autofac;
|
|
|
|
namespace Aurora.test.ControllerTests
|
|
|
|
{
|
|
|
|
public class EventTest
|
|
|
|
{
|
|
|
|
private RemotePartyService.RemotePartyServiceClient _remotePartyService;
|
|
|
|
private Channel _channel;
|
|
|
|
private IContainer _container;
|
|
|
|
private IServerService _serverService;
|
|
|
|
|
|
|
|
#region Setup
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
_container = SetupUtil.SetupOneTime();
|
|
|
|
_remotePartyService = SetupUtil.Setup(ref _container, ref _serverService, ref _channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public async Task TearDown()
|
|
|
|
{
|
|
|
|
await _serverService.Stop();
|
|
|
|
await _channel.ShutdownAsync();
|
|
|
|
_container.Dispose();
|
|
|
|
}
|
|
|
|
#endregion Setup
|
|
|
|
[Test]
|
|
|
|
[TestCase(EventType.MediaPlaying)]
|
|
|
|
public void Asdf(EventType value)
|
|
|
|
{
|
|
|
|
Assert.AreEqual(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[TestCase(EventType.MediaPlaying)]
|
|
|
|
[TestCase(EventType.MediaStopped)]
|
|
|
|
[TestCase(EventType.MemberCreated)]
|
|
|
|
[TestCase(EventType.MemberDeleted)]
|
|
|
|
public async Task TestEventSubscriptions(EventType value)
|
|
|
|
{
|
|
|
|
using (var scope = _container.BeginLifetimeScope())
|
|
|
|
{
|
|
|
|
IEventManager eventManager = scope.Resolve<IEventManager>();
|
|
|
|
|
|
|
|
//Create new party member
|
|
|
|
Member member = _remotePartyService.CreateMember(new CreateMemberRequest()
|
|
|
|
{
|
|
|
|
Parent = "party1",
|
|
|
|
Member = new Member()
|
|
|
|
{
|
|
|
|
UserName = "newMember1",
|
|
|
|
IpAddress = ServerService.GetLocalIPAddress(),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//Subscribe to event type
|
|
|
|
_remotePartyService.CreateEventSubscription(new CreateEventSubscriptionRequest()
|
|
|
|
{
|
|
|
|
Parent = member.Name,
|
|
|
|
EventSubscription = new EventSubscription()
|
|
|
|
{
|
|
|
|
Type = value
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
BaseEvent @event = new BaseEvent
|
|
|
|
{
|
|
|
|
EventType = value,
|
|
|
|
};
|
|
|
|
//Fire event
|
|
|
|
|
|
|
|
CancellationTokenSource eventCancellationTokenSource = new CancellationTokenSource();
|
|
|
|
BaseEvent newEvent = null;
|
|
|
|
|
|
|
|
Task.Run(async () => { await Task.Delay(1000); eventManager.FireEvent(@event); });
|
|
|
|
|
|
|
|
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remotePartyService
|
|
|
|
.GetEvents(new GetEventsRequest() { Parent = member.Name }))
|
|
|
|
{
|
|
|
|
while ((!eventCancellationTokenSource.Token.IsCancellationRequested &&
|
|
|
|
await eventStream.ResponseStream.MoveNext(eventCancellationTokenSource.Token)))
|
|
|
|
{
|
|
|
|
newEvent = new BaseEvent(eventStream.ResponseStream.Current);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Assert.AreEqual(newEvent.EventType, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|