public void FlatJsonRoundTrip() { var input = new UTinyRegistry(); var structType = input.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); structType.CreateField("IntField", (UTinyType.Reference)UTinyType.Int32); structType.CreateField("FloatField", (UTinyType.Reference)UTinyType.Int32); structType.CreateField("StringField", (UTinyType.Reference)UTinyType.Int32); var module = input.CreateModule( UTinyId.New(), "TestModule"); module.AddStructReference((UTinyType.Reference)structType); using (var json = new MemoryStream()) using (var command = new MemoryStream()) { // Write the data model to a stream as json // mem -> json Serialization.FlatJson.BackEnd.Persist(json, structType, module); json.Position = 0; var reader = new StreamReader(json); { Debug.Log(reader.ReadToEnd()); } json.Position = 0; // Read the data model // json -> commands Serialization.FlatJson.FrontEnd.Accept(json, command); command.Position = 0; // Create a registry to hold accepted objects var output = new UTinyRegistry(); // Process the command // commands -> mem Serialization.CommandStream.FrontEnd.Accept(command, output); Assert.IsNotNull(output.FindById <UTinyType>(structType.Id)); Assert.IsNotNull(output.FindById <UTinyModule>(module.Id)); } }
public void StreamingRoundTrip() { var input = new UTinyRegistry(); var type = input.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); type.CreateField("IntField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("FloatField", (UTinyType.Reference)UTinyType.Int32); type.CreateField("StringField", (UTinyType.Reference)UTinyType.Int32); var module = input.CreateModule( UTinyId.New(), "TestModule"); module.AddStructReference((UTinyType.Reference)type); using (var command = new MemoryStream()) { // Write the data model to a stream as json // mem -> command BackEnd.Persist(command, type, module); command.Position = 0; // Create a registry to hold accepted objects var output = new UTinyRegistry(); // Process the command // commands -> mem FrontEnd.Accept(command, output); Assert.IsNotNull(output.FindById <UTinyType>(type.Id)); Assert.IsNotNull(output.FindById <UTinyModule>(module.Id)); } }
public void NameChangeTest() { var registry = new UTinyRegistry(); var type = registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct ); var module = registry.CreateModule( UTinyId.New(), "TestModule" ); module.AddStructReference((UTinyType.Reference)type); module.Refresh(); type.Name = "NewStruct"; Debug.Log(module.ToString()); }