Skip to content

Commit

Permalink
Merge pull request #4 from Wintellect/fsharp-tests-demo
Browse files Browse the repository at this point in the history
Add solution for using F# for unit testing a PCL
  • Loading branch information
jwood803 committed Aug 13, 2015
2 parents 0800492 + d003aa5 commit e49964a
Show file tree
Hide file tree
Showing 56 changed files with 1,148 additions and 18 deletions.
19 changes: 4 additions & 15 deletions PhoneWordFSharp/PhoneWordFSharp.Droid/PhoneWordFSharp.Droid.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{F2A71F9B-5D33-465A-A702-920D77279786}</ProjectTypeGuids>
<ProjectGuid>de4ae3a4-bd59-4e63-8b3b-d2f44ed80386</ProjectGuid>
<ProjectGuid>{DE4AE3A4-BD59-4E63-8B3B-D2F44ED80386}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>PhoneWordFSharp.Droid</RootNamespace>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
Expand All @@ -22,10 +22,10 @@
<Name>PhoneWordFSharp.Droid</Name>
<NuGetPackageImportStamp>db602b22</NuGetPackageImportStamp>
<SelectedDevice>XAP - Nexus 4 (KitKat) - API 19</SelectedDevice>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
Expand All @@ -47,6 +47,8 @@
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<ConsolePause>false</ConsolePause>
<Tailcalls>true</Tailcalls>
<DefineConstants>
</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.FSharp.targets" />
<ItemGroup>
Expand All @@ -66,7 +68,6 @@
<ItemGroup>
<Reference Include="FormsViewGroup">
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core">
Expand All @@ -78,32 +79,20 @@
<Reference Include="System.Core" />
<Reference Include="Xamarin.Android.Support.v4">
<HintPath>..\packages\Xamarin.Android.Support.v4.21.0.3.0\lib\MonoAndroid10\Xamarin.Android.Support.v4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Platform.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Platform.Android">
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\packages\Xamarin.Forms.1.4.2.6359\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PhoneWordFSharp.Core\PhoneWordFSharp.Core.fsproj">
<Name>PhoneWordFSharp.Core</Name>
<Project>{c748221e-7d7d-46b1-a50d-98a8ce92c0b6}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<Import Project="..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="PhoneWordFSharp.Droid.PhoneWordFSharp.Droid" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="19" />
<application android:label="PhoneWordFSharp.Droid" android:icon="@drawable/Icon"></application>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="PhoneWordFSharp.Droid">
<uses-sdk />
<application android:label="PhoneWordFSharp.Droid">
</application>
</manifest>
12 changes: 12 additions & 0 deletions UITestDemo/Add.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace UITestDemo
{
public static class Add
{
public static int AddItems(int a, int b)
{
return a + b;
}
}
}
49 changes: 49 additions & 0 deletions UITestDemo/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Xamarin.Forms;
using System.Threading.Tasks;

namespace UITestDemo
{
public class App : Application
{
INavigation _navigation;

new public static App Current {
get {
return (App)Application.Current;
}
}

public App()
{
var navRoot = new NavigationPage(new MainPage() { Title = "Main Page" });

_navigation = navRoot.Navigation;

MainPage = navRoot;
}

public async Task NavigateToDetailPage()
{
var page = new DetailPage();

page.SetValue(NavigationPage.BackButtonTitleProperty, "Back");

await _navigation.PushAsync(page);
}

protected override void OnStart()
{
// Handle when your app starts
}

protected override void OnSleep()
{
// Handle when your app sleeps
}

protected override void OnResume()
{
// Handle when your app resumes
}
}
}
8 changes: 8 additions & 0 deletions UITestDemo/DetailPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="UITestDemo.DetailPage">

<Label HorizontalOptions="Center" VerticalOptions="Center" Text="Detail page" />
</ContentPage>
12 changes: 12 additions & 0 deletions UITestDemo/DetailPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace UITestDemo
{
public partial class DetailPage : ContentPage
{
public DetailPage()
{
InitializeComponent();
}
}
}
19 changes: 19 additions & 0 deletions UITestDemo/Droid/Assets/AboutAssets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".

These files will be deployed with your package and will be accessible using Android's
AssetManager, like this:

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

InputStream input = Assets.Open ("my_asset.txt");
}
}

Additionally, some Android functions will automatically load asset files:

Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
26 changes: 26 additions & 0 deletions UITestDemo/Droid/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace UITestDemo.Droid
{
[Activity(Label = "UITestDemo.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);

LoadApplication(new App());
}
}
}

6 changes: 6 additions & 0 deletions UITestDemo/Droid/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.uitestdemo">
<uses-sdk android:minSdkVersion="15" />
<application android:label="UITestDemo">
</application>
</manifest>
28 changes: 28 additions & 0 deletions UITestDemo/Droid/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Android.App;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("UITestDemo.Droid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("jonwood")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

44 changes: 44 additions & 0 deletions UITestDemo/Droid/Resources/AboutResources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.

For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:

Resources/
drawable/
icon.png

layout/
main.axml

values/
strings.xml

In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:

public class R {
public class drawable {
public const int icon = 0x123;
}

public class layout {
public const int main = 0x456;
}

public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}

You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.
82 changes: 82 additions & 0 deletions UITestDemo/Droid/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UITestDemo/Droid/Resources/drawable/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e49964a

Please sign in to comment.