-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd62d2f
commit d3b1997
Showing
5 changed files
with
161 additions
and
1 deletion.
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
69 changes: 69 additions & 0 deletions
69
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.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,69 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Xamarin.ProjectTools; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Build.Framework; | ||
using System.Text; | ||
using Xamarin.Android.Tasks; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Xamarin.Android.Build.Tests { | ||
|
||
[TestFixture] | ||
[Parallelizable (ParallelScope.Children)] | ||
public class GetDependenciesTest : BaseTest { | ||
|
||
[Test] | ||
public void ManifestFileDoesNotExist () | ||
{ | ||
IBuildEngine engine = new MockBuildEngine (TestContext.Out); | ||
var task = new CalculateProjectDependencies { | ||
BuildEngine = engine | ||
}; | ||
|
||
task.BuildToolsVersion = "26.0.1"; | ||
task.TargetFrameworkVersion = "v8.0"; | ||
task.ManifestFile = new TaskItem ("AndroidManifest.xml"); | ||
task.Execute (); | ||
Assert.IsNotNull (task.Dependencies); | ||
Assert.AreEqual (4, task.Dependencies.Length); | ||
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tool" && x.GetMetadata ("Version") == "26.0.1"), | ||
"Dependencies should contains a build-tool version 26.0.1"); | ||
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform" && x.GetMetadata ("Version") == "26"), | ||
"Dependencies should contains a platform version 26"); | ||
} | ||
|
||
[Test] | ||
public void ManifestFileExists () | ||
{ | ||
IBuildEngine engine = new MockBuildEngine (TestContext.Out); | ||
var task = new CalculateProjectDependencies { | ||
BuildEngine = engine | ||
}; | ||
|
||
var path = Path.Combine (Root, "temp", TestName); | ||
Directory.CreateDirectory (path); | ||
var manifestFile = Path.Combine (path, "AndroidManifest.xml"); | ||
File.WriteAllText (manifestFile, @"<?xml version='1.0' ?> | ||
<manifest xmlns:android='http://schemas.android.com/apk/res/android' android:versionCode='1' android:versionName='1.0' package='Mono.Android_Tests'> | ||
<uses-sdk android:minSdkVersion='10' /> | ||
</manifest>"); | ||
|
||
task.BuildToolsVersion = "26.0.1"; | ||
task.TargetFrameworkVersion = "v8.0"; | ||
task.ManifestFile = new TaskItem (manifestFile); | ||
Assert.IsTrue(task.Execute ()); | ||
Assert.IsNotNull (task.Dependencies); | ||
Assert.AreEqual (5, task.Dependencies.Length); | ||
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tool" && x.GetMetadata ("Version") == "26.0.1"), | ||
"Dependencies should contain a build-tool version 26.0.1"); | ||
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform" && x.GetMetadata ("Version") == "26"), | ||
"Dependencies should contain a platform version 26"); | ||
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform" && x.GetMetadata ("Version") == "10"), | ||
"Dependencies should contain a platform version 10"); | ||
|
||
Directory.Delete (path, recursive: true); | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...amarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/MockBuildEngine.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,84 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Xamarin.Android.Build.Tests { | ||
public class MockBuildEngine : IBuildEngine, IBuildEngine2, IBuildEngine3, IBuildEngine4 { | ||
public MockBuildEngine (TextWriter output) | ||
{ | ||
this.Output = output; | ||
} | ||
|
||
private TextWriter Output { get; } | ||
|
||
int IBuildEngine.ColumnNumberOfTaskNode => -1; | ||
|
||
bool IBuildEngine.ContinueOnError => false; | ||
|
||
int IBuildEngine.LineNumberOfTaskNode => -1; | ||
|
||
string IBuildEngine.ProjectFileOfTaskNode => "this.xml"; | ||
|
||
bool IBuildEngine2.IsRunningMultipleNodes => false; | ||
|
||
bool IBuildEngine.BuildProjectFile (string projectFileName, string [] targetNames, IDictionary globalProperties, IDictionary targetOutputs) => true; | ||
|
||
void IBuildEngine.LogCustomEvent (CustomBuildEventArgs e) | ||
{ | ||
this.Output.WriteLine ($"Custom: {e.Message}"); | ||
} | ||
|
||
void IBuildEngine.LogErrorEvent (BuildErrorEventArgs e) | ||
{ | ||
this.Output.WriteLine ($"Error: {e.Message}"); | ||
} | ||
|
||
void IBuildEngine.LogMessageEvent (BuildMessageEventArgs e) | ||
{ | ||
this.Output.WriteLine ($"Message: {e.Message}"); | ||
} | ||
|
||
void IBuildEngine.LogWarningEvent (BuildWarningEventArgs e) | ||
{ | ||
this.Output.WriteLine ($"Warning: {e.Message}"); | ||
} | ||
|
||
private Dictionary<object, object> Tasks = new Dictionary<object, object> (); | ||
|
||
void IBuildEngine4.RegisterTaskObject (object key, object obj, RegisteredTaskObjectLifetime lifetime, bool allowEarlyCollection) | ||
{ | ||
Tasks.Add (key, obj); | ||
} | ||
|
||
object IBuildEngine4.GetRegisteredTaskObject (object key, RegisteredTaskObjectLifetime lifetime) | ||
{ | ||
return null; | ||
} | ||
|
||
object IBuildEngine4.UnregisterTaskObject (object key, RegisteredTaskObjectLifetime lifetime) | ||
{ | ||
var obj = Tasks [key]; | ||
Tasks.Remove (key); | ||
return obj; | ||
} | ||
|
||
BuildEngineResult IBuildEngine3.BuildProjectFilesInParallel (string [] projectFileNames, string [] targetNames, IDictionary [] globalProperties, IList<string> [] removeGlobalProperties, string [] toolsVersion, bool returnTargetOutputs) | ||
{ | ||
throw new NotImplementedException (); | ||
} | ||
|
||
void IBuildEngine3.Yield () { } | ||
|
||
void IBuildEngine3.Reacquire () { } | ||
|
||
bool IBuildEngine2.BuildProjectFile (string projectFileName, string [] targetNames, IDictionary globalProperties, IDictionary targetOutputs, string toolsVersion) => true; | ||
|
||
bool IBuildEngine2.BuildProjectFilesInParallel (string [] projectFileNames, string [] targetNames, IDictionary [] globalProperties, IDictionary [] targetOutputsPerProject, string [] toolsVersion, bool useResultsCache, bool unloadProjectsOnCompletion) => true; | ||
} | ||
} |
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