PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs

http://github.com/jagregory/fluent-nhibernate
C# | 74 lines | 61 code | 13 blank | 0 comment | 0 complexity | 0dfca826782794642fc9919c758ac616 MD5 | raw file
Possible License(s): BSD-3-Clause, CC-BY-SA-3.0, Apache-2.0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using FluentNHibernate.Mapping;
  5. using FluentNHibernate.MappingModel.Output;
  6. using Machine.Specifications;
  7. using Machine.Specifications.Model;
  8. using FluentAssertions;
  9. namespace FluentNHibernate.Specs.FluentInterface
  10. {
  11. public class when_generating_the_output_for_a_resolved_component_reference
  12. {
  13. Establish context = () =>
  14. {
  15. inline_component = new ClassMap<Target>();
  16. inline_component.Id(x => x.Id);
  17. inline_component.Component(x => x.ComponentProperty1, c => c.Map(x => x.Property));
  18. inline_component.Component(x => x.ComponentProperty2, c => c.Map(x => x.Property));
  19. external_component = new ComponentMap<Component>();
  20. external_component.Map(x => x.Property);
  21. reference_component = new ClassMap<Target>();
  22. reference_component.Id(x => x.Id);
  23. reference_component.Component(x => x.ComponentProperty1);
  24. reference_component.Component(x => x.ComponentProperty2);
  25. };
  26. Because of = () =>
  27. {
  28. inline_xml = render_xml(x => x.Add(inline_component));
  29. referenced_xml = render_xml(x =>
  30. {
  31. x.Add(reference_component);
  32. x.Add(external_component);
  33. });
  34. };
  35. It should_be_rendered_the_same_as_an_inline_component = () =>
  36. referenced_xml.Should().Be(inline_xml);
  37. private static string render_xml(Action<FluentNHibernate.PersistenceModel> addMappings)
  38. {
  39. var model = new FluentNHibernate.PersistenceModel();
  40. addMappings(model);
  41. var mappings = model.BuildMappings();
  42. var doc = new MappingXmlSerializer().Serialize(mappings.First());
  43. return doc.OuterXml;
  44. }
  45. private static ClassMap<Target> inline_component;
  46. private static ClassMap<Target> reference_component;
  47. private static ComponentMap<Component> external_component;
  48. private static string inline_xml;
  49. private static string referenced_xml;
  50. private class Target
  51. {
  52. public int Id { get; set;}
  53. public Component ComponentProperty1 { get; set; }
  54. public Component ComponentProperty2 { get; set; }
  55. }
  56. private class Component
  57. {
  58. public string Property { get; set; }
  59. }
  60. }
  61. }