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: nunitlite
Source File: AssertThatTests.cs
[Test]
        public void AssertionPasses_BooleanWithMessageAndArgs()
        {
            Assert.That(2 + 2 == 4, "Not Equal to {0}", 4);
        }

2. Example

Project: nunitlite
Source File: AssertThatTests.cs
[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: nunit
Source File: AssertThatTests.cs
[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
[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

Project: NSubstitute
Source File: ExceptionsSpecs.cs
[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);
            }
        }

6. Example

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

7. Example

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

8. Example

Project: nunit
Source File: NUnit2XmlOutputWriterTests.cs
[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: AssertThatTests.cs
[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"));
        }

10. Example

Project: nunit-console
Source File: NUnit2XmlResultWriterTests.cs
[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
        }

11. Example

Project: nunit-console
Source File: NUnit2XmlResultWriterTests.cs
[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
        }

12. Example

Project: nunit-console
Source File: NUnit2XmlResultWriterTests.cs
[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
        }

13. Example

Project: JsonLD.Entities
Source File: Readme.cs
[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);
    }

14. Example

Project: Cirqus
Source File: TestLoadAggregatesFromView.cs
[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))));
        }

15. Example

Project: msbuildtasks
Source File: DependencyGraphTaskTest.cs
[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

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

17. Example

Project: Cirqus
Source File: TestLoadAggregatesFromView.cs
[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

Project: ContinuousTests
Source File: TestLexer.cs
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;
        }

19. Example

Project: ContinuousTests
Source File: TestLexer.cs
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: ContinuousTests
Source File: TestLexer.cs
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: msgpack-cli
Source File: AutoMessagePackSerializerTest.Types.cs
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
		}

22. Example

Project: nunitlite
Source File: TestContextTests.cs
[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")));
        }

23. Example

Project: msgpack-rpc-cli
Source File: TimeoutWatcherTest.cs
[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();
				}
			}
		}

24. Example

Project: AutoTest.Net
Source File: TestLexer.cs
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;
        }

25. Example

Project: AutoTest.Net
Source File: TestLexer.cs
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: AutoTest.Net
Source File: TestLexer.cs
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
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

Project: msgpack-cli
Source File: AutoMessagePackSerializerTest.Types.cs
internal static void Verify<T>( T expected, T actual )
		{
			if ( expected == null )
			{
			/n ..... /n //View Source file for more details /n }