public void Recorded_Method_Model_Test_Recording_Method_Init()
        {
            var guid       = Guid.NewGuid();
            var targetType = TestClass.Method1Entry.TargetType;
            var methodName = TestClass.Method1Entry.Method.Name;
            var serTarget  = "blah";
            var arg        = new List <object>()
            {
                2.0,
                "blah"
            };
            var methodBase = TestClass.Method1Entry.Method;
            var returnVal  = "foo";
            var serValue   = new SerializedValue(targetType, serTarget);

            var recordingMethod = new RecordingMethod(guid, serValue, arg, methodBase);

            recordingMethod.CloseOutMethodWithReturnVal(returnVal);

            var SUT = new RecordedMethod(recordingMethod);

            for (int i = 0; i < SUT.Args.Count; i++)
            {
                Assert.IsTrue(SUT.Args[i].Equals(arg[i]));
            }
            Assert.IsTrue(SUT.Identifier.Equals(guid));
            Assert.IsTrue(SUT.InstanceAtExecutionTime.Value.Equals(serTarget));
            Assert.IsTrue(SUT.MethodException == null);
            Assert.IsTrue(SUT.MethodData.MethodName == methodName);
            Assert.IsTrue(SUT.ReturnVal.GetType().Equals(returnVal.GetType()));
            Assert.IsTrue(SUT.ReturnVal.Equals(returnVal));
            Assert.IsTrue(SUT.SubMethods != null);
            Assert.IsTrue(SUT.TargetType.Equals(targetType));
        }
示例#2
0
        internal static TenantPartitionHint Deserialize(byte[] buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            int num  = 0;
            int num2 = SerializedValue.ParseInt32(buffer, ref num);

            if (num2 < 1)
            {
                throw new InvalidSerializedFormatException("Invalid version for the serialized blob: " + num2.ToString());
            }
            TenantPartitionHint.SerializedTenantHintFlags serializedTenantHintFlags = (TenantPartitionHint.SerializedTenantHintFlags)SerializedValue.ParseInt32(buffer, ref num);
            Guid?guid = null;

            if ((serializedTenantHintFlags & TenantPartitionHint.SerializedTenantHintFlags.ExternalDirectoryOrganizationIdPresent) == TenantPartitionHint.SerializedTenantHintFlags.ExternalDirectoryOrganizationIdPresent)
            {
                guid = new Guid?(SerializedValue.ParseGuid(buffer, ref num));
            }
            string text  = SerializedValue.ParseString(buffer, ref num);
            string text2 = SerializedValue.ParseString(buffer, ref num);

            if (text != null && text2 != null)
            {
                PartitionId partitionId = new PartitionId(text2);
                return(new TenantPartitionHint(partitionId, text));
            }
            if (guid != null)
            {
                return(new TenantPartitionHint(guid.Value));
            }
            return(new TenantPartitionHint(TenantPartitionHint.ExternalDirectoryOrganizationIdForRootOrg));
        }
        public bool Equals(SerializedPropertyInfo other)
        {
            if (other == null)
            {
                return(false);
            }

            if (IsString != other.IsString)
            {
                return(false);
            }

            if (!ReferenceEquals(SerializedValue, other.SerializedValue))
            {
                if (SerializedValue == null || other.SerializedValue == null)
                {
                    return(false);
                }

                if (!SerializedValue.Equals(other.SerializedValue))
                {
                    return(false);
                }
            }

            return(true);
        }
        private void DrawField(FieldInfo fieldInfo, SerializedProperty field)
        {
            var serializedValueProperty = field.FindPropertyRelative(nameof(SerializedField.fieldValue));

            if (typeof(UnityEngine.Object).IsAssignableFrom(fieldInfo.FieldType))
            {
                var objectValue = serializedValueProperty.FindPropertyRelative(nameof(SerializedValue.objectValue));
                EditorGUILayout.ObjectField(objectValue, fieldInfo.FieldType, new GUIContent(ObjectNames.NicifyVariableName(fieldInfo.Name)));
            }
            else
            {
                var stringValue     = serializedValueProperty.FindPropertyRelative(nameof(SerializedValue.stringValue));
                var serializedValue = new SerializedValue
                {
                    stringValue = string.IsNullOrWhiteSpace(stringValue.stringValue) ? null : stringValue.stringValue
                };

                if (typeDrawers.TryGetValue(fieldInfo.FieldType, out var drawer))
                {
                    EditorGUI.BeginChangeCheck();
                    var newValue = drawer(fieldInfo, serializedValue.GetValue(fieldInfo));

                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedValue.SetValue(fieldInfo, newValue);
                        stringValue.stringValue = serializedValue.stringValue;
                    }
                }
                else
                {
                    DrawUnrecognizedField(field);
                }
            }
        }
 public Type ResolveClassTypeFor(SerializedValue serializedValue)
 {
     if("true".Equals(serializedValue.ValueOfAtrributeNamed(XsAttribute.Null), StringComparison.InvariantCultureIgnoreCase))
             return typeof (XNull);
     var classType = serializedValue.ValueOfAtrributeNamed(XsAttribute.classType);
     return Type.GetType(classType);
 }
 public Type ResolveFieldTypeFor(Field field, SerializedValue serializedField)
 {
     var classAttribute = serializedField.ValueOfAtrributeNamed(XsAttribute.classType);
     Type fieldType = field.FieldType;
     if (!string.IsNullOrEmpty(classAttribute)) fieldType = Type.GetType(resolveTypeFrom(classAttribute));
     return fieldType;
 }
        public void Recorded_Method_Manager_Sub_Method_With_Invalid_Return_Should_Clear_From_Cache()
        {
            var mockCache = new Mock <IExecutionCache>();
            var mockStack = new Mock <IExecutionStack>();

            var _methods = new List <RecordingMethod>();

            var serTarget     = new SerializedValue(typeof(int), "1");
            var args          = new List <object>();
            var recMethod     = new RecordingMethod(Guid.NewGuid(), serTarget, args, TestClass.Method1Entry.Method);
            var subMethodGuid = Guid.NewGuid();

            recMethod.SubMethods.Add(new RecordedSubMethod(subMethodGuid, typeof(int), new List <object>(), typeof(int), TestClass.Method1Entry.Method));

            mockCache.Setup(x => x.GetMethods(It.IsAny <int>())).Returns(new List <RecordingMethod>()
            {
                recMethod
            });
            mockStack.Setup(x => x.ExecutingGuid(It.IsAny <int>())).Returns(subMethodGuid);

            var SUT = new RecordingMethodManager(mockCache.Object, _defaultThreadProvider.Object, mockStack.Object, _defaultSerializer.Object);

            var procData = TestSubClass.Method1Exit;

            procData.AddVerificationFailures(new List <VerificationFailure>()
            {
                new TypeSerializationFailure(typeof(double))
            });
            SUT.ProcessCapture(procData);

            Assert.IsTrue(_methods.Count == 0);
        }
        public void Recorded_Method_Manager_Instance_Verifier_Fail_Should_Still_Add_Sub_Method()
        {
            var mockCache = new Mock <IExecutionCache>();
            var mockStack = new Mock <IExecutionStack>();

            var serTarget = new SerializedValue(typeof(int), "1");
            var args      = new List <object>();
            var _methods  = new List <RecordingMethod>()
            {
                new RecordingMethod(Guid.NewGuid(), serTarget, args, TestClass.Method1Entry.Method)
            };

            mockCache.Setup(x => x.GetMethods(It.IsAny <int>())).Returns(_methods);
            mockStack.Setup(x => x.ExecutingGuid(It.IsAny <int>())).Returns(_methods[0].Identifier);

            var SUT = new RecordingMethodManager(mockCache.Object, _defaultThreadProvider.Object, mockStack.Object, _defaultSerializer.Object);

            var procData = TestSubClass.Method1Entry;

            procData.AddVerificationFailures(new List <VerificationFailure>()
            {
                new TypeSerializationFailure(typeof(double))
            });
            SUT.ProcessCapture(procData);

            Assert.IsTrue(_methods.Count == 1);
            Assert.IsTrue(_methods[0].SubMethods.Count == 1);
        }
        private SerializedProperty GetOrCreateField(SerializedProperty collectionProperty, FieldInfo fieldInfo)
        {
            for (var i = 0; i < collectionProperty.arraySize; i++)
            {
                var field = collectionProperty.GetArrayElementAtIndex(i);
                if (field.FindPropertyRelative(nameof(SerializedField.fieldName)).stringValue == fieldInfo.Name)
                {
                    return(field);
                }
            }
            collectionProperty.arraySize++;

            var serializedField   = collectionProperty.GetArrayElementAtIndex(collectionProperty.arraySize - 1);
            var fieldNameProperty = serializedField.FindPropertyRelative(nameof(SerializedField.fieldName));

            fieldNameProperty.stringValue = fieldInfo.Name;

            var fieldValueProperty = serializedField.FindPropertyRelative(nameof(SerializedField.fieldValue));
            var serializedValue    = new SerializedValue();

            if (specialDefaultValueCreators.TryGetValue(fieldInfo.FieldType, out var creator))
            {
                serializedValue.SetValue(fieldInfo, creator());
            }
            else
            {
                serializedValue.SetValue(fieldInfo, fieldInfo.FieldType.IsValueType ? Activator.CreateInstance(fieldInfo.FieldType) : (object)null);
            }

            fieldValueProperty.FindPropertyRelative(nameof(SerializedValue.stringValue)).stringValue          = serializedValue.stringValue;
            fieldValueProperty.FindPropertyRelative(nameof(SerializedValue.objectValue)).objectReferenceValue = null;

            return(serializedField);
        }
示例#10
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken token = JToken.ReadFrom(reader);

            SerializedValue <JToken> result = new SerializedValue <JToken>(mFormatter, token);

            return(result);
        }
示例#11
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((ContentTypeProperty != null ? ContentTypeProperty.Id.GetHashCode() : 0) * 397) ^
                (SerializedValue != null ? SerializedValue.GetHashCode() : 0));
     }
 }
        public void Ctor_OnlyAssemblyQualifiedName_Null()
        {
            const string assemblyQualifiedName = "some assembly qualified name";

            var subject = new SerializedValue(assemblyQualifiedName);

            Assert.AreEqual(assemblyQualifiedName, subject.AssemblyQualifiedName);
            Assert.AreEqual(SerializationFormat.Null, subject.Format);
        }
        public void Ctor_ByteArray_Binary()
        {
            const string assemblyQualifiedName = "some assembly qualified name";
            var          data = new byte[] { 2, 3, 4, 54 };

            var subject = new SerializedValue(assemblyQualifiedName, data);

            Assert.AreEqual(assemblyQualifiedName, subject.AssemblyQualifiedName);
            Assert.AreEqual(data, subject.BinaryData);
            Assert.AreEqual(SerializationFormat.BinaryFormatter, subject.Format);
        }
        public void Ctor_String_Json()
        {
            const string assemblyQualifiedName = "some assembly qualified name";
            const string data = "some string data";

            var subject = new SerializedValue(assemblyQualifiedName, data);

            Assert.AreEqual(assemblyQualifiedName, subject.AssemblyQualifiedName);
            Assert.AreEqual(data, subject.JsonData);
            Assert.AreEqual(SerializationFormat.UnityJson, subject.Format);
        }
示例#15
0
        public void DeserializeGeneric_TypeNotAssignalbe_Throws()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            var serializationInfo = new SerializedValue(typeof(TestData).AssemblyQualifiedName, "12345");
            var subject           = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);

            Assert.Throws <InvalidOperationException>(() => subject.Deserialize <int>(serializationInfo));
        }
示例#16
0
        public RecordingMethod(Guid id, SerializedValue serializedTarget, List <object> args, MethodBase method)
        {
            this.Identifier = id;
            this.TargetType = serializedTarget.Type;
            this.InstanceAtExecutionTime = serializedTarget;
            this.SubMethods = new List <RecordedSubMethod>();
            this.MethodName = method.Name;
            this.Method     = method;

            this.Args = args;
        }
示例#17
0
        public void Ctor_ParameterNotNull_PropertiesInitialized()
        {
            const string     name       = "memberName";
            const MemberType memberType = MemberType.Property;
            var serializedValue         = new SerializedValue("fef");

            var subject = new SerializedMember(name, memberType, serializedValue);

            Assert.AreEqual(name, subject.Name);
            Assert.AreEqual(memberType, subject.MemberType);
            Assert.IsTrue(ReferenceEquals(serializedValue, subject.SerializedValue));
        }
        private RecordingMethod InitTestModel()
        {
            var instance = new SerializedValue(typeof(string), "test");
            var args     = new List <object>()
            {
                "arg1",
                2,
                DateTime.Now
            };

            return(new RecordingMethod(Guid.NewGuid(), instance, args, DataHelper.MathPowerData.Entry.Method));
        }
        public override int GetHashCode()
        {
            int result = HashCodeSeedValue;

            result = (result * HashCodeCombiningValue) + IsString.GetHashCode();
            if (SerializedValue != null)
            {
                result = (result * HashCodeCombiningValue) + SerializedValue.GetHashCode();
            }

            return(result);
        }
示例#20
0
        public void Deserialize_NullFormatted_Null()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            var serializationInfo = new SerializedValue(typeof(TestData).AssemblyQualifiedName);
            var subject           = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);

            var result = subject.Deserialize(serializationInfo);

            Assert.IsNull(result);
        }
示例#21
0
        public void Deserialize_TypeNotResolved_Throws()
        {
            var serializationInfo = new SerializedValue("12345", "12345");
            var subject           = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);
            var testData = new TestData();

            _unityJsonSerializerMock.Setup(mock => mock.Deserialize(It.IsAny <Type>(), It.IsAny <string>()))
            .Returns(testData);

            Assert.Throws <InvalidOperationException>(() => subject.Deserialize(serializationInfo));
        }
示例#22
0
        /// <summary>
        /// 역직렬화를 통해, 객체를 반환한다.
        /// </summary>
        /// <returns></returns>
        public override object GetDeserializedObject()
        {
            if (SerializedValue == null)
            {
                return(null);
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("직렬화 객체 (수형[{0}])에 대해 [{1}] 역직렬화를 수행합니다... ", ObjectTypeName, Method);
            }

            var objectType = Type.GetType(ObjectTypeName, true, true);

            return(JsonTool.DeserializeFromText(SerializedValue.ToText(), objectType));
        }
示例#23
0
 private void _read()
 {
     _lenFilename         = m_io.ReadU4le();
     _filename            = m_io.ReadBytes(LenFilename);
     _lenDataUncompressed = m_io.ReadU4le();
     _timestamp           = m_io.ReadU4le();
     _lenDataCompressed   = m_io.ReadU4le();
     _crc32       = m_io.ReadU4le();
     _flags       = new FileFlags(m_io, this, m_root);
     _lenMetadata = m_io.ReadU4le();
     if (LenMetadata != 0)
     {
         __raw_metadata = m_io.ReadBytes(LenMetadata);
         var io___raw_metadata = new KaitaiStream(__raw_metadata);
         _metadata = new SerializedValue(io___raw_metadata, this, m_root);
     }
 }
示例#24
0
        public void Deserialize_JsonFormatted_Deserialized()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            var serializationInfo = new SerializedValue(typeof(TestData).AssemblyQualifiedName, "12345");
            var subject           = new Formatter(
                _binarySerializerMock.Object,
                _unityJsonSerializerMock.Object,
                _formatSelectorMock.Object);
            var testData = new TestData();

            _unityJsonSerializerMock.Setup(mock => mock.Deserialize(It.IsAny <Type>(), It.IsAny <string>()))
            .Returns(testData);

            var result = subject.Deserialize(serializationInfo);

            Assert.AreEqual(testData, result);
        }
示例#25
0
        internal void ReadProperties(XmlReader reader, string endElement)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == endElement)
                    {
                        return;
                    }
                    break;

                case XmlNodeType.Element:
                    string propertyName = reader.LocalName;
                    if (propertyName == "Properties")
                    {
                        propertyName = reader.GetAttribute(0);
                        Properties p = new Properties();
                        p.ReadProperties(reader, "Properties");
                        properties[propertyName] = p;
                    }
                    else if (propertyName == "Array")
                    {
                        propertyName             = reader.GetAttribute(0);
                        properties[propertyName] = ReadArray(reader);
                    }
                    else if (propertyName == "SerializedValue")
                    {
                        propertyName             = reader.GetAttribute(0);
                        properties[propertyName] = new SerializedValue(reader.ReadInnerXml());
                    }
                    else
                    {
                        properties[propertyName] = reader.HasAttributes ? reader.GetAttribute(0) : null;
                    }
                    break;
                }
            }
        }
示例#26
0
        public void Reset()
        {
            objects.Clear();
            if (Internal.Serializer == null)
            {
                return;
            }

            for (int i = 0; i < Internal.Serializer.ValueWrappers.Count; i++)
            {
                SerializedValue value = Internal.Serializer.ValueWrappers.Array[i];
                if (value == null || value.Value == null)
                {
                    continue;
                }

                objects.Add(new PropertiesValue(i, this, value));
            }
        }
示例#27
0
        public void Execution_Recorder_Finished_Method_Should_Be_Added_To_DAL()
        {
            var _helper  = new Mock <IRecordedMethodHelper>();
            var _manager = new Mock <IRecordingMethodManager>();

            var entry  = TestClass.Method1Entry;
            var serVal = new SerializedValue(entry.TargetType, "");

            var recMethod = new RecordingMethod(Guid.NewGuid(), serVal, entry.MethodArgs, entry.Method);

            recMethod.CloseOutMethodWithReturnVal(TestClass.Method1Exit.ReturnValue);

            _manager.Setup(x => x.ProcessCapture(It.IsAny <InterceptionProcessingData>())).Raises(f => f.MethodRecordingComplete += null, new MethodRecordingCompleteEventArgs(recMethod));

            var SUT = new ExecutionRecorderProcess(_manager.Object, _helper.Object);

            SUT.ExecuteProcess(TestClass.Method1Entry);

            _helper.Verify(x => x.AddRecordedMethod(It.IsAny <RecordedMethod>()), Times.Once);
        }
        public void Recorded_Method_Manager_Method_Entry_Wont_Raise_Complete_Event()
        {
            var mockCache = new Mock <IExecutionCache>();
            var mockStack = new Mock <IExecutionStack>();

            var instanceSer = new SerializedValue(typeof(int), "1");
            var _methods    = new List <RecordingMethod>()
            {
                TestClass.Method1EntryRecording
            };

            mockCache.Setup(x => x.GetMethods(It.IsAny <int>())).Returns(_methods);
            mockStack.Setup(x => x.ExecutingGuid(It.IsAny <int>())).Returns(_methods.FirstOrDefault().Identifier);

            var SUT = new RecordingMethodManager(mockCache.Object, _defaultThreadProvider.Object, mockStack.Object, _defaultSerializer.Object);

            SUT.MethodRecordingComplete += SUT_MethodRecordingComplete;
            SUT.ProcessCapture(TestClass.Method1Entry);

            Assert.IsTrue(_methodCompleteEventRaised == false);
        }
示例#29
0
 private void _read()
 {
     _lenManifest = m_io.ReadU4le();
     _numFiles    = m_io.ReadU4le();
     _apiVersion  = new ApiVersion(m_io, this, m_root);
     _flags       = new GlobalFlags(m_io, this, m_root);
     _lenAlias    = m_io.ReadU4le();
     _alias       = m_io.ReadBytes(LenAlias);
     _lenMetadata = m_io.ReadU4le();
     if (LenMetadata != 0)
     {
         __raw_metadata = m_io.ReadBytes(LenMetadata);
         var io___raw_metadata = new KaitaiStream(__raw_metadata);
         _metadata = new SerializedValue(io___raw_metadata, this, m_root);
     }
     _fileEntries = new List <FileEntry>();
     for (var i = 0; i < NumFiles; i++)
     {
         _fileEntries.Add(new FileEntry(m_io, this, m_root));
     }
 }
        private void PopulateSerializableFields()
        {
            serializableStaticFields.Clear();
            serializableInstanceFields.Clear();

            if (entityStateType == null)
            {
                return;
            }

            var allFieldsInType = entityStateType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            var filteredFields  = allFieldsInType.Where(fieldInfo =>
            {
                bool canSerialize         = SerializedValue.CanSerializeField(fieldInfo);
                bool shouldSerialize      = !fieldInfo.IsStatic || (fieldInfo.DeclaringType == entityStateType);
                bool doesNotHaveAttribute = fieldInfo.GetCustomAttribute <HideInInspector>() == null;
                return(canSerialize && shouldSerialize && doesNotHaveAttribute);
            });

            serializableStaticFields.AddRange(filteredFields.Where(fieldInfo => fieldInfo.IsStatic));
            serializableInstanceFields.AddRange(filteredFields.Where(fieldInfo => !fieldInfo.IsStatic));
        }
示例#31
0
        public void Recorded_Method_Model_Test_Equality_Override()
        {
            var guid       = Guid.NewGuid();
            var targetType = TestClass.Method1Entry.TargetType;
            var methodName = TestClass.Method1Entry.Method.Name;
            var serTarget  = "blah";
            var arg        = new List <object>()
            {
                2.0,
                "blah"
            };
            var methodBase = TestClass.Method1Entry.Method;
            var returnVal  = "foo";
            var serValue   = new SerializedValue(targetType, serTarget);

            var recordingMethod = new RecordingMethod(guid, serValue, arg, methodBase);
            var recordedMethod  = new RecordedMethod(recordingMethod);

            Assert.IsTrue(recordedMethod.Equals(recordedMethod));
            Assert.IsFalse(recordedMethod.Equals(new RecordedMethod(Guid.NewGuid())));
            Assert.IsTrue(recordedMethod.Equals(new RecordedMethod(guid)));
        }
        public void Recorded_Method_Manager_Method_Exception_Raises_Complete_Event()
        {
            var mockCache = new Mock <IExecutionCache>();
            var mockStack = new Mock <IExecutionStack>();

            var serTarget = new SerializedValue(typeof(int), "1");
            var args      = new List <object>();
            var _methods  = new List <RecordingMethod>()
            {
                new RecordingMethod(Guid.NewGuid(), serTarget, args, TestClass.Method1Entry.Method)
            };

            mockCache.Setup(x => x.GetMethods(It.IsAny <int>())).Returns(_methods);
            mockStack.Setup(x => x.ExecutingGuid(It.IsAny <int>())).Returns(_methods.FirstOrDefault().Identifier);

            var SUT = new RecordingMethodManager(mockCache.Object, _defaultThreadProvider.Object, mockStack.Object, _defaultSerializer.Object);

            SUT.MethodRecordingComplete += SUT_MethodRecordingComplete;
            SUT.ProcessCapture(TestClass.Method1Exception);

            Assert.IsTrue(_methodCompleteEventRaised == true);
        }