Skip to content

Commit acc07ed

Browse files
committed
Let the unit testing begin...
1 parent cd758b3 commit acc07ed

File tree

10 files changed

+199
-15
lines changed

10 files changed

+199
-15
lines changed

PushSharp.Apple/ApplePushChannel.cs

-3
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,6 @@ void Cleanup()
275275
//See if anything is here to process
276276
if (sentNotifications.Count > 0)
277277
{
278-
lock(connectLock)
279-
Connect();
280-
281278
//Don't expire any notifications while we are in a connecting state, o rat least ensure all notifications have been sent
282279
// in case we may have no connection because no notifications were causing a connection to be initiated
283280
if (connected)

PushSharp.Core/PushBroker.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace PushSharp
99
{
1010
public class PushBroker : IDisposable
1111
{
12-
private Dictionary<Type, List<PushServiceBase>> registeredServices;
12+
private Dictionary<Type, List<IPushService>> registeredServices;
1313

1414
public ChannelEvents Events;
1515

1616
public PushBroker(bool autoRegisterPushServices = true)
1717
{
1818
this.Events = new ChannelEvents();
19-
registeredServices = new Dictionary<Type, List<PushServiceBase>>();
19+
registeredServices = new Dictionary<Type, List<IPushService>>();
2020
}
2121

2222
public void RegisterService<TPushNotification>(PushServiceBase pushService) where TPushNotification : Notification
@@ -28,7 +28,7 @@ public void RegisterService<TPushNotification>(PushServiceBase pushService) wher
2828
if (registeredServices.ContainsKey(pushNotificationType))
2929
registeredServices[pushNotificationType].Add(pushService);
3030
else
31-
registeredServices.Add(pushNotificationType, new List<PushServiceBase>() { pushService });
31+
registeredServices.Add(pushNotificationType, new List<IPushService>() { pushService });
3232
}
3333

3434
public void QueueNotification<TPushNotification>(TPushNotification notification) where TPushNotification : Notification
@@ -37,6 +37,18 @@ public void QueueNotification<TPushNotification>(TPushNotification notification)
3737

3838
if (registeredServices.ContainsKey(pushNotificationType))
3939
registeredServices[pushNotificationType].ForEach(pushService => pushService.QueueNotification(notification));
40+
else
41+
throw new IndexOutOfRangeException("There are no Registered Services that handle this type of Notification");
42+
}
43+
44+
public IEnumerable<IPushService> GetRegistrations<TNotification>()
45+
{
46+
var type = typeof(TNotification);
47+
48+
if (registeredServices != null && registeredServices.ContainsKey(type))
49+
return registeredServices[type];
50+
51+
return null;
4052
}
4153

4254
public void StopAllServices(bool waitForQueuesToFinish = true)

PushSharp.Sample/Program.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static void Main(string[] args)
4444

4545

4646
push.RegisterAppleService(appleSettings);
47-
48-
push.QueueNotification(push.AppleNotification().ForDeviceToken(""));
47+
48+
push.QueueNotification(push.AppleNotification().ForDeviceToken("1071737321559691b28fffa1aa4c8259d970fe0fc496794ad0486552fc9ec3db"));
4949

5050

5151

@@ -82,11 +82,11 @@ static void Main(string[] args)
8282
//Fluent construction of an iOS notification
8383
//IMPORTANT: For iOS you MUST MUST MUST use your own DeviceToken here that gets generated within your iOS app itself when the Application Delegate
8484
// for registered for remote notifications is called, and the device token is passed back to you
85-
push.QueueNotification(new AppleNotification()
86-
.ForDeviceToken("1071737321559691b28fffa1aa4c8259d970fe0fc496794ad0486552fc9ec3db")
87-
.WithAlert("1 Alert Text!")
88-
.WithSound("default")
89-
.WithBadge(7));
85+
/// push.QueueNotification(new AppleNotification()
86+
/// .ForDeviceToken("1071737321559691b28fffa1aa4c8259d970fe0fc496794ad0486552fc9ec3db")
87+
// .WithAlert("1 Alert Text!")
88+
// .WithSound("default")
89+
// .WithBadge(7));
9090

9191
//Fluent construction of an Android GCM Notification
9292
//IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!

PushSharp.WindowsPhone/WindowsPhonePushChannel.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public WindowsPhonePushChannel(IPushService pushService) : base(pushService)
1919
public override void SendNotification(Notification notification)
2020
{
2121
var wpNotification = notification as WindowsPhoneNotification;
22-
23-
22+
2423
var wr = HttpWebRequest.Create(wpNotification.EndPointUrl) as HttpWebRequest;
2524
wr.ContentType = "text/xml";
2625
wr.Method = "POST";

PushSharp.sln

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PushSharp.Windows", "PushSh
3131
EndProject
3232
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PushSharp.WindowsPhone", "PushSharp.WindowsPhone\PushSharp.WindowsPhone.csproj", "{9947F510-BA9A-4045-A648-BAB687D8F513}"
3333
EndProject
34+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{295A5325-0BC1-4FA1-B13C-7577D2B582B7}"
35+
EndProject
36+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PushSharp.Tests", "Tests\PushSharp.Tests\PushSharp.Tests.csproj", "{39313686-9B5F-4680-9D5C-373C3E2C87CF}"
37+
EndProject
3438
Global
3539
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3640
Debug|Any CPU = Debug|Any CPU
@@ -111,6 +115,16 @@ Global
111115
{9947F510-BA9A-4045-A648-BAB687D8F513}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
112116
{9947F510-BA9A-4045-A648-BAB687D8F513}.Release|Mixed Platforms.Build.0 = Release|Any CPU
113117
{9947F510-BA9A-4045-A648-BAB687D8F513}.Release|x86.ActiveCfg = Release|Any CPU
118+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
121+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
122+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Debug|x86.ActiveCfg = Debug|Any CPU
123+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
124+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Release|Any CPU.Build.0 = Release|Any CPU
125+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
126+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
127+
{39313686-9B5F-4680-9D5C-373C3E2C87CF}.Release|x86.ActiveCfg = Release|Any CPU
114128
EndGlobalSection
115129
GlobalSection(SolutionProperties) = preSolution
116130
HideSolutionNode = FALSE
@@ -122,6 +136,7 @@ Global
122136
{9947F510-BA9A-4045-A648-BAB687D8F513} = {C09BBA3E-9CF3-4479-A4C3-3006820E2046}
123137
{1B9A3A8B-3690-4435-BF9C-B557BF2713DB} = {04A9AE38-795E-4CB5-A9AD-C1FA83DC342C}
124138
{5961A8F2-DE0A-4BBA-BEB3-B99C19C301A8} = {04A9AE38-795E-4CB5-A9AD-C1FA83DC342C}
139+
{39313686-9B5F-4680-9D5C-373C3E2C87CF} = {295A5325-0BC1-4FA1-B13C-7577D2B582B7}
125140
EndGlobalSection
126141
GlobalSection(MonoDevelopProperties) = preSolution
127142
StartupItem = PushSharp.Sample\PushSharp.Sample.csproj

PushSharp.sln.DotSettings.user

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=9FC697A246C243EEA162B3FA956D46A0/@KeyIndexDefined">True</s:Boolean>
3+
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=9FC697A246C243EEA162B3FA956D46A0/Name/@EntryValue">CoreTests</s:String>
4+
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=9FC697A246C243EEA162B3FA956D46A0/XmlSerializedElements/@EntryValue">&lt;Session&gt;&lt;Elements&gt;&lt;UnitTestElement Provider="nUnit" Id="PushSharp.Tests.CoreTests" type="NUnitTestFixtureElement" Project="39313686-9B5F-4680-9D5C-373C3E2C87CF" /&gt;&lt;UnitTestElement Provider="nUnit" Id="PushSharp.Tests.CoreTests.TestAppleRegistration" ParentId="PushSharp.Tests.CoreTests" type="NUnitTestElement" TypeName="PushSharp.Tests.CoreTests" MethodName="TestAppleRegistration" Project="39313686-9B5F-4680-9D5C-373C3E2C87CF" /&gt;&lt;/Elements&gt;&lt;/Session&gt;</s:String></wpf:ResourceDictionary>

Tests/PushSharp.Tests/CoreTests.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
using PushSharp;
9+
using PushSharp.Apple;
10+
11+
namespace PushSharp.Tests
12+
{
13+
[TestFixture]
14+
public class CoreTests
15+
{
16+
private PushBroker broker;
17+
private byte[] appleCert;
18+
19+
[SetUp]
20+
public void Setup()
21+
{
22+
appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../../Resources/PushSharp.Apns.Sandbox.p12"));
23+
broker = new PushBroker(false);
24+
}
25+
26+
[Test]
27+
public void TestAppleRegistration()
28+
{
29+
broker.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "pushsharp"));
30+
Assert.IsNotEmpty(broker.GetRegistrations<AppleNotification>());
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("PushSharp.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("PushSharp.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("6050d52f-fbbd-42ac-b292-8c2b275fff29")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{39313686-9B5F-4680-9D5C-373C3E2C87CF}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>PushSharp.Tests</RootNamespace>
11+
<AssemblyName>PushSharp.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
36+
<HintPath>..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Xml" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="CoreTests.cs" />
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="packages.config" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<ProjectReference Include="..\..\PushSharp.Android\PushSharp.Google.csproj">
55+
<Project>{71e27c37-fbbf-481b-934b-1f7dbde3c5d6}</Project>
56+
<Name>PushSharp.Google</Name>
57+
</ProjectReference>
58+
<ProjectReference Include="..\..\PushSharp.Apple\PushSharp.Apple.csproj">
59+
<Project>{83c67156-893d-4aff-9169-db34771989cb}</Project>
60+
<Name>PushSharp.Apple</Name>
61+
</ProjectReference>
62+
<ProjectReference Include="..\..\PushSharp.Core\PushSharp.Core.csproj">
63+
<Project>{836f225f-6cd9-48de-910c-70f8a7cf54aa}</Project>
64+
<Name>PushSharp.Core</Name>
65+
</ProjectReference>
66+
<ProjectReference Include="..\..\PushSharp.WindowsPhone\PushSharp.WindowsPhone.csproj">
67+
<Project>{9947f510-ba9a-4045-a648-bab687d8f513}</Project>
68+
<Name>PushSharp.WindowsPhone</Name>
69+
</ProjectReference>
70+
<ProjectReference Include="..\..\PushSharp.Windows\PushSharp.Windows.csproj">
71+
<Project>{0ec3a31e-b869-4465-abdc-90c2e3ccc17d}</Project>
72+
<Name>PushSharp.Windows</Name>
73+
</ProjectReference>
74+
</ItemGroup>
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
77+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
78+
Other similar extension points exist, see Microsoft.Common.targets.
79+
<Target Name="BeforeBuild">
80+
</Target>
81+
<Target Name="AfterBuild">
82+
</Target>
83+
-->
84+
</Project>

Tests/PushSharp.Tests/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="2.6.2" targetFramework="net45" />
4+
</packages>

0 commit comments

Comments
 (0)