diff --git a/PebbleSharp.Net45.Tests/IntegrationTests.cs b/PebbleSharp.Net45.Tests/IntegrationTests.cs new file mode 100644 index 0000000..00abe01 --- /dev/null +++ b/PebbleSharp.Net45.Tests/IntegrationTests.cs @@ -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 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 ) ); + } + } +} \ No newline at end of file diff --git a/PebbleSharp.Net45.Tests/PebbleSharp.Net45.Tests.csproj b/PebbleSharp.Net45.Tests/PebbleSharp.Net45.Tests.csproj index c85c24e..2f947f6 100644 --- a/PebbleSharp.Net45.Tests/PebbleSharp.Net45.Tests.csproj +++ b/PebbleSharp.Net45.Tests/PebbleSharp.Net45.Tests.csproj @@ -51,6 +51,7 @@ +