public void ComplexEnumStringsInts() { //Arrange int vala = 123; int valb = 545; string valsa = "String1"; string valsb = "ZXCVFDSW"; eLocateBy loc = eLocateBy.ByName; NewPayLoad pl = new NewPayLoad("ComplexEnumStringsInts"); pl.AddValue(vala); pl.AddValue(valb); pl.AddValue(valsa); pl.AddValue(valsb); pl.AddEnumValue(loc); pl.ClosePackage(); // Act byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); int vala2 = pl2.GetValueInt(); int valb2 = pl2.GetValueInt(); string valsa2 = pl2.GetValueString(); string valsb2 = pl2.GetValueString(); string Loc2 = pl2.GetValueEnum(); //Assert Assert.AreEqual(vala, vala2); Assert.AreEqual(valb, valb2); Assert.AreEqual(valsa, valsa2); Assert.AreEqual(valsb, valsb2); Assert.AreEqual(loc.ToString(), Loc2); }
public void ComplexStringWith2Ints() { //Arrange int vala = 1237435; int valb = -185; string vals = "Not so long String"; NewPayLoad pl = new NewPayLoad("ComplexStringWith2Ints"); pl.AddValue(vala); pl.AddValue(valb); pl.AddValue(vals); pl.ClosePackage(); // Act byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); int vala2 = pl2.GetValueInt(); int valb2 = pl2.GetValueInt(); string vals2 = pl2.GetValueString(); //Assert Assert.AreEqual(vala, vala2); Assert.AreEqual(valb, valb2); Assert.AreEqual(vals, vals2); }
public void NoStructTest() { string first = "fffffffffffffffffffffffffff"; string last = "lllllllllllllllllllllllllll"; int age = 25; //Arrange NewPayLoad pl = new NewPayLoad("ppl"); pl.AddValue(first); pl.AddValue(last); pl.AddValue(age); pl.ClosePackage(); // Act byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); string first2 = pl2.GetValueString(); string last2 = pl2.GetValueString(); int age2 = pl2.GetValueInt(); //Assert Assert.AreEqual(first, first2, "first"); Assert.AreEqual(last, last2, "last"); Assert.AreEqual(age, age2, "age"); }
public void ClientSendCalcSum() { // Arrange NewPayLoad PL = new NewPayLoad("CalcSum", 100000000); //Act NewPayLoad PLRC = mMyGingerClient.Send(PL); int total = PLRC.GetValueInt(); //Assert // Assert.AreEqual("ClientMessage", PLRC.Name, "PLRC.Name = ClientMessage"); // Assert.AreEqual("Processing Started", txt2); }
public void IntMaxValue() { //Arrange int val = Int16.MaxValue; NewPayLoad pl = new NewPayLoad("IntMaxValue"); pl.AddValue(val); pl.ClosePackage(); // Act byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); int val2 = pl2.GetValueInt(); //Assert Assert.AreEqual(val, val2); }
public void NegativeInt() { //Arrange int val = -123; NewPayLoad pl = new NewPayLoad("NegativeInt"); pl.AddValue(val); pl.ClosePackage(); // Act byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); int val2 = pl2.GetValueInt(); //Assert Assert.AreEqual(val, val2); }
private NewPayLoad AttachDisplay(NewPayLoad pl) { string host = pl.GetValueString(); int port = pl.GetValueInt(); RemoteObjectsClient c = new RemoteObjectsClient(); c.Connect(host, port); //TODO: fix hard coded !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Assembly driverAssembly = Assembly.LoadFrom(@"C:\Yaron\TFS\Ginger\Devs\GingerNextVer_Dev\GingerWebServicesPlugin\bin\Debug\netstandard2.0\WebServices.GingerPlugin.dll"); Type t = driverAssembly.GetType("Amdocs.Ginger.WebServices.IWebServicesDriverDisplay"); // We do all using reflection, since we don't have ref to the driver dll, it will load at run time MethodInfo mi = typeof(RemoteObjectsClient).GetMethod("GetObject").MakeGenericMethod(new Type[] { t }); object driverDisplayRemoteObject = mi.Invoke(c, new object[] { "ID aas as !!!" }); mDriver.GetType().GetMethod("AttachDisplay").Invoke(mDriver, new object[] { driverDisplayRemoteObject }); return(new NewPayLoad("OK", "Done")); }
// Handle Client request private NewPayLoad HandlePayLoad(NewPayLoad PL) { switch (PL.Name) { case "Echo": string txt = PL.GetValueString(); NewPayLoad PLEcho = new NewPayLoad("EchoBack", txt); return(PLEcho); case "DummyAction": NewPayLoad PLDummy = new NewPayLoad("OK", "Done"); return(PLDummy); case "SpeedTest": NewPayLoad PLSpeedTest = new NewPayLoad("OK", "Speedy"); return(PLSpeedTest); case "SlowResponse1000": Thread.Sleep(1000); NewPayLoad PLOK1000 = new NewPayLoad("OK1000", "Done"); return(PLOK1000); case "LongAction": Thread.Sleep(10000); NewPayLoad PLOKLongAction = new NewPayLoad("LongActionDone", "Done"); return(PLOKLongAction); case "CalcSum": int num = PL.GetValueInt(); int total = 0; for (int j = 0; j < num; j++) { total += j; } NewPayLoad PLOKTotalAction = new NewPayLoad("Total", total); return(PLOKTotalAction); default: throw new Exception("Unknown PayLoad Action - " + PL.Name); } }
// Handle Client request private NewPayLoad HandlePayLoad(NewPayLoad PL) { switch (PL.Name) { case "GetObject": string id = PL.GetValueString(); object obj = GetObjectHandler(id); RemoteObjectHandle remoteObjectHandle = new RemoteObjectHandle(); Guid guid = Guid.NewGuid(); remoteObjectHandle.GUID = guid; remoteObjectHandle.Object = obj; //check if the object have Dispatcher - means GUI element so STA thread then run it on the STA, so we keep the Dispatcher for the invoke part later PropertyInfo PI = obj.GetType().GetProperty("Dispatcher"); if (PI != null) { object DispObj = obj; dynamic d = DispObj; // It means it is UI control - so invoke on the UI control Dispatcher, this way we avoid code on the page to change the UI on the Dispatcher every time // temp comment for build // !!!!!!!!! d. requires Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo // remoteObjectHandle.Dispatcher = d.Dispatcher; } mObjects.Add(guid, remoteObjectHandle); NewPayLoad PLEcho = new NewPayLoad("Object", guid.ToString()); return(PLEcho); case "SendObject": string txt2 = "a=1;b=2"; NewPayLoad PLEcho2 = new NewPayLoad("Object", txt2); return(PLEcho2); case "Invoke": Guid objguid = Guid.Parse(PL.GetValueString()); string methodName = PL.GetValueString(); RemoteObjectHandle ROH; // Get the object by guid bool bFound = mObjects.TryGetValue(objguid, out ROH); object obj1 = ROH.Object; //TODO: if not found... MethodInfo mi = obj1.GetType().GetMethod(methodName); int ParamCounter = PL.GetValueInt(); object[] param = new object[ParamCounter]; for (int i = 0; i < ParamCounter; i++) { param[i] = PL.GetValueByObjectType(); } // invoke object rc = null; // temp comment for build // !!!!!!!!! d. requires Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo //if (ROH.Dispatcher == null) //{ // // Non UI object safe to call from another thread // rc = mi.Invoke(obj1, param); //} //else //{ // // It means the obj is UI control like driver Page- so invoke on the UI control Dispatcher, // // this way we avoid code on the page to change the UI on the Dispatcher every time we do UI changes and avoid getting exception // ROH.Dispatcher.BeginInvoke( // (Action)(() => { // rc = mi.Invoke(obj1, param); // } // )); //} // return result NewPayLoad PLRC = new NewPayLoad("OK"); if (rc != null) { PLRC.AddValueByObjectType(rc); } else { PLRC.AddValue("NULL"); PLRC.AddValue("NULL"); } PLRC.ClosePackage(); return(PLRC); default: throw new InvalidOperationException("Unknown PayLoad Action - " + PL.Name); } }