From 27d24bff69508165cdc16797e4781e36bd173af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Fri, 17 Jun 2016 14:38:51 +0200 Subject: [TextTemplatingUnitTest] Added unit test for resolving reference and fixed TemplateGeneratorTest --- .../DummyTemplateGenerator.cs | 44 ++++++++++++++++++++++ .../Mono.TextTemplating.Tests/GenerationTests.cs | 11 +++++- .../Mono.TextTemplating.Tests.csproj | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 main/src/addins/TextTemplating/Mono.TextTemplating.Tests/DummyTemplateGenerator.cs (limited to 'main/src/addins/TextTemplating') diff --git a/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/DummyTemplateGenerator.cs b/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/DummyTemplateGenerator.cs new file mode 100644 index 0000000000..6ddd9d9a41 --- /dev/null +++ b/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/DummyTemplateGenerator.cs @@ -0,0 +1,44 @@ +// +// DummyTemplateGenerator.cs +// +// Author: +// David Karlaš +// +// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Reflection; + +namespace Mono.TextTemplating.Tests +{ + public class DummyTemplateGenerator : TemplateGenerator + { + protected override string ResolveAssemblyReference (string assemblyReference) + { + var assemblyName = new AssemblyName (assemblyReference).Name; + if (assemblyName == typeof (Uri).Assembly.GetName ().Name) + return typeof (Uri).Assembly.Location;//System.dll + else if (assemblyName == typeof (System.Linq.Enumerable).Assembly.GetName ().Name) + return typeof (System.Linq.Enumerable).Assembly.Location;//System.Core.dll + return base.ResolveAssemblyReference (assemblyReference); + } + } +} + diff --git a/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/GenerationTests.cs b/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/GenerationTests.cs index 7558e37a13..fb26f8d23d 100644 --- a/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/GenerationTests.cs +++ b/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/GenerationTests.cs @@ -40,12 +40,21 @@ namespace Mono.TextTemplating.Tests [Test] public void TemplateGeneratorTest () { - var gen = new TemplateGenerator (); + var gen = new DummyTemplateGenerator (); string tmp = null; gen.ProcessTemplate (null, "<#@ template language=\"C#\" #>", ref tmp, out tmp); Assert.AreEqual (0, gen.Errors.Count, "ProcessTemplate"); } + [Test] + public void ImportReferencesTest () + { + var gen = new DummyTemplateGenerator (); + string tmp = null; + gen.ProcessTemplate (null, "<#@ assembly name=\"System.dll\" #>\n<#@ assembly name=\"System.Core.dll\" #>", ref tmp, out tmp); + Assert.AreEqual (0, gen.Errors.Count, "ImportReferencesTest"); + } + [Test] public void Generate () { diff --git a/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/Mono.TextTemplating.Tests.csproj b/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/Mono.TextTemplating.Tests.csproj index ed523be4cf..6cf7db406b 100644 --- a/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/Mono.TextTemplating.Tests.csproj +++ b/main/src/addins/TextTemplating/Mono.TextTemplating.Tests/Mono.TextTemplating.Tests.csproj @@ -44,6 +44,7 @@ + -- cgit v1.2.3