public void IsArrayType() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsArrayType(null as object)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsArrayType(null as Type)); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType("hello")); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(1L)); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(AttributeTargets.All)); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(new List <int>())); Assert.DoesNotThrow(() => Assert.IsArrayType(new int[0])); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType <string>()); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType <long>()); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType <AttributeTargets>()); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType <List <int> >()); Assert.DoesNotThrow(() => Assert.IsArrayType <int[]>()); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType <IEnumerable <int> >()); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(typeof(string))); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(typeof(long))); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(typeof(AttributeTargets))); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(typeof(List <int>))); Assert.DoesNotThrow(() => Assert.IsArrayType(typeof(int[]))); Assert.ThrowsExact <AssertionException>(() => Assert.IsArrayType(typeof(IEnumerable <int>))); }
public void NotEmpty() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.NotEmpty <int>(null)); Assert.ThrowsExact <AssertionException>(() => Assert.NotEmpty(new int[] { })); Assert.ThrowsExact <AssertionException>(() => Assert.NotEmpty(string.Empty)); Assert.DoesNotThrow(() => Assert.NotEmpty(new[] { 1, 2, 3 })); }
public void Null() { Assert.DoesNotThrow(() => Assert.Null(null as string)); Assert.DoesNotThrow(() => Assert.Null(null as int?)); Assert.ThrowsExact <AssertionException>(() => Assert.Null(new object())); Assert.ThrowsExact <AssertionException>(() => Assert.Null((1 as int?))); }
public void IsWithinDelta() { Assert.DoesNotThrow(() => Assert.IsWithinDelta(0.0001f, 0.0002f, 0.0001f)); Assert.DoesNotThrow(() => Assert.IsWithinDelta(0.0001d, 0.0002d, 0.0001d)); Assert.ThrowsExact <AssertionException>(() => Assert.IsWithinDelta(0.0001f, 0.0002f, 0.00002f)); Assert.ThrowsExact <AssertionException>(() => Assert.IsWithinDelta(0.0001d, 0.0002d, 0.00002d)); }
public void ThrowsExactPredicate() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.ThrowsExact <AssertionException>(null, e => e != null)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.ThrowsExact <AssertionException>(EmptyNoThrow, null as Func <AssertionException, bool>)); Assert.DoesNotThrow(() => Assert.ThrowsExact <Exception>(ThrowsPlain, e => e != null)); Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <DerivedExceptionTest>(ThrowsBase, e => e != null)); Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <ArgumentException>(EmptyNoThrow, e => e != null)); Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <NotSupportedException>(() => { throw new ArgumentNullException(); }, e => e != null)); Assert.DoesNotThrow(() => Assert.ThrowsExact <DerivedExceptionTest>(ThrowsDerived, e => e != null)); Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <ExceptionTest>(ThrowsDerived, e => e != null)); Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <DerivedExceptionTest>(ThrowsDerived, e => e == null)); Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <ExceptionTest>(ThrowsDerived, e => e == null)); try { Assert.ThrowsExact <ArgumentNullException>(() => { throw new InvalidOperationException("Testing"); }, e => e != null); // This should not occur throw new InvalidOperationException(); } catch (AssertionException e) { if (e.InnerException.GetType() != typeof(InvalidOperationException)) { // This should not occur throw; } } catch (Exception) { // This should not occur throw; } Assert.ThrowsExact <AssertionException>(() => Assert.ThrowsExact <Exception>(() => { throw new Exception(); }, e => e.InnerException != null)); Assert.DoesNotThrow(() => Assert.ThrowsExact <Exception>(() => { throw new Exception("Test", new InvalidOperationException("Inner")); }, e => e.InnerException != null && e.InnerException.GetType() == typeof(InvalidOperationException) && e.InnerException.Message == "Inner")); }
public void CombinedErrAndOutPlusTwoNumber() { ProcessResult result = null; Assert.DoesNotThrow(() => { using (var process = new ProcessSpawnerWithCombinedErrAndOut(TestApplications.PlusTwoNumberInfo)) { process.OnInputRequested += (buf, writer) => { if (string.IsNullOrEmpty(buf)) { return(ProcessInputHandleResult.Ignored); } if (buf == "878") { return(ProcessInputHandleResult.Ignored); } if (buf != "Please enter a number...") { Assert.Fail(); return(ProcessInputHandleResult.Ignored); } writer.WriteLine("876"); return(ProcessInputHandleResult.Handled); }; result = process.Run(); } }); Assert.NotNull(result); Assert.NotNull(result.FullOutput); Assert.Equal(result.FullOutput, @"Please enter a number... 878"); Assert.DoesNotThrow(() => { using (var process = new ProcessSpawnerWithCombinedErrAndOut(TestApplications.PlusTwoNumberInfo)) { process.OnInputRequested += (buf, writer) => { if (string.IsNullOrEmpty(buf)) { return(ProcessInputHandleResult.Ignored); } if (buf == "Bad number") { return(ProcessInputHandleResult.Ignored); } if (buf != "Please enter a number...") { Assert.Fail(); return(ProcessInputHandleResult.Ignored); } writer.WriteLine("abc"); return(ProcessInputHandleResult.Handled); }; result = process.Run(); } }); Assert.NotNull(result); Assert.NotNull(result.FullOutput); Assert.Equal(result.FullOutput, @"Please enter a number... Bad number"); }
public void CombinedErrAndOutSimpleInterspersed() { ProcessResult result = null; Assert.DoesNotThrow(() => { using (var process = new ProcessSpawnerWithCombinedErrAndOut(TestApplications.SimpleInterspersedInfo)) { result = process.Run(); } }); Assert.NotNull(result); Assert.Equal(result.ExitCode, 3); Assert.GreaterThan(result.PeakPagedMemorySize, 0); Assert.GreaterThan(result.PeakVirtualMemorySize, 0); Assert.GreaterThan(result.PeakWorkingSet, 0); Assert.NotEqual(result.StartTime, DateTime.MinValue); Assert.NotEqual(result.ExitTime, DateTime.MinValue); Assert.GreaterThan(result.ExitTime - result.StartTime, TimeSpan.Zero); Assert.NotNull(result.FullOutput); Assert.Null(result.FullStd); Assert.Null(result.FullError); Assert.Equal(result.FullOutput, @"abc def abc def abc def def abc aabbccddeeff"); }
public void CombinedAndSplitErrAndOutNakedInput() { ProcessResult result = null; Assert.DoesNotThrow(() => { using (var process = new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.NakedInput)) { process.OnInputRequested += (buf, writer) => { if (!string.IsNullOrEmpty(buf) && buf != "acb876") { Assert.Fail(); } writer.WriteLine("acb876"); return(ProcessInputHandleResult.Handled); }; result = process.Run(); } }); Assert.NotNull(result); Assert.NotNull(result.FullOutput); Assert.NotNull(result.FullStd); Assert.NotNull(result.FullError); Assert.Equal(result.FullOutput, @"acb876"); Assert.Equal(result.FullStd, @"acb876"); Assert.Equal(result.FullError, @""); }
public void CombinedAndSplitErrAndOutConstructor() { // File only Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string)) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo)) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty)) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary)) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo)) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed)) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo)) { } }); // File/args only Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string, null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo, null as object[])) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty, null as object[])) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary, null as object[])) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo, null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string, "abc")) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo, "abc")) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty, "abc")) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary, "abc")) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo, "abc")) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed, null as object[])) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo, null as object[])) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed, "abc")) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo, "abc")) { } }); // File/escaper/args Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string, null, null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo, null, null as object[])) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty, null, null as object[])) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary, null, null as object[])) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo, null, null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as string, null, "abc")) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(null as FileInfo, null, "abc")) { } }); Assert.ThrowsExact <ArgumentException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(string.Empty, null, "abc")) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinary, null, "abc")) { } }); Assert.ThrowsExact <FileNotFoundException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.InvalidBinaryInfo, null, "abc")) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed, null, null as object[])) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo, null, null as object[])) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo, new WindowsCommandLineArgumentEscaper(), null as object[])) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed, null, "abc")) { } }); Assert.ThrowsExact <ArgumentNullException>(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo, null, "abc")) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersed, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); Assert.DoesNotThrow(() => { using (new ProcessSpawnerWithCombinedAndSplitErrAndOut(TestApplications.SimpleInterspersedInfo, new WindowsCommandLineArgumentEscaper(), "abc")) { } }); }
public void CountSequence() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.Count(null as int[], 1)); Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { }, 1)); Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { 0 }, -1)); Assert.DoesNotThrow(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 5)); Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 4)); Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 6)); }
public void DirectoryNotExists() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.DirectoryNotExists(null as string)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.DirectoryNotExists(null as DirectoryInfo)); Assert.DoesNotThrow(() => Assert.DirectoryNotExists(NonExistingDirectory)); Assert.DoesNotThrow(() => Assert.DirectoryNotExists(NonExistingDirectoryInfo)); Assert.DoesNotThrow(() => Assert.DirectoryNotExists(new DirectoryInfo(NonExistingDirectory))); Assert.ThrowsExact <AssertionException>(() => Assert.DirectoryNotExists(ExistingDirectory)); Assert.ThrowsExact <AssertionException>(() => Assert.DirectoryNotExists(ExistingDirectoryInfo)); }
public void FileNotExists() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.FileNotExists(null as string)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.FileNotExists(null as FileInfo)); Assert.DoesNotThrow(() => Assert.FileNotExists(NonExistingFile)); Assert.DoesNotThrow(() => Assert.FileNotExists(NonExistingFileInfo)); Assert.DoesNotThrow(() => Assert.FileNotExists(new FileInfo(NonExistingFile))); Assert.ThrowsExact <AssertionException>(() => Assert.FileNotExists(ExistingFile)); Assert.ThrowsExact <AssertionException>(() => Assert.FileNotExists(ExistingFileInfo)); }
public void DoesNotContain() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.DoesNotContain <int>(null, 1)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.DoesNotContain("ABC", 'c', null as IEqualityComparer <char>)); Assert.ThrowsExact <ArgumentException>(() => Assert.DoesNotContain <int>(new int[] { }, 1)); Assert.DoesNotThrow(() => Assert.DoesNotContain(new int[] { 2 }, 1)); Assert.ThrowsExact <AssertionException>(() => Assert.DoesNotContain(new int[] { 2 }, 2)); Assert.DoesNotThrow(() => Assert.DoesNotContain("ABC", 'd', new CharCaseInvariantComparer())); Assert.ThrowsExact <AssertionException>(() => Assert.DoesNotContain("ABC", 'c', new CharCaseInvariantComparer())); }
public void IsNotMatch() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotMatch(null as Regex, string.Empty)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotMatch(new Regex(string.Empty), null)); Assert.DoesNotThrow(() => Assert.IsNotMatch("abc", "cba")); Assert.DoesNotThrow(() => Assert.IsNotMatch(new Regex("abc"), "cba")); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotMatch("abc", "abc")); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotMatch(new Regex("abc"), "abc")); }
public void False() { Assert.Throws <ArgumentNullException>(() => Assert.False(null as Func <bool>)); Assert.DoesNotThrow(() => Assert.False(false)); Assert.DoesNotThrow(() => Assert.False(() => false)); Assert.ThrowsExact <AssertionException>(() => Assert.False(true)); Assert.ThrowsExact <AssertionException>(() => Assert.False(null as bool?)); Assert.ThrowsExact <AssertionException>(() => Assert.False(() => true)); Assert.ThrowsExact <AssertionException>(() => Assert.False(() => null as bool?)); }
public void None() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.None(null as int[], v => v == 0)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.None(new int[] { }, null)); Assert.ThrowsExact <ArgumentException>(() => Assert.None(new int[] { }, v => v == 0)); Assert.ThrowsExact <AssertionException>(() => Assert.None(new int[] { 1, 2, 3, 4, 5 }, v => v >= 3)); Assert.DoesNotThrow(() => Assert.None(new int[] { 1, 2, 3, 4, 5 }, v => v > 10)); Assert.ThrowsExact <AssertionException>(() => Assert.None(new int[] { 1, 2, 3, 4, 5 }, v => v == 1)); }
public void IsNegativeInfinity() { Assert.ThrowsExact <AssertionException>(() => Assert.IsNegativeInfinity(float.NaN)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNegativeInfinity(double.NaN)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNegativeInfinity(float.PositiveInfinity)); Assert.DoesNotThrow(() => Assert.IsNegativeInfinity(float.NegativeInfinity)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNegativeInfinity(1.34f)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNegativeInfinity(double.PositiveInfinity)); Assert.DoesNotThrow(() => Assert.IsNegativeInfinity(double.NegativeInfinity)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNegativeInfinity(1.34d)); }
public void ExceptionAttachments() { var exception = new AssertionException("Testing {0}", 123); try { Assert.DoesNotThrow(() => { throw new ArgumentException(); }, exception); } catch (AssertionException e) { Assert.Equal(e.Message, "Testing 123"); } }
public void NotSame() { Assert.ThrowsExact <AssertionException>(() => Assert.NotSame <object>(null, null)); Assert.ThrowsExact <AssertionException>(() => { object o = new object(); Assert.NotSame(o, o); }); Assert.DoesNotThrow(() => Assert.NotSame(new object(), null)); Assert.DoesNotThrow(() => Assert.NotSame(null, new object())); Assert.DoesNotThrow(() => Assert.NotSame(new object(), new object())); }
public void Equal() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.Equal(null as object, null as object, null as IEqualityComparer <object>)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.Equal(null as object, null as object, null as IEqualityComparer)); Assert.DoesNotThrow(() => Assert.Equal(1, 1)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(1, 0)); Assert.DoesNotThrow(() => Assert.Equal(null, null)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(null as string, "hello")); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(null as string, 0)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal("000", "0000")); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, new[] { 1, 2, 3 })); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2, 4 }, new[] { 1, 2, 3 })); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, null)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(new[] { 1, 2 }, new List <int>() { 1, 2 })); Assert.DoesNotThrow(() => Assert.Equal(new[] { 1, 2, 3 }, new[] { 1, 2, 3 })); var arr1 = new[] { new[] { 1, 2 }, new[] { 2, 1 }, }; Assert.DoesNotThrow(() => Assert.Equal(arr1, arr1)); var arr2 = new[] { new[] { 2, 1 }, new[] { 1, 2 }, }; Assert.ThrowsExact <AssertionException>(() => Assert.Equal(arr1, arr2)); arr2 = new[] { new[] { 1, 2 }, new[] { 2, 1 }, }; Assert.DoesNotThrow(() => Assert.Equal(arr1, arr2)); var enumImpl1 = new EnumerableImpl(1, 2); var enumImpl2 = new EnumerableImpl(2, 1); Assert.DoesNotThrow(() => Assert.Equal(enumImpl1, enumImpl1)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal(enumImpl1, enumImpl2)); enumImpl2 = new EnumerableImpl(1, 2); Assert.DoesNotThrow(() => Assert.Equal(enumImpl1, enumImpl2)); Assert.DoesNotThrow(() => Assert.Equal("abc", "ABC", StringComparer.InvariantCultureIgnoreCase)); Assert.DoesNotThrow(() => Assert.Equal("abc" as object, "ABC" as object, StringComparer.InvariantCultureIgnoreCase)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal("abc", "BBB", StringComparer.InvariantCultureIgnoreCase)); Assert.ThrowsExact <AssertionException>(() => Assert.Equal("abc" as object, "BBB" as object, StringComparer.InvariantCultureIgnoreCase)); }
public void GreaterThan() { int minValue = 1; int value = 2; Assert.ThrowsExact <ArgumentNullException>(() => Assert.GreaterThan <string>(null, "z")); Assert.ThrowsExact <ArgumentNullException>(() => Assert.GreaterThan <string>("a", null)); Assert.DoesNotThrow(() => Assert.GreaterThan(value, minValue)); Assert.ThrowsExact <AssertionException>(() => Assert.GreaterThan(minValue, minValue)); Assert.ThrowsExact <AssertionException>(() => Assert.GreaterThan(minValue - 5, minValue)); Assert.DoesNotThrow(() => Assert.GreaterThan(minValue + 5, minValue)); }
public void LessThanEqual() { int minValue = 1; int value = 2; Assert.ThrowsExact <ArgumentNullException>(() => Assert.LessThanEqual <string>(null, "z")); Assert.ThrowsExact <ArgumentNullException>(() => Assert.LessThanEqual <string>("a", null)); Assert.ThrowsExact <AssertionException>(() => Assert.LessThanEqual(value, minValue)); Assert.DoesNotThrow(() => Assert.LessThanEqual(minValue, minValue)); Assert.DoesNotThrow(() => Assert.LessThanEqual(minValue - 5, minValue)); Assert.ThrowsExact <AssertionException>(() => Assert.LessThanEqual(minValue + 5, minValue)); }
public void Exactly() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.Exactly(null as int[], 1, v => v == 0)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.Exactly(new int[] { }, 1, null)); Assert.ThrowsExact <ArgumentException>(() => Assert.Exactly(new int[] { }, 1, v => v == 0)); Assert.ThrowsExact <ArgumentException>(() => Assert.Exactly(new int[] { 0 }, -1, v => v == 0)); Assert.DoesNotThrow(() => Assert.Exactly(new int[] { 1, 2, 3, 4, 5 }, 3, v => v >= 3)); Assert.DoesNotThrow(() => Assert.Exactly(new int[] { 1, 2, 3, 4, 5 }, 5, v => v < 10)); Assert.ThrowsExact <AssertionException>(() => Assert.Exactly(new int[] { 1, 2, 3, 4, 5 }, 4, v => v < 10)); Assert.ThrowsExact <AssertionException>(() => Assert.Exactly(new int[] { 1, 2, 3, 4, 5 }, 6, v => v < 10)); Assert.ThrowsExact <AssertionException>(() => Assert.Exactly(new int[] { 1, 2, 3, 4, 5 }, 5, v => v > 10)); Assert.ThrowsExact <AssertionException>(() => Assert.Exactly(new int[] { 1, 2, 3, 4, 5 }, 5, v => v == 1)); }
public void CountElement() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.Count(null as int[], 1, 1)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.Count("ABC", 1, 'c', null as IEqualityComparer <char>)); Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { }, 1, 1)); Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { 0 }, -1, 0)); Assert.DoesNotThrow(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 1, 1)); Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 4, 3, 4, 5 }, 2, 3)); Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 4, 3, 4, 5 }, 3, 4)); Assert.DoesNotThrow(() => Assert.Count("ABC", 1, 'c', new CharCaseInvariantComparer())); Assert.ThrowsExact <AssertionException>(() => Assert.Count("ABC", 2, 'c', new CharCaseInvariantComparer())); Assert.ThrowsExact <AssertionException>(() => Assert.Count("ABC", 0, 'c', new CharCaseInvariantComparer())); }
public void IsNotType() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotType <string>(null)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotType <int>(1)); Assert.DoesNotThrow(() => Assert.IsNotType <int?>(1)); Assert.DoesNotThrow(() => Assert.IsNotType <int>(1L)); Assert.DoesNotThrow(() => Assert.IsNotType <int>("hello")); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotType(null, typeof(string))); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotType("hello", null)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotType(1, typeof(int))); Assert.DoesNotThrow(() => Assert.IsNotType(1, typeof(int?))); Assert.DoesNotThrow(() => Assert.IsNotType(1L, typeof(int))); Assert.DoesNotThrow(() => Assert.IsNotType("hello", typeof(int))); }
public void IsNotAssignableFromType() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotAssignableFromType <string>(null)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType <int>(1)); Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType <long>(1)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType <int>(new int?(1))); Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType <int>("hello")); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotAssignableFromType(null, typeof(string))); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotAssignableFromType("hello", null)); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType(1, typeof(int))); Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType(1, typeof(long))); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotAssignableFromType(new int?(1), typeof(int))); Assert.DoesNotThrow(() => Assert.IsNotAssignableFromType("hello", typeof(int))); }
public void EndsWith() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.EndsWith(null, new int[0])); Assert.ThrowsExact <ArgumentNullException>(() => Assert.EndsWith(new int[0], null)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.EndsWith("abcd", "abc", null as IEqualityComparer <char>)); Assert.ThrowsExact <ArgumentException>(() => Assert.EndsWith(new int[0], new int[1])); Assert.ThrowsExact <ArgumentException>(() => Assert.EndsWith(new int[1], new int[0])); Assert.ThrowsExact <ArgumentException>(() => Assert.EndsWith(new int[1], new int[2])); Assert.DoesNotThrow(() => Assert.EndsWith("hello", "llo")); Assert.DoesNotThrow(() => Assert.EndsWith(new[] { 1, 2, 3, 4 }, new[] { 3, 4 })); Assert.ThrowsExact <AssertionException>(() => Assert.EndsWith("hello", "kko")); Assert.ThrowsExact <AssertionException>(() => Assert.EndsWith(new[] { 1, 2, 3, 4 }, new[] { 2, 3 })); Assert.DoesNotThrow(() => Assert.EndsWith("hello", "LLO", new CharCaseInvariantComparer())); Assert.ThrowsExact <AssertionException>(() => Assert.EndsWith("hello", "KKO", new CharCaseInvariantComparer())); }
public void InRangeEqual() { int minValue = 1; int maxValue = 10; Assert.ThrowsExact <ArgumentNullException>(() => Assert.InRangeEqual <string>(null, "z", "z")); Assert.ThrowsExact <ArgumentNullException>(() => Assert.InRangeEqual <string>("a", null, "z")); Assert.ThrowsExact <ArgumentNullException>(() => Assert.InRangeEqual <string>("a", "z", null)); Assert.DoesNotThrow(() => Assert.InRangeEqual(2, minValue, maxValue)); Assert.DoesNotThrow(() => Assert.InRangeEqual(minValue, minValue, maxValue)); Assert.DoesNotThrow(() => Assert.InRangeEqual(maxValue, minValue, maxValue)); Assert.ThrowsExact <AssertionException>(() => Assert.InRangeEqual(minValue - 5, minValue, maxValue)); Assert.DoesNotThrow(() => Assert.InRangeEqual(minValue + 5, minValue, maxValue)); Assert.DoesNotThrow(() => Assert.InRangeEqual(maxValue - 5, minValue, maxValue)); Assert.ThrowsExact <AssertionException>(() => Assert.InRangeEqual(maxValue + 5, minValue, maxValue)); }
public void StartsWith() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.StartsWith(null, new int[0])); Assert.ThrowsExact <ArgumentNullException>(() => Assert.StartsWith(new int[0], null)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.StartsWith("abcd", "abc", null as IEqualityComparer <char>)); Assert.ThrowsExact <ArgumentException>(() => Assert.StartsWith(new int[0], new int[1])); Assert.ThrowsExact <ArgumentException>(() => Assert.StartsWith(new int[1], new int[0])); Assert.ThrowsExact <ArgumentException>(() => Assert.StartsWith(new int[1], new int[2])); Assert.DoesNotThrow(() => Assert.StartsWith("hello", "hel")); Assert.DoesNotThrow(() => Assert.StartsWith(new[] { 1, 2, 3, 4 }, new[] { 1, 2 })); Assert.ThrowsExact <AssertionException>(() => Assert.StartsWith("hello", "jel")); Assert.ThrowsExact <AssertionException>(() => Assert.StartsWith(new[] { 1, 2, 3, 4 }, new[] { 2, 3 })); Assert.DoesNotThrow(() => Assert.StartsWith("hello", "HEL", new CharCaseInvariantComparer())); Assert.ThrowsExact <AssertionException>(() => Assert.StartsWith("hello", "JEL", new CharCaseInvariantComparer())); }
public void IsNotStrictSubsetOf() { Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotStrictSubsetOf(null, new int[0])); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotStrictSubsetOf(new int[0], null)); Assert.ThrowsExact <ArgumentNullException>(() => Assert.IsNotStrictSubsetOf("abcd", "abc", null as IEqualityComparer <char>)); Assert.ThrowsExact <ArgumentException>(() => Assert.IsNotStrictSubsetOf(new int[0], new int[1])); Assert.ThrowsExact <ArgumentException>(() => Assert.IsNotStrictSubsetOf(new int[1], new int[0])); Assert.ThrowsExact <ArgumentException>(() => Assert.IsNotStrictSubsetOf(new int[1], new int[2])); Assert.ThrowsExact <ArgumentException>(() => Assert.IsNotStrictSubsetOf(new[] { 1 }, new[] { 1 })); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotStrictSubsetOf("Musky", "usk")); Assert.DoesNotThrow(() => Assert.IsNotStrictSubsetOf("Musky", "elk")); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotStrictSubsetOf(new[] { 1, 2, 3, 4, 5 }, new[] { 1, 2, 3 })); Assert.ThrowsExact <ArgumentException>(() => Assert.IsNotStrictSubsetOf(new[] { 1, 2, 3, 4, 5 }, new[] { 1, 2, 3, 4, 5 })); Assert.DoesNotThrow(() => Assert.IsNotStrictSubsetOf(new[] { 1, 2, 3, 4, 5 }, new[] { 1, 2, 3, 6 })); Assert.ThrowsExact <AssertionException>(() => Assert.IsNotStrictSubsetOf("Musky", "musk", new CharCaseInvariantComparer())); Assert.DoesNotThrow(() => Assert.IsNotStrictSubsetOf("Musky", "abc", new CharCaseInvariantComparer())); }