public void ShouldThrowWhenMappingDuplicateIds()
        {
            var mappedComponent = new MappedComponent(0, typeof (TestComponent));
            var mappedMethod = mappedComponent.MapMethod(0, typeof (TestComponent).GetMethod("PublicMethod"));

            Action action = () => mappedComponent.MapMethod(mappedMethod.Id, typeof (TestComponent).GetMethod("PublicMethod"));
            action.ShouldThrow<ArgumentException>();
        }
        public void ShouldGetMappedMethodByMethodInfo()
        {
            var mappedComponent = new MappedComponent(0, typeof (TestComponent));
            var mappedMethod = mappedComponent.MapMethod(0, typeof (TestComponent).GetMethod("PublicMethod"));

            var foundMethod = mappedComponent.GetMethod(mappedMethod.MethodInfo);
            foundMethod.ShouldBe(mappedMethod);
        }
Пример #3
0
        public MappedMethod(MappedComponent mappedComponent, byte id, MethodInfo methodInfo)
        {
            MappedComponent = mappedComponent;

            Id = id;
            MethodInfo = methodInfo;

            ParametersTypes = MethodInfo.GetParameters().Select(t => t.ParameterType).ToArray();
        }
Пример #4
0
        public MappedMethod(MappedComponent mappedComponent, byte id, MethodInfo methodInfo)
        {
            MappedComponent = mappedComponent;

            Id         = id;
            MethodInfo = methodInfo;

            ParametersTypes = MethodInfo.GetParameters().Select(t => t.ParameterType).ToArray();
        }
        public void ShouldAutoMapPublicAndInstanceMethods()
        {
            var mappedComponent = new MappedComponent(0, typeof (TestComponent));
            mappedComponent.AutomapMethods();

            mappedComponent.MappedMethods.Any(t => t.MethodInfo == typeof (TestComponent).GetMethod("StaticMethod")).ShouldBeFalse();
            mappedComponent.MappedMethods.Any(t => t.MethodInfo == typeof (TestComponent).GetMethod("PublicMethod")).ShouldBeTrue();
            mappedComponent.MappedMethods.Any(t => t.MethodInfo == typeof (TestComponent).GetMethod("PrivateMethod")).ShouldBeFalse();
        }
Пример #6
0
        public MappedComponent MapComponent(byte componentId, Type componentType)
        {
            if (_mappedComponents[componentId] != null)
                throw new ArgumentException($"Failed to map component '{componentType}', a component with id '{componentId}' has already been mapped", nameof (componentId));

            var component = new MappedComponent(componentId, componentType);
            _mappedComponents[componentId] = component;

            return component;
        }
        public void ShouldMapMethod()
        {
            var mappedComponent = new MappedComponent(0, typeof (TestComponent));
            var mappedMethod = mappedComponent.MapMethod(0, typeof (TestComponent).GetMethod("PublicMethod"));

            mappedComponent.MappedMethods.ShouldContain(mappedMethod);

            mappedMethod.Id.ShouldBe((byte) 0);
            mappedMethod.MethodInfo.ShouldBe(typeof (TestComponent).GetMethod("PublicMethod"));
            mappedMethod.MappedComponent.ShouldBe(mappedComponent);
        }
Пример #8
0
        public MappedComponent MapComponent(byte componentId, Type componentType)
        {
            if (_mappedComponents[componentId] != null)
            {
                throw new ArgumentException($"Failed to map component '{componentType}', a component with id '{componentId}' has already been mapped", nameof(componentId));
            }

            var component = new MappedComponent(componentId, componentType);

            _mappedComponents[componentId] = component;

            return(component);
        }