NUnit.Framework.Assert.That(bool, string)

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

200 Examples 7

1. Example

Project: Bigtable-dotnet
Source File: Temp.cs
View license
[Test]
        public void Todo()
        {
            Assert.That(_admin != null, "AdminClient created");
            Assert.That(_data != null, "DataClient created");
        }

2. Example

Project: SAML2
Source File: AssertionUtil.cs
View license
public static X509Certificate2 GetCertificate()
        {
            if (_cert == null)
            {
                _cert = new X509Certificate2(@"Certificates\sts_dev_certificate.pfx", "test1234");
                Assert.That(_cert.HasPrivateKey, "Certificate no longer contains a private key. Modify test.");
            }

            return _cert;
        }

3. Example

Project: Divan
Source File: CouchTest.cs
View license
[Test, ExpectedException(typeof(InvalidOperationException))]
        public void ShouldHandleStreaming()
        {
            var design = new CouchDesignDocument("test", db);
            design.AddView("docs", "function (doc) { emit(null, null); } ");
            design.Synch();

            var doc = new CouchJsonDocument("{\"_id\":\"123\", \"CPU\": \"Intel\"}");
            db.SaveDocument(doc);

            var result = db.Query("test", "docs").StreamResult<CouchDocument>();

            Assert.That(result.FirstOrDefault() != null, "there should be one doc present");

            try
            {
                // this should throw an invalid operation exception
                result.FirstOrDefault();
            }
            finally
            {
                db.DeleteDocument(doc);
                db.DeleteDocument(design);
            }
        }

4. Example

Project: XPlatUtils
Source File: MessengerTests.cs
View license
[Test]
        public void Unsubscribe ()
        {
            Action<TestMessage> action = _ => Assert.That (false, "This event should not fire!");

            messenger.Subscribe (action);
            messenger.Unsubscribe (action);
            messenger.Publish (new TestMessage (this));
        }

5. Example

Project: mathnet-iridium
Source File: NumberTest.cs
View license
[Test]
        public void TestIncrementDecrementStep()
        {
            const double x0 = 1e-100;
            const double x1 = 1e+0;
            const double x2 = 1e+100;
            const double x3 = 1e+200;
            const double x4 = -1e+100;

            double y0 = Number.Increment(x0) - x0;
            double y1 = Number.Increment(x1) - x1;
            double y2 = Number.Increment(x2) - x2;
            double y3 = Number.Increment(x3) - x3;
            double y4 = Number.Increment(x4) - x4;

            Assert.That(y0 < y1, "A");
            Assert.That(y1 < y2, "B");
            Assert.That(y2 < y3, "C");
            Assert.That(y2 == y4, "D");
         }

6. Example

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

7. Example

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

8. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomULongWithMaximum()
        {
            ulong val = _randomizer.NextULong(1066UL);
            Assert.That(val < 1066UL, "Out of range");
        }

9. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomUShortInRange()
        {
            ushort min = 42;
            ushort max = 99;
            ushort val = _randomizer.NextUShort(min, max);
            Assert.That(val >= min && val < max, "Out of range");
        }

10. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomUIntWithMaximum()
        {
            uint val = _randomizer.NextUInt(100u);
            Assert.That(val >= 0u && val < 100u, "Out of range");
        }

11. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomFloatInRange()
        {
            float f = _randomizer.NextFloat(0.2f, 0.7f);
            Assert.That(f >= 0.2f && f < 0.7f, "Out of range");
        }

12. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomUShortWithMaximum()
        {
            ushort zero = 0;
            ushort max = 100;
            ushort us = _randomizer.NextUShort(max);
            Assert.That(us >= zero && us < max, "Out of range");
        }

13. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomShortInRange()
        {
            short min = -10;
            short max = 100;
            short s = _randomizer.NextShort(min, max);
            Assert.That(s >= min && s < max, "Out of range");
        }

14. Example

Project: nunit
Source File: WarningTests.cs
View license
[Test]
        public void FailingWarning_CallsExceptionStringFunc()
        {
            // Arrange
            var funcWasCalled = false;
            Func<string> getExceptionMessage = () =>
            {
                funcWasCalled = true;
                return "Func was called";
            };

            // Act
            using (new TestExecutionContext.IsolatedContext())
                Warn.Unless(1 + 1 == 1, getExceptionMessage);

            // Assert
            Assert.That(funcWasCalled, "The getExceptionMessage function was not called when it should have been.");
        }

15. Example

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

16. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomLongWithMaximum()
        {
            long val = _randomizer.NextLong(1066L);
            Assert.That(val >= 0L && val < 1066L, "Out of range");
        }

17. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomFloatWithMaximum()
        {
            float f = _randomizer.NextFloat(100.0f);
            Assert.That(f >= 0.0f && f < 100.0f, "Out of range");
        }

18. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomLongInRange()
        {
            long val = _randomizer.NextLong(1066L, 1942L);
            Assert.That(val >= 1066L && val < 1942L, "Out of range");
        }

19. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomShortWithMaximum()
        {
            short zero = 0;
            short max = 100;
            short s = _randomizer.NextShort(max);
            Assert.That(s >= zero && s < max, "Out of range");
        }

20. Example

Project: nunit
Source File: WarningTests.cs
View license
[Test]
        public void PassingAssertion_DoesNotCallExceptionStringFunc()
        {
            // Arrange
            var funcWasCalled = false;
            Func<string> getExceptionMessage = () =>
            {
                funcWasCalled = true;
                return "Func was called";
            };

            // Act
            using (new TestExecutionContext.IsolatedContext())
                Warn.Unless(0 + 1 == 1, getExceptionMessage);

            // Assert
            Assert.That(!funcWasCalled, "The getExceptionMessage function was called when it should not have been.");
        }

21. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomULongInRange()
        {
            ulong val = _randomizer.NextULong(1066UL, 1942UL);
            Assert.That(val >= 1066UL && val < 1942UL, "Out of range");
        }

22. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomUIntInRange()
        {
            uint val = _randomizer.NextUInt(42u, 99u);
            Assert.That(val >= 42u && val < 99u, "Out of range");
        }

23. Example

Project: Orchard
Source File: AccountControllerTests.cs
View license
[Test]

        public void UsersShouldNotBeAbleToRegisterIfInvalidEmail(
            [Values(
                @"NotAnEmail", 
                @"@NotAnEmail",
                @"""test\blah""@example.com",
                "\"test\rblah\"@example.com",
                @"""test""blah""@example.com",
                @"[email protected]",
                @"[email protected]",
                @"[email protected]",
                @"[email protected]",
                @"@example.com",
                @"Ima [email protected]")]
            string email) {

            var registrationSettings = _container.Resolve<IWorkContextAccessor>().GetContext().CurrentSite.As<RegistrationSettingsPart>();
            registrationSettings.UsersCanRegister = true;
            registrationSettings.UsersAreModerated = false;
            registrationSettings.UsersMustValidateEmail = false;

            _session.Flush();

            _controller.ModelState.Clear();
            var result = _controller.Register("bar", email, "66554321", "66554321");
 
            Assert.That(((ViewResult)result).ViewData.ModelState.Count == 1,"Invalid email address.");
        }

24. Example

Project: sc2replay-csharp
Source File: ReplayTests.cs
View license
[Test, TestCaseSource("TestReplays")]
        public void ReplayHasEvents(string filename)
        {
            Replay replay = Replay.Parse(filename);

            Assert.That(replay.PlayerEvents != null, "Events failed to parse.");
        }

25. Example

View license
private bool OnGetContentControlParameters(object parameterObj)
		{
			var param = parameterObj as Tuple<string, string, XmlNode[]>;
			if (param == null)
				return false;
			var result = param.Item3;
			Assert.That(param.Item2 == "lexiconDictionary" || param.Item2 == "reversalToolEditComplete", "No params for tool: " + param.Item2);
			result[0] = param.Item2 == "lexiconDictionary" ? m_testControlDictNode : m_testControlRevNode;
			return true;
		}

26. Example

View license
[Test]
		public void DoImport_AddsNewPublications()
		{
			var configFile=FileUtils.GetTempFile("uni/n ..... /n //View Source file for more details /n }

27. Example

Project: SimpleBrowser
Source File: Selectors.cs
View license
[Test]
		public void SearchingAnInputElementBySeveralSelectingMethods()
		{
			Browser b = new Brows/n ..... /n //View Source file for more details /n }

28. Example

Project: SimpleBrowser
Source File: Selectors.cs
View license
[Test]
		public void SearchingAnElementBySeveralSelectingMethods()
		{
			Browser b = new Browser();
			b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));

			var colorBox = b.Find("first-checkbox"); // find by id
			Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with ID first-checkbox");

			colorBox = b.Select("*[type=checkbox][checked]");
			Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with type checkbox and checked");
		}

29. Example

View license
[Observation]
		public void it_recognizes_that_branch_within_PossibleTransitions_collection()
		{
			var wf = new StatefulWorkflow<Entity>()
				.Yield("broke")
				.Yield("begin")
				.When(x => true).BreakWithStatus("broke")
				.Yield("didn't break");

			Assert.That(wf.PossibleTransitions.Any(x => (string)x.From == "begin" && (string)x.To == "broke"),
				"PossibleTransitions should contain the potential transition from 'begin' to 'broke'");
		}

30. Example

View license
[Transaction]
		public virtual ITransaction VerifyInAmbient()
		{
			Assert.That(System.Transactions.Transaction.Current != null,
			            "The current transaction mustn't be null.");

			Assert.That(_Manager.CurrentTransaction != null,
			            "The current transaction in the transaction manager mustn't be null.");

			return _Manager.CurrentTransaction.Value;
		}

31. Example

Project: Castle.Transactions
Source File: MyService.cs
View license
[Transaction]
		public virtual ITransaction VerifyInAmbient()
		{
			Assert.That(System.Transactions.Transaction.Current != null,
			            "The current transaction mustn't be null.");

			Assert.That(_Manager.CurrentTransaction != null,
				"The current transaction in the transaction manager mustn't be null.");

			return _Manager.CurrentTransaction.Value;
		}

32. Example

Project: CIAPI.CS
Source File: KoanAssert.cs
View license
public static void That(bool isTrue, string message)
        {
            try
            {
                Assert.That(isTrue, message);
            }
            catch (Exception ex)
            {
                throw new FailedToReachEnlightenmentException(ex.Message);
            }
        }

33. Example

View license
[Test]
        public void UsesProvidedIComparer()
        {
            MyComparer comparer = new MyComparer();
            Assert.That(rangeConstraint.Using(comparer).Matches(19));
            Assert.That(comparer.Called, "Comparer was not called");
        }

34. Example

View license
[Test]
        public void UsesProvidedIComparer()
        {
            MyComparer comparer = new MyComparer();
            Assert.That(rangeConstraint.Using(comparer).Matches(19));
            Assert.That(comparer.Called, "Comparer was not called");
        }

35. Example

View license
[Test]
        public void UsesProvidedIComparer()
        {
            MyComparer comparer = new MyComparer();
            Assert.That(rangeConstraint.Using(comparer).Matches(19));
            Assert.That(comparer.Called, "Comparer was not called");
        }

36. Example

Project: Divan
Source File: CouchTest.cs
View license
[Test, ExpectedException(typeof(CouchNotFoundException))]
        public void ShouldHaveExtendedExceptionMessages()
        {
            try
            {
                db.Query("invalid", "view").GetResult();
            }
            catch (CouchException ex)
            {
                Assert.That(ex.Message.Contains("reason: "), String.Format("Expected extended exception text, with 'reason' field, received '{0}'", ex.Message));
            }
        }

37. Example

Project: mathnet-iridium
Source File: SortingTest.cs
View license
[Test]
        public void TestAppliedSetSorting()
        {
            const int len = 0x1 << 10;
            SystemRandomSource random = new SystemRandomSource();

            Set<int> set = new Set<int>();

            for(int i = 0; i < len; i++)
            {
                set.Add(random.Next());
            }

            // default sorting (Ascending)
            set.Sort();

            // just check that the order is as expected, not that the items are correct
            for(int i = 1; i < set.Count; i++)
            {
                Assert.That(set[i] >= set[i - 1], "Sort Order - " + i.ToString());
            }
        }

38. Example

View license
[Test]
        [TestCaseSource(typeof(ValueAtMinimumSource))]
        public void ValueAtMinimum(TestFunctions.TestCase test_case)
        {
            if (test_case.MinimizingPoint != null)
            {
                var value_at_minimum = test_case.Function.SsqValue(test_case.MinimizingPoint);
                Assert.That(
                    Math.Abs(value_at_minimum - test_case.MinimalValue) < 1e-3,
                    $"Function value at minimum not as expected."
                );
            }
        }

39. Example

Project: CallSharp
Source File: FragTests.cs
View license
[Test]
    [TestCase("a b c", " ", "a", " b ")]
    public void StringToStringFragmentationTest(string input, params string[] expectedOutputs)
    {
      var items = fe.Frag(input, typeof(string));
      foreach (var eo in expectedOutputs)
        Assert.That(items.Contains(eo), $"expected the result set [{string.Join(",", items)}] to contain [{eo}]");
    }

40. Example

Project: CallSharp
Source File: FragTests.cs
View license
[Test]
    [TestCase("abc", 'a', 'b', 'c')]
    public void StringToCharFragmentationTests(string input, params char[] expectedOutputs)
    {
      var items = fe.Frag(input, typeof(char));
      foreach (var eo in expectedOutputs)
        Assert.That(items.Contains(eo), $"expected the result set [{string.Join(",", items)}] to contain [{eo}]");
    }

41. Example

View license
[Test]
		public void InheritedInterfaceOverridesGetHashCode()
		{
			Assert.That(ReflectHelper.OverridesGetHashCode(typeof(IMyBaseWithEqual)), "does override.");
			Assert.That(ReflectHelper.OverridesGetHashCode(typeof(IMyInheritedWithEqual)), "does override.");
			Assert.That(ReflectHelper.OverridesGetHashCode(typeof(IComplex)), "does override.");
		}

42. Example

View license
[Test]
		public void InheritedInterfaceOverridesEquals()
		{
			Assert.That(ReflectHelper.OverridesEquals(typeof(IMyBaseWithEqual)), "does override.");
			Assert.That(ReflectHelper.OverridesEquals(typeof(IMyInheritedWithEqual)), "does override.");
			Assert.That(ReflectHelper.OverridesEquals(typeof(IComplex)), "does override.");
		}

43. Example

Project: NSubstitute
Source File: ReceivedCalls.cs
View license
[Test]
        public void Should_receive_call_even_when_call_is_stubbed_to_throw_an_exception()
        {
            _car.GetCapacityInLitres().Returns(x => { throw new InvalidOperationException(); });

            var exceptionThrown = false;
            try { _car.GetCapacityInLitres(); }
            catch { exceptionThrown = true; }

            _car.Received().GetCapacityInLitres();
            Assert.That(exceptionThrown, "An exception should have been thrown for this to actually test whether calls that throw exceptions are received.");
        }

44. Example

Project: NSubstitute
Source File: ReceivedCalls.cs
View license
[Test]
        public void Should_receive_call_when_a_callback_for_call_throws_an_exception()
        {
            _car.When(x => x.Rev()).Do(x => { throw new InvalidOperationException(); });

            var exceptionThrown = false;
            try { _car.Rev(); }
            catch { exceptionThrown = true; }

            _car.Received().Rev();
            Assert.That(exceptionThrown, "An exception should have been thrown for this to actually test whether calls that throw exceptions are received.");
        }

45. Example

Project: nunit
Source File: AssertThatTests.cs
View license
[Test]
        public void PassingAssertion_DoesNotCallExceptionStringFunc()
        {
            // Arrange
            var funcWasCalled = false;
            Func<string> getExceptionMessage = () =>
                {
                    funcWasCalled = true;
                    return "Func was called";
                };

            // Act
            Assert.That(0 + 1 == 1, getExceptionMessage);

            // Assert
            Assert.That(!funcWasCalled, "The getExceptionMessage function was called when it should not have been.");
        }

46. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomDoubleWithMaximum()
        {
            double d = _randomizer.NextDouble(100.0);
            Assert.That(d >= 0.0 && d < 100.0, "Out of range");
        }

47. Example

Project: nunit
Source File: AssumeThatTests.cs
View license
[Test]
        public void PassingAssertion_DoesNotCallExceptionStringFunc()
        {
            // Arrange
            var funcWasCalled = false;
            Func<string> getExceptionMessage = () =>
            {
                funcWasCalled = true;
                return "Func was called";
            };

            // Act
            Assume.That(0 + 1 == 1, getExceptionMessage);

            // Assert
            Assert.That(!funcWasCalled, "The getExceptionMessage function was called when it should not have been.");
        }

48. Example

Project: nunit
Source File: TextUIReportTests.cs
View license
[Test]
        [Ignore("Test needs modification")]
        public void ReportSequenceTest()
        {
            var textRunner = new TextRunner();
            textRunner.ReportResults(_result);

            int last = -1;

            foreach (string title in REPORT_SEQUENCE)
            {
                var index = Report.IndexOf(title);
                Assert.That(index >= 0, "Report not found: " + title);
                Assert.That(index > last, "Report out of sequence: " + title);
            }
        }

49. Example

Project: nunit
Source File: RandomizerTests.cs
View license
[Test]
        public void RandomDoubleInRange()
        {
            double d = _randomizer.NextDouble(0.2, 0.7);
            Assert.That(d >= 0.2 && d < 0.7, "Out of range");
        }

50. Example

Project: sc2replay-csharp
Source File: ReplayTests.cs
View license
[Test, TestCaseSource("TestReplays")]
        public void ReplayParseWithoutEvents(string filename)
        {
            Replay replay = Replay.Parse(filename, true);

            Assert.That(replay != null);
            Assert.That(replay.PlayerEvents == null, "The replay still had parsed events.");
        }