Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kareem613 committed Feb 9, 2014
1 parent 643ca80 commit 20a42ca
Show file tree
Hide file tree
Showing 17 changed files with 607 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ Generated_Code #added for RIA/Silverlight projects
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
SharpSpark.Tests/App.config
7 changes: 7 additions & 0 deletions SharpSpark.Tests/App.config.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="accessToken" value="[access token here]"/>
<add key="deviceId" value="[device id here]"/>
</appSettings>
</configuration>
36 changes: 36 additions & 0 deletions SharpSpark.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("sharpspark.tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("sharpspark.tests")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("eb6b72e1-5002-4dd8-97d6-31fc9f9ec948")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
97 changes: 97 additions & 0 deletions SharpSpark.Tests/SharpSpark.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9D4E71FE-7394-43FA-A4D4-F75E004EF319}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>sharpspark.tests</RootNamespace>
<AssemblyName>sharpspark.tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="SparkClientTests.cs" />
<Compile Include="TinkerUnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpSpark\SharpSpark.csproj">
<Project>{75c52157-bb62-4888-a321-dc7962de313d}</Project>
<Name>SharpSpark</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config.sample">
<SubType>Designer</SubType>
</None>
<None Include="App.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
1 change: 1 addition & 0 deletions SharpSpark.Tests/SharpSparkTests.playlist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Playlist Version="1.0"><Add Test="sharpspark.tests.UnitTest1.GivenLowPin7WhenDigitalWriteHighExpectPinoutHigh" /><Add Test="sharpspark.tests.UnitTest1.GivenLowPin7WhenDigitalReadExpectPinoutLow" /><Add Test="sharpspark.tests.UnitTest1.GivenLowA5WhenAnalogReadExpectLow" /><Add Test="sharpspark.tests.UnitTest1.GivenA5WhenAnalogWrite255Expect255" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenLowA5WhenAnalogReadExpectLow" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenLowPin7WhenDigitalWriteHighExpectPinoutHigh" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenA5WhenAnalogWrite255Expect255" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenLowPin7WhenDigitalReadExpectPinoutLow" /><Add Test="sharpspark.tests.SparkClientTests.GivenClientInfoExpectDeviceName" /><Add Test="sharpspark.tests.SparkClientTests.GivenClientInfoExpectDeviceInfo" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenLowPin7WhenDigitalWriteHighExpectValidReturnValue" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenLowA5WhenAnalogReadExpectValidReturnValue" /><Add Test="sharpspark.tests.TinkerUnitTests.GivenA5WhenAnalogWrite255ExpectValidReturnValue" /><Add Test="sharpspark.tests.SparkClientTests.GivenInvalidFunctionExpectError" /><Add Test="sharpspark.tests.SparkClientTests.GivenOfflineDeviceFunctionExpectErrorTimedOut" /><Add Test="sharpspark.tests.SparkClientTests.GivenInvalidFunctionExpectErrorFunctionNotFound" /></Playlist>
51 changes: 51 additions & 0 deletions SharpSpark.Tests/SparkClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Maybe5.SharpSpark;
using System.Configuration;

namespace Maybe5.SharpSpark.Tests
{
[TestClass]
public class SparkClientTests
{
SparkClient client;

[TestInitialize]
public void Setup()
{
var accessToken = ConfigurationManager.AppSettings["accessToken"];
var deviceId = ConfigurationManager.AppSettings["deviceId"];
client = new SparkClient(accessToken, deviceId);
}

[TestMethod]
public void GivenClientInfoExpectDeviceInfo()
{
SparkDevice device = client.GetDevice();

Assert.IsNotNull(device);
Assert.IsNotNull(device.Name);
Assert.AreEqual(client.DeviceId, device.Id);
}

[TestMethod]
public void GivenInvalidFunctionExpectErrorFunctionNotFound()
{
SparkResult result = client.ExecuteFunction("thisdoesnotexist");

Assert.IsTrue(result.HasErrors);
Assert.AreEqual("Function not found", result.ErrorResult.Error);
}

[Ignore]//This test only passes if the device is offline
[TestMethod]
public void GivenOfflineDeviceFunctionExpectErrorTimedOut()
{
SparkResult result = client.ExecuteFunction("digitalRead");

Assert.IsTrue(result.HasErrors);
Assert.AreEqual("Timed out.", result.ErrorResult.Error);
}

}
}
57 changes: 57 additions & 0 deletions SharpSpark.Tests/TinkerUnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Maybe5.SharpSpark;
using System.Configuration;


namespace Maybe5.SharpSpark.Tests
{
[TestClass]
public class TinkerUnitTests
{
TinkerClient client;

[TestInitialize]
public void Setup()
{
var accessToken = ConfigurationManager.AppSettings["accessToken"];
var deviceId = ConfigurationManager.AppSettings["deviceId"];
client = new TinkerClient(accessToken, deviceId);
}

[TestMethod]
public void GivenLowPin7WhenDigitalReadExpectPinoutLow()
{
var pinValue = client.DigitalRead(TinkerClient.DigitalPins.D7);

Assert.AreEqual(TinkerClient.DigitalValue.Low, pinValue);
}

[TestMethod]
public void GivenLowPin7WhenDigitalWriteHighExpectValidReturnValue()
{
client.DigitalWrite(TinkerClient.DigitalPins.D7, TinkerClient.DigitalValue.High);

var pinValue = client.DigitalRead(TinkerClient.DigitalPins.D7);

Assert.AreNotEqual(TinkerClient.ERROR_RETURN_VALUE, pinValue);
}

[TestMethod]
public void GivenLowA5WhenAnalogReadExpectValidReturnValue()
{

var pinValue = client.AnalogRead(TinkerClient.AnalogPins.A5);

Assert.AreNotEqual(TinkerClient.ERROR_RETURN_VALUE, pinValue);
}

[TestMethod]
public void GivenA5WhenAnalogWrite255ExpectValidReturnValue()
{
var pinValue = client.AnalogRead(TinkerClient.AnalogPins.A5);

Assert.AreNotEqual(TinkerClient.ERROR_RETURN_VALUE, pinValue);
}
}
}
28 changes: 28 additions & 0 deletions SharpSpark.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSpark.Tests", "SharpSpark.Tests\SharpSpark.Tests.csproj", "{9D4E71FE-7394-43FA-A4D4-F75E004EF319}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSpark", "SharpSpark\SharpSpark.csproj", "{75C52157-BB62-4888-A321-DC7962DE313D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D4E71FE-7394-43FA-A4D4-F75E004EF319}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D4E71FE-7394-43FA-A4D4-F75E004EF319}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D4E71FE-7394-43FA-A4D4-F75E004EF319}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D4E71FE-7394-43FA-A4D4-F75E004EF319}.Release|Any CPU.Build.0 = Release|Any CPU
{75C52157-BB62-4888-A321-DC7962DE313D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75C52157-BB62-4888-A321-DC7962DE313D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75C52157-BB62-4888-A321-DC7962DE313D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75C52157-BB62-4888-A321-DC7962DE313D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
42 changes: 42 additions & 0 deletions SharpSpark/CloudApiHttpClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Net.Http;

namespace Maybe5.SharpSpark
{
class CloudApiHttpClient
{
public string AccessToken { get; private set; }
public string DeviceId { get; private set; }

public CloudApiHttpClient(string accessToken, string deviceId)
{
AccessToken = accessToken;
DeviceId = deviceId;
}

public string GetRawResultForGet(string variableName)
{
using (var client = new HttpClient())
{
var result = client.GetAsync(String.Format("https://api.spark.io/v1/devices/{0}/{1}?access_token={2}", DeviceId, variableName, AccessToken)).Result;
result.EnsureSuccessStatusCode();
return result.Content.ReadAsStringAsync().Result;
}
}


public HttpResponseMessage GetRawResultForPost(string functionKey, string[] args)
{
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("params", String.Join(",",args))
});
return client.PostAsync(String.Format("https://api.spark.io/v1/devices/{0}/{1}?access_token={2}", DeviceId, functionKey, AccessToken), content).Result;

}
}
}
}
36 changes: 36 additions & 0 deletions SharpSpark/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SharpSpark")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SharpSpark")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("01ced307-07e0-47d6-9a3b-13ad769f4ff9")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 20a42ca

Please sign in to comment.