public void Fire() { // setup MockRepository mocks = new MockRepository(); IMissileLaunchingSystem system = mocks.CreateMock<IMissileLaunchingSystem>(); Factory<IMissileLaunchingSystem>.RegisterFake(system); // code under test: FiringSolution fire = new FiringSolution(new TargetingSystem()); using (mocks.Record()) { // read from left to right, not inner to outer Expect.Call(system.SendLaunchOrders(fire)).Return("Test Successful"); } // did it work? using(mocks.Playback()) { string result = fire.Fire(); Assert.AreEqual("Test Successful", result); } // teardown Factory<IMissileLaunchingSystem>.ClearFakes(); }
/// <summary> /// Sends the launch orders. /// </summary> /// <param name="solution">The solution.</param> /// <returns>true if successful, false otherwise</returns> public string SendLaunchOrders(FiringSolution solution) { #region Incredibly complicated, top-secret, and very sensitive launch system happens here return "Fired a Very Real Missile with warhead, caused an international incident. (Congrats)"; #endregion }
/// <summary> /// Sends the launch orders. /// </summary> /// <param name="solution">The solution.</param> /// <returns>true if successful, false otherwise</returns> public bool SendLaunchOrders(FiringSolution solution) { #region Incredibly complicated, top-secret, and very sensitive launch system happens here return true; #endregion }
public FiringSolution ReticulateSplines(double vector) { if (storedVector.Equals(0)) { storedVector = vector; return this; } else { FiringSolution newSol = new FiringSolution(system); newSol.storedVector = (Math.Log(storedVector) + Math.Log(vector)) / system.GeographicBias; return newSol; } }
public void CalculateSplines_PositiveVector_Simple() { MockRepository mocks = new MockRepository(); ITargetingSystem targetingSystem = mocks.CreateMock<ITargetingSystem>(); using (mocks.Record()) { Expect.Call(targetingSystem.GeographicBias).Return(1.0); } using (mocks.Playback()) { FiringSolution firstSol = new FiringSolution(targetingSystem); firstSol.Vector = 1; FiringSolution result = firstSol.ReticulateSplines(1); Assert.That(result.Vector,Is.EqualTo(0.0)); } }
public FiringSolution ReticulateSplines(double vector) { FiringSolution newSol = new FiringSolution(system); newSol.storedVector = (Math.Log(storedVector) + Math.Log(vector)) / system.GeographicBias; return newSol; }
public string SendLaunchOrders(FiringSolution solution) { return "Only pretended to fire a missile. The world is safe."; }
public void VectorCantBeZero() { MockRepository mocks = new MockRepository(); ITargetingSystem targetingSystem = mocks.CreateMock<ITargetingSystem>(); using (mocks.Record()) { // nothing to record - our mock won't get called } using (mocks.Playback()) { FiringSolution firstSol = new FiringSolution(targetingSystem); try { firstSol.Vector = 0; firstSol.ReticulateSplines(1); Assert.Fail("should have gotten an InvalidVectorException here"); } catch(InvalidVectorException) { // success } } }
/// <summary> /// Determine an appropriate firing solution to blow this target up /// </summary> /// <returns></returns> public FiringSolution ComputeFiringSolution() { FiringSolution current = new FiringSolution(this); // TEST // to compute a solution, first we have to access data written from the // ACHES-7529-MUX superprocessing mainframe - the only way we get // this information is by reading in a text file on the disk. // because of the way the software that accesses the mainframe works, the only // place this file can be written is C:\FiringSolution_Mainframe_Info.txt IList<double> precomputedVectors = ReadVectors(); foreach(double d in precomputedVectors) { current = current.ReticulateSplines(d); } return current; }
public FiringSolution ReticulateSplines(double vector) { // TEST: this doesn't work right if Vector property wasn't set (vector = 0, storedVector = 0) if (vector.Equals(0.0) || storedVector.Equals(0.0)) { throw new InvalidVectorException("vector can't be zero"); } // TEST: its discovered that this doesnt work right if vector is negative bool wasNegative = false; if (vector < 0) { wasNegative = true; vector = Math.Abs(vector); } FiringSolution newSol = new FiringSolution(system); newSol.storedVector = (Math.Log(Math.Abs(storedVector)) + Math.Log(vector))/system.GeographicBias; if (wasNegative) { newSol.storedVector = 0 - newSol.storedVector; } return newSol; }