//test the the get and remove methonds, using the add method during the test to confirm. //the function is inserting legal flight to the server, ask for it again and delete it. //to make sure the remove method worked as expected - we check for number of items. //in this scenario - we should find 0 item. public void Add_Get_RemoveServer_LegalInput_ReturnValidAnswers() { var actualLen = 0; var expectedLen = 0; var flightCtrlManager = new FlightControlManager(); var dummyServer = new Server { ServerId = "testName", ServerURL = "https://www.testUrl.com" }; flightCtrlManager.AddServer(dummyServer); var result = flightCtrlManager.GetServers(); foreach (var item in result) { Assert.AreEqual(dummyServer.ServerId, item.ServerId); Assert.AreEqual(dummyServer.ServerURL, item.ServerURL); } flightCtrlManager.RemoveServer(dummyServer.ServerId); result = flightCtrlManager.GetServers(); foreach (var item in result) { actualLen++; } Assert.AreEqual(expectedLen, actualLen); }
private void InitializeSuffixes() { AddSuffix("PARTSNAMED", new OneArgsSuffix <ListValue, string>(GetPartsNamed)); AddSuffix("PARTSTITLED", new OneArgsSuffix <ListValue, string>(GetPartsTitled)); AddSuffix("PARTSDUBBED", new OneArgsSuffix <ListValue, string>(GetPartsDubbed)); AddSuffix("MODULESNAMED", new OneArgsSuffix <ListValue, string>(GetModulesNamed)); AddSuffix("PARTSINGROUP", new OneArgsSuffix <ListValue, string>(GetPartsInGroup)); AddSuffix("MODULESINGROUP", new OneArgsSuffix <ListValue, string>(GetModulesInGroup)); AddSuffix("PARTSTAGGED", new OneArgsSuffix <ListValue, string>(GetPartsTagged)); AddSuffix("ALLTAGGEDPARTS", new NoArgsSuffix <ListValue>(GetAllTaggedParts)); AddSuffix("PARTS", new NoArgsSuffix <ListValue>(GetAllParts)); AddSuffix("DOCKINGPORTS", new NoArgsSuffix <ListValue>(() => Vessel.PartList("dockingports", Shared))); AddSuffix("ELEMENTS", new NoArgsSuffix <ListValue>(() => Vessel.PartList("elements", Shared))); AddSuffix("CONTROL", new Suffix <FlightControl>(() => FlightControlManager.GetControllerByVessel(Vessel))); AddSuffix("BEARING", new Suffix <float>(() => VesselUtils.GetTargetBearing(CurrentVessel, Vessel))); AddSuffix("HEADING", new Suffix <float>(() => VesselUtils.GetTargetHeading(CurrentVessel, Vessel))); AddSuffix("AVAILABLETHRUST", new Suffix <double>(() => VesselUtils.GetAvailableThrust(Vessel))); AddSuffix("AVAILABLETHRUSTAT", new OneArgsSuffix <double, double>(GetAvailableThrustAt)); AddSuffix("MAXTHRUST", new Suffix <double>(() => VesselUtils.GetMaxThrust(Vessel))); AddSuffix("MAXTHRUSTAT", new OneArgsSuffix <double, double>(GetMaxThrustAt)); AddSuffix("FACING", new Suffix <Direction>(() => VesselUtils.GetFacing(Vessel))); AddSuffix("ANGULARMOMENTUM", new Suffix <Vector>(() => new Vector(Vessel.angularMomentum))); AddSuffix("ANGULARVEL", new Suffix <Vector>(() => RawAngularVelFromRelative(Vessel.angularVelocity))); AddSuffix("MASS", new Suffix <float>(() => Vessel.GetTotalMass())); AddSuffix("VERTICALSPEED", new Suffix <double>(() => Vessel.verticalSpeed)); AddSuffix("SURFACESPEED", new Suffix <double>(() => Vessel.horizontalSrfSpeed)); AddSuffix("AIRSPEED", new Suffix <double>(() => (Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.findWorldCenterOfMass())).magnitude, "the velocity of the vessel relative to the air")); AddSuffix(new[] { "SHIPNAME", "NAME" }, new SetSuffix <string>(() => Vessel.vesselName, RenameVessel, "The KSP name for a craft, cannot be empty")); AddSuffix("TYPE", new SetSuffix <string>(() => Vessel.vesselType.ToString(), RetypeVessel, "The Ship's KSP type (e.g. rover, base, probe)")); AddSuffix("SENSORS", new Suffix <VesselSensors>(() => new VesselSensors(Vessel))); AddSuffix("TERMVELOCITY", new Suffix <double>(() => { throw new KOSAtmosphereDeprecationException("17.2", "TERMVELOCITY", "<None>", string.Empty); })); AddSuffix("LOADED", new Suffix <bool>(() => Vessel.loaded)); AddSuffix("ROOTPART", new Suffix <PartValue>(() => PartValueFactory.Construct(Vessel.rootPart, Shared))); AddSuffix("DRYMASS", new Suffix <float>(() => Vessel.GetDryMass(), "The Ship's mass when empty")); AddSuffix("WETMASS", new Suffix <float>(Vessel.GetWetMass, "The Ship's mass when full")); AddSuffix("RESOURCES", new Suffix <ListValue <AggregateResourceValue> >(() => AggregateResourceValue.FromVessel(Vessel, Shared), "The Aggregate resources from every part on the craft")); AddSuffix("PACKDISTANCE", new SetSuffix <float>( () => { return(System.Math.Min(Vessel.vesselRanges.landed.pack, Vessel.vesselRanges.prelaunch.pack)); }, value => { Vessel.vesselRanges.landed.pack = value; Vessel.vesselRanges.splashed.pack = value; Vessel.vesselRanges.prelaunch.pack = value; })); AddSuffix("ISDEAD", new NoArgsSuffix <bool>(() => (Vessel.state == Vessel.State.DEAD))); AddSuffix("STATUS", new Suffix <String>(() => Vessel.situation.ToString())); //// Although there is an implementation of lat/long/alt in Orbitible, //// it's better to use the methods for vessels that are faster if they're //// available: AddSuffix("LATITUDE", new Suffix <float>(() => VesselUtils.GetVesselLatitude(Vessel))); AddSuffix("LONGITUDE", new Suffix <double>(() => VesselUtils.GetVesselLongitude(Vessel))); AddSuffix("ALTITUDE", new Suffix <double>(() => Vessel.altitude)); }
// test the the get and remove methonds, using the add method during the test to confirm. // the function is inserting illegal flight to the server, ask for it again and delete it. // to make sure the remove method worked as expected - we check for number of items. // in this scenario - we should find 1 item. public void Add_RemoveServer_ElegalInput_ReturnsOneItem() { var actualLen = 0; var expectedLen = 1; var wrongID = "wringID"; var flightCtrlManager = new FlightControlManager(); var dummyServer = new Server { ServerId = "testName", ServerURL = "https://www.testUrl.com" }; flightCtrlManager.AddServer(dummyServer); var result = flightCtrlManager.GetServers(); flightCtrlManager.RemoveServer(wrongID); result = flightCtrlManager.GetServers(); foreach (var item in result) { actualLen++; } Assert.AreEqual(expectedLen, actualLen); }
public FlightControl GetFlightControl() { ThrowIfNotCPUVessel(); return(FlightControlManager.GetControllerByVessel(Vessel)); }
public override object GetSuffix(string suffixName) { switch (suffixName) { case "CONTROL": return(FlightControlManager.GetControllerByVessel(Vessel)); case "DIRECTION": var vector = (Vessel.GetWorldPos3D() - context.Vessel.GetWorldPos3D()); return(new Direction(vector, false)); case "DISTANCE": return((float)GetDistance()); case "BEARING": return(VesselUtils.GetTargetBearing(context.Vessel, Vessel)); case "HEADING": return(VesselUtils.GetTargetHeading(context.Vessel, Vessel)); case "PROGRADE": return(GetPrograde()); case "RETROGRADE": return(GetRetrograde()); case "MAXTHRUST": return(VesselUtils.GetMaxThrust(Vessel)); case "VELOCITY": return(new VesselVelocity(Vessel)); case "GEOPOSITION": return(new GeoCoordinates(Vessel)); case "LATITUDE": return(VesselUtils.GetVesselLattitude(Vessel)); case "LONGITUDE": return(VesselUtils.GetVesselLongitude(Vessel)); case "FACING": return(GetFacing()); case "UP": return(new Direction(Vessel.upAxis, false)); case "NORTH": return(new Direction(VesselUtils.GetNorthVector(Vessel), false)); case "BODY": return(new BodyTarget(Vessel.mainBody, Vessel)); case "ANGULARMOMENTUM": return(new Direction(Vessel.angularMomentum, true)); case "ANGULARVEL": return(new Direction(Vessel.angularVelocity, true)); case "MASS": return(Vessel.GetTotalMass()); case "VERTICALSPEED": return(Vessel.verticalSpeed); case "SURFACESPEED": return(Vessel.horizontalSrfSpeed); case "AIRSPEED": return ((Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.GetWorldPos3D())) .magnitude); //the velocity of the vessel relative to the air); case "VESSELNAME": return(Vessel.vesselName); case "ALTITUDE": return(Vessel.altitude); case "APOAPSIS": return(Vessel.orbit.ApA); case "PERIAPSIS": return(Vessel.orbit.PeA); case "SENSORS": return(new VesselSensors(Vessel)); case "TERMVELOCITY": return(VesselUtils.GetTerminalVelocity(Vessel)); case "LOADED": return(Vessel.loaded); case "OBT": return(new OrbitInfo(Vessel.orbit, Vessel)); } // Is this a resource? double dblValue; if (VesselUtils.TryGetResource(Vessel, suffixName, out dblValue)) { return(dblValue); } return(base.GetSuffix(suffixName)); }
public override object GetSuffix(string suffixName) { switch (suffixName) { case "CONTROL": return(FlightControlManager.GetControllerByVessel(Vessel)); case "BEARING": return(VesselUtils.GetTargetBearing(CurrentVessel, Vessel)); case "HEADING": return(VesselUtils.GetTargetHeading(CurrentVessel, Vessel)); case "MAXTHRUST": return(VesselUtils.GetMaxThrust(Vessel)); case "FACING": return(GetFacing()); case "ANGULARMOMENTUM": return(new Direction(Vessel.angularMomentum, true)); case "ANGULARVEL": return(new Direction(Vessel.angularVelocity, true)); case "MASS": return(Vessel.GetTotalMass()); case "VERTICALSPEED": return(Vessel.verticalSpeed); case "SURFACESPEED": return(Vessel.horizontalSrfSpeed); case "AIRSPEED": return ((Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.GetWorldPos3D())) .magnitude); //the velocity of the vessel relative to the air); //DEPRICATED VESSELNAME case "VESSELNAME": case "SHIPNAME": return(Vessel.vesselName); // Although there is an implementation of lat/long/alt in Orbitible, // it's better to use the methods for vessels that are faster if they're // available: case "LATITUDE": return(VesselUtils.GetVesselLattitude(Vessel)); case "LONGITUDE": return(VesselUtils.GetVesselLongitude(Vessel)); case "ALTITUDE": return(Vessel.altitude); case "SENSORS": return(new VesselSensors(Vessel)); case "TERMVELOCITY": return(VesselUtils.GetTerminalVelocity(Vessel)); case "LOADED": return(Vessel.loaded); } // Is this a resource? double dblValue; if (VesselUtils.TryGetResource(Vessel, suffixName, out dblValue)) { return(dblValue); } return(base.GetSuffix(suffixName)); }