|
| 1 | +using NUnit.Framework; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.IO; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using Umbraco.Core.Composing; |
| 9 | +using Umbraco.ModelsBuilder.Building; |
| 10 | +using Umbraco.ModelsBuilder.Configuration; |
| 11 | + |
| 12 | +namespace Umbraco.ModelsBuilder.Tests |
| 13 | +{ |
| 14 | + [TestFixture] |
| 15 | + public class BuilderCompilerTests |
| 16 | + { |
| 17 | + private string _tempDir; |
| 18 | + |
| 19 | + [SetUp] |
| 20 | + public void Setup() |
| 21 | + { |
| 22 | + _tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
| 23 | + Directory.CreateDirectory(_tempDir); |
| 24 | + |
| 25 | + Current.Reset(); |
| 26 | + Current.UnlockConfigs(); |
| 27 | + Current.Configs.Add(() => new Config()); |
| 28 | + } |
| 29 | + |
| 30 | + [TearDown] |
| 31 | + public void TearDown() |
| 32 | + { |
| 33 | + if (_tempDir != null && Directory.Exists(_tempDir)) |
| 34 | + Directory.Delete(_tempDir, true); |
| 35 | + } |
| 36 | + |
| 37 | + [Test] |
| 38 | + public void CanCompile() |
| 39 | + { |
| 40 | + var type1 = new TypeModel |
| 41 | + { |
| 42 | + Id = 1, |
| 43 | + Alias = "type1", |
| 44 | + ClrName = "Type1", |
| 45 | + ParentId = 0, |
| 46 | + BaseType = null, |
| 47 | + ItemType = TypeModel.ItemTypes.Content, |
| 48 | + }; |
| 49 | + |
| 50 | + var types = new[] { type1 }; |
| 51 | + |
| 52 | + var code = new Dictionary<string, string>(); |
| 53 | + |
| 54 | + var parseResult = new CodeParser().Parse(code); |
| 55 | + var builder = new TextBuilder(types, parseResult); |
| 56 | + var btypes = builder.TypeModels; |
| 57 | + var btype0 = btypes[0]; |
| 58 | + |
| 59 | + var sb = new StringBuilder(); |
| 60 | + builder.Generate(sb, btype0); |
| 61 | + |
| 62 | + var text = sb.ToString(); |
| 63 | + |
| 64 | + var compiler = new Compiler(); |
| 65 | + compiler.Compile("Whatever", new Dictionary<string, string> { { "code", text } }, _tempDir); |
| 66 | + Assert.IsTrue(File.Exists(Path.Combine(_tempDir, "Whatever.dll"))); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments