NUnit.Framework.Assert.That(bool, string, params object[])

Here are the examples of the csharp api class NUnit.Framework.Assert.That(bool, string, params object[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

28 Examples 7

1. Example

Project: nunit
Source File: AssertThatTests.cs
View license
[Test]
        public void AssertionPasses_BooleanWithMessageAndArgs()
        {
            Assert.That(2 + 2 == 4, "Not Equal to {0}", 4);
        }

2. Example

Project: nunitlite
Source File: AssertThatTests.cs
View license
[Test, ExpectedException(typeof(AssertionException), ExpectedMessage = "got 5", MatchType = MessageMatch.Contains)]
        public void FailureThrowsAssertionException_BooleanWithMessageAndArgs()
        {
            Assert.That(2 + 2 == 5, "got {0}", 5);
        }

3. Example

Project: nunitlite
Source File: AssertThatTests.cs
View license
[Test]
        public void AssertionPasses_BooleanWithMessageAndArgs()
        {
            Assert.That(2 + 2 == 4, "Not Equal to {0}", 4);
        }

4. Example

Project: ini-parser
Source File: IniParserFile_Test.cs
View license
[Test, Description("Checks existence of test INI files")]
        public void CheckTestFilesExists()
        {
            Assert.That(File.Exists(strGoodINIFilePath), "Correct INI file {0} does not exists", strGoodINIFilePath);
            Assert.That(File.Exists(strBadINIFilePath), "Invalid INI file {0} does not exists", strBadINIFilePath);
            Assert.That(File.Exists(strEmptyINIFilePath), "Empty INI file {0} does not exists", strEmptyINIFilePath);
        }

5. Example

View license
[Test]
        public void TestResults_HasValidDateAttribute()
        {
            string dateString = RequiredAttribute(_topNode, "date");
#if !NETCF
            DateTime date;
            Assert.That(DateTime.TryParse(dateString, out date), "Invalid date attribute: {0}", dateString);
#endif
        }

6. Example

View license
[Test]
        public void TestResults_HasValidTimeAttribute()
        {
            string timeString = RequiredAttribute(_topNode, "time");
#if !NETCF
            DateTime time;
            Assert.That(DateTime.TryParse(timeString, out time), "Invalid time attribute: {0}", timeString);
#endif
        }

7. Example

View license
[Test]
        public void TestFixture_HasValidTimeAttribute()
        {
#if NETCF
            RequiredAttribute(suiteNode, "time");
#else
            double time;
            var timeString = RequiredAttribute(_fixtureNode, "time");
            // NOTE: We use the TryParse overload with 4 args because it's supported in .NET 1.1
            var success = double.TryParse(timeString,System.Globalization.NumberStyles.Float,System.Globalization.NumberFormatInfo.InvariantInfo, out time);
            Assert.That(success, "{0} is an invalid value for time", timeString);
#endif
        }

8. Example

Project: nunit
Source File: NUnit2XmlOutputWriterTests.cs
View license
[Test]
        public void TestSuite_HasValidTimeAttribute()
        {
            double time;
            var timeString = RequiredAttribute(suiteNode, "time");
            // NOTE: We use the TryParse overload with 4 args because it's supported in .NET 1.1
            var success = double.TryParse(timeString,System.Globalization.NumberStyles.Float,System.Globalization.NumberFormatInfo.InvariantInfo, out time);
            Assert.That(success, "{0} is an invalid value for time", timeString);
        }

9. Example

Project: nunit
Source File: NUnit2XmlOutputWriterTests.cs
View license
[Test]
        public void TestResults_HasValidTimeAttribute()
        {
            string timeString = RequiredAttribute(topNode, "time");
            DateTime time;
            Assert.That(DateTime.TryParse(timeString, out time), "Invalid time attribute: {0}", timeString);
        }

10. Example

Project: NSubstitute
Source File: ExceptionsSpecs.cs
View license
[Test]
        public void All_nsub_exceptions_should_implement_serialisation_ctor_so_its_stacktrace_can_be_preserved()
        {
            /* This is meant to be good practice (http://msdn.microsoft.com/en-us/library/ms229064.aspx), but
             * at one stage was also (or still is?) used to preserve stack traces from RaiseEventHandler.
             */
            foreach (var exceptionType in _exceptionTypes)
            {
                Assert.That(
                    exceptionType
                        .GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)
                        .Any(IsSerialisationConstructor)
                , "{0} does not have a protected serialisation constructor. i.e. ctor(SerializationInfo, StreamingContext).", exceptionType);
            }
        }

11. Example

Project: JsonLD.Entities
Source File: Readme.cs
View license
[Test]
    public void Context_can_be_built_with_vocabulary_base()
    {
        // given
        var expected = @"
{
    'translations': {
        '@id': 'http://vocab.example.com/terms#translations',
        '@type': '@id',
        '@container': '@language'
    }
}";

        // when
        dynamic context = Multilanguage.Context;

        // then
        Assert.That(JToken.DeepEquals(context, JObject.Parse(expected)), "Actual context was {0}", context);
    }

12. Example

Project: nunit
Source File: NUnit2XmlOutputWriterTests.cs
View license
[Test]
        public void TestResults_HasValidDateAttribute()
        {
            string dateString = RequiredAttribute(topNode, "date");
            DateTime date;
            Assert.That(DateTime.TryParse(dateString, out date), "Invalid date attribute: {0}", dateString);
        }

13. Example

Project: nunit
Source File: AssertThatTests.cs
View license
[Test]
        public void FailureThrowsAssertionException_BooleanWithMessageAndArgs()
        {
            var ex = Assert.Throws<AssertionException>(() => Assert.That(2 + 2 == 5, "got {0}", 5));
            Assert.That(ex.Message, Does.Contain("got 5"));
        }

14. Example

Project: JsonLD.Entities
Source File: Readme.cs
View license
[Test]
public void BuildComplexContextSimply()
{
    // given
    const string expected = @"
{
    '/n ..... /n //View Source file for more details /n }

15. Example

View license
[Test]
        public void Test01_ProjectReferenceDoesNotExist()
        {
            var test = new Test(@"Test01_ProjectReferenceDoesNotExist\Project01\Project01.csproj", null);

            Exception exception = null;
            bool result = true;
            try
            {
                test.DeleteOutput();
                result = test.Execute();
            }
            catch(Exception ex)
            {
                exception = ex;
            }

            Assert.That(!result, "Any error should lead to negative result");
            Assert.That(exception == null, "Exception {0} was not expected", exception);

            var fileExist = test.DeleteOutput();
            Assert.That(!fileExist, "In case of error there should not be file generated");
        }

16. Example

View license
[Test]
        public void CanAccessAggregateRootInView()
        {
            _eventDispatcher.AddViewManager(_viewManager1);

            _cirqus.ProcessCommand(new MyCommand("rootid"));
            _cirqus.ProcessCommand(new MyCommand("rootid"));
            _cirqus.ProcessCommand(new MyCommand("rootid"));
            _cirqus.ProcessCommand(new MyCommand("rootid"));
            var lastResult = _cirqus.ProcessCommand(new MyCommand("rootid"));

            _eventDispatcher.WaitUntilProcessed(lastResult, TimeSpan.FromSeconds(3)).Wait();

            var view = _viewManager1.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("rootid"));

            Assert.That(view.Calls.All(c => c.Item1 == c.Item2), "Registered calls contained a call where the version of the loaded aggregate root did not correspond to the version of the event that the view got to process: {0}",
                string.Join(", ", view.Calls.Select(c => string.Format("{0}/{1}", c.Item1, c.Item2))));
        }

17. Example

View license
[Test]
        public void CanAccessAggregateRootInViewWithImplicitDeductionOfGlobalSequenceNumberInView()
        {
            _eventDispatcher.AddViewManager(_viewManager2);

            _cirqus.ProcessCommand(new MyCommand("rootid"));
            _cirqus.ProcessCommand(new MyCommand("rootid"));
            _cirqus.ProcessCommand(new MyCommand("rootid"));
            _cirqus.ProcessCommand(new MyCommand("rootid"));

            var lastResult = _cirqus.ProcessCommand(new MyCommand("rootid"));

            _eventDispatcher.WaitUntilProcessed(lastResult, TimeSpan.FromSeconds(3)).Wait();

            var view = _viewManager2.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("rootid"));

            Assert.That(view, Is.Not.Null);

            Assert.That(view.Calls.All(c => c.Item1 == c.Item2), "Registered calls contained a call where the version of the loaded aggregate root did not correspond to the version of the event that the view got to process: {0}",
                string.Join(", ", view.Calls.Select(c => string.Format("{0}/{1}", c.Item1, c.Item2))));
        }

18. Example

View license
[Test]
		public void TestReset_CanStartAgain()
		{
			using ( var target = new TimeoutWatcher() )
			using ( var waitHandle = new ManualResetEventSlim() )
			{
				target.Timeout += ( sender, e ) => waitHandle.Set();
				for ( int i = 0; i < 2; i++ )
				{
					Assert.That( target.IsTimeout, Is.False, "Attempt: {0}", i );
					target.Start( _timeout );
					Assert.That( waitHandle.Wait( TimeSpan.FromSeconds( 1 ) ), "Attempt: {0}", i );
					Assert.That( target.IsTimeout, Is.True, "Attempt: {0}", i );
					target.Reset();
					waitHandle.Reset();
				}
			}
		}

19. Example

Project: AutoTest.Net
Source File: TestLexer.cs
View license
private void _checkOutput(string sequence, LexToken[] expected)
        {
            Lexer lexer;
            StringBuilder recognized;
            string error;
            int i;
            int j;

            lexer = new Lexer();
            lexer.Parse(sequence);

            recognized = new StringBuilder();

            i = 0;
            while (lexer.Next())
            {
                recognized.Append(lexer.CurrentToken.Text);

                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
                    expected[i],
                    lexer.CurrentToken,
                    recognized.ToString());

                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);

                i++;
            }

            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");

            error = "missing ";
            j = i;
            while (j < expected.Length)
            {
                error += expected[j].ToString();
                error += ", ";
                ++j;
            }

            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);

            return;
        }

20. Example

Project: AutoTest.Net
Source File: TestLexer.cs
View license
private void _checkOutput(string sequence, LexToken[] expected)
        {
            Lexer lexer;
            StringBuilder recognized;
            string error;
            int i;
            int j;

            lexer = new Lexer();
            lexer.Parse(sequence);

            recognized = new StringBuilder();

            i = 0;
            while (lexer.Next())
            {
                recognized.Append(lexer.CurrentToken.Text);

                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
                    expected[i],
                    lexer.CurrentToken,
                    recognized.ToString());

                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);

                i++;
            }

            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");

            error = "missing ";
            j = i;
            while (j < expected.Length)
            {
                error += expected[j].ToString();
                error += ", ";
                ++j;
            }

            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);

            return;
        }

21. Example

Project: ContinuousTests
Source File: TestLexer.cs
View license
private void _checkOutput(string sequence, LexToken[] expected)
        {
            Lexer lexer;
            StringBuilder recognized;
            string error;
            int i;
            int j;

            lexer = new Lexer();
            lexer.Parse(sequence);

            recognized = new StringBuilder();

            i = 0;
            while (lexer.Next())
            {
                recognized.Append(lexer.CurrentToken.Text);

                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
                    expected[i],
                    lexer.CurrentToken,
                    recognized.ToString());

                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);

                i++;
            }

            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");

            error = "missing ";
            j = i;
            while (j < expected.Length)
            {
                error += expected[j].ToString();
                error += ", ";
                ++j;
            }

            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);

            return;
        }

22. Example

Project: AutoTest.Net
Source File: TestLexer.cs
View license
private void _checkOutput(string sequence, LexToken[] expected)
        {
            Lexer lexer;
            StringBuilder recognized;
            string error;
            int i;
            int j;

            lexer = new Lexer();
            lexer.Parse(sequence);

            recognized = new StringBuilder();

            i = 0;
            while (lexer.Next())
            {
                recognized.Append(lexer.CurrentToken.Text);

                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
                    expected[i],
                    lexer.CurrentToken,
                    recognized.ToString());

                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);

                i++;
            }

            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");

            error = "missing ";
            j = i;
            while (j < expected.Length)
            {
                error += expected[j].ToString();
                error += ", ";
                ++j;
            }

            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);

            return;
        }

23. Example

Project: nunitlite
Source File: TestContextTests.cs
View license
[Test]
        public void TestCanAccessTestDirectory()
        {
            string testDirectory = TestContext.CurrentContext.TestDirectory;
            Assert.NotNull(testDirectory);
            Assert.That(Directory.Exists(testDirectory), "Directory not found: {0}", testDirectory);
            Assert.That(File.Exists(Path.Combine(testDirectory, "nunitlite.tests.exe")));
        }

24. Example

View license
private static void AssertArraySegmentEquals( object x, object y )
		{
#if !NETFX_CORE && !NETSTANDARD1_1 && !NETSTANDARD1_3
			var type = typeof( ArraySegmentEqualityComparer<> ).MakeGenericType( x.GetType().GetGenericArguments()[ 0 ] );
			Assert.That(
				( bool )type.InvokeMember( "Equals", BindingFlags.InvokeMethod, null, Activator.CreateInstance( type ), new[] { x, y } ),
				"Expected:{1}{0}Actual :{2}",
				Environment.NewLine,
				x,
				y
			);
#else
			var elementType = x.GetType().GetTypeInfo().GenericTypeArguments[ 0 ];
			var type = typeof( ArraySegmentEqualityComparer<> ).MakeGenericType( elementType );
			Assert.That(
				( bool )type.GetRuntimeMethod( "Equals", new[] { x.GetType(), x.GetType() } ).Invoke( Activator.CreateInstance( type ), new[] { x, y } ),
				"Expected:{1}{0}Actual :{2}",
				Environment.NewLine,
				x,
				y
			);
#endif // !NETFX_CORE && !NETSTANDARD1_1 && !NETSTANDARD1_3
		}

25. Example

Project: ContinuousTests
Source File: TestLexer.cs
View license
private void _checkOutput(string sequence, LexToken[] expected)
        {
            Lexer lexer;
            StringBuilder recognized;
            string error;
            int i;
            int j;

            lexer = new Lexer();
            lexer.Parse(sequence);

            recognized = new StringBuilder();

            i = 0;
            while (lexer.Next())
            {
                recognized.Append(lexer.CurrentToken.Text);

                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
                    expected[i],
                    lexer.CurrentToken,
                    recognized.ToString());

                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);

                i++;
            }

            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");

            error = "missing ";
            j = i;
            while (j < expected.Length)
            {
                error += expected[j].ToString();
                error += ", ";
                ++j;
            }

            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);

            return;
        }

26. Example

Project: ContinuousTests
Source File: TestLexer.cs
View license
private void _checkOutput(string sequence, LexToken[] expected)
        {
            Lexer lexer;
            StringBuilder recognized;
            string error;
            int i;
            int j;

            lexer = new Lexer();
            lexer.Parse(sequence);

            recognized = new StringBuilder();

            i = 0;
            while (lexer.Next())
            {
                recognized.Append(lexer.CurrentToken.Text);

                error = String.Format("Token [{0}] was expected, but lexer returned [{1}] instead, near: [{2}].",
                    expected[i],
                    lexer.CurrentToken,
                    recognized.ToString());

                Assert.That(lexer.CurrentToken, Is.EqualTo(expected[i]), error);

                i++;
            }

            Assert.That(lexer.Next(), Is.False, "Error, there are unvisited tokens left.");

            error = "missing ";
            j = i;
            while (j < expected.Length)
            {
                error += expected[j].ToString();
                error += ", ";
                ++j;
            }

            Assert.That(i == expected.Length, "Error, more tokens were expected. {0}", error);

            return;
        }

27. Example

Project: RestMvc
Source File: Routes.cs
View license
public override bool Matches(object requestText)
        {
            var route = FindRoute(new TestRequest(requestText.ToString()));
            Assert.That(route, Is.Not.Null, "Did not find route");

            foreach (var key in expectations.Keys)
            {
                Assert.That(route.Values.ContainsKey(key), Is.True, "Missing route value {0}", key);
                Assert.That(String.Equals(expectations[key], route.Values[key].ToString(), StringComparison.InvariantCultureIgnoreCase),
                    "Expected '{0}', not '{1}' for '{2}'", expectations[key], route.Values[key], key);
            }
            return true;
        }

28. Example

View license
internal static void Verify<T>( T expected, T actual )
		{
			if ( expected == null )
			{
			/n ..... /n //View Source file for more details /n }