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()); }
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_create_class_mapping() { var eventSourceType = typeof(CodeFirstEventSource); var mapping = TargetMapping.DeriveMapping("testEventSource", "root", eventSourceType.GetTypeInfo()); var classMapping = mapping as TargetClassMapping; Assert.IsNotNull(mapping); Assert.IsNotNull(classMapping); Assert.AreEqual("testEventSource", mapping.TargetName); Assert.AreEqual("root.testEventSource", mapping.MappingId); Assert.AreEqual(typeof(CodeFirstEventSource), mapping.UnderlyingTypInfo); Assert.AreEqual(1, classMapping.Children.Count()); Assert.AreEqual(7, classMapping.Attributes.Count()); var methodMapping = classMapping.Children.First() as TargetMethodMapping; Assert.IsNotNull(methodMapping); Assert.AreEqual("Events", methodMapping.TargetName); Assert.AreEqual("root.testEventSource.Events", methodMapping.MappingId); Assert.AreEqual(typeof(CodeFirstEvent), methodMapping.UnderlyingTypInfo); Assert.AreEqual(1, methodMapping.Children.Count()); Assert.AreEqual(13, methodMapping.Attributes.Count()); var paramMapping = methodMapping.Children.First() as TargetParameterMapping; Assert.IsNotNull(methodMapping); Assert.AreEqual("Parameters", paramMapping.TargetName); Assert.AreEqual("root.testEventSource.Events.Parameters", paramMapping.MappingId); Assert.AreEqual(typeof(CodeFirstEventParam), paramMapping.UnderlyingTypInfo); Assert.AreEqual(0, paramMapping.Children.Count()); Assert.AreEqual(3, paramMapping.Attributes.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"); }
// Event Handlers // Called by the input field UI Button when pressed private void OnInputFieldClicked(int index, int actionElementMapToReplaceId) { if (index < 0 || index >= rows.Count) { return; // index out of range } ControllerMap keyboardMap = player.controllers.maps.GetMap(ControllerType.Keyboard, 0, category, layout); ControllerMap mouseMap = player.controllers.maps.GetMap(ControllerType.Mouse, 0, category, layout); // Cannot replace a keyboard binding on a Mouse Map or vice versa // Replacement cross device has to be done by removing the other // binding manually after input is mapped. // Determine which map the replacement binding exists on and store that information. ControllerMap controllerMapWithReplacement; // Determine if the replacement is on the keyboard or mouse map if (keyboardMap.ContainsElementMap(actionElementMapToReplaceId)) { controllerMapWithReplacement = keyboardMap; } else if (mouseMap.ContainsElementMap(actionElementMapToReplaceId)) { controllerMapWithReplacement = mouseMap; } else { controllerMapWithReplacement = null; // not a replacement } // Store the information about the replacement if any _replaceTargetMapping = new TargetMapping() { actionElementMapId = actionElementMapToReplaceId, controllerMap = controllerMapWithReplacement }; // Begin listening for input on both keyboard and mouse at the same time inputMapper_keyboard.Start( new InputMapper.Context() { actionId = rows[index].action.id, controllerMap = keyboardMap, actionRange = rows[index].actionRange, actionElementMapToReplace = keyboardMap.GetElementMap(actionElementMapToReplaceId) } ); inputMapper_mouse.Start( new InputMapper.Context() { actionId = rows[index].action.id, controllerMap = mouseMap, actionRange = rows[index].actionRange, actionElementMapToReplace = mouseMap.GetElementMap(actionElementMapToReplaceId) } ); statusUIText.text = "Listening..."; }
public void Can_create_parameter_mapping() { var eventSourceType = typeof(CodeFirstEventParam); var mapping = TargetMapping.DeriveMapping("testEventParam", "xyz", eventSourceType.GetTypeInfo()); Assert.IsNotNull(mapping); Assert.IsInstanceOfType(mapping, typeof(TargetParameterMapping)); Assert.AreEqual("testEventParam", mapping.TargetName); Assert.AreEqual("xyz.testEventParam", mapping.MappingId); Assert.AreEqual(typeof(CodeFirstEventParam), mapping.UnderlyingTypInfo); }
public void Can_create_method_mapping() { var eventSourceType = typeof(CodeFirstEvent); var mapping = TargetMapping.DeriveMapping("testEvent", "abc", eventSourceType.GetTypeInfo()); Assert.IsNotNull(mapping); Assert.IsInstanceOfType(mapping, typeof(TargetMethodMapping)); Assert.AreEqual("testEvent", mapping.TargetName); Assert.AreEqual("abc.testEvent", mapping.MappingId); Assert.AreEqual(typeof(CodeFirstEvent), mapping.UnderlyingTypInfo); }
public void Can_create_property_mapping() { var propertyType = typeof(CodeFirstMetadataTest.PropertyChanged.CodeFirstProperty); var mapping = TargetMapping.DeriveMapping("testEventParam", "xyz", propertyType.GetTypeInfo()); Assert.IsNotNull(mapping); Assert.IsInstanceOfType(mapping, typeof(TargetPropertyMapping)); Assert.AreEqual("testEventParam", mapping.TargetName); Assert.AreEqual("xyz.testEventParam", mapping.MappingId); Assert.AreEqual(typeof(CodeFirstMetadataTest.PropertyChanged.CodeFirstProperty), mapping.UnderlyingTypInfo); }
public void Can_create_property_changed_namespace_mapping() { var namespaceType = typeof(CodeFirstClassGroup); var mapping = TargetMapping.DeriveMapping("testPropParam", "xyz", namespaceType.GetTypeInfo()); Assert.IsNotNull(mapping); Assert.IsInstanceOfType(mapping, typeof(TargetNamespaceMapping)); Assert.AreEqual("testPropParam", mapping.TargetName); Assert.AreEqual("xyz.testPropParam", mapping.MappingId); Assert.AreEqual(typeof(CodeFirstClassGroup), mapping.UnderlyingTypInfo); }
public T LoadFrom(IRoot root, string attributeIdentifier) { if (ShouldRun(root, attributeIdentifier)) { // TODO: We need to be more flexible and look for the desired element and then map from that level var cfNamespace = root.Namespaces.First(); var returnType = typeof(T); var mapping = TargetMapping.DeriveMapping("root", "root", returnType.GetTypeInfo()) as TargetNamespaceMapping; //var mapper = new CodeFirstMapper(); var mapper = serviceProvider.GetMapper2 <T>(); var newObj = mapper.Map(mapping, cfNamespace, null); return(newObj as T); } return(null); }
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()); }
// Event Handlers // Called by the input field UI Button when pressed private void OnInputFieldClicked(int index, int actionElementMapToReplaceId) { if (index < 0 || index >= rows.Count) { return; // index out of range } ControllerMap keyboardMap = player.controllers.maps.GetMap(ControllerType.Keyboard, 0, category, layout); ControllerMap mouseMap = player.controllers.maps.GetMap(ControllerType.Mouse, 0, category, layout); // Cannot replace a keyboard binding on a Mouse Map or vice versa // Replacement cross device has to be done by removing the other // binding manually after input is mapped. // Determine which map the replacement binding exists on and store that information. ControllerMap controllerMapWithReplacement; // Determine if the replacement is on the keyboard or mouse map if (keyboardMap.ContainsElementMap(actionElementMapToReplaceId)) { controllerMapWithReplacement = keyboardMap; } else if (mouseMap.ContainsElementMap(actionElementMapToReplaceId)) { controllerMapWithReplacement = mouseMap; } else { controllerMapWithReplacement = null; // not a replacement } // Store the information about the replacement if any _replaceTargetMapping = new TargetMapping() { actionElementMapId = actionElementMapToReplaceId, controllerMap = controllerMapWithReplacement }; // Begin listening for input, but use a coroutine so it starts only after a short delay to prevent // the button bound to UI Submit from binding instantly when the input field is activated. StartCoroutine(StartListeningDelayed(index, keyboardMap, mouseMap, actionElementMapToReplaceId)); }
public void Can_create_property_changed_class_mapping() { var propClassType = typeof(CodeFirstClass); var mapping = TargetMapping.DeriveMapping("testPropChange", "root", propClassType.GetTypeInfo()); var classMapping = mapping as TargetClassMapping; Assert.IsNotNull(mapping); Assert.IsNotNull(classMapping); Assert.AreEqual("testPropChange", mapping.TargetName); Assert.AreEqual("root.testPropChange", mapping.MappingId); Assert.AreEqual(typeof(CodeFirstClass), mapping.UnderlyingTypInfo); Assert.AreEqual(1, classMapping.Children.Count()); Assert.AreEqual(5, classMapping.Attributes.Count()); var propertyMapping = classMapping.Children.First() as TargetPropertyMapping; Assert.IsNotNull(propertyMapping); Assert.AreEqual("Properties", propertyMapping.TargetName); Assert.AreEqual("root.testPropChange.Properties", propertyMapping.MappingId); Assert.AreEqual(typeof(CodeFirstProperty), propertyMapping.UnderlyingTypInfo); Assert.AreEqual(8, propertyMapping.Attributes.Count()); }
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()); }