Skip to content

Commit

Permalink
Make the service more unit-testable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Wood committed May 31, 2020
1 parent ec0716e commit 1dad219
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ await service.ConnectAsync("192.168.1.82");

// Examples
await service.Audio.MuteAsync();
await service.Control.PlayAsync();
await service.Control.SendIntentAsync(ControlIntent.Home);
await service.Apps.LaunchAsync("abc");

service.Close();
Expand Down
12 changes: 6 additions & 6 deletions src/WebOsTv.Net/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace WebOsTv.Net
{
public interface IService
{
ApiService Api { get; }
AppsService Apps { get; }
AudioService Audio { get; }
ControlService Control { get; }
NotificationService Notifications { get; }
TvService Tv { get; }
IApiService Api { get; }
IAppsService Apps { get; }
IAudioService Audio { get; }
IControlService Control { get; }
INotificationService Notifications { get; }
ITvService Tv { get; }
Task ConnectAsync(string hostName);
void Close();
}
Expand Down
12 changes: 6 additions & 6 deletions src/WebOsTv.Net/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public Service(IClient client)
Tv = new TvService(client);
}

public ApiService Api { get; }
public AppsService Apps { get; }
public AudioService Audio { get; }
public ControlService Control { get; }
public NotificationService Notifications { get; }
public TvService Tv { get; }
public virtual IApiService Api { get; }
public virtual IAppsService Apps { get; }
public virtual IAudioService Audio { get; }
public virtual IControlService Control { get; }
public virtual INotificationService Notifications { get; }
public virtual ITvService Tv { get; }

public async Task ConnectAsync(string hostName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WebOsTv.Net/Services/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WebOsTv.Net.Services
{
public class ApiService
public class ApiService : IApiService
{
private readonly IClient _client;

Expand Down
2 changes: 1 addition & 1 deletion src/WebOsTv.Net/Services/AppsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WebOsTv.Net.Services
{
public class AppsService
public class AppsService : IAppsService
{
private readonly IClient _client;

Expand Down
2 changes: 1 addition & 1 deletion src/WebOsTv.Net/Services/AudioService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WebOsTv.Net.Services
{
public class AudioService
public class AudioService : IAudioService
{
private readonly IClient _client;

Expand Down
2 changes: 1 addition & 1 deletion src/WebOsTv.Net/Services/ControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace WebOsTv.Net.Services
{
public class ControlService
public class ControlService : IControlService
{
private readonly IClient _client;

Expand Down
10 changes: 10 additions & 0 deletions src/WebOsTv.Net/Services/IApiService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using WebOsTv.Net.Responses.Api;

namespace WebOsTv.Net.Services
{
public interface IApiService
{
Task<ServiceListResponse.ServiceItem[]> ListServicesAsync();
}
}
15 changes: 15 additions & 0 deletions src/WebOsTv.Net/Services/IAppsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using WebOsTv.Net.Responses.Apps;

namespace WebOsTv.Net.Services
{
public interface IAppsService
{
Task CloseAsync(string appId);
Task<string> GetCurrentAsync();
Task LaunchAsync(string appId);
Task LaunchBrowserAsync(string url);
Task LaunchYouTubeVideoAsync(string videoId);
Task<ListLaunchPointsResponse.LaunchPoint[]> ListAsync();
}
}
14 changes: 14 additions & 0 deletions src/WebOsTv.Net/Services/IAudioService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Threading.Tasks;

namespace WebOsTv.Net.Services
{
public interface IAudioService
{
Task<AudioService.VolumeDetails> VolumeGetAsync();
Task VolumeDownAsync(int by = 1);
Task VolumeUpAsync(int by = 1);
Task MuteAsync();
Task UnmuteAsync();
Task SetVolumeAsync(int volume);
}
}
9 changes: 9 additions & 0 deletions src/WebOsTv.Net/Services/IControlService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace WebOsTv.Net.Services
{
public interface IControlService
{
Task SendIntentAsync(ControlService.ControlIntent intent);
}
}
9 changes: 9 additions & 0 deletions src/WebOsTv.Net/Services/INotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace WebOsTv.Net.Services
{
public interface INotificationService
{
Task SendToastAsync(string message);
}
}
19 changes: 19 additions & 0 deletions src/WebOsTv.Net/Services/ITvService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Threading.Tasks;
using WebOsTv.Net.Responses.Tv;

namespace WebOsTv.Net.Services
{
public interface ITvService
{
Task ChannelDownAsync();
Task<ChannelListResponse.Channel[]> ListChannelsAsync();
Task ChannelUpAsync();
Task<ExternalInputListResponse.Device[]> ListInputsAsync();
Task<GetChannelProgramInfoResponse.ProgramItem[]> GetProgramInfoAsync();
Task<string> GetCurrentChannelAsync();
Task SetInputAsync(string inputId);
Task TurnOn3dAsync();
Task TurnOff3dAsync();
Task<ThreeDimensionStatusResponse.Status3d> Get3dStatusAsync();
}
}
2 changes: 1 addition & 1 deletion src/WebOsTv.Net/Services/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WebOsTv.Net.Services
{
public class NotificationService
public class NotificationService : INotificationService
{
private readonly IClient _client;

Expand Down
2 changes: 1 addition & 1 deletion src/WebOsTv.Net/Services/TvService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace WebOsTv.Net.Services
{
public class TvService
public class TvService : ITvService
{
private readonly IClient _client;

Expand Down
6 changes: 3 additions & 3 deletions src/WebOsTv.Net/WebOsTv.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<RepositoryUrl>https://github.com/cpwood/WebOsTv.Net</RepositoryUrl>
<PackageProjectUrl>https://github.com/cpwood/WebOsTv.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.0</Version>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 1dad219

Please sign in to comment.