/// <summary> /// Converts the value of the current <see cref="Operation"/> object to its equivalent string representation /// using the specified format and culture-specific format information. /// </summary> /// <param name="format">The format string. May contain the names of the properties to print enclosed in curly braces like '{<see cref="P:OperationNumber"/>}'. /// If a given property could not be found on the top-level, then it is looked after in the CustomData dictionary. /// If it wasn't found there either, a default string is printed.</param> /// <param name="options">Options to use for controlling formatting.</param> /// <param name="formatProvider">The format provider to use for formatting.</param> /// <returns>A string representation of value of the current <see cref="Operation"/> object as specified by format and provider.</returns> public string ToString(string format, ObjectFormatterOptions options, IFormatProvider formatProvider) { ExtendedObjectExpressionFormatter <Operation> formatter = new ExtendedObjectExpressionFormatter <Operation>(ResolveProperty); formatter.Options = options; return(formatter.ToString(this, format)); }
private void ToStringAndAssertException(string fileName, CustomScriptExecutionException.Reason reason) { string path = GetTestDataFilePath(string.Format("Shared\\ObjectExpressionsTests\\Scripts\\{0}", fileName)); Mock mock = new Mock(); ExtendedObjectExpressionFormatter <Mock> formatter = new ExtendedObjectExpressionFormatter <Mock>(); string value = formatter.ToString(mock, "{$cs=" + path + "}"); Assert.IsTrue(formatter.HasError); Assert.AreEqual(reason, formatter.Error.FailureReason); }
public void BasicExtendedScriptTest() { Mock mock = new Mock(); string path = GetTestDataFilePath("Shared\\ObjectExpressionsTests\\Scripts\\BasicExtendedScriptTest.cs"); ExtendedObjectExpressionFormatter <Mock> formatter = new ExtendedObjectExpressionFormatter <Mock>(); string value = formatter.ToString(mock, "{$cs=" + path + "}"); Assert.AreEqual("42", value); Assert.IsFalse(formatter.HasError); }
public void BasicExtendedScriptTest() { Mock mock = new Mock(); string path = GetTestDataFilePath("Shared\\ObjectExpressionsTests\\Scripts\\BasicExtendedScriptTest.cs"); ExtendedObjectExpressionFormatter<Mock> formatter = new ExtendedObjectExpressionFormatter<Mock>(); string value = formatter.ToString(mock, "{$cs=" + path + "}"); Assert.AreEqual("42", value); Assert.IsFalse(formatter.HasError); }
public void SecondPassScriptTest() { Mock mock = new Mock(); string wd = Utilities.GetWorkingDirectory(); string path = Path.Combine(wd, "Shared\\ObjectExpressionsTests\\Scripts\\SecondPassScriptTest.cs"); ExtendedObjectExpressionFormatter <Mock> formatter = new ExtendedObjectExpressionFormatter <Mock>(); string value = formatter.ToString(mock, "{$cs=" + path + "}"); Assert.AreEqual("The holy numeric value is: 42!", value); Assert.IsFalse(formatter.HasError); }
public void OperationScriptTest() { Operation operation = new Operation(); operation.Id = 42; string wd = Utilities.GetWorkingDirectory(); string path = Path.Combine(wd, "Shared\\ObjectExpressionsTests\\Scripts\\OperationScriptTest.cs"); ExtendedObjectExpressionFormatter<Operation> formatter = new ExtendedObjectExpressionFormatter<Operation>(); string value = formatter.ToString(operation, "{$cs=" + path + "}"); Assert.AreEqual(operation.Id.ToString(), value); Assert.IsFalse(formatter.HasError); }
public void OperationScriptTest() { Operation operation = new Operation(); operation.Id = 42; string wd = Utilities.GetWorkingDirectory(); string path = Path.Combine(wd, "Shared\\ObjectExpressionsTests\\Scripts\\OperationScriptTest.cs"); ExtendedObjectExpressionFormatter <Operation> formatter = new ExtendedObjectExpressionFormatter <Operation>(); string value = formatter.ToString(operation, "{$cs=" + path + "}"); Assert.AreEqual(operation.Id.ToString(), value); Assert.IsFalse(formatter.HasError); }
private void TestUserInputCommand_Execute(object parameter) { string result = ""; try { if (SelectedEntry.UseIFormattable) { IFormattable formattable = (IFormattable)SelectedEntry.Instance; result = formattable.ToString(InputText, CultureInfo.CurrentUICulture); } else { ExtendedObjectExpressionFormatter <object> formatter = new ExtendedObjectExpressionFormatter <object>(); result = formatter.ToString(SelectedEntry.Instance, InputText); } } catch (InvalidCastException ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SeedEntryTestTypeIsNotIFormattable, SelectedEntry.Instance.GetType().Name); Logger.Instance.LogException(this, ex); result = Properties.Resources.SeedEntryTestFailed.ToUpperInvariant(); } catch (AssertionFailedException ex) { Logger.Instance.LogException(this, ex); result = ex.Message.ToUpperInvariant(); } catch (Exception ex) { Logger.Instance.LogException(this, ex); result = Properties.Resources.SeedEntryTestFailed.ToUpperInvariant(); } if (result != null) { ResultText = result; OnPropertyChanged("ResultText"); } }
public void SecondPassScriptTest() { Mock mock = new Mock(); string wd = Utilities.GetWorkingDirectory(); string path = Path.Combine(wd, "Shared\\ObjectExpressionsTests\\Scripts\\SecondPassScriptTest.cs"); ExtendedObjectExpressionFormatter<Mock> formatter = new ExtendedObjectExpressionFormatter<Mock>(); string value = formatter.ToString(mock, "{$cs=" + path + "}"); Assert.AreEqual("The holy numeric value is: 42!", value); Assert.IsFalse(formatter.HasError); }
private void ToStringAndAssertException(string fileName, CustomScriptExecutionException.Reason reason) { string path = GetTestDataFilePath(string.Format("Shared\\ObjectExpressionsTests\\Scripts\\{0}", fileName)); Mock mock = new Mock(); ExtendedObjectExpressionFormatter<Mock> formatter = new ExtendedObjectExpressionFormatter<Mock>(); string value = formatter.ToString(mock, "{$cs=" + path + "}"); Assert.IsTrue(formatter.HasError); Assert.AreEqual(reason, formatter.Error.FailureReason); }
private void TestUserInputCommand_Execute(object parameter) { string result = ""; try { if (SelectedEntry.UseIFormattable) { IFormattable formattable = (IFormattable)SelectedEntry.Instance; result = formattable.ToString(InputText, CultureInfo.CurrentUICulture); } else { ExtendedObjectExpressionFormatter<object> formatter = new ExtendedObjectExpressionFormatter<object>(); result = formatter.ToString(SelectedEntry.Instance, InputText); } } catch (InvalidCastException ex) { Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SeedEntryTestTypeIsNotIFormattable, SelectedEntry.Instance.GetType().Name); Logger.Instance.LogException(this, ex); result = Properties.Resources.SeedEntryTestFailed.ToUpperInvariant(); } catch (AssertionFailedException ex) { Logger.Instance.LogException(this, ex); result = ex.Message.ToUpperInvariant(); } catch (Exception ex) { Logger.Instance.LogException(this, ex); result = Properties.Resources.SeedEntryTestFailed.ToUpperInvariant(); } if (result != null) { ResultText = result; OnPropertyChanged("ResultText"); } }