forked from Keboo/PebbleSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Bost
committed
Feb 18, 2015
1 parent
b8f72ac
commit c3e7200
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using PebbleSharp.Core; | ||
using PebbleSharp.Core.Responses; | ||
|
||
namespace PebbleSharp.Net45.Tests | ||
{ | ||
[TestClass] | ||
public class IntegrationTests | ||
{ | ||
private static Pebble _Pebble; | ||
|
||
[ClassInitialize] | ||
public static void Startup( TestContext context ) | ||
{ | ||
_Pebble = PebbleNet45.DetectPebbles().SingleOrDefault(); | ||
Assert.IsNotNull( _Pebble, "Could not find pebble" ); | ||
_Pebble.ConnectAsync().Wait(); | ||
} | ||
|
||
[ClassCleanup] | ||
public static void Cleanup() | ||
{ | ||
_Pebble.Disconnect(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task CanGetCurrentTime() | ||
{ | ||
TimeResponse response = await _Pebble.GetTimeAsync(); | ||
AssertSuccessfulResult( response ); | ||
} | ||
|
||
[TestMethod] | ||
public async Task CanSetTime() | ||
{ | ||
await _Pebble.SetTimeAsync( DateTime.Now ); | ||
TimeResponse respnse = await _Pebble.GetTimeAsync(); | ||
AssertSuccessfulResult( respnse ); | ||
Assert.IsTrue( DateTime.Now - respnse.Time < TimeSpan.FromSeconds( 10 ) ); | ||
} | ||
|
||
[TestMethod] | ||
public async Task CanGetFirmwareInfo() | ||
{ | ||
FirmwareVersionResponse firmwareResponse = await _Pebble.GetFirmwareVersionAsync(); | ||
AssertSuccessfulResult( firmwareResponse ); | ||
Assert.IsNotNull( firmwareResponse.Firmware ); | ||
Assert.IsNotNull( firmwareResponse.RecoveryFirmware ); | ||
} | ||
|
||
// ReSharper disable once UnusedParameter.Local | ||
private static void AssertSuccessfulResult<T>( T response ) | ||
where T : ResponseBase | ||
{ | ||
Assert.IsNotNull( response, string.Format( "{0} was null", typeof( T ).Name ) ); | ||
Assert.IsTrue( response.Success, string.Concat( Environment.NewLine, | ||
string.Format( "{0} failed", typeof( T ).Name ), | ||
response.ErrorMessage, | ||
response.ErrorDetails ) ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters