public void CreateTest() { var ser = new XActionWriter(); var actionFactory = new ActionsFactory(); var vals = Enum.GetValues(typeof(ActionCode)); foreach (ActionCode type in vals) { if ((byte)type <= 0x80) { var action = actionFactory.Create(type); try { var res = ser.Serialize(action); var actualName = res.Name.LocalName; var expectedName = type.ToString(); if (type == ActionCode.End) { expectedName = "EndAction"; } if (actualName != expectedName) { Console.WriteLine("Warning: Incosistent naming, Action type: {0}, Class: {1}", type, actualName); } } catch (Exception) { Assert.Fail("Couldnt serialize: {0}", type); } } } }
public void WriteOneByteActionsTest() { var vals = Enum.GetValues(typeof(ActionCode)); var factory = new ActionsFactory(); foreach (ActionCode type in vals) { if ((byte)type < 0x80) { var action = factory.Create(type); var xAction = XAction.ToXml(action); Assert.AreEqual(xAction.Name.LocalName, XActionNames.FromActionCode(type)); } } }
public ActionBase Deserialize(XElement xAction) { ActionBase action; if (xAction.Name.LocalName != "Unknown") { var actionCode = XActionNames.FromNodeName(xAction.Name.LocalName); action = _factory.Create(actionCode); } else { action = new ActionUnknown((ActionCode)xAction.RequiredByteAttribute("type")); } action.AcceptVisitor(this, xAction); return(action); }
public void AllActionsBuildTest() { var factory = new ActionsFactory(); var vals = Enum.GetValues(typeof(ActionCode)); foreach (ActionCode type in vals) { var action = factory.Create(type); Assert.IsNotNull(action); if (action.GetType().Name != "Action" + type.ToString()) { Console.WriteLine("Warning: Incosistent naming, Action code: {0}, Class: {1}", type, action.GetType().Name); } var actualType = action.ActionCode; Assert.AreEqual(type, actualType); } }
public void WriteOneByteActionsTest() { var vals = Enum.GetValues(typeof(ActionCode)); var factory = new ActionsFactory(); foreach (ActionCode type in vals) { if ((byte)type < 0x80) { var action = factory.Create(type); var mem = new MemoryStream(); var writer = new SwfStreamWriter(mem); var actionWriter = new ActionWriter(writer); actionWriter.WriteAction(action); var buffer = mem.ToArray(); Assert.AreEqual(1, buffer.Length); Assert.AreEqual((byte)type, buffer[0]); } } }