public void TestFieldOf()
        {
            var obj = new DummyType();

            var actualField = typeof(DummyType).GetField("String");
            var field = ReflectionUtility.FieldOf(() => obj.String);

            Assert.IsNotNull(field);
            Assert.AreEqual(actualField, field);
        }
Example #2
0
        public void TryConstructor()
        {
            string aa = typeof(DummyType).Assembly.GetName().Name;

            DummyType dummy = typeof(DummyType)
                              .GetConstructor(new [] { typeof(string) })
                              .Invoke(new object[] { "" }) as DummyType;

            dummy = Activator.CreateInstance(typeof(DummyType), "") as DummyType;

            DummyType.InnerDummyClass innerDummy = typeof(DummyType).GetTypeInfo()
                                                   .GetNestedTypes().First()
                                                   .GetConstructor(Array.Empty <Type>())
                                                   .Invoke(Array.Empty <object>()) as DummyType.InnerDummyClass;
        }
        public void StringNoTruncateAttributeTest()
        {
            var str = new string('a', 1200);

            var dummyInstance = new DummyType {
                IntProp = 42, StringProp = str
            };

            var json = _payloadItemSerializer.Serialize(dummyInstance);
            var deserializedDummyInstance = JsonConvert.DeserializeObject <DummyType>(json);

            deserializedDummyInstance.Should().NotBeNull();
            deserializedDummyInstance.StringProp.Should().Be(str);
            deserializedDummyInstance.IntProp.Should().Be(42);
        }
        public void DictionaryNoTruncateAttributeTest()
        {
            var str = new string('a', 1200);

            var dummyInstance = new DummyType();

            dummyInstance.DictionaryProp["foo"] = str;

            var json = SerializePayloadItem(dummyInstance);
            var deserializedDummyInstance = JsonConvert.DeserializeObject(json) as JObject;

            Assert.NotNull(deserializedDummyInstance);

            Assert.Equal(str.Length, deserializedDummyInstance["dictionaryProp"].Value <JObject>()["foo"]?.Value <string>()?.Length);
            Assert.Equal(str, deserializedDummyInstance["dictionaryProp"].Value <JObject>()["foo"].Value <string>());
        }
        public void StringNoTruncateAttributeTest()
        {
            var str = new string('a', 1200);

            var dummyInstance = new DummyType {
                IntProp = 42, StringProp = str
            };

            var json = SerializePayloadItem(dummyInstance);
            var deserializedDummyInstance = JsonConvert.DeserializeObject <DummyType>(json);

            Assert.NotNull(deserializedDummyInstance);

            Assert.Equal(str.Length, deserializedDummyInstance.StringProp.Length);
            Assert.Equal(str, deserializedDummyInstance.StringProp);
            Assert.Equal(42, deserializedDummyInstance.IntProp);
        }
        public void NullableTimeSpanWithValue()
        {
            var settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;
            settings.Converters.Add(new TimeSpanConverter());

            var original = new DummyType {
                TimeSpan = TimeSpan.FromMinutes(1), Text = "someText"
            };

            var serialized = JsonConvert.SerializeObject(original, settings);

            var deserialized = JsonConvert.DeserializeObject <DummyType>(serialized, settings);

            Assert.NotNull(deserialized);
            Assert.Equal(deserialized.TimeSpan, TimeSpan.FromMinutes(1));
        }
Example #7
0
        public void TestMethodOf()
        {
            var obj = new DummyType();

            var actualMethod1 = typeof(DummyType).GetMethod("DoWork", Type.EmptyTypes);
            var actualMethod2 = typeof(DummyType).GetMethod("DoWork", new[] { typeof(string) });
            var actualMethod3 = typeof(DummyType).GetMethod("GetValue", new[] { typeof(string), typeof(int) });
            var method1       = ReflectionUtility.MethodOf(() => obj.DoWork());
            var method2       = ReflectionUtility.MethodOf(() => obj.DoWork(string.Empty));
            var method3       = ReflectionUtility.MethodOf(() => obj.GetValue(string.Empty, 0));

            Assert.IsNotNull(method1);
            Assert.IsNotNull(method2);
            Assert.IsNotNull(method3);
            Assert.AreEqual(actualMethod1, method1);
            Assert.AreEqual(actualMethod2, method2);
            Assert.AreEqual(actualMethod3, method3);
        }
        public void TestMethodOf()
        {
            var obj = new DummyType();

            var actualMethod1 = typeof(DummyType).GetMethod("DoWork", Type.EmptyTypes);
            var actualMethod2 = typeof(DummyType).GetMethod("DoWork", new[] { typeof(string) });
            var actualMethod3 = typeof(DummyType).GetMethod("GetValue", new[] { typeof(string), typeof(int) });
            var method1 = ReflectionUtility.MethodOf(() => obj.DoWork());
            var method2 = ReflectionUtility.MethodOf(() => obj.DoWork(string.Empty));
            var method3 = ReflectionUtility.MethodOf(() => obj.GetValue(string.Empty, 0));

            Assert.IsNotNull(method1);
            Assert.IsNotNull(method2);
            Assert.IsNotNull(method3);
            Assert.AreEqual(actualMethod1, method1);
            Assert.AreEqual(actualMethod2, method2);
            Assert.AreEqual(actualMethod3, method3);
        }
        public void DictionaryNoTruncateAttributeTest()
        {
            var str = new string('a', 1200);

            var dummyInstance = new DummyType();

            dummyInstance.DictionaryProp["foo"] = str;

            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var json = JsonConvert.SerializeObject(dummyInstance, settings);
            var deserializedDummyInstance = JsonConvert.DeserializeObject(json) as JObject;

            Assert.NotNull(deserializedDummyInstance);

            Assert.Equal(str.Length, deserializedDummyInstance["dictionaryProp"].Value <JObject>()["foo"]?.Value <string>()?.Length);
            Assert.Equal(str, deserializedDummyInstance["dictionaryProp"].Value <JObject>()["foo"].Value <string>());
        }
        public void StringNoTruncateAttributeTest()
        {
            var str = new string('a', 1200);

            var dummyInstance = new DummyType {
                IntProp = 42, StringProp = str
            };

            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var json = JsonConvert.SerializeObject(dummyInstance, settings);
            var deserializedDummyInstance = JsonConvert.DeserializeObject <DummyType>(json);

            Assert.NotNull(deserializedDummyInstance);

            Assert.Equal(str.Length, deserializedDummyInstance.StringProp.Length);
            Assert.Equal(str, deserializedDummyInstance.StringProp);
            Assert.Equal(42, deserializedDummyInstance.IntProp);
        }
        private static IProcess DummyProcess()
        {
            var product = new DummyType()
            {
                Id       = 42,
                Name     = "Bob",
                Foo      = 1337,
                Bobs     = new[] { 1, 3, 7, 42, 1337 },
                Identity = new ProductIdentity("123456", 01),
                Part     = new ProductPartLink <DummyType>(2)
                {
                    Product = new DummyType
                    {
                        Identity = new ProductIdentity("654321", 01),
                        Name     = "Thomas",
                        Foo      = 42
                    }
                }
            };
            var process = new ProductionProcess
            {
                Id     = 42,
                Recipe = new DummyRecipe
                {
                    Id          = 42,
                    Name        = "AwesomeRecipe",
                    OrderNumber = "123321",
                    Product     = product,
                    Config      = new Dictionary <string, string> {
                        { "Foo", "Blah" }
                    }
                },
                ProductInstance = product.CreateInstance()
            };

            process.ProductInstance.Id = 42;
            ((DummyInstance)process.ProductInstance).Blah = (float)0.815;

            return(process);
        }
Example #12
0
        public IEnumerator StartLuaSvr(Action <bool> onComplete)
        {
            if (ResourceManager.Instance.State != ResourceManager.RMState.AssetBundleManifestLoadEnd)
            {
                global::Debug.LogError("StartLuaSvr fail ResourceManager not ready");
                onComplete(false);
                yield break;
            }
            string      initModulePath  = this.GetModulePath(this.m_luaInitModuleName);
            TextAsset   initModuleAsset = null;
            IEnumerator iter            = ResourceManager.Instance.LoadAsset <TextAsset>(initModulePath, delegate(string lpath, TextAsset lasset)
            {
                initModuleAsset = lasset;
            }, false, false);

            yield return(iter);

            if (initModuleAsset == null)
            {
                global::Debug.LogError("StartLuaSvr fail load initModuleAsset fail");
                onComplete(false);
                yield break;
            }
            ResourceManager.Instance.MakeAssetBundleDontUnload(initModulePath);
            this.m_luaSvr = new LuaSvr();
            LuaSvr.mainState.loaderDelegate = new LuaState.LoaderDelegate(this.LuaLoader);
            this.m_luaSvr.init(null, delegate
            {
                if (!string.IsNullOrEmpty(this.m_luaInitModuleName))
                {
                    this.m_luaSvr.start(this.m_luaInitModuleName);
                }
                this.m_luaProtoBufExtensionHandler = LuaProtoBufExtensionHandler.Create();
                DummyType.InitLuaModule(LuaSvr.mainState);
            }, LuaSvrFlag.LSF_EXTLIB);
            onComplete(true);
            yield break;
        }
Example #13
0
 // Token: 0x060002FF RID: 767 RVA: 0x0000EDD4 File Offset: 0x0000CFD4
 public void AddConfigDataItemForLuaDummyType(string typeName, DummyType dataItem)
 {
     this.m_owner.AddConfigDataItemForLuaDummyType(typeName, dataItem);
 }
        public void TestPropertyOf()
        {
            var obj = new DummyType();

            var actualProp = typeof(DummyType).GetProperty("Integer");
            var prop = ReflectionUtility.PropertyOf(() => obj.Integer);

            Assert.IsNotNull(prop);
            Assert.AreEqual(actualProp, prop);
        }
 public DummyValue(DummyType type)
 {
     ProductType = type;
 }