/main/tests/Ide.Tests/MonoDevelop.Ide.Projects/ResourcesTests.cs

https://github.com/directhex/monodevelop · C# · 85 lines · 40 code · 8 blank · 37 comment · 3 complexity · 5aefbf54831b7513b12dc10eada9648e MD5 · raw file

  1. //
  2. // ResourcesTests.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez <llsan@microsoft.com>
  6. //
  7. // Copyright (c) 2017 Microsoft
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using System.IO;
  28. using System.Linq;
  29. using System.Threading.Tasks;
  30. using MonoDevelop.Core;
  31. using MonoDevelop.Ide.CustomTools;
  32. using MonoDevelop.Projects;
  33. using NUnit.Framework;
  34. using UnitTests;
  35. namespace MonoDevelop.Ide.Projects
  36. {
  37. public class ResourcesTests: IdeTestBase
  38. {
  39. /// <summary>
  40. /// Tests that files generated from .resx files for .NET Core and .NET Standard
  41. /// projects use "typeof(Resources).GetTypeInfo().Assembly" instead of
  42. /// "typeof(Resources).Assembly". Without the GetTypeInfo the project will not
  43. /// compile with NET Core below version 2.0
  44. /// </summary>
  45. [Test]
  46. [TestCase("DotNetCoreProject")]
  47. [TestCase("NetStandardProject")]
  48. [Platform(Exclude = "Win")]
  49. public async Task BuildDotNetCoreProjectAfterGeneratingResources(string projectName)
  50. {
  51. FilePath solFile = Util.GetSampleProject("DotNetCoreResources", "DotNetCoreResources.sln");
  52. using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile)) {
  53. var p = (DotNetProject)sol.Items.FirstOrDefault (item => item.Name == projectName);
  54. var resourceFile = p.Files.FirstOrDefault (f => f.FilePath.FileName == "Resources.resx");
  55. var customToolResult = new SingleFileCustomToolResult ();
  56. await ResXFileCodeGenerator.GenerateFile (resourceFile, customToolResult, true);
  57. Assert.IsTrue (customToolResult.Success);
  58. // Running a restore for a .NET Core project can take a long time if
  59. // no packages are cached. So instead we just check the generated resource file.
  60. //var res = await p.RunTarget (Util.GetMonitor (), "Restore", ConfigurationSelector.Default);
  61. //Assert.AreEqual (0, res.BuildResult.Errors.Count);
  62. //res = await p.RunTarget (Util.GetMonitor (), "Build", ConfigurationSelector.Default);
  63. //Assert.AreEqual (0, res.BuildResult.Errors.Count);
  64. var generatedResourceFile = resourceFile.FilePath.ChangeExtension (".Designer.cs");
  65. bool foundLine = false;
  66. foreach (string line in File.ReadAllLines (generatedResourceFile)) {
  67. if (line.Contains ("typeof")) {
  68. string lineWithoutSpaces = line.Replace (" ", "");
  69. foundLine = lineWithoutSpaces.EndsWith ("typeof(Resources).GetTypeInfo().Assembly);", StringComparison.Ordinal);
  70. break;
  71. }
  72. }
  73. Assert.IsTrue (foundLine);
  74. }
  75. }
  76. }
  77. }