public void DataObject_CanBeSavedAndRetrievedById() { var guid = new Guid("AA37A611-B7F4-4EE8-AE2F-D32FB2D0D151"); var distractorguid = new Guid("00000000-B7F4-4EE8-AE2F-D32FB2D0D151"); var o = new SimpleDataObject() { BooleanValue = true, DoubleValue = 32, Int32Value = 64, GuidValue = guid, StringValue = "a string" }; o.Save(); var distractor = new SimpleDataObject() { GuidValue = distractorguid }; distractor.Save(); var test = SimpleDataObject.Get(guid); AssertFullMatch(o, test); }
public void DataObject_CanBeRetrievedByString() { var guid = new Guid("AB37A611-B7F4-4EE8-AE2F-D32FB2D0D151"); var distractorguid = new Guid("00000000-B7F4-4EE8-AE2F-D32FB2D0D151"); var str = "retrieval string"; var o = new SimpleDataObject() { BooleanValue = true, DoubleValue = 12, Int32Value = 24, GuidValue = guid, StringValue = str }; o.Save(); var distractor = new SimpleDataObject() { GuidValue = distractorguid }; distractor.Save(); var test = SimpleDataObject.Get(new SimpleDataObject() { StringValue = str }); Assert.AreEqual(1, test.Count); AssertFullMatch(o, test[0]); }
public void TestJSONInvokeSingle() { string key = "foo"; DataContext context = new DataContext(); SampleSimpleDataControl ctl = Samples.GetSimpleDataControl(); int startingCount = context.DataItemCount; context.RegisterDataItem(key, ctl); context.SetAllowReflectiveSerialization(key, true); Assert.AreEqual(startingCount + 1, context.DataItemCount); //context.ResolveDataValues(); MemoryStream s = new MemoryStream(); StreamWriter writer = new StreamWriter(s); context.WriteClientContext(writer); writer.Flush(); string result = DataContext.GetStreamContent(s); SimpleDataObject rawData = (SimpleDataObject)ctl.Value; Assert.IsTrue(result.IndexOf(rawData.MyString) > -1, "Data not found in client context"); Assert.AreNotEqual(rawData.MyString, result, "Client context did not wrap"); }
static StackAllocTests() { //Pre JIT StackAllocTests.SimpleObject = StackAlloc <SimpleObject> .Alloc(stackalloc byte[StackAlloc <SimpleObject> .AllocAmount]); StackAllocTests.SimpleDataObject = StackAlloc <SimpleDataObject> .Alloc(stackalloc byte[StackAlloc <SimpleDataObject> .AllocAmount], 0L); }
public void PropertyObjectInvokersLoad() { GenericExpressionEvalWrapper.ClearRegisteredTypes(); string valExpr = "MyString"; DataContext context = new DataContext(); string testString = "Test String"; SimpleDataObject data = new SimpleDataObject(1, testString, 2.2); GenericExpressionEvalWrapper wrapper = new GenericExpressionEvalWrapper(data, false); object rslt = wrapper.ResolveExpressionValue(valExpr); Assert.IsNotNull(rslt, "Result is null"); string result = rslt.ToString(); Assert.AreEqual(testString, result, "Direct ResolveExpressionValue call failed"); Assert.AreEqual(result, WrapperUtility.ResolveExpressionValue(valExpr, data, GenericExpressionEvalWrapper.GetDataPropertyEvaluator(data.GetType()))); DataContext dc = new DataContext(); dc.RegisterDataItem("foo", wrapper); string dcResult = dc.CalculateVariableValue("${foo." + valExpr + "}"); Assert.AreEqual(testString, dcResult, "DataContext gave incorrect result"); }
public void DataObject_CanSerializeDoubles() { var o = new SimpleDataObject() { DoubleValue = 3.2 }; var d = o.ToDictionary(); Assert.AreEqual("3.2", d["DoubleValue"]); }
public void DataObject_CanSerializeInt32s() { var o = new SimpleDataObject() { Int32Value = 32 }; var d = o.ToDictionary(); Assert.AreEqual("32", d["Int32Value"]); }
public void DataObject_CanSerializeStrings() { var o = new SimpleDataObject() { StringValue = "a string" }; var d = o.ToDictionary(); Assert.AreEqual("a string", d["StringValue"]); }
public void DataObject_DoesNotSerializeBooleansByDefault() { var ot = new SimpleDataObject() { BooleanValue = true }; var dt = ot.ToDictionary(); Assert.IsFalse(dt.ContainsKey("BooleanValue")); }
public void NoHeapAllocConstructor() { long before = GC.GetTotalAllocatedBytes(precise: true); StackAllocTests.SimpleDataObject = StackAlloc <SimpleDataObject> .Alloc(stackalloc byte[StackAlloc <SimpleDataObject> .AllocAmount], StackAllocTests.SimpleDataObjectValue); long after = GC.GetTotalAllocatedBytes(precise: true); Assert.Equal(before, after); Assert.Equal(StackAllocTests.SimpleDataObject.Value, StackAllocTests.SimpleDataObject.Value); }
public static void AssertFullMatch(SimpleDataObject a, SimpleDataObject b) { var dict_a = a.ToDictionary(); var dict_b = b.ToDictionary(); Assert.AreEqual(dict_a.Count, dict_b.Count); foreach (var k in dict_a.Keys) { Assert.AreEqual(dict_a[k], dict_b[k]); } }
public void SimpleData() { var simple = new SimpleDataObject(barack, null); simple.InitializeData(); Assert.AreEqual(barack.Name, simple.Data[nameof(barack.Name)]); Assert.AreEqual(barack.Children, simple.Data[nameof(barack.Children)]); var clone = (Person)simple.Value; Assert.AreEqual(barack.Name, clone.Name); Assert.AreEqual(barack.Children, clone.Children); // well, the DNA test would say they're the clone's as well ;) }
public void DataObject_CanSerializeGuids() { var guidstring = "CA37A611-B7F4-4EE8-AE2F-D32FB2D0D151"; var guid = new Guid(guidstring); var o = new SimpleDataObject() { GuidValue = guid }; var d = o.ToDictionary(); Assert.AreEqual(guidstring.ToLower(), d["GuidValue"]); }
public void PropertyDataObjectRecognized() { GenericExpressionEvalWrapper.ClearRegisteredTypes(); string testString = "Test String"; SimpleDataObject data = new SimpleDataObject(1, testString, 2.2); GenericExpressionEvalWrapper wrapper = new GenericExpressionEvalWrapper(data); int invokerCount = GenericExpressionEvalWrapper.GetDataFieldEvaluator(data.GetType()).Count; Assert.AreEqual(invokerCount, 0); Assert.Less(0, GenericExpressionEvalWrapper.GetDataPropertyEvaluator(data.GetType()).Count, "Property invokers not loaded"); }
public void AnyObjectSimpleData() { var timmy = new Person("Timmy", null, null); var lassie = new Dog("Lassie", timmy); var simple = new SimpleDataObject(lassie, null); simple.InitializeData(); Assert.AreEqual(lassie.Name, simple.Data[nameof(lassie.Name)]); Assert.AreEqual(lassie.Owner, simple.Data[nameof(lassie.Owner)]); var clone = (Dog)simple.Value; Assert.AreEqual(lassie.Name, clone.Name); Assert.AreEqual(lassie.Owner, clone.Owner); }
public void DataObject_CanSerializeBooleans() { var ot = new SimpleDataObject() { BooleanValue = true }; var dt = ot.ToDictionary(true); Assert.AreEqual("1", dt["BooleanValue"]); var of = new SimpleDataObject() { BooleanValue = false }; var df = of.ToDictionary(true); Assert.AreEqual("0", df["BooleanValue"]); }
public override void OnInspectorGUI() { // Make sure object is up-to-date and we are displaying correct values: serializedObject.Update(); // Draw default body content: base.OnInspectorGUI(); // Draw 'refresh' button: if (GUILayout.Button("Refresh")) { // A list of all matching assets in the project that we will populate: List <SimpleDataObject> assetsInProject = new List <SimpleDataObject>(); // Get guids for assets that match the given type: string[] guids = AssetDatabase.FindAssets("t:SimpleDataObject"); for (int i = 0; i < guids.Length; i++) { // Using the asset guid, get a full path to the asset itself: string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]); // Using the asset path, load the object itself: SimpleDataObject asset = AssetDatabase.LoadAssetAtPath <SimpleDataObject>(assetPath); // If nothing went wrong, then add the asset to our list: if (asset != null) { assetsInProject.Add(asset); } } // Check if the target of this inspector is a SimpleDataCollection and cast it as that type: if (target is SimpleDataCollection simpleDataCollection) { // Finally, set the new list of objects on our collection: simpleDataCollection.SetDataObjectList(assetsInProject); } } // Apply any changes we made to the object: serializedObject.ApplyModifiedProperties(); }
public void SimpleDataGameState() { Galaxy.Load("freeefurball_1.gam"); var gal = Galaxy.Current; var simple = new SimpleDataObject(gal); var sandbox = BuildSandbox(); simple.Context.KnownObjects.Clear(); sandbox.SetData("galaxy", simple); // can we make a new galaxy over there and get some data out? var data = (SimpleDataObject)sandbox.CreateInstanceAndUnwrap(Assembly.GetAssembly(typeof(SimpleDataObject)).FullName, typeof(SimpleDataObject).FullName); data.SimpleData = simple.SimpleData; var data2 = new SimpleDataObject(); data2.SimpleData = data.SimpleData; var galcopy = data2.Reconstitute <Galaxy>(); Assert.AreEqual(gal.Empires[0].Name, galcopy.Empires[0].Name); }
public void DuplicateKeyAcrossViews(string val1, string val2, string viewDef1, string viewDef2, string ctlDef1, string ctlDef2, string testView1, string testView2, bool expectedView2Defined) { string key = "foo"; DataContext dc = new DataContext(); SimpleDataObject data1 = new SimpleDataObject(); data1.MyString = val1; SampleSimpleDataControl ctl1 = new SampleSimpleDataControl(data1); ctl1.Key = key; ctl1.RawTag = ctlDef1; SimpleDataObject data2 = new SimpleDataObject(); data2.MyString = val2; SampleSimpleDataControl ctl2 = new SampleSimpleDataControl(data2); ctl2.Key = key; ctl2.RawTag = ctlDef2; dc.RegisterDataItem(ctl1, viewDef1); dc.RegisterDataItem(ctl2, viewDef2); Assert.AreEqual(true, dc.MasterData[key].IsValidForView(testView1), "View1 validity failed"); Assert.AreEqual(expectedView2Defined, dc.MasterData[key].IsValidForView(testView2), "View2 validity not expected"); string result; string var = "${foo.MyString}"; dc.ActiveViewScope = testView1; Assert.AreEqual(val1, dc.GetVariableValue(var), "Failed check on testView1"); dc.ActiveViewScope = testView2; Assert.AreEqual(val2, dc.GetVariableValue(var), "Failed check on testView2"); }
public void SimpleDataObject2XMLDocumentTest() { SimpleDataObject simpleDataObject = new SimpleDataObject(); string name = "Tomcat"; int age = 15; KeyGuid pk = (KeyGuid)simpleDataObject.__PrimaryKey; simpleDataObject.Name = name; simpleDataObject.Age = age; Console.WriteLine("Записали Name: " + simpleDataObject.Name + " Age: " + simpleDataObject.Age); ICSSoft.STORMNET.DataObject dObjToXML = simpleDataObject; var serializedObj = ToolXML.DataObject2XMLDocument(ref dObjToXML); ICSSoft.STORMNET.DataObject dObjFromXML = null; bool babah = false; try { ToolXML.XMLDocument2DataObject(ref dObjFromXML, serializedObj); } catch (ArgumentNullException) { babah = true; } Assert.True(babah); SimpleDataObject simpleDataObjectFromXML = new SimpleDataObject(); dObjFromXML = simpleDataObjectFromXML; ToolXML.XMLDocument2DataObject(ref dObjFromXML, serializedObj); Assert.Equal(((SimpleDataObject)dObjFromXML).Name, name); Assert.Equal(((SimpleDataObject)dObjFromXML).Age, age); Assert.Equal(dObjFromXML.__PrimaryKey, pk); }