Esempio n. 1
0
        public void Can_map_eventsource_method()
        {
            var root = RDom.CSharp.Load(csharpCode);

            Assert.IsNotNull(root, "Root is null");
            var cfMethod = root.Namespaces.First().Classes.First().Methods.First();

            Assert.IsNotNull(cfMethod, "cfClass is null");
            var eventSourceType = typeof(CodeFirstEventSource);
            var classMapping    = TargetMapping.DeriveMapping("testEventSource", "test", eventSourceType.GetTypeInfo()) as TargetClassMapping;

            Assert.IsNotNull(classMapping, "classMapping is null");
            var methodMapping = classMapping.Children.First();

            Assert.IsNotNull(methodMapping, "methodMapping is null");
            var provider = new CodeFirst.Provider.ServiceProvider();
            var mapper   = new CodeFirstMapper2 <CodeFirstEvent>(provider);
            var newObj   = mapper.Map(methodMapping, cfMethod, null);
            var newEvent = newObj as CodeFirstEvent;

            Assert.IsNotNull(newObj);
            Assert.IsNotNull(newEvent);
            CheckEvent(newEvent,
                       name: "foo",
                       version: 2,
                       keywords: (EventKeywords)3);

            Assert.AreEqual(2, newEvent.Parameters.Count());
        }
Esempio n. 2
0
        public void Can_map_eventsource_parameter()
        {
            var root = RDom.CSharp.Load(csharpCode);

            Assert.IsNotNull(root, "Root is null");
            var cfParameter = root.Namespaces.First().Classes.First().Methods.First().Parameters.First();

            Assert.IsNotNull(cfParameter, "cfParameter is null");
            var eventSourceType = typeof(CodeFirstEventSource);
            var classMapping    = TargetMapping.DeriveMapping("testEventSource", "test", eventSourceType.GetTypeInfo()) as TargetClassMapping;

            Assert.IsNotNull(classMapping, "classMapping is null");
            var paramterMapping = classMapping.Children.First().Children.First();

            Assert.IsNotNull(paramterMapping, "paramterMapping is null");
            var provider     = new CodeFirst.Provider.ServiceProvider();
            var mapper       = new CodeFirstMapper2 <CodeFirstEventParam>(provider);
            var newObj       = mapper.Map(paramterMapping, cfParameter, null);
            var newParameter = newObj as CodeFirstEventParam;

            Assert.IsNotNull(newObj);
            Assert.IsNotNull(newParameter);
            CheckEventParameter(newParameter,
                                name: "Bar",
                                typeName: "Int32");
        }
        public void Can_map_prop_changed_class()
        {
            var root = RDom.CSharp.Load(@"
            namespace CodeFirstTest
            {
            /// <summary>
            /// This is the class
            /// </summary>
            public class Customer
            {   }
            }");
             Assert.IsNotNull(root, "Root is null");
             var cfClass = root.Namespaces.First().Classes.First();
             Assert.IsNotNull(cfClass, "cfClass is null");
             var propertyType = typeof(CodeFirstClass);
             var classMapping = TargetMapping.DeriveMapping("testPropChanged", "test", propertyType.GetTypeInfo()) as TargetClassMapping;
             var provider = new CodeFirst.Provider.ServiceProvider();
             var mapper = new CodeFirstMapper2<CodeFirstClass>(provider);
             var newObj = mapper.Map(classMapping, cfClass, null);
             var newClass = newObj as CodeFirstClass;
             Assert.IsNotNull(newObj);
             Assert.IsNotNull(newClass);
             var expectedXmlComment = "<member name=\"T:CodeFirstTest.Customer\">\r\n    <summary>\r\n    This is the class\r\n    </summary>\r\n</member>\r\n";

             CheckClass(newClass,
                 className: "Customer",
                 namespaceName: "CodeFirstTest",
                 scopeAccess: ScopeAccess.Public,
                 comments: null,
                 xmlCommentString: expectedXmlComment);
             Assert.AreEqual(0, newClass.Properties.Count());
        }
        public void Can_map_prop_changed_class()
        {
            var root = RDom.CSharp.Load(@"
namespace CodeFirstTest
{
    /// <summary>
    /// This is the class
    /// </summary>
    public class Customer
    {   }
}");

            Assert.IsNotNull(root, "Root is null");
            var cfClass = root.Namespaces.First().Classes.First();

            Assert.IsNotNull(cfClass, "cfClass is null");
            var propertyType = typeof(CodeFirstClass);
            var classMapping = TargetMapping.DeriveMapping("testPropChanged", "test", propertyType.GetTypeInfo()) as TargetClassMapping;
            var provider     = new CodeFirst.Provider.ServiceProvider();
            var mapper       = new CodeFirstMapper2 <CodeFirstClass>(provider);
            var newObj       = mapper.Map(classMapping, cfClass, null);
            var newClass     = newObj as CodeFirstClass;

            Assert.IsNotNull(newObj);
            Assert.IsNotNull(newClass);
            var expectedXmlComment = "<member name=\"T:CodeFirstTest.Customer\">\r\n    <summary>\r\n    This is the class\r\n    </summary>\r\n</member>\r\n";

            CheckClass(newClass,
                       className: "Customer",
                       namespaceName: "CodeFirstTest",
                       scopeAccess: ScopeAccess.Public,
                       comments: null,
                       xmlCommentString: expectedXmlComment);
            Assert.AreEqual(0, newClass.Properties.Count());
        }
        public void Can_map_prop_changed_property()
        {
            var root = RDom.CSharp.Load(csharpCode);

            Assert.IsNotNull(root, "Root is null");
            var cfProperties = root.Namespaces.First().Classes.First().Properties.ToArray();

            Assert.AreEqual(4, cfProperties.Count());
            var eventSourceType = typeof(CodeFirstClass);
            var classMapping    = TargetMapping.DeriveMapping("testPropChanged", "test", eventSourceType.GetTypeInfo()) as TargetClassMapping;

            Assert.IsNotNull(classMapping, "classMapping is null");
            var propertyMapping = classMapping.Children.First();

            Assert.IsNotNull(propertyMapping, "propertyMapping is null");
            var provider    = new CodeFirst.Provider.ServiceProvider();
            var mapper      = new CodeFirstMapper2 <CodeFirstProperty>(provider);
            var newObj      = mapper.Map(propertyMapping, cfProperties[0], null);
            var newProperty = newObj as CodeFirstProperty;

            Assert.IsNotNull(newObj);
            Assert.IsNotNull(newProperty);
            CheckProperty(newProperty,
                          name: "FirstName",
                          typeName: "string");
        }
Esempio n. 6
0
        public void Can_map_eventsource_namespace()
        {
            var root = RDom.CSharp.Load(csharpCode);

            Assert.IsNotNull(root, "Root is null");
            var cfNamespace = root.Namespaces.First();

            Assert.IsNotNull(cfNamespace, "cfNamespace is null");
            var eventSourceType  = typeof(CodeFirstEventSourceGroup);
            var namespaceMapping = TargetMapping.DeriveMapping("testEventSource", "test", eventSourceType.GetTypeInfo()) as TargetNamespaceMapping;

            Assert.IsNotNull(namespaceMapping, "namespaceMapping is null");
            var provider     = new CodeFirst.Provider.ServiceProvider();
            var mapper       = new CodeFirstMapper2 <CodeFirstEventSourceGroup>(provider);
            var newObj       = mapper.Map(namespaceMapping, cfNamespace, null);
            var newNamespace = newObj as CodeFirstEventSourceGroup;

            Assert.IsNotNull(newObj);
            Assert.IsNotNull(newNamespace);
            Assert.AreEqual("CodeFirstTest", newNamespace.Name);
            Assert.AreEqual(1, newNamespace.EventSources.Count());
        }
Esempio n. 7
0
        public void Can_map_eventsource_class()
        {
            var root = RDom.CSharp.Load(@"
namespace CodeFirstTest
{
    [LocalizationResources(""Fred"")]
    [EventSourceName(""KadGen-Test-Temp"")]
    [SemanticLogEntry()]
    public class NormalEventSource
    {   }
}");

            Assert.IsNotNull(root, "Root is null");
            var cfClass = root.Namespaces.First().Classes.First();

            Assert.IsNotNull(cfClass, "cfClass is null");
            var eventSourceType = typeof(CodeFirstEventSource);
            var classMapping    = TargetMapping.DeriveMapping("testEventSource", "test", eventSourceType.GetTypeInfo()) as TargetClassMapping;
            var provider        = new CodeFirst.Provider.ServiceProvider();
            var mapper          = new CodeFirstMapper2 <CodeFirstEventSource>(provider);
            var newObj          = mapper.Map(classMapping, cfClass, null);
            var newEventSource  = newObj as CodeFirstEventSource;

            Assert.IsNotNull(newObj);
            Assert.IsNotNull(newEventSource);
            // TODO: KD 10/20/2014 Localization fails becuase only Attribute values, not attributes with positional attribute values are recongized
            CheckEventSource(newEventSource,
                             name: "NormalEventSource",
                             isLocalized: true,
                             localizationResources: "Fred",
                             eventSourceName: "KadGen-Test-Temp",
                             namespaceName: "CodeFirstTest",
                             scopeAccess: ScopeAccess.Public,
                             comments: null,
                             xmlCommentString: null);
            Assert.AreEqual(0, newEventSource.Events.Count());
        }
 public void Can_map_prop_changed_namespace()
 {
     var root = RDom.CSharp.Load(csharpCode);
      Assert.IsNotNull(root, "Root is null");
      var cfNamespace = root.Namespaces.First();
      Assert.IsNotNull(cfNamespace, "cfNamespace is null");
      var classType = typeof(CodeFirstClassGroup);
      var namespaceMapping = TargetMapping.DeriveMapping("testPropChanged", "test", classType.GetTypeInfo()) as TargetNamespaceMapping;
      Assert.IsNotNull(namespaceMapping, "namespaceMapping is null");
      var provider = new CodeFirst.Provider.ServiceProvider();
      var mapper = new CodeFirstMapper2<CodeFirstClassGroup>(provider);
      var newObj = mapper.Map(namespaceMapping, cfNamespace, null);
      var newNamespace = newObj as CodeFirstClassGroup;
      Assert.IsNotNull(newObj);
      Assert.IsNotNull(newNamespace);
      Assert.AreEqual("CodeFirstTest", newNamespace.Name);
      Assert.AreEqual(1, newNamespace.Classes.Count());
 }
 public void Can_map_prop_changed_property()
 {
     var root = RDom.CSharp.Load(csharpCode);
      Assert.IsNotNull(root, "Root is null");
      var cfProperties = root.Namespaces.First().Classes.First().Properties.ToArray();
      Assert.AreEqual(4, cfProperties.Count());
      var eventSourceType = typeof(CodeFirstClass);
      var classMapping = TargetMapping.DeriveMapping("testPropChanged", "test", eventSourceType.GetTypeInfo()) as TargetClassMapping;
      Assert.IsNotNull(classMapping, "classMapping is null");
      var propertyMapping = classMapping.Children.First();
      Assert.IsNotNull(propertyMapping, "propertyMapping is null");
       var provider = new CodeFirst.Provider.ServiceProvider();
      var mapper = new CodeFirstMapper2<CodeFirstProperty>(provider);
      var newObj = mapper.Map(propertyMapping, cfProperties[0], null);
      var newProperty = newObj as CodeFirstProperty;
      Assert.IsNotNull(newObj);
      Assert.IsNotNull(newProperty);
      CheckProperty(newProperty,
          name: "FirstName",
          typeName: "string");
 }