/// <summary> /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>. /// </summary> /// <returns> /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>. /// </returns> public override string ToString() { var writer = new DescriptionWriter(); DescribeTo(writer); return(writer.ToString()); }
void Awake() { GameObject _description = GameObject.FindGameObjectWithTag("DescriptionBox"); _tutorial = _description.GetComponent <TutorialVoice>(); _writer = _description.GetComponentInParent <DescriptionWriter>(); }
public void FormatsNullAsNull() { DescriptionWriter writer = new DescriptionWriter(); writer.Write((object)null); Assert.AreEqual("null", writer.ToString()); }
private static string DescriptionOf(ISelfDescribing selfDescribing) { TextWriter writer = new DescriptionWriter(); selfDescribing.DescribeTo(writer); return(writer.ToString()); }
private void AssertDescriptionIsEqual(IExpectation expectation, string expected) { DescriptionWriter writer = new DescriptionWriter(); expectation.DescribeActiveExpectationsTo(writer); Assert.AreEqual(expected, writer.ToString()); }
public void HighlightsOtherValuesWhenWrittenAsObject() { DescriptionWriter writer = new DescriptionWriter(); object anInt = 1; writer.Write(anInt); Assert.AreEqual("<1>(System.Int32)", writer.ToString()); }
public void FormatsStringsInCSharpSyntaxWhenWrittenAsObject() { DescriptionWriter writer = new DescriptionWriter(); object aString = "hello \"world\""; writer.Write(aString); Assert.AreEqual("\"hello \\\"world\\\"\"", writer.ToString()); }
void Awake() { _sceneFader = GetComponent <Fading>(); _restart = transform.GetChild(0).gameObject; _writer = GameObject.FindGameObjectWithTag("DescriptionBox").GetComponentInParent <DescriptionWriter>(); _inventory = GameObject.FindGameObjectWithTag("Inventory").GetComponent <InventoryLogic>(); _player = (GameObject)RetainedObjects[RetainedObjects.Count - 1]; //always place player last _cameraLead = (GameObject)RetainedObjects[RetainedObjects.Count - 2]; // always place lead next to last }
void Start() { _guard = GameObject.FindGameObjectWithTag("Guard"); _leadMover = GameObject.FindGameObjectWithTag("CameraLead").GetComponent <CameraLeadController>(); _writer = GetComponentInParent <DescriptionWriter>(); //StartCoroutine(WriteTutorial()); StartCoroutine(ShowGuard()); }
void Start() { _inventory = GameObject.FindGameObjectWithTag("Inventory").GetComponent <InventoryLogic>(); _firstCoin = _inventory.ReturnToolDb().ToolDatabase[1]; _writer = GetComponentInParent <DescriptionWriter>(); _tutorial = GetComponent <TutorialVoice>(); _leadMover = GameObject.FindGameObjectWithTag("CameraLead").GetComponent <CameraLeadController>(); _firstClick = GameObject.FindGameObjectWithTag("Guard").GetComponent <FirstClick>(); _cameraFx = GameObject.FindGameObjectWithTag("CameraGroup").GetComponent <CameraController>(); _tutFunc = new CommonTutorialFunctions(); _key = _tutFunc.GetLootables("key"); }
void Start() { GameObject _description = GameObject.FindGameObjectWithTag("DescriptionBox"); _tutorial = _description.GetComponent <TutorialVoice>(); _writer = _description.GetComponentInParent <DescriptionWriter>(); _leadMover = GameObject.FindGameObjectWithTag("CameraLead").GetComponent <CameraLeadController>(); _cameraFx = GameObject.FindGameObjectWithTag("CameraGroup").GetComponent <CameraController>(); _player = GameObject.FindGameObjectWithTag("Player"); _tutFunc = new CommonTutorialFunctions(); _coin = _tutFunc.GetLootables("coin"); }
/// <summary> /// Verifies that the <paramref name="actualValue"/> is matched by the <paramref name="matcher"/>. /// </summary> /// <param name="actualValue">The actual value.</param> /// <param name="matcher">The matcher.</param> /// <exception cref="ExpectationException">Thrown if value does not match.</exception> public static void That(object actualValue, Matcher matcher) { if (matcher == null) { throw new ArgumentNullException("matcher"); } if (!matcher.Matches(actualValue)) { var writer = new DescriptionWriter(); WriteDescriptionOfFailedMatch(writer, actualValue, matcher); throw new ExpectationException(writer.ToString()); } }
/// <summary> /// Throws an exception listing all unmet expectations. /// </summary> private void FailUnmetExpectations() { var writer = new DescriptionWriter(); writer.WriteLine("Not all expected invocations were performed."); _expectations.DescribeUnmetExpectationsTo(writer); ClearExpectations(); var message = writer.ToString(); if (message != Constants.ERROR_OCCURED_IN_SETUP) { throw new UnmetExpectationException(writer.ToString()); } }
/// <summary> /// Indicates that this method will throw an <see cref="Exception"/>. /// </summary> /// <typeparam name="T">The type of <see cref="Exception"/> to throw.</typeparam> /// <param name="comment">A description of the reason for this expectation.</param> /// <param name="matchers">An array of matchers to match the exception string.</param> public void Throws <T>(string comment, params Matcher[] matchers) where T : Exception { try { _action(); } catch (T ex) { _exception = ex; if (matchers != null) { foreach (var matcher in matchers) { if (!matcher.Matches(ex.ToString())) { var writer = new DescriptionWriter(); writer.Write("Matching failed due to "); matcher.DescribeTo(writer); throw new Exception(Environment.NewLine + writer + Environment.NewLine, ex); } } } //all matchers matched so this was expected var uie = ex as UnexpectedInvocationException; if (uie != null) { //clear this exception because it was expected uie.Factory.ClearException(); } } if (_exception == null) { if (string.IsNullOrEmpty(comment)) { throw new UnmetExpectationException("The expected action did not throw an exception when it was invoked."); } else { throw new UnmetExpectationException(comment); } } }
/// <summary> /// Throws an exception indicating that the specified invocation is not expected. /// </summary> /// <param name="invocation">The invocation.</param> private void FailUnexpectedInvocation(Invocation invocation) { var writer = new DescriptionWriter(); //var unexpectedWriter = new DescriptionWriter(); var expectedWriter = new DescriptionWriter(); //((ISelfDescribing)invocation).DescribeTo(unexpectedWriter); _expectations.DescribeTo(expectedWriter); //expectations.DescribeActiveExpectationsTo(expectedWriter); string theexpectations = expectedWriter.ToString().Replace(EqualMatcher.EQUAL_TO, string.Empty); //if (theexpectations.Contains(unexpectedWriter.ToString())) //{ // writer.WriteLine(); // writer.WriteLine("What happened? An expectation listed below is similar to the unexpected call above."); // writer.WriteLine("Why did this happen? A parameter reference in your expectation refers to a different instance than the reference used in the call."); // writer.WriteLine("How to fix this: Use a matcher, override .Equals() on the class, or adjust your API."); // writer.WriteLine(); //} if (theexpectations.Contains(", returning an invoker") && invocation.Method.IsEvent()) { writer.WriteLine(); writer.WriteLine("If this exception was unexpected, the delegates used in the expectation and invocation may be different. To bind to *any* delegate, use 'null' in the expectation."); writer.WriteLine(); } // try catch to get exception with stack trace. try { //throw new UnexpectedInvocationException(invocation, topOrdering, writer.ToString()); throw new UnexpectedInvocationException(this, invocation, _expectations.Root, writer.ToString()); } catch (UnexpectedInvocationException e) { // remember only first exception if (_thrownUnexpectedInvocationException == null) { _thrownUnexpectedInvocationException = e; } //always rethrow the first exception (that could have caused the rest i.e. a dispose to be called when it shouldn't have) throw _thrownUnexpectedInvocationException; } }
/// <summary> /// Constructs a <see cref="UnexpectedInvocationException"/> with the given parameters. /// </summary> /// <param name="factory">The MockFactory that threw this exception</param> /// <param name="invocation">The unexpected invocation</param> /// <param name="expectations">The expectations collection to describe</param> /// <param name="message">A message to help the user understand what was unexpected</param> internal UnexpectedInvocationException(MockFactory factory, Invocation invocation, IExpectationList expectations, string message) { if (factory == null) { throw new ArgumentNullException("factory"); } if (invocation == null) { throw new ArgumentNullException("invocation"); } if (expectations == null) { throw new ArgumentNullException("expectations"); } Factory = factory; var writer = new DescriptionWriter(); writer.WriteLine(); if (invocation.IsPropertySetAccessor) { writer.WriteLine(UNEXPECTED_PROPERTY_SETTER_PREFIX); } else if (invocation.IsPropertyGetAccessor) { writer.WriteLine(UNEXPECTED_PROPERTY_GETTER_PREFIX); } else { writer.WriteLine(MESSAGE_PREFIX); } writer.Write(" "); ((ISelfDescribing)invocation).DescribeTo(writer); writer.Write(message); //expectations.DescribeActiveExpectationsTo(writer); //expectations.DescribeUnmetExpectationsTo(writer); expectations.DescribeTo(writer); _message = writer.ToString(); }
void Awake() { _writer = GetComponentInParent <DescriptionWriter>(); }
public CmdLineOptionDefinitionBuilder Description(DescriptionWriter<CmdLineOptionDefinition> descriptionWriter) { _definition.DescriptionWriter = descriptionWriter; return this; }