Пример #1
0
    public static void MissingFieldException_Ctor2()
    {
        MissingFieldException i = new MissingFieldException("Created MissingFieldException");

        Assert.Equal("Created MissingFieldException", i.Message);
        Assert.Equal(COR_E_MISSINGFIELD, i.HResult);
    }
Пример #2
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Create a new MissingFieldException instance,string is empty.");

        try
        {
            string expectString = string.Empty;
            //Create the application domain setup information.
            MissingFieldException myMissingFieldException = new MissingFieldException(expectString);
            if (myMissingFieldException.Message != expectString)
            {
                TestLibrary.TestFramework.LogError("002.1", "the MissingFieldException ctor error occurred.the message should be " + expectString);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Create a new MissingFieldException instance,string is empty.");

        try
        {
            string expectString = string.Empty;
            //Create the application domain setup information.
            MissingFieldException myMissingFieldException = new MissingFieldException(expectString);
            if (myMissingFieldException.Message != expectString)
            {
                TestLibrary.TestFramework.LogError("002.1", "the MissingFieldException ctor error occurred.the message should be " + expectString);
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: the parameter string is null.");
        try
        {
            string                expectValue  = null;
            ArgumentException     dpoExpection = new ArgumentException();
            MissingFieldException myException  = new MissingFieldException(expectValue, dpoExpection);
            if (myException == null)
            {
                TestLibrary.TestFramework.LogError("002.1", "MissingFieldException instance can not create correctly.");
                retVal = false;
            }
            if (myException.Message == expectValue)
            {
                TestLibrary.TestFramework.LogError("002.2", "the Message should return the default value.");
                retVal = false;
            }
            if (!(myException.InnerException is ArgumentException))
            {
                TestLibrary.TestFramework.LogError("002.3", "the InnerException should return MissingFieldException.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
        private static void InitializeTypePropertyExceptions(Type instanceType, Type returnType, string propertyName, System.Reflection.PropertyInfo property, out Exception exception)
        {
            if (!typePropertyExceptions.ContainsKey(instanceType))
            {
                typePropertyExceptions.Add(instanceType, new Dictionary <string, Dictionary <Type, Exception> >());
            }

            if (!typePropertyExceptions[instanceType].ContainsKey(propertyName))
            {
                typePropertyExceptions[instanceType].Add(propertyName, new Dictionary <Type, Exception>());
            }

            if (typePropertyExceptions[instanceType][propertyName].ContainsKey(returnType))
            {
                ReflectionExtensions.HasPropertyException(instanceType, returnType, propertyName, out exception);
            }
            else
            {
                exception = null;
                if (property == null)
                {
                    exception = new MissingFieldException(instanceType.Name, propertyName);
                }

                if (property.PropertyType != returnType ||
                    !property.PropertyType.IsSubclassOf(returnType))
                {
                    exception = new InvalidCastException();
                }

                typePropertyExceptions[instanceType][propertyName].Add(returnType, exception);
            }
        }
 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest2: the parameter string is null.");
     try
     {
         string expectValue = null;
         MissingFieldException myException = new MissingFieldException(expectValue);
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("002.1", "MissingFieldException instance can not create correctly.");
             retVal = false;
         }
         if (myException.Message == expectValue)
         {
             TestLibrary.TestFramework.LogError("002.2", "the Message should return the default value.");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of MissingFieldException.");
        try
        {
            string                expectValue       = "HELLO";
            ArgumentException     notFoundException = new ArgumentException();
            MissingFieldException myException       = new MissingFieldException(expectValue, notFoundException);
            if (myException == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "MissingFieldException instance can not create correctly.");
                retVal = false;
            }
            if (myException.Message != expectValue)
            {
                TestLibrary.TestFramework.LogError("001.2", "the Message should return " + expectValue);
                retVal = false;
            }
            if (!(myException.InnerException is ArgumentException))
            {
                TestLibrary.TestFramework.LogError("001.3", "the InnerException should return ArgumentException.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of MissingFieldException.");
     try
     {
         string expectValue = "HELLO";
         MissingFieldException myException = new MissingFieldException(expectValue);
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("001.1", "MissingFieldException instance can not create correctly.");
             retVal = false;
         }
         if (myException.Message != expectValue)
         {
             TestLibrary.TestFramework.LogError("001.2", "the Message should return " + expectValue);
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
Пример #9
0
    public static void MissingFieldException_Ctor2()
    {
        MissingFieldException i = new MissingFieldException("Created MissingFieldException");

        Assert.Equal("Created MissingFieldException", i.Message);
        Assert.Equal(COR_E_MISSINGFIELD, i.HResult);
    }
Пример #10
0
        public static void Ctor_Empty()
        {
            var exception = new MissingFieldException();

            Assert.NotEmpty(exception.Message);
            Assert.Equal(COR_E_MISSINGFIELD, exception.HResult);
        }
Пример #11
0
    public static void MissingFieldException_Ctor1()
    {
        MissingFieldException i = new MissingFieldException();

        //Assert.Equal("Attempted to access a non-existing field.", i.Message, "TestCtor1_001 failed");
        Assert.Equal(COR_E_MISSINGFIELD, i.HResult);
    }
Пример #12
0
        public static void Ctor_String()
        {
            string message   = "Created MissingFieldException";
            var    exception = new MissingFieldException(message);

            Assert.Equal(message, exception.Message);
            Assert.Equal(COR_E_MISSINGFIELD, exception.HResult);
        }
Пример #13
0
        public static void Ctor_String_String()
        {
            string className  = "class";
            string memberName = "member";
            var    exception  = new MissingFieldException(className, memberName);

            Assert.Contains(className, exception.Message);
            Assert.Contains(memberName, exception.Message);
        }
Пример #14
0
        /* Performs loading of address of field
         * (corresponds to CILPE.CFG.LoadFieldAddr class)
         */
        public void Perform_LoadFieldAddr(FieldInfo field, out Exception exc)
        {
            exc = null;

            if (!field.IsStatic)
            {
                Value objVal = Pop();

                if (objVal is NullValue)
                {
                    exc = new NullReferenceException();
                }
                else
                {
                    object obj = null;

                    if (objVal is ObjectReferenceValue)
                    {
                        obj = (objVal as ObjectReferenceValue).Obj;
                    }
                    else if (objVal is PointerValue)
                    {
                        obj = (objVal as PointerValue).GetReferencedObject();
                    }
                    else
                    {
                        throw new InvalidOperandException();
                    }

                    try
                    {
                        field.GetValue(obj);
                    }
                    catch (ArgumentException)
                    {
                        exc = new MissingFieldException();
                    }

                    if (exc == null)
                    {
                        if (objVal is ObjectReferenceValue)
                        {
                            push(new PointerToObjectFieldValue(obj, field));
                        }
                        else
                        {
                            push(new PointerToStructFieldValue(objVal as PointerValue, field));
                        }
                    }
                }
            }
            else
            {
                push(new PointerToObjectFieldValue(field));
            }
        }
Пример #15
0
    public static void MissingFieldException_Ctor3()
    {
        Exception ex = new Exception("Created inner exception");
        MissingFieldException i = new MissingFieldException("Created MissingFieldException", ex);

        Assert.Equal("Created MissingFieldException", i.Message);
        Assert.Equal(COR_E_MISSINGFIELD, i.HResult);
        Assert.Equal(i.InnerException.Message, "Created inner exception");
        Assert.Equal(i.InnerException.HResult, ex.HResult);
    }
Пример #16
0
    public static void MissingFieldException_Ctor3()
    {
        Exception             ex = new Exception("Created inner exception");
        MissingFieldException i  = new MissingFieldException("Created MissingFieldException", ex);

        Assert.Equal("Created MissingFieldException", i.Message);
        Assert.Equal(COR_E_MISSINGFIELD, i.HResult);
        Assert.Equal(i.InnerException.Message, "Created inner exception");
        Assert.Equal(i.InnerException.HResult, ex.HResult);
    }
        public static void Ctor_String_String()
        {
            string className  = "class";
            string memberName = "member";
            var    exception  = new MissingFieldException(className, memberName);

            Assert.Contains(className, exception.Message);
            Assert.Contains(memberName, exception.Message);
            Assert.Equal(COR_E_MISSINGFIELD, exception.HResult);
        }
Пример #18
0
        private static void Main()
        {
            var logger = new LoggerConfiguration()
                         .WriteTo.Udp("localhost", 9999, AddressFamily.InterNetwork, new Log4jTextFormatter())
                         .WriteTo.Console()
                         .MinimumLevel.Verbose()
                         .CreateLogger();

            ////var logger = new LoggerConfiguration()
            ////    .WriteTo.Udp("localhost", 9998, AddressFamily.InterNetwork, new Log4netTextFormatter())
            ////    .WriteTo.Console()
            ////    .MinimumLevel.Verbose()
            ////    .CreateLogger();

            var sourceGenerator   = new SourceGenerator();
            var messageGenerator  = new MessageGenerator();
            var logLevelGenerator = new LogLevelGenerator();

            while (true)
            {
                var source  = sourceGenerator.Generate();
                var message = messageGenerator.Generate();

                switch (logLevelGenerator.Generate())
                {
                case 1:
                    logger.Information("Source: {@source}, Message: {@message}", source, message);
                    break;

                case 2:
                    logger.Warning("{@source}, {@message}", source, message);
                    break;

                case 3:
                    logger.Error("Something went wrong: {@source}, {@message}", source, message);
                    break;

                case 4:
                    var exception = new MissingFieldException(message.Value);
                    logger.Fatal(exception, "Fatal Error!!! {@message}", message);
                    break;

                case 5:
                case 6:
                    logger.Debug("Simple debugging output {@source}, {@message}", source, message);
                    break;

                default:
                    logger.Verbose("{@source} = {@message}", source.Name, message.Value);
                    break;
                }

                Thread.Sleep(1000);
            }
        }
Пример #19
0
        public static void Ctor_String_Exception()
        {
            string message        = "Created MissingFieldException";
            var    innerException = new Exception("Created inner exception");
            var    exception      = new MissingFieldException(message, innerException);

            Assert.Equal(message, exception.Message);
            Assert.Equal(COR_E_MISSINGFIELD, exception.HResult);
            Assert.Same(innerException, exception.InnerException);
            Assert.Equal(innerException.HResult, exception.InnerException.HResult);
        }
Пример #20
0
        /// <summary>
        /// 定义 <see cref="INotifyPropertyChanged.PropertyChanged"/> 事件的触发方法,并添加到当前类型。
        /// </summary>
        /// <param name="type">要定义方法的 <see cref="TypeBuilder"/> 对象。</param>
        /// <param name="propertyChangedField">
        /// <see cref="INotifyPropertyChanged.PropertyChanged"/> 事件委托的字段。</param>
        /// <returns>定义的 <see cref="INotifyPropertyChanged.PropertyChanged"/> 事件的触发方法。</returns>
        /// <exception cref="ArgumentException"><paramref name="propertyChangedField"/>
        /// 的类型不为 <see cref="PropertyChangedEventHandler"/>。</exception>
        /// <exception cref="ArgumentNullException">存在为 <see langword="null"/> 的参数。</exception>
        internal static MethodBuilder DefineOnPropertyChangedMethod(
            this TypeBuilder type, FieldInfo propertyChangedField)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (propertyChangedField is null)
            {
                throw new ArgumentNullException(nameof(propertyChangedField));
            }
            if (propertyChangedField.FieldType != typeof(PropertyChangedEventHandler))
            {
                var inner = new MissingFieldException();
                throw new ArgumentException(inner.Message, nameof(propertyChangedField), inner);
            }

            var method = type.DefineMethod("OnPropertyChanged",
                                           MethodAttributes.Family | MethodAttributes.Virtual |
                                           MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                                           typeof(void), new[] { typeof(PropertyChangedEventArgs) });

            method.DefineParameter(1, ParameterAttributes.None, "e");

            var il = method.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, propertyChangedField);
            il.Emit(OpCodes.Dup);
            var invokeLabel = il.DefineLabel();

            il.Emit(OpCodes.Brtrue_S, invokeLabel);
            il.Emit(OpCodes.Pop);
            il.Emit(OpCodes.Ret);
            il.MarkLabel(invokeLabel);
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Callvirt,
                    typeof(PropertyChangedEventHandler).GetMethod(
                        nameof(PropertyChangedEventHandler.Invoke),
                        new[] { typeof(object), typeof(PropertyChangedEventArgs) }) !);
            il.Emit(OpCodes.Ret);

            return(method);
        }
Пример #21
0
 // Test the MissingFieldException class.
 public void TestMissingFieldException()
 {
     ExceptionTester.CheckMain(typeof(MissingFieldException),
                               unchecked ((int)0x80131511));
                     #if !ECMA_COMPAT && CONFIG_SERIALIZATION
     MissingFieldException e;
     e = new MissingFieldException("x", "y");
     SerializationInfo info =
         new SerializationInfo(typeof(MissingFieldException),
                               new FormatterConverter());
     StreamingContext context = new StreamingContext();
     e.GetObjectData(info, context);
     AssertEquals("MissingFieldException (1)",
                  "x", info.GetString("MMClassName"));
     AssertEquals("MissingFieldException (2)",
                  "y", info.GetString("MMMemberName"));
                     #endif
 }
Пример #22
0
 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of MissingFieldException.");
     try
     {
         MissingFieldException myException = new MissingFieldException();
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("001.1", "MissingFieldException instance can not create correctly.");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
Пример #23
0
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of MissingFieldException.");
        try
        {
            MissingFieldException myException = new MissingFieldException();
            if (myException == null)
            {
                TestLibrary.TestFramework.LogError("001.1", "MissingFieldException instance can not create correctly.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
Пример #24
0
    public void ExceptionIsThrownWhenNonTransientExceptionOccursDuringAsyncEnd()
    {
        RetryPolicy <MockErrorDetectionStrategy> policy = this.retryManager.GetRetryPolicy <MockErrorDetectionStrategy>("Incremental, 5 retries");

        int count1 = 0;

        policy.Retrying += (_, args) =>
        {
            Assert.IsInstanceOfType(args.LastException, typeof(InvalidCastException));
            count1 = args.CurrentRetryCount;
        };

        TestAsyncOperation asyncInstance = new()
        {
            CountToThrowAtEnd          = 3,
            ExceptionToThrowAtEnd      = new InvalidCastException(),
            FatalException             = new MissingFieldException(),
            ThrowFatalExceptionAtBegin = false
        };

        try
        {
            policy
            .ExecuteAsync(() =>
                          Task.Factory.FromAsync(asyncInstance.BeginMethod, asyncInstance.EndMethod, null))
            .Wait(TimeSpan.FromSeconds(5));
        }
        catch (AggregateException ex)
        {
            Assert.AreEqual(2, count1);
            Assert.AreEqual(1, ex.InnerExceptions.Count);

            throw ex.InnerException !;
        }

        Assert.Fail("Test should throw");
    }
Пример #25
0
 /// <summary>
 /// Gets instance field.
 /// </summary>
 /// <param name="fieldName">Name of field.</param>
 /// <param name="nonPublic"><see langword="true"/> to reflect non-public field.</param>
 /// <returns>Instance field.</returns>
 /// <exception cref="MissingEventException">Field doesn't exist.</exception>
 public static Field <T, V> Require(string fieldName, bool nonPublic = false)
 => Get(fieldName, nonPublic) ?? throw MissingFieldException.Create <T, V>(fieldName);
Пример #26
0
        /* Performs storing to field
         * (corresponds to CILPE.CFG.StoreField class)
         */
        public void Perform_StoreField(FieldInfo field, out Exception exc)
        {
            exc = null;
            Value fldVal = Pop().FromStack(field.FieldType);

            object val;

            if (fldVal is StructValue)
            {
                val = (fldVal as StructValue).Obj;
            }
            else if (fldVal is NullValue)
            {
                val = null;
            }
            else if (fldVal is ObjectReferenceValue)
            {
                val = (fldVal as ObjectReferenceValue).Obj;
            }
            else
            {
                throw new InvalidOperandException();
            }

            Value  objVal = null;
            object obj    = null;

            if (!field.IsStatic)
            {
                objVal = Pop();

                if (objVal is ObjectReferenceValue)
                {
                    obj = (objVal as ObjectReferenceValue).Obj;
                }
                else if (objVal is PointerValue)
                {
                    obj = (objVal as PointerValue).GetReferencedObject();
                }
                else if (objVal is NullValue)
                {
                    exc = new NullReferenceException();
                }
                else
                {
                    throw new InvalidOperandException();
                }
            }

            if (exc == null)
            {
                try
                {
                    field.SetValue(obj, val);
                }
                catch (ArgumentException)
                {
                    exc = new MissingFieldException();
                }

                if (objVal is PointerValue && obj.GetType().IsValueType)
                {
                    (objVal as PointerValue).SetReferencedValue(new StructValue(obj as ValueType));
                }
            }
        }
Пример #27
0
 /// <summary>
 /// Reflects static property.
 /// </summary>
 /// <param name="propertyName">Name of property.</param>
 /// <param name="nonPublic">True to reflect non-public property.</param>
 /// <returns>Instance property.</returns>
 /// <exception cref="MissingPropertyException">Property doesn't exist.</exception>
 public static Reflection.Property <V> RequireStatic(string propertyName, bool nonPublic = false)
 => GetStatic(propertyName, nonPublic) ?? throw MissingFieldException.Create <T, V>(propertyName);
Пример #28
0
 public static void MissingFieldException_Ctor1()
 {
     MissingFieldException i = new MissingFieldException();
     //Assert.Equal("Attempted to access a non-existing field.", i.Message, "TestCtor1_001 failed");
     Assert.Equal(COR_E_MISSINGFIELD, i.HResult);
 }
	// Test the MissingFieldException class.
	public void TestMissingFieldException()
			{
				ExceptionTester.CheckMain(typeof(MissingFieldException),
										  unchecked((int)0x80131511));
			#if !ECMA_COMPAT && CONFIG_SERIALIZATION
				MissingFieldException e;
				e = new MissingFieldException("x", "y");
				SerializationInfo info =
					new SerializationInfo(typeof(MissingFieldException),
										  new FormatterConverter());
				StreamingContext context = new StreamingContext();
				e.GetObjectData(info, context);
				AssertEquals("MissingFieldException (1)",
							 "x", info.GetString("MMClassName"));
				AssertEquals("MissingFieldException (2)",
							 "y", info.GetString("MMMemberName"));
			#endif
			}
Пример #30
0
 /// <summary>
 /// Gets static field.
 /// </summary>
 /// <param name="fieldName">Name of field.</param>
 /// <param name="nonPublic"><see langword="true"/> to reflect non-public field.</param>
 /// <returns>Instance field.</returns>
 /// <exception cref="MissingEventException">Field doesn't exist.</exception>
 public static Reflection.Field <V> RequireStatic(string fieldName, bool nonPublic = false)
 => GetStatic(fieldName, nonPublic) ?? throw MissingFieldException.Create <T, V>(fieldName);
Пример #31
0
        /* Performs loading from field
         * (corresponds to CILPE.CFG.LoadField class)
         */
        public void Perform_LoadField(FieldInfo field, out Exception exc)
        {
            exc = null;
            object fld = null;

            if (field.IsStatic)
            {
                fld = field.GetValue(null);
            }
            else
            {
                Value objVal = Pop();

                if (objVal is NullValue)
                {
                    exc = new NullReferenceException();
                }
                else
                {
                    object obj = null;

                    if (objVal is ObjectReferenceValue)
                    {
                        obj = (objVal as ObjectReferenceValue).Obj;
                    }
                    else if (objVal is PointerValue)
                    {
                        obj = (objVal as PointerValue).GetReferencedObject();
                    }
                    else if (objVal is StructValue)
                    {
                        obj = (objVal as StructValue).Obj;
                    }
                    else
                    {
                        throw new InvalidOperandException();
                    }

                    try
                    {
                        fld = field.GetValue(obj);
                    }
                    catch (ArgumentException)
                    {
                        exc = new MissingFieldException();
                    }
                }
            }

            if (exc == null)
            {
                Type type = field.FieldType;
                if (type.IsValueType)
                {
                    Push(new StructValue(fld as ValueType));
                }
                else if (fld == null)
                {
                    Push(new NullValue());
                }
                else
                {
                    Push(new ObjectReferenceValue(fld));
                }
            }
        }