-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from winappkits/UnitTests
Unit tests
- Loading branch information
Showing
12 changed files
with
272 additions
and
14 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
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
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
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
23 changes: 23 additions & 0 deletions
23
XPlatformCloudKit/XPlatformCloudKit.Tests/AzureMobileServiceTest.cs
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,23 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Threading.Tasks; | ||
|
||
namespace XPlatformCloudKit.Tests | ||
{ | ||
[TestClass] | ||
public class AzureMobileServiceTest | ||
{ | ||
[TestMethod] | ||
public async Task ValidateAzureMobileService() | ||
{ | ||
AppSettings.MobileServiceAddress = "https://xplatformcloudkit.azure-mobile.net/"; | ||
AppSettings.MobileServiceApplicationKey = "UYZnUrrabofKBELSRdRsmCGboyDGMJ15"; | ||
var azureMobileService = new DataServices.AzureMobileService(); | ||
|
||
var items = await azureMobileService.GetItems(); | ||
|
||
Assert.AreEqual(6, items.Count); | ||
Assert.AreEqual("Captain America", items[0].Title); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
XPlatformCloudKit/XPlatformCloudKit.Tests/LocalItemsFileServiceTest.cs
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,35 @@ | ||
using System; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Threading.Tasks; | ||
using XPlatformCloudKit.DataServices; | ||
using XPlatformCloudKit.Services; | ||
using XPlatformCloudKit.Tests.Services; | ||
|
||
namespace XPlatformCloudKit.Tests | ||
{ | ||
/// <summary> | ||
/// Summary description for LocalItemsFileServiceTest | ||
/// </summary> | ||
[TestClass] | ||
public class LocalItemsFileServiceTest | ||
{ | ||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext t) | ||
{ | ||
ServiceLocator.ResourceFileService = new TestResourceFileService(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ValidateLocalItemsFileService() | ||
{ | ||
var localItemsFileService = new LocalItemsFileService(); | ||
|
||
var items = await localItemsFileService.GetItems(); | ||
|
||
Assert.AreEqual(3, items.Count); | ||
Assert.AreEqual("Warning", items[0].Subtitle); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
XPlatformCloudKit/XPlatformCloudKit.Tests/RemoteAppSettingsTest.cs
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,67 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using XPlatformCloudKit.Services; | ||
using Cirrious.CrossCore; | ||
using XPlatformCloudKit.ViewModels; | ||
using XPlatformCloudKit.Tests.Services; | ||
using XPlatformCloudKit.DataServices; | ||
using Cirrious.CrossCore.IoC; | ||
using Cirrious.MvvmCross.Plugins.File; | ||
using Cirrious.MvvmCross.Plugins.File.Wpf; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
|
||
namespace XPlatformCloudKit.Tests | ||
{ | ||
[TestClass] | ||
public class RemoteAppSettingsTest | ||
{ | ||
public static int loadingOfDataSourcesTimeOutInMilliseconds = 30000; | ||
public static AutoResetEvent waitHandle = new AutoResetEvent(false); | ||
public static ItemsShowcaseViewModel.LoadCompletedEventHandler eventHandler = delegate (object sender, EventArgs e) | ||
{ | ||
waitHandle.Set(); // signal that the finished event was raised | ||
}; | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext t) | ||
{ | ||
ServiceLocator.AzureMobileService = new AzureMobileService(); | ||
ServiceLocator.ResourceFileService = new TestResourceFileService(); | ||
ServiceLocator.MessageService = new TestMessageService(); | ||
|
||
var iocProvider = MvxSimpleIoCContainer.Initialize(); | ||
Mvx.RegisterSingleton<IMvxFileStore>(new MvxWpfFileStore()); | ||
} | ||
|
||
[TestMethod] | ||
public void ValidateRemoteAppSettingsService() | ||
{ | ||
Debug.WriteLine("Initial App Name = " + AppSettings.ApplicationName); | ||
Assert.IsFalse(AppSettings.ApplicationName.Contains("Remote Application"), "Application currently uses an inconclusive name of " + AppSettings.ApplicationName); | ||
|
||
AppSettings.EnableRemoteAppSettings = true; | ||
AppSettings.RemoteAppSettingsService = "http://pjdecarlo.com/playground/XPCKSampleRemoteAppSettings/AppSettings.html"; | ||
|
||
var itemsShowcaseViewModel = new ItemsShowcaseViewModel(true); // Ignore cache to retrieve AppSettings file from remote source | ||
MonitorLoadingItems(itemsShowcaseViewModel); | ||
Debug.WriteLine("Initial DataSources Loaded " + DateTime.Now.ToString()); | ||
|
||
Debug.WriteLine("Final App Name = " + AppSettings.ApplicationName); | ||
Assert.IsTrue(AppSettings.ApplicationName.Contains("Remote Application"), | ||
"Expected Remote Application Identifier not found."); // Will fail if invalid or no AppSettings file was retrieved | ||
} | ||
|
||
public static void MonitorLoadingItems(ItemsShowcaseViewModel itemsShowcaseViewModel) | ||
{ | ||
itemsShowcaseViewModel.LoadCompleted += eventHandler; | ||
|
||
if (!waitHandle.WaitOne(loadingOfDataSourcesTimeOutInMilliseconds, false)) | ||
{ | ||
Assert.Fail("Loading of DataSources timed out after " + loadingOfDataSourcesTimeOutInMilliseconds + " ms"); | ||
} | ||
|
||
itemsShowcaseViewModel.LoadCompleted -= eventHandler; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
XPlatformCloudKit/XPlatformCloudKit.Tests/RssServiceTest.cs
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,30 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using XPlatformCloudKit.Models; | ||
using XPlatformCloudKit.DataServices; | ||
using System.Threading.Tasks; | ||
|
||
namespace XPlatformCloudKit.Tests | ||
{ | ||
[TestClass] | ||
public class RssServiceTest | ||
{ | ||
[TestMethod] | ||
public async Task ValidateRssService() | ||
{ | ||
//If value == -1, ensures all items are fetched | ||
AppSettings.RssMaxItemsPerFeed = -1; | ||
AppSettings.RssAddressCollection = | ||
new UrlSource[] { | ||
new UrlSource() { Url = "http://reddit.com/.rss", Group = "Reddit" }, | ||
new UrlSource() { Url = "http://reddit.com/r/technology/.rss", Group = "Reddit Technology" }, | ||
new UrlSource() { Url = "http://www.bing.com/search?q=tesla&format=rss", Group = "Bing example"} | ||
}; | ||
var rssService = new RssService(); | ||
|
||
var items = await rssService.GetItems(); | ||
|
||
Assert.IsTrue(items.Count > 0, "Error: Zero items retrieved from RSS Service"); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
XPlatformCloudKit/XPlatformCloudKit.Tests/TwitterServiceTest.cs
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,45 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Threading.Tasks; | ||
using XPlatformCloudKit.Models; | ||
using XPlatformCloudKit.DataServices; | ||
using XPlatformCloudKit.Services; | ||
using XPlatformCloudKit.Tests.Services; | ||
using AsyncOAuth; | ||
using System.Security.Cryptography; | ||
|
||
namespace XPlatformCloudKit.Tests | ||
{ | ||
[TestClass] | ||
public class TwitterServiceTest | ||
{ | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext t) | ||
{ | ||
//Oauth Init | ||
OAuthUtility.ComputeHash = (key, buffer) => { using (var hmac = new HMACSHA1(key)) { return hmac.ComputeHash(buffer); } }; | ||
} | ||
|
||
[TestMethod] | ||
public async Task ValidateTwitterService() | ||
{ | ||
ServiceLocator.MessageService = new TestMessageService(); | ||
//Created @ https://apps.twitter.com, found under "manage api keys" | ||
AppSettings.TwitterConsumerKey = "F4OL4vtT0PidHiWuBaWePDEj8"; | ||
AppSettings.TwitterConsumerSecret = "GC7hETzCvSsGkCPgqN1fEVCBUsszk9wgZ5wt8kn8Dg2TWw05bE"; | ||
//In "manage api keys" scroll down to create access tokens | ||
AppSettings.TwitterAccessToken = "1395095078-OJQnXgyLvLAPOYwTP4r13yDMRK2lcWDZXouCZBd"; | ||
AppSettings.TwitterAccessSecret = "7Hb4bChKQNOXhYwKJtQq3X8Vt9NZeRbZAKr1R9UFwcpjx"; | ||
AppSettings.TwitterAddressCollection = new UrlSource[] | ||
{ | ||
new UrlSource {Url = "https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=pjdecarlo", Group = "PJDeCarlo"} | ||
}; | ||
var twitterService = new TwitterService(); | ||
|
||
var items = await twitterService.GetItems(); | ||
|
||
Assert.IsTrue(items.Count > 0, "Error: Zero items retrieved from Twitter Service"); | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
XPlatformCloudKit/XPlatformCloudKit.Tests/YoutubeServiceTest.cs
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,31 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Threading.Tasks; | ||
using XPlatformCloudKit.Models; | ||
using XPlatformCloudKit.DataServices; | ||
|
||
namespace XPlatformCloudKit.Tests | ||
{ | ||
[TestClass] | ||
public class YoutubeServiceTest | ||
{ | ||
[TestMethod] | ||
public async Task ValidYoutubeService() | ||
{ | ||
//Created @ https://code.google.com/apis/console, enable YouTube Data API v3 under APIs then click Credentials | ||
//Under Public API Access - click "Create New Key" | ||
AppSettings.YoutubePublicAPIKey = "AIzaSyCfyarRgBTEHzpC1IaTqdjhen01rRBR-ow"; | ||
AppSettings.YoutubeAddressCollection = new UrlSource [] | ||
{ | ||
new UrlSource {Url = "https://www.googleapis.com/youtube/v3/playlistItems?playlistId=PL0OTHVsGLN2medBm9k-VFtB6cvUbP9n6B&part=snippet&maxResults=50&fields=items%2CnextPageToken&key=" + AppSettings.YoutubePublicAPIKey, Group = "Youtube Playlist"} | ||
}; | ||
var youtubeService = new YoutubeService(); | ||
|
||
var items = await youtubeService.GetItems(); | ||
|
||
Assert.IsTrue(items.Count > 0, "Error: Zero items retrieved from Twitter Service"); | ||
Assert.AreEqual(200, items.Count); | ||
Assert.AreEqual("Candy Crush Saga Level 1", items[0].Title); | ||
} | ||
} | ||
} |
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