123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using GenericDisplayCommand;
- using GenericDisplayCommand.Controls;
- using GenericDisplayCommand.Controls.V1;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Xml;
- using System.Xml.Serialization;
- namespace GenericDisplayCommandTest
- {
- [TestClass]
- public class UnitTest1
- {
- private LinearLayout ConstuctCarPlateLabel(string carPlate, string hint, string hintColor)
- {
- var label = new LinearLayout()
- {
- Id = carPlate,
- Height = "match_parent",
- Width = "match_parent",
- Orientation = "horizontal",
- AllowActions = new List<AllowAction>() { AllowAction.Select, AllowAction.Drag, AllowAction.Drop },
- };
- label.Views.Add(new TextView()
- {
- Text = carPlate,
- Background = "White",
- AllowActions = new List<AllowAction>() { AllowAction.Select, AllowAction.Drag }
- });
- label.Views.Add(new TextView() { Text = hint, Background = hintColor, PaddingLeft = "2dp" });
- return label;
- }
- public class A
- {
- public LinearLayout Host { get; set; }
- }
- [TestMethod]
- public void TestMethod1()
- {
- LinearLayout advLinearLayout = new LinearLayout();
- advLinearLayout.Views.Add(new VideoView() { Src = "mp4.avi" });
- advLinearLayout.Orientation = "vertical";
- advLinearLayout.Height = "0dp";
- advLinearLayout.WeightSum = 4.ToString();
- advLinearLayout.Width = "match_parent";
- LinearLayout middleLinearLayout = new LinearLayout()
- {
- Orientation = "horizontal",
- Height = "0dp",
- Weight = 3.ToString(CultureInfo.InvariantCulture),
- Width = "match_parent",
- };
- #region middle_left
- LinearLayout middle_left_LinearLayout = new LinearLayout()
- {
- Height = "match_parent",
- Width = "0dp",
- Weight = (7.5f).ToString(CultureInfo.InvariantCulture),
- };
- var carPlatesGridView = new GridView() { NumColumns = 3 };
- List<Tuple<string, string>> carPlateLabels = new List<Tuple<string, string>>();
- carPlateLabels.Add(new Tuple<string, string>("ACD343", "车牌付"));
- carPlateLabels.Add(new Tuple<string, string>("BCDFSADF", "普通用户"));
- carPlateLabels.Add(new Tuple<string, string>("CDF23423DF", "车牌付"));
- carPlateLabels.Add(new Tuple<string, string>("D232f23DF", "普通用户"));
- carPlateLabels.Add(new Tuple<string, string>("Eadfvvhjk3DF", "车牌付"));
- for (int i = 0; i < carPlateLabels.Count; i++)
- {
- carPlatesGridView.Views.Add(this.ConstuctCarPlateLabel(carPlateLabels[i].Item1,
- carPlateLabels[i].Item2, "Yellow"));
- }
- middle_left_LinearLayout.Views.Add(carPlatesGridView);
- #endregion
- #region middle right
- LinearLayout middle_right_LinearLayout = new LinearLayout()
- {
- Height = "match_parent",
- Width = "0dp",
- Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
- };
- var errorCarPlatesGridView = new GridView() { NumColumns = 1 };
- List<Tuple<string, string>> errorCarPlateLabels = new List<Tuple<string, string>>();
- errorCarPlateLabels.Add(new Tuple<string, string>("QCD343", "交易出错"));
- errorCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "交易超时"));
- errorCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "交易被取消"));
- errorCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "交易状态未知"));
- errorCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "交易出错"));
- for (int i = 0; i < errorCarPlateLabels.Count; i++)
- {
- errorCarPlatesGridView.Views.Add(this.ConstuctCarPlateLabel(errorCarPlateLabels[i].Item1,
- errorCarPlateLabels[i].Item2, "Red"));
- }
- middle_right_LinearLayout.Views.Add(errorCarPlatesGridView);
- #endregion
- LinearLayout bottomLinearLayout = new LinearLayout()
- {
- Orientation = "horizontal",
- Height = "0dp",
- Weight = 3.ToString(CultureInfo.InvariantCulture),
- WeightSum = 10.ToString(CultureInfo.InvariantCulture),
- Width = "match_parent",
- };
- #region firstNozzleLinearLayout
- LinearLayout firstNozzleLinearLayout = new LinearLayout()
- {
- Orientation = "vertical",
- Height = "match_parent",
- Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
- Width = "0dp",
- };
- List<Tuple<string, string>> firstNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "车牌付加油中"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "车牌付待付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("T232f23DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Qadfvvhjk3DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("H232f23DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Madfvvhjk3DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("N232f23DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Vadfvvhjk3DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("K232f23DF", "车牌付已支付"));
- firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Ladfvvhjk3DF", "车牌付已支付"));
- for (int i = 0; i < firstNozzleBoundCarPlateLabels.Count; i++)
- {
- firstNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(firstNozzleBoundCarPlateLabels[i].Item1,
- firstNozzleBoundCarPlateLabels[i].Item2, "Blue"));
- }
- firstNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 1 });
- #endregion
- bottomLinearLayout.Views.Add(firstNozzleLinearLayout);
- #region second NozzleLinearLayout
- LinearLayout secondNozzleLinearLayout = new LinearLayout()
- {
- Orientation = "vertical",
- Height = "match_parent",
- Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
- Width = "0dp",
- };
- List<Tuple<string, string>> secondNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "车牌付加油中"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "车牌付待付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("T232f23DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Qadfvvhjk3DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("H232f23DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Madfvvhjk3DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("N232f23DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Vadfvvhjk3DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("K232f23DF", "车牌付已支付"));
- secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Ladfvvhjk3DF", "车牌付已支付"));
- for (int i = 0; i < secondNozzleBoundCarPlateLabels.Count; i++)
- {
- secondNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(secondNozzleBoundCarPlateLabels[i].Item1,
- secondNozzleBoundCarPlateLabels[i].Item2, "Blue"));
- }
- secondNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 2 });
- #endregion
- bottomLinearLayout.Views.Add(secondNozzleLinearLayout);
- #region third NozzleLinearLayout
- LinearLayout thirdNozzleLinearLayout = new LinearLayout()
- {
- Orientation = "vertical",
- Height = "match_parent",
- Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
- Width = "0dp",
- };
- List<Tuple<string, string>> thirdNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "车牌付加油中"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "车牌付待付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("T232f23DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Qadfvvhjk3DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("H232f23DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Madfvvhjk3DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("N232f23DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Vadfvvhjk3DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("K232f23DF", "车牌付已支付"));
- thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Ladfvvhjk3DF", "车牌付已支付"));
- for (int i = 0; i < thirdNozzleBoundCarPlateLabels.Count; i++)
- {
- thirdNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(thirdNozzleBoundCarPlateLabels[i].Item1,
- thirdNozzleBoundCarPlateLabels[i].Item2, "Blue"));
- }
- thirdNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 3 });
- #endregion
- bottomLinearLayout.Views.Add(thirdNozzleLinearLayout);
- #region fourth NozzleLinearLayout
- LinearLayout fourthNozzleLinearLayout = new LinearLayout()
- {
- Orientation = "vertical",
- Height = "match_parent",
- Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
- Width = "0dp",
- };
- List<Tuple<string, string>> fourthNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "车牌付加油中"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "车牌付待付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("T232f23DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Qadfvvhjk3DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("H232f23DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Madfvvhjk3DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("N232f23DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Vadfvvhjk3DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("K232f23DF", "车牌付已支付"));
- fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("Ladfvvhjk3DF", "车牌付已支付"));
- for (int i = 0; i < fourthNozzleBoundCarPlateLabels.Count; i++)
- {
- fourthNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(fourthNozzleBoundCarPlateLabels[i].Item1,
- fourthNozzleBoundCarPlateLabels[i].Item2, "Blue"));
- }
- fourthNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 4 });
- #endregion
- bottomLinearLayout.Views.Add(fourthNozzleLinearLayout);
- LinearLayout root = new LinearLayout();
- root.Orientation = "vertical";
- root.Height = "match_parent";
- root.Width = "match_parent";
- root.WeightSum = 10.ToString(CultureInfo.InvariantCulture);
- root.Views.Add(advLinearLayout);
- root.Views.Add(middleLinearLayout);
- root.Views.Add(bottomLinearLayout);
- var genericDisplayCommand = new GenericDisplayCommandV1Wrapper() { Version = 1, Control = root };
- XmlSerializer xmlSerializer = new XmlSerializer(typeof(GenericDisplayCommandV1Wrapper),
- new Type[] { typeof(LinearLayout), typeof(VideoView), typeof(TextView), typeof(NozzleView) });
- //MemoryStream ms = new MemoryStream();
- //xmlSerializer.Serialize(ms, root);
- var message = "";
- using (var sww = new StringWriter())
- {
- using (XmlWriter writer = XmlWriter.Create(sww))
- {
- xmlSerializer.Serialize(writer, genericDisplayCommand);
- var xml = sww.ToString(); // Your XML
- message = xml;
- }
- }
- //string json = JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.None,
- // new JsonSerializerSettings
- // {
- // NullValueHandling = NullValueHandling.Ignore
- // });
- }
- /// <summary>
- /// Test the deserialize method of message type GernericDisplayCommand
- /// </summary>
- [TestMethod]
- public void TestMethod2()
- {
-
- var rootLinearlayout = new LinearLayout();
- var plateLinearlayout = new LinearLayout() { Id = "978"};
- plateLinearlayout.AllowActions = new List<AllowAction>() { AllowAction.Drag };
- var pumpLinearlayout = new LinearLayout() { Id = "13", AllowActions = new List<AllowAction>(){AllowAction.Drop}};
- rootLinearlayout.Views.Add(plateLinearlayout);
- rootLinearlayout.Views.Add(pumpLinearlayout);
- var genericDisplayCommand = new GenericDisplayCommandV1Wrapper(){Control = rootLinearlayout,Version = 1};
- var head = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
- var s= /*head +*/ @"<GenericDisplayCommand><LinearLayout><Height></Height><Id></Id><LinearLayout><AllowActions><AllowAction>Drag</AllowAction></AllowActions ><Height></Height><Id>978</Id><Orientation></Orientation><Weight>0</Weight><WeightSum>0</WeightSum><Width>0</Width></LinearLayout><LinearLayout><AllowActions><AllowAction>Drop</AllowAction></AllowActions><Height>0</Height><Id>13</Id><Orientation></Orientation><Weight>0</Weight><WeightSum>0</WeightSum><Width>0</Width></LinearLayout><Orientation></Orientation><Weight>0</Weight><WeightSum>0</WeightSum><Width>0</Width></LinearLayout><Version>1</Version></GenericDisplayCommand> ";
- XmlSerializer xmldeSerializer = new XmlSerializer(typeof(GenericDisplayCommandV1Wrapper),
- new Type[] { typeof(LinearLayout), typeof(VideoView), typeof(TextView), typeof(NozzleView) });
- s = @"<GenericDisplayCommand><LinearLayout><AllowActions><AllowAction>Submit</AllowAction></AllowActions><Height></Height><Id>436</Id><Orientation></Orientation><Weight></Weight><WeightSum></WeightSum><Width></Width></LinearLayout><Version>1</Version></GenericDisplayCommand>";
- var message = "";
- using (var sww = new StringWriter())
- {
- using (XmlWriter writer = XmlWriter.Create(sww))
- {
- xmldeSerializer.Serialize(writer, genericDisplayCommand);
- var xml = sww.ToString(); // Your XML
- message = xml;
- }
- }
- using (var sr = new StringReader(s))
- {
- var result = (GenericDisplayCommandV1Wrapper)xmldeSerializer.Deserialize(sr);
- }
- }
- }
- }
|