Skip to content

Commit

Permalink
Adding integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Bost committed Feb 18, 2015
1 parent b8f72ac commit c3e7200
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions PebbleSharp.Net45.Tests/IntegrationTests.cs
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 ) );
}
}
}
1 change: 1 addition & 0 deletions PebbleSharp.Net45.Tests/PebbleSharp.Net45.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
</Choose>
<ItemGroup>
<Compile Include="Crc32Net45Tests.cs" />
<Compile Include="IntegrationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BundleNet45Tests.cs" />
</ItemGroup>
Expand Down

0 comments on commit c3e7200

Please sign in to comment.