public void GetDynamicMemberNames_should_contain_properties() { var context = new HxlTemplateContext(new { a = "", b = "" }); Assert.SetEqual(new[] { "a", "b", "TemplateFactory", "Data", "DataProviders", "Parent" }, context.GetDynamicMemberNames().ToArray()); }
public void TryGetMember_should_obtain_owner_property() { var context = new HxlTemplateContext(new { a = "hello", }); var binder = new FakeGetMemberBinder("a"); object result; Assert.True(context.TryGetMember(binder, out result)); Assert.Equal("hello", result); }
protected void GenerateAndAssert() { // TODO Stage the stream context fixture instead to avoid strange names var type = this.Assembly.GetTypes().Single(t => t.Name.EndsWith("input_hxl", StringComparison.Ordinal)); var template = (HxlTemplate)Activator.CreateInstance(type); var expected = ExpectedHtml; string actual = null; try { HxlTemplateContext context = HxlTemplateContext.WithData(null, this.Data); var factory = new HxlTemplateFactoryCollection(); factory.AddAssembly(this.Assembly); context.TemplateFactory = factory; actual = this.ActualHtml = template.TransformText(context); } catch (Exception ex) { string tempFile2 = WriteCompilerOutput("<error>", expected); Assert.Fail("Failed transforming text: {0} - {1}", tempFile2, ex); } // TODO Assert on generated code // TODO Whitespace normalization should be an option because future tests will need to look for it actual = NormalizeForComparison(actual); expected = NormalizeForComparison(expected); bool result = string.Equals((actual), (expected)); if (!result) { string tempFile = WriteCompilerOutput(actual, expected); string message = string.Format("Comparison failed: {0}", tempFile); // Console.WriteLine(message); Assert.Equal(expected, actual); } // Check lines of generated source foreach (var m in ExpectedSource) { if (!this.GeneratedSource.Contains(m)) { string temp = WriteCompilerOutput(actual, expected); Assert.Fail("Generated source missing line: {0} ({1})", m, temp); } } // Cache the output WriteCompilerOutput(actual, expected); }