Added basic unit tests for all controllers
This commit is contained in:
@ -7,6 +7,7 @@ using Aurora.Design.Views.Profile;
|
||||
using Aurora.Design.Views.Songs;
|
||||
using Aurora.Design.Views.Stations;
|
||||
using Aurora.Services.ClientService;
|
||||
using Aurora.Services.Server.EventManager;
|
||||
using Autofac;
|
||||
using LibVLCSharp.Shared;
|
||||
using Xamarin.Forms;
|
||||
@ -31,6 +32,7 @@ namespace Aurora
|
||||
_builder.RegisterType<SettingsService>().As<ISettingsService>().SingleInstance();
|
||||
_builder.RegisterType<ClientService>().As<IClientService>().SingleInstance();
|
||||
_builder.RegisterType<LibraryService>().As<ILibraryService>().SingleInstance();
|
||||
_builder.RegisterType<EventManager>().As<IEventManager>().SingleInstance();
|
||||
_builder.RegisterType<MainView>().SingleInstance();
|
||||
_builder.RegisterType<AlbumsViewModel>();
|
||||
_builder.RegisterType<ArtistsViewModel>();
|
||||
|
@ -3,7 +3,9 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using Aurora.Proto.PartyV2;
|
||||
using Aurora.Services.Library;
|
||||
using Aurora.Services.Settings;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Services.Server.EventManager;
|
||||
using Autofac;
|
||||
|
||||
namespace Aurora.Services.Server.Controllers
|
||||
@ -11,11 +13,13 @@ namespace Aurora.Services.Server.Controllers
|
||||
public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase
|
||||
{
|
||||
private ILibraryService _libraryService;
|
||||
private ISettingsService _settingsService;
|
||||
private IEventManager _eventManager;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for partial class
|
||||
/// </summary>
|
||||
public RemotePartyController(string partyName, string description, ILibraryService libraryService)
|
||||
public RemotePartyController(string partyName, string description, ILibraryService libraryService, ISettingsService settingsService, IEventManager eventManager)
|
||||
{
|
||||
this._startDateTime = DateTime.UtcNow;
|
||||
this._displayName = partyName;
|
||||
@ -24,10 +28,11 @@ namespace Aurora.Services.Server.Controllers
|
||||
this._mediaList = new SortedList<string, Media>();
|
||||
|
||||
_libraryService = libraryService;
|
||||
this._settingsService = settingsService;
|
||||
|
||||
string userName = "testUser";
|
||||
string userName = _settingsService.Username;
|
||||
|
||||
this._eventManager = new EventManager.EventManager();
|
||||
this._eventManager = eventManager;
|
||||
|
||||
this._hostMember = new Member()
|
||||
{
|
||||
@ -54,7 +59,7 @@ namespace Aurora.Services.Server.Controllers
|
||||
metadata = media.Metadata as AudioMetadata;
|
||||
|
||||
Media data = new Media();
|
||||
data.Name = media.Id;
|
||||
data.Name = string.Format("{0}/{1}", partyName, media.Id);
|
||||
if (metadata.Title != null)
|
||||
{
|
||||
data.Title = metadata.Title;
|
||||
|
@ -15,8 +15,6 @@ namespace Aurora.Services.Server.Controllers
|
||||
private Member _hostMember;
|
||||
private DateTime _startDateTime;
|
||||
|
||||
private EventManager.EventManager _eventManager;
|
||||
|
||||
public override Task<Party> GetParty(Proto.General.Empty request, Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
Party party = new Party()
|
||||
|
@ -6,7 +6,7 @@ using Aurora.Proto.PartyV2;
|
||||
|
||||
namespace Aurora.Services.Server.EventManager
|
||||
{
|
||||
public class EventManager
|
||||
public class EventManager : IEventManager
|
||||
{
|
||||
#region Fields
|
||||
private Dictionary<string, List<EventType>> _subscriptionList;
|
||||
|
60
Aurora/Services/Server/EventManager/IEventManager.cs
Normal file
60
Aurora/Services/Server/EventManager/IEventManager.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aurora.Proto.PartyV2;
|
||||
|
||||
namespace Aurora.Services.Server.EventManager
|
||||
{
|
||||
public interface IEventManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the list of event type subscriptions for a given sessionIdentifier id.
|
||||
/// </summary>
|
||||
/// <param name="sessionIdentifier">sessionIdentifier Id</param>
|
||||
/// <returns></returns>
|
||||
List<EventType> GetSubscriptionList(string sessionIdentifier);
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of event subscriptions for a given sessionIdentifier
|
||||
/// </summary>
|
||||
/// <param name="sessionIdentifier">sessionIdentifier Id</param>
|
||||
/// <returns></returns>
|
||||
int GetSubscriptionCount(string sessionIdentifier);
|
||||
|
||||
/// <summary>
|
||||
/// Add a new subscription
|
||||
/// </summary>
|
||||
/// <param name="sessionIdentifier"></param>
|
||||
/// <param name="type"></param>
|
||||
bool AddSubscription(string sessionIdentifier, EventType type);
|
||||
|
||||
/// <summary>
|
||||
/// Add a list of subscriptions. This unsubscribes from unused events.
|
||||
/// </summary>
|
||||
/// <param name="sessionIdentifier">The browser sessionIdentifier id.</param>
|
||||
/// <param name="types">The list of event types to subscribe to.</param>
|
||||
void AddSubscriptionList(string sessionIdentifier, List<EventType> types);
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribe from a given event type.
|
||||
/// </summary>
|
||||
/// <param name="sessionIdentifier">sessionIdentifier Id</param>
|
||||
/// <param name="type">Event Type to be removed</param>
|
||||
void RemoveSubscription(string sessionIdentifier, EventType type);
|
||||
|
||||
void RemoveSubscriptionList(string sessionIdentifier, List<EventType> types);
|
||||
|
||||
/// <summary>
|
||||
/// Remove all subscriptons for a given sessionIdentifier.
|
||||
/// </summary>
|
||||
/// <param name="sessionIdentifier">sessionIdentifier Id</param>
|
||||
void RemoveAllSubscriptions(string sessionIdentifier);
|
||||
|
||||
void AddEventHandler(Action<BaseEvent> action, Action cancel, string sessionIdentifierId);
|
||||
|
||||
void RemoveEventHandler(string sessionIdentifierId);
|
||||
|
||||
void CancelEventStream(string sessionIdentifierId);
|
||||
|
||||
void FireEvent(BaseEvent bEvent);
|
||||
}
|
||||
}
|
@ -4,7 +4,9 @@ using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Grpc.Core;
|
||||
using Aurora.Services.Server.Controllers;
|
||||
using Aurora.Services.Settings;
|
||||
using Aurora.Services.Library;
|
||||
using Aurora.Services.Server.EventManager;
|
||||
using Aurora.Proto.PartyV2;
|
||||
|
||||
|
||||
@ -16,6 +18,8 @@ namespace Aurora.Services.Server
|
||||
private string _hostname;
|
||||
private Grpc.Core.Server _server;
|
||||
private ILibraryService _libraryService;
|
||||
private ISettingsService _settingsService;
|
||||
private IEventManager _eventManager;
|
||||
|
||||
//Implementation class declarations
|
||||
private RemotePartyController _remotePartyController;
|
||||
@ -23,10 +27,12 @@ namespace Aurora.Services.Server
|
||||
/// <summary>
|
||||
/// Constructor. Registers GRPC service implementations.
|
||||
/// </summary>
|
||||
public ServerService(ILibraryService libraryService)
|
||||
public ServerService(ILibraryService libraryService, ISettingsService settingsService, IEventManager eventManager)
|
||||
{
|
||||
string host = GetLocalIPAddress();
|
||||
this._libraryService = libraryService;
|
||||
this._settingsService = settingsService;
|
||||
this._eventManager = eventManager;
|
||||
if (string.IsNullOrWhiteSpace(host))
|
||||
{
|
||||
throw new Exception("This device must have a valid IP address");
|
||||
@ -71,7 +77,12 @@ namespace Aurora.Services.Server
|
||||
};
|
||||
|
||||
//Construct implementations
|
||||
_remotePartyController = new RemotePartyController(partyName, description, _libraryService);
|
||||
_remotePartyController = new RemotePartyController(
|
||||
partyName,
|
||||
description,
|
||||
_libraryService,
|
||||
_settingsService,
|
||||
_eventManager);
|
||||
|
||||
// Register grpc RemoteService with singleton server service
|
||||
RegisterService(RemotePartyService.BindService(_remotePartyController));
|
||||
|
Reference in New Issue
Block a user