Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 988336a

Browse files
committed
adding readme with release steps, and working through running tests locally instead of on device
1 parent 44e663a commit 988336a

10 files changed

+362
-218
lines changed

Android-Libtester/Android-Libtester.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
<Compile Include="Properties\AssemblyInfo.cs" />
5757
<Compile Include="TestClient.cs" />
5858
<Compile Include="TestUser.cs" />
59-
<Compile Include="TestAppData.cs" />
6059
<Compile Include="ReflectionHelper.cs" />
6160
<Compile Include="LinqBuilderTest.cs" />
62-
<Compile Include="MyEntity.cs" />
6361
<Compile Include="TestIntAppData.cs" />
62+
<Compile Include="MyEntity.cs" />
63+
<Compile Include="TestAppData.cs" />
6464
</ItemGroup>
6565
<ItemGroup>
6666
<None Include="Resources\AboutResources.txt" />

LibTester/DefaultContext.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LinqExtender;
4+
using Ast = LinqExtender.Ast;
5+
6+
namespace LibTester
7+
{
8+
/// <summary>
9+
/// Default context to be queried.
10+
/// </summary>
11+
/// <typeparam name="T">Target type</typeparam>
12+
public class DefaultContext<T> : ExpressionVisitor, IQueryContext<T>
13+
{
14+
/// <summary>
15+
/// Invoked during execution of the query , with the
16+
/// pre populated expression tree.
17+
/// </summary>
18+
/// <param name="expression">Target expression block</param>
19+
/// <returns>Expected result</returns>
20+
public IEnumerable<T> Execute(Ast.Expression expression)
21+
{
22+
//TODO: Visit the extender expression to build your meta
23+
24+
this.Visit(expression);
25+
26+
///TOOD: return your result.
27+
return null;
28+
}
29+
}
30+
}

LibTester/ExpressionVisitor.cs

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using LinqExtender;
3+
using Ast = LinqExtender.Ast;
4+
5+
6+
namespace LibTester
7+
{
8+
public class ExpressionVisitor
9+
{
10+
internal Ast.Expression Visit(Ast.Expression expression)
11+
{
12+
switch (expression.CodeType)
13+
{
14+
case CodeType.BlockExpression:
15+
return VisitBlockExpression((Ast.BlockExpression)expression);
16+
case CodeType.TypeExpression:
17+
return VisitTypeExpression((Ast.TypeExpression)expression);
18+
case CodeType.LambdaExpresion:
19+
return VisitLambdaExpression((Ast.LambdaExpression)expression);
20+
case CodeType.LogicalExpression:
21+
return VisitLogicalExpression((Ast.LogicalExpression)expression);
22+
case CodeType.BinaryExpression:
23+
return VisitBinaryExpression((Ast.BinaryExpression)expression);
24+
case CodeType.LiteralExpression:
25+
return VisitLiteralExpression((Ast.LiteralExpression)expression);
26+
case CodeType.MemberExpression:
27+
return VisitMemberExpression((Ast.MemberExpression)expression);
28+
case CodeType.OrderbyExpression:
29+
return VisitOrderbyExpression((Ast.OrderbyExpression)expression);
30+
}
31+
32+
throw new ArgumentException("Expression type is not supported");
33+
}
34+
35+
public virtual Ast.Expression VisitTypeExpression(Ast.TypeExpression typeExpression)
36+
{
37+
return typeExpression;
38+
}
39+
40+
public virtual Ast.Expression VisitBlockExpression(Ast.BlockExpression blockExpression)
41+
{
42+
foreach (var expression in blockExpression.Expressions)
43+
this.Visit(expression);
44+
45+
return blockExpression;
46+
}
47+
48+
public virtual Ast.Expression VisitLogicalExpression(Ast.LogicalExpression expression)
49+
{
50+
this.Visit(expression.Left);
51+
this.Visit(expression.Right);
52+
return expression;
53+
}
54+
55+
public virtual Ast.Expression VisitLambdaExpression(Ast.LambdaExpression expression)
56+
{
57+
if (expression.Body != null)
58+
return this.Visit(expression.Body);
59+
return expression;
60+
}
61+
62+
public virtual Ast.Expression VisitBinaryExpression(Ast.BinaryExpression expression)
63+
{
64+
this.Visit(expression.Left);
65+
this.Visit(expression.Right);
66+
67+
return expression;
68+
}
69+
70+
public virtual Ast.Expression VisitMemberExpression(Ast.MemberExpression expression)
71+
{
72+
return expression;
73+
}
74+
75+
public virtual Ast.Expression VisitLiteralExpression(Ast.LiteralExpression expression)
76+
{
77+
return expression;
78+
}
79+
80+
public virtual Ast.Expression VisitOrderbyExpression(Ast.OrderbyExpression expression)
81+
{
82+
return expression;
83+
}
84+
85+
}
86+
}

LibTester/LibTester.csproj

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{F305304B-081C-44B5-BE53-F24A07BCDC56}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<RootNamespace>LibTester</RootNamespace>
9+
<AssemblyName>LibTester</AssemblyName>
10+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<DebugType>full</DebugType>
15+
<Optimize>false</Optimize>
16+
<OutputPath>bin\Debug</OutputPath>
17+
<DefineConstants>DEBUG;</DefineConstants>
18+
<ErrorReport>prompt</ErrorReport>
19+
<WarningLevel>4</WarningLevel>
20+
<ConsolePause>false</ConsolePause>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
<DebugType>full</DebugType>
24+
<Optimize>true</Optimize>
25+
<OutputPath>bin\Release</OutputPath>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<ConsolePause>false</ConsolePause>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<Reference Include="System" />
32+
<Reference Include="nunit.framework">
33+
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
34+
</Reference>
35+
<Reference Include="LinqExtender">
36+
<HintPath>..\packages\LinqExtender.3.0.1\lib\LinqExtender.dll</HintPath>
37+
</Reference>
38+
</ItemGroup>
39+
<ItemGroup>
40+
<Compile Include="Test.cs" />
41+
<Compile Include="TestAppData.cs" />
42+
<Compile Include="ExpressionVisitor.cs" />
43+
<Compile Include="DefaultContext.cs" />
44+
<Compile Include="MyEntity.cs" />
45+
</ItemGroup>
46+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
47+
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
48+
<ItemGroup>
49+
<None Include="packages.config" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<ProjectReference Include="..\Kinvey-Xamarin\Kinvey-Xamarin.csproj">
53+
<Project>{6644D98D-026B-48E9-95A3-61C4D98D82E7}</Project>
54+
<Name>Kinvey-Xamarin</Name>
55+
</ProjectReference>
56+
<ProjectReference Include="..\Kinvey-Utils\Kinvey-Utils.csproj">
57+
<Project>{444456B1-5B55-48D6-9637-00ADCA92B7C9}</Project>
58+
<Name>Kinvey-Utils</Name>
59+
</ProjectReference>
60+
<ProjectReference Include="..\RestSharp.Portable\RestSharp.Portable.csproj">
61+
<Project>{BA2352E1-CB07-4795-A2EB-F70720B2BBC9}</Project>
62+
<Name>RestSharp.Portable</Name>
63+
</ProjectReference>
64+
</ItemGroup>
65+
</Project>

LibTester/MyEntity.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using RestSharp;
3+
4+
5+
namespace AndroidLibtester
6+
{
7+
public class MyEntity
8+
{
9+
10+
public MyEntity(string id){
11+
this.ID = id;
12+
}
13+
14+
public MyEntity(){}
15+
16+
public string ID {get; set;}
17+
18+
19+
public string Name{get;set;}
20+
21+
22+
public string Email{get;set;}
23+
24+
25+
public string lowercasetest{get;set;}
26+
27+
28+
public bool IsAvailable{get; set;}
29+
30+
}
31+
}
32+

LibTester/Test.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using NUnit.Framework;
2+
using System;
3+
4+
namespace LibTester
5+
{
6+
[TestFixture ()]
7+
public class Test
8+
{
9+
[Test ()]
10+
public void TestCase ()
11+
{
12+
// Assert.True (false);
13+
}
14+
}
15+
}
16+

LibTester/TestAppData.cs

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using NUnit.Framework;
3+
using KinveyXamarin;
4+
using System.Reflection;
5+
using RestSharp;
6+
using LinqExtender;
7+
8+
namespace AndroidLibtester
9+
{
10+
[TestFixture]
11+
public class TestAppData
12+
{
13+
14+
string appkey = "123";
15+
string appsecret = "123";
16+
Client testClient;
17+
AppData<MyEntity> testData;
18+
string myCollection = "myCollection";
19+
20+
[SetUp]
21+
public void Setup ()
22+
{
23+
testClient = new Client.Builder (appkey, appsecret).build ();
24+
testData = testClient.AppData<MyEntity> (myCollection, typeof(MyEntity));
25+
}
26+
27+
28+
[TearDown]
29+
public void Tear ()
30+
{
31+
}
32+
33+
34+
[Test()]
35+
public void TestGetEntity()
36+
{
37+
38+
string someID = "some id";
39+
AppData<MyEntity>.GetEntityRequest req = testData.GetEntityBlocking (someID);
40+
41+
RestRequest restReq = req.BuildRestRequest ();
42+
Assert.True (restReq.Method == Method.GET);
43+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
44+
return p.Type == ParameterType.UrlSegment;
45+
}).Count >= 2);
46+
47+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
48+
return p.Type == ParameterType.HttpHeader;
49+
}).Count >= 3);
50+
51+
}
52+
53+
[Test()]
54+
public void TestGetAll()
55+
{
56+
AppData<MyEntity>.GetRequest req = testData.GetBlocking ();
57+
58+
RestRequest restReq = req.BuildRestRequest ();
59+
Assert.True (restReq.Method == Method.GET);
60+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
61+
return p.Type == ParameterType.UrlSegment;
62+
}).Count >= 1);
63+
64+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
65+
return p.Type == ParameterType.HttpHeader;
66+
}).Count >= 3);
67+
68+
}
69+
70+
[Test()]
71+
public void TestSaveEntity()
72+
{
73+
74+
AppData<MyEntity>.SaveRequest req = testData.SaveBlocking (new MyEntity());
75+
76+
RestRequest restReq = req.BuildRestRequest ();
77+
Assert.True (restReq.Method == Method.POST);
78+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
79+
return p.Type == ParameterType.UrlSegment;
80+
}).Count >= 1);
81+
82+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
83+
return p.Type == ParameterType.HttpHeader;
84+
}).Count >= 3);
85+
86+
}
87+
88+
[Test()]
89+
public void TestDeleteEntity()
90+
{
91+
string someID = "some id";
92+
AppData<MyEntity>.DeleteRequest req = testData.DeleteBlocking (someID);
93+
94+
RestRequest restReq = req.BuildRestRequest ();
95+
Assert.True (restReq.Method == Method.DELETE);
96+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
97+
return p.Type == ParameterType.UrlSegment;
98+
}).Count >= 1);
99+
100+
Assert.True (restReq.Parameters.FindAll (delegate(Parameter p){
101+
return p.Type == ParameterType.HttpHeader;
102+
}).Count >= 3);
103+
104+
}
105+
106+
107+
}
108+
}
109+

LibTester/packages.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="LinqExtender" version="3.0.1" targetFramework="net45" />
4+
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
5+
<package id="NUnit" version="2.6.3" targetFramework="net45" />
6+
</packages>

0 commit comments

Comments
 (0)