/// <summary> /// Asserts that a specific value exists for the given column. Also asserts that the column exists /// </summary> /// <param name="columnName">The column name (case-sensitive)</param> /// <param name="expectedValue">The expected value. Respects <see cref="Comparisons.Abstract.IComparison"/> objects</param> /// <returns>Returns the same <see cref="RowResult"/> object</returns> public RowResult AssertValue(string columnName, object expectedValue) { _queryResult.AssertColumnExists(columnName); object value = _row[columnName]; ValueValidation.Assert(_queryResult.TestFramework, expectedValue, value, $"Column {columnName} in row {_rowNumber}"); return(this); }
public void ValueValidation_Assert_AssertString_AreEqual_ThrowNoError() { object requestedValue = null; string requestedMessage = null; Mock <IComparison> state = new Mock <IComparison>(MockBehavior.Strict); state .Setup(p => p.Assert(It.IsAny <ITestFramework>(), It.IsAny <object>(), It.IsAny <string>())) .Callback <ITestFramework, object, string>((s, p, q) => { requestedValue = p; requestedMessage = q; }); Assert.DoesNotThrow(() => ValueValidation.Assert(_testFramework, state.Object, "ABC", "Custom assertion")); state .Verify(p => p.Assert(It.IsAny <ITestFramework>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.AreEqual("ABC", requestedValue); Assert.AreEqual("Custom assertion", requestedMessage); }
/// <summary> /// Asserts that the value matches the expected value /// </summary> /// <param name="expectedValue">The expected value. Respects <see cref="Comparisons.Abstract.IComparison"/> objects</param> /// <returns>Returns the same <see cref="ScalarResult{T}"/> object</returns> public ScalarResult <T> AssertValue(object expectedValue) { ValueValidation.Assert(TestFramework, expectedValue, RawData, $"Scalar result"); return(this); }
public void ValueValidation_Assert_AssertState_AreNotEqual_ThrowError() { object requestedValue = null; string requestedMessage = null; Mock <IComparison> state = new Mock <IComparison>(MockBehavior.Strict); state .Setup(p => p.Assert(It.IsAny <ITestFramework>(), It.IsAny <object>(), It.IsAny <string>())) .Callback <ITestFramework, object, string>((s, p, q) => { requestedValue = p; requestedMessage = q; }) .Throws(new Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException()); Assert.Throws <Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException>(() => ValueValidation.Assert(_testFramework, state.Object, "ValueA", "Custom assertion")); state .Verify(p => p.Assert(It.IsAny <ITestFramework>(), It.IsAny <object>(), It.IsAny <string>()), Times.Once); Assert.AreEqual("ValueA", requestedValue); Assert.AreEqual("Custom assertion", requestedMessage); }
public void ValueValidation_Assert_DifferentTypes_AreNotEqual(object expectedValue, object actualValue, string expectedMessage) { var exception = Assert.Throws <Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException>(() => ValueValidation.Assert(_testFramework, expectedValue, actualValue, "Custom assertion")); Assert.AreEqual($"Assert.AreEqual failed. {expectedMessage}. Custom assertion has an unexpected value", exception.Message); }
public void ValueValidation_Assert_ExpectStringActualInt_AreNotEqual() { var exception = Assert.Throws <Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException>(() => ValueValidation.Assert(_testFramework, "123", 123, "Custom assertion")); Assert.AreEqual($"Assert.AreEqual failed. Expected:<123 (System.String)>. Actual:<123 (System.Int32)>. Custom assertion has an unexpected value", exception.Message); }
public void ValueValidation_Assert_ExpectDBNull_AreEqual() { Assert.DoesNotThrow(() => ValueValidation.Assert(_testFramework, DBNull.Value, DBNull.Value, "Custom assertion")); }
public void ValueValidation_Assert_BasicObjects_AreNotEqual(object expectedValue, object actualValue) { var exception = Assert.Throws <Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException>(() => ValueValidation.Assert(_testFramework, expectedValue, actualValue, "Custom assertion")); Assert.AreEqual($"Assert.AreEqual failed. Expected:<{ expectedValue }>. Actual:<{ actualValue }>. Custom assertion has an unexpected value", exception.Message); }
public void ValueValidation_Assert_BasicObjects_AreEqual(object expectedValue, object actualValue) { Assert.DoesNotThrow(() => ValueValidation.Assert(_testFramework, expectedValue, actualValue, "Custom assertion")); }