Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ public class InfoPlistGeneratorTests {
[Test]
public void GenerateCodeNullTemplateFile ()
{
Assert.ThrowsAsync<ArgumentNullException> (() =>
InfoPlistGenerator.GenerateCodeAsync (null, "Project Name"));
Assert.Throws<ArgumentNullException> (() =>
InfoPlistGenerator.GenerateCode (null, "Project Name"));
}

[Test]
public void GenerateCodeNullProjectName ()
{
var tmp = Path.GetTempFileName ();
File.WriteAllText (tmp, "Hello");
using (var stream = new FileStream (tmp, FileMode.Open)) {
Assert.ThrowsAsync<ArgumentNullException> (() => InfoPlistGenerator.GenerateCodeAsync (stream, null));
}

File.Delete (tmp);
Assert.Throws<ArgumentNullException> (() => InfoPlistGenerator.GenerateCode ("Hello", null));
}

[Test]
Expand All @@ -39,7 +33,7 @@ public async Task GenerateCode ()
await file.WriteAsync (fakeTemplate);
}

var result = await InfoPlistGenerator.GenerateCodeAsync (File.OpenRead (templatePath), projectName);
var result = InfoPlistGenerator.GenerateCode (File.ReadAllText (templatePath), projectName);
try {
StringAssert.DoesNotContain (InfoPlistGenerator.ApplicationNameReplacement, result);
StringAssert.DoesNotContain (InfoPlistGenerator.IndentifierReplacement, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@ public class InfoPlistGenerator {
public static readonly string IndentifierReplacement = "%BUNDLE INDENTIFIER%";
public static readonly string WatchAppIndentifierReplacement = "%WATCHAPP INDENTIFIER%";

public static async Task<string> GenerateCodeAsync (Stream template, string projectName)
public static string GenerateCode (string template, string projectName)
{
if (template == null)
throw new ArgumentNullException (nameof (template));
if (projectName == null)
throw new ArgumentNullException (nameof (projectName));
// got the lines we want to add, read the template and substitute
using (var reader = new StreamReader (template)) {
var result = await reader.ReadToEndAsync ();
result = result.Replace (ApplicationNameReplacement, projectName);
result = result.Replace (IndentifierReplacement, $"com.xamarin.bcltests.{projectName}");
result = result.Replace (WatchAppIndentifierReplacement, $"com.xamarin.bcltests.{projectName}.container");
return result;
}
var result = template;
result = result.Replace (ApplicationNameReplacement, projectName);
result = result.Replace (IndentifierReplacement, $"com.xamarin.bcltests.{projectName}");
result = result.Replace (WatchAppIndentifierReplacement, $"com.xamarin.bcltests.{projectName}.container");
return result;
}

// Generates the code for the type registration using the give path to the template to use
public static string GenerateCode (Stream template, string projectName) => GenerateCodeAsync (template, projectName).Result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public static class RegisterTypeGenerator {
static readonly string KeysReplacement = "%KEY VALUES%";
static readonly string IsxUnitReplacement = "%IS XUNIT%";

public static async Task<string> GenerateCodeAsync ((string FailureMessage, Dictionary<string, TypeDefinition> Types) typeRegistration, bool isXunit,
Stream template)
public static string GenerateCode ((string FailureMessage, Dictionary<string, TypeDefinition> Types) typeRegistration, bool isXunit, string template)
{
var importStringBuilder = new StringBuilder ();
var keyValuesStringBuilder = new StringBuilder ();
Expand All @@ -35,13 +34,11 @@ public static async Task<string> GenerateCodeAsync ((string FailureMessage, Dict
}

// got the lines we want to add, read the template and substitute
using (var reader = new StreamReader (template)) {
var result = await reader.ReadToEndAsync ();
result = result.Replace (UsingReplacement, importStringBuilder.ToString ());
result = result.Replace (KeysReplacement, keyValuesStringBuilder.ToString ());
result = result.Replace (IsxUnitReplacement, isXunit ? "true" : "false");
return result;
}
var result = template;
result = result.Replace (UsingReplacement, importStringBuilder.ToString ());
result = result.Replace (KeysReplacement, keyValuesStringBuilder.ToString ());
result = result.Replace (IsxUnitReplacement, isXunit ? "true" : "false");
return result;
}
}
}
Loading