Beispiel #1
0
        public void Is_MethodSignature_name_set()
        {
            Type       currentType    = GetType();
            MethodInfo testMethodInfo = currentType.GetMethod("TestMethod");

            MethodSignatureDto methodSignature = MethodSignatureDto.FromMethod(testMethodInfo);

            Assert.AreEqual(testMethodInfo.Name, methodSignature.MethodName);
        }
Beispiel #2
0
        public void Can_initialize_MethodSignature_from_method_info()
        {
            Type       currentType    = GetType();
            MethodInfo testMethodInfo = currentType.GetMethod("TestMethod");

            MethodSignatureDto methodSignature = MethodSignatureDto.FromMethod(testMethodInfo);

            Assert.IsNotNull(methodSignature);
        }
Beispiel #3
0
        public void ReadCallback(IAsyncResult ar)
        {
            StateObject state = (StateObject)ar.AsyncState;

            Socket = state.WorkSocket;
            ISocketMessage message = new JsonSocketMessage();

            try
            {
                int bytesRead = Socket.EndReceive(ar);

                if (bytesRead > 0)
                {
                    foreach (var msg in message.Deserialize(state.Buffer))
                    {
                        switch (msg.MessageType)
                        {
                        case SocketMessageType.Method:
                            MethodRecievedEvent?.Invoke(this,
                                                        MethodSignatureDto.DeserializeMethodObject(msg.Message));
                            break;

                        case SocketMessageType.Methods:
                            break;

                        case SocketMessageType.MethodExecution:
                            break;

                        case SocketMessageType.Identity:
                            ClientIdentificationEvent?.Invoke(this, Guid.Parse(msg.Message));
                            break;

                        case SocketMessageType.Normal:
                            MessageRecievedEvent?.Invoke(this, msg);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }

                    Socket.BeginReceive(state.Buffer, 0, state.BufferSize, 0, ReadCallback, state);
                }

                else
                {
                }
            }
            catch (SocketException e)
            {
                _logger.Warn(e.Message);
            }
        }
Beispiel #4
0
        public void Is_declaring_type_correct()
        {
            Type               currentType     = GetType();
            MethodInfo         testMethodInfo  = currentType.GetMethod("TestMethod");
            MethodSignatureDto methodSignature = MethodSignatureDto.FromMethod(testMethodInfo);

            var actualAssemblyName   = methodSignature.DeclaringType.Assemblyname;
            var expectedAssemblyName = currentType.Assembly.FullName;

            var actualClassName   = methodSignature.DeclaringType.ClassName;
            var expectedClassName = currentType.FullName;

            Assert.AreEqual(actualAssemblyName, expectedAssemblyName);
            Assert.AreEqual(actualClassName, expectedClassName);
        }
Beispiel #5
0
        private static void SendExampleMethodSignature()
        {
            Type       type       = typeof(Program);
            MethodInfo methodInfo = type.GetMethod("ExampleMethod");

            MethodSignatureDto method = MethodSignatureDto.FromMethod(methodInfo);


            ISocketMessage socketMessage = new JsonSocketMessage();

            socketMessage.MessageType = SocketMessageType.Method;
            socketMessage.Message     = MethodSignatureDto.SerializeMethodObject(method);

            CommunicationClient.Send(socketMessage);
        }
        /// <summary>
        /// Gets the MethodSignatureDto of a specific method within a Type.
        /// <see cref="MethodSignatureDto"/> for more information about the DTO.
        /// </summary>
        /// <param name="type">Type to get MethodSignature from</param>
        /// <param name="methodName">The method within type to get MethodSignatureDto for</param>
        /// <returns></returns>
        public static MethodSignatureDto GetMethodSignature(this Type type, string methodName)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type), "The provided type cannot be null");
            }

            if (methodName == "")
            {
                throw new ArgumentException("The provided methodName cannot be empty", methodName);
            }

            if (methodName == null)
            {
                throw new ArgumentNullException(nameof(methodName), "The provided methodName cannot be null");
            }

            return(MethodSignatureDto.FromMethod(type.GetMethod(methodName)));
        }
Beispiel #7
0
 public void Is_argument_exception_thrown_when_MethodDeserialization_string_is_null()
 {
     MethodSignatureDto.DeserializeMethodObject(null);
 }
Beispiel #8
0
        public void Is_argument_exception_thrown_when_MethodDeserialization_string_is_empty()
        {
            string json = "";

            MethodSignatureDto.DeserializeMethodObject(json);
        }
Beispiel #9
0
        public void Is_exception_thrown_when_methodinfo_is_null()
        {
            MethodSignatureDto methodSignature = MethodSignatureDto.FromMethod(null);

            Assert.IsNull(methodSignature);
        }
Beispiel #10
0
        public void Is_jsonserialization_exception_thrown_when_json_object_is_parsed_to_MethodsDeserialization()
        {
            string invalidJson = "{\"IsMember\" : true, \"Name\" : \"John\", \"Age\" : 24}";

            MethodSignatureDto.DeserializeMethodArray(invalidJson);
        }
Beispiel #11
0
        public void Is_jsonreader_exception_thrown_when_MethodDeserialization_string_is_invalid()
        {
            string invalidJson = "this is not valid json";

            MethodSignatureDto.DeserializeMethodObject(invalidJson);
        }