NUnit.Framework.Assert.Throws(NUnit.Framework.TestDelegate)

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

200 Examples 7

1. Example

Project: Projac
Source File: ConnectedProjectionTests.cs
View license
[Test]
            public void WhenHandlerCanNotBeNull()
            {
                Assert.Throws<ArgumentNullException>(
                    () => new RegisterNullHandler());
            }

2. Example

View license
[Test]
        public void WhenHandlerWithSingleCommandCanNotBeNull()
        {
            Assert.Throws<ArgumentNullException>(() => _sut.When((Func<object, SqlNonQueryCommand>)null));
        }

3. Example

Project: Projac
Source File: ResolveTests.cs
View license
[Test]
        public void WhenEqualToHandlerMessageTypeHandlersCanNotBeNull()
        {
            Assert.Throws<ArgumentNullException>(() =>
                Resolve.WhenEqualToHandlerMessageType(null));
        }

4. Example

View license
[Test]
        public void NonQueryStatementFormatIfParameterCountLimitedTo2098WhenConditionIsMet()
        {
            Assert.Throws<ArgumentException>(() => Sql.NonQueryStatementFormatIf(true, "", ParameterCountLimitedExceeded.Instance.All).ToArray());
        }

5. Example

View license
[Test]
        public void WhenHandlerWithCommandEnumerationCanNotBeNull()
        {
            Assert.Throws<ArgumentNullException>(() => _sut.When((Func<object, IEnumerable<SqlNonQueryCommand>>)null));
        }

6. Example

View license
[TestCaseSource("CurrentNotStartedCases")]
        public void EnumeratorCurrentReturnsExpectedResultWhenNotStarted(
            IEnumerator sut)
        {
            Assert.Throws<InvalidOperationException>(
                () => { var _ = sut.Current; });
        }

7. Example

View license
[TestCaseSource("CurrentCompletedCases")]
        public void EnumeratorCurrentReturnsExpectedResultWhenCompleted(
            IEnumerator sut)
        {
            Assert.Throws<InvalidOperationException>(
                () => { var _ = sut.Current; });
        }

8. Example

View license
[Test]
        public void NonQueryProcedureFormatUnlessParameterCountNotLimitedTo2098WhenConditionIsMet()
        {
            Assert.Throws<ArgumentException>(() => TSql.NonQueryProcedureFormatUnless(false, "", ParameterCountLimitedExceeded.Instance.All).ToArray());
        }

9. Example

View license
[Test]
        public void WhenSyncHandlerCanNotBeNull()
        {
            var sut = new AnonymousConnectedProjectionBuilder<object>();
            Assert.Throws<ArgumentNullException>(() => sut.When((Action<object, object>)null));
        }

10. Example

View license
[Test]
        public void NonQueryStatementFormatIfParameterCountLimitedTo2098WhenConditionIsMet()
        {
            Assert.Throws<ArgumentException>(() => TSql.NonQueryStatementFormatIf(true, "", ParameterCountLimitedExceeded.Instance.All).ToArray());
        }

11. Example

Project: Projac
Source File: ConcurrentResolveTests.cs
View license
[Test]
        public void WhenEqualToHandlerMessageTypeHandlersCanNotBeNull()
        {
            Assert.Throws<ArgumentNullException>(() =>
                ConcurrentResolve.WhenEqualToHandlerMessageType(null));
        }

12. Example

View license
[Test]
        public void QueryUnlessParameterCountNotLimitedTo2098WhenConditionIsMet()
        {
            Assert.Throws<ArgumentException>(() => Sql.QueryStatementUnless(false, "", ParameterCountLimitedExceeded.Instance).ToArray());
        }

13. Example

Project: BizUnit
Source File: DeleteTests.cs
View license
[Test]
        public void TestCaseValidationTest()
        {
            var step = new CreateStep();
            var tc = new TestCase();
            tc.ExecutionSteps.Add(step);
            Assert.Throws<ArgumentNullException>(() => { var bu = new TestRunner(tc); });            
        }

14. Example

Project: FluentPath
Source File: PathTests.cs
View license
[Test]
        public void MakeRelativeWithRelativePathThrows() {
            Assert.Throws(
                typeof (InvalidOperationException),
                () => Path.Get("foo").MakeRelative());
        }

15. Example

Project: FluentPath
Source File: PathTests.cs
View license
[Test]
        public void NullPathThrows() {
            Assert.Throws(
                typeof (ArgumentNullException),
                () => new Path((string[])null));
        }

16. Example

Project: FluentPath
Source File: PathTests.cs
View license
[Test]
        public void MakeRelativeWithOtherPathThrows() {
            Assert.Throws(
                typeof (InvalidOperationException),
                () => Path.Get(_sep + "foo")
                          .MakeRelativeTo(_sep + "baz"));
        }

17. Example

Project: FluentPath
Source File: PathTests.cs
View license
[Test]
        public void CantCreatePathFromNoTokens() {
            Assert.Throws<ArgumentException>(() => Path.Get());
        }

18. Example

Project: FluentPath
Source File: PathTests.cs
View license
[Test]
        public void FirstPathFailsOnEmptyCollection() {
            Assert.Throws<InvalidOperationException>(() => new Path().First());
        }

19. Example

View license
[Test]
		[Category("UsesObsoleteExpectedExceptionAttribute")]
		public void AddNewPath_NullPath_Throws()
		{
			Assert.Throws<ArgumentNullException>(() =>_MostRecentPathsList.AddNewPath(null));
		}

20. Example

View license
[Test]
		public void GetXmlDomFromHtml_HasErrors_ReportsError()
		{
			Assert.Throws<ApplicationException>(() => XmlHtmlConverter.GetXmlDomFromHtml("<!DOCTYPE html><html><head>    <blahblah> </head></html>", false));
		}

21. Example

View license
[Test]
		public void Get_Unrecognized_Throws()
		{
			Assert.Throws<System.Net.WebException>(() => ApiTest.GetString(_server, endPoint: "foo[0-9]bar", endOfUrlForTest: "foobar",
				 handler: request => request.PostSucceeded()));
		}

22. Example

View license
[Test]
		public void CreateBookRecord_NotLoggedIn_Throws()
		{
			Assert.Throws<ApplicationException>(() =>_client.CreateBookRecord("{\"bookInstanceId\":\"123\"}"));
		}

23. Example

Project: BloomDesktop
Source File: BloomS3ClientTests.cs
View license
[Test]
		public void DownloadBook_DoesNotExist_Throws()
		{
			Assert.Throws<DirectoryNotFoundException>(() => _client.DownloadBook(BloomS3Client.UnitTestBucketName, "notthere", _workFolder.FolderPath));
		}

24. Example

Project: BloomDesktop
Source File: HtmlHandlerTests.cs
View license
[Test]
		public void Find2WayDifferences_Throws()
		{
			Assert.Throws<NotImplementedException>(() => new BloomHtmlFileTypeHandler().Find2WayDifferences(null, null, null));
		}

25. Example

View license
[Test]
        public void TestNextWithReplacementThrowsWith0Weight()
        {
            Target.Add(1, 0);
            Assert.Throws<InvalidOperationException>(() => Target.NextWithReplacement());
        }

26. Example

View license
[Test]
        public void TestAddThrowsOnNegativeWeight()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => Target.Add(1, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => Target.Add(1, int.MinValue));
        }

27. Example

View license
[Test]
        public void TestBracketShorthandThrowsOnNegativeWeight()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => Target[1] = -1 );
            Assert.Throws<ArgumentOutOfRangeException>(() => Target[2] = Int32.MinValue);
        }

28. Example

View license
[Test]
        public void TestBracketShorthandThrowsOnKeyNotFound()
        {
            Assert.Throws<KeyNotFoundException>(() => { int a = Target[1]; });
        }

29. Example

View license
[Test]
        public void TestGetWeightThrowsOnKeyNotFound()
        {
            Assert.Throws<KeyNotFoundException>(() => Target.GetWeight(1));
        }

30. Example

View license
[Test]
        public void TestNextWithRemovalThrows()
        {
            Assert.Throws<InvalidOperationException>(() => Target.NextWithRemoval());
        }

31. Example

View license
[Test]
        public void TestSetWeightThrowsOnNegativeWeight()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => Target.SetWeight(1, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => Target.SetWeight(1, int.MinValue));
        }

32. Example

View license
[Test]
        public void TestNextWithRemovalThrowsWith0Weight()
        {
            Target.Add(1, 0);
            Assert.Throws<InvalidOperationException>(() => Target.NextWithRemoval());
        }

33. Example

View license
[Test]
        public void TestNextWithReplacementThrows()
        {
            Assert.Throws<InvalidOperationException>(() => Target.NextWithReplacement());
        }

34. Example

View license
[Test]
        public void TestAddThrowsOnDuplicateKey()
        {
            Target.Add(1, 2);
            Assert.Throws<ArgumentException>(() => Target.Add(1, 2));
            Assert.Throws<ArgumentException>(() => Target.Add(1, 1));
            Assert.Throws<ArgumentException>(() => Target.Add(1));
        }

35. Example

View license
[Test]
        public void TestFirstThrowsOnEmptyQueue()
        {
            Assert.Throws<InvalidOperationException>(() => { var a = Queue.First; });
        }

36. Example

View license
[Test]
        public void TestDequeueThrowsOnEmptyQueue2()
        {
            Node node1 = new Node(1);
            Node node2 = new Node(2);

            Enqueue(node1);
            Enqueue(node2);

            Dequeue();
            Dequeue();

            Assert.Throws<InvalidOperationException>(() => Queue.Dequeue());
        }

37. Example

View license
[Test]
        public void TestFirstThrowsOnEmptyQueue2()
        {
            Node node1 = new Node(1);
            Node node2 = new Node(2);

            Enqueue(node1);
            Enqueue(node2);

            Dequeue();
            Dequeue();

            Assert.Throws<InvalidOperationException>(() => { var a = Queue.First; });
        }

38. Example

View license
[Test]
        public void TestUpdatePriorityThrowsOnNodeNotInQueue()
        {
            Node node = new Node(1);

            Assert.Throws<InvalidOperationException>(() => Queue.UpdatePriority(node, 2));
        }

39. Example

View license
[Test]
        public void TestRemoveThrowsOnNodeNotInQueue()
        {
            Node node = new Node(1);

            Assert.Throws<InvalidOperationException>(() => Queue.Remove(node));
        }

40. Example

View license
[Test]
        public void TestDequeueThrowsOnEmptyQueue()
        {
            Assert.Throws<InvalidOperationException>(() => Queue.Dequeue());
        }

41. Example

View license
[Test]
        public void When_CopyToInvalidIndex_Expect_ArgumentOutOfRangeException()
        {
            var input = new[] {"a", "b", "c"};
            var enumerableCollection = new EnumerableCollection<string>(input, input.Length);
            var output = new string[3];
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                enumerableCollection.CopyTo(output, 1);
            });
        }

42. Example

View license
[Test]
        public void When_CopyToTooSmallArray_Expect_ArgumentOutOfRangeException()
        {
            var input = new[] {"a", "b", "c"};
            var enumerableCollection = new EnumerableCollection<string>(input, input.Length);
            var output = new string[2];
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                enumerableCollection.CopyTo(output, 0);
            });
        }

43. Example

Project: Cropper
Source File: ImagePairNamesTests.cs
View license
[Test]
        public void Evaluating_equals_throws_an_exception_if_the_object_is_not_an_ImagePairNames()
        {
            ImagePairNames pair = new ImagePairNames();
            object obj = new object();

            Assert.Throws<InvalidCastException>(() => pair.Equals(obj));
        }

44. Example

Project: Cropper
Source File: ImagePairNamesTests.cs
View license
[Test]
        public void GetHashCode_throws_an_exception_if_FullSize_is_null()
        {
            string thumbnail = "thumbnail";

            ImagePairNames pair = new ImagePairNames(null, thumbnail);

            Assert.Throws<NullReferenceException>(() => pair.GetHashCode());
        }

45. Example

Project: Cropper
Source File: ImagePairNamesTests.cs
View license
[Test]
        public void GetHashCode_throws_an_exception_if_Thumbnail_is_null()
        {
            string fullSize = "fullSize";

            ImagePairNames pair = new ImagePairNames(fullSize, null);

            Assert.Throws<NullReferenceException>(() => pair.GetHashCode());
        }

46. Example

Project: Cropper
Source File: DesignablePluginTests.cs
View license
[Test]
        public void Connect_throws_exception_when_IPersistableOutput_is_null()
        {
            Assert.Throws<ArgumentNullException>(() => new FakeDesignablePlugin().Connect(null));
        }

47. Example

Project: BrightstarDB
Source File: BinaryStoreTests.cs
View license
[Test]
        public override void TestRevertToCommitPoint()
        {
            Assert.Throws<Client.BrightstarClientException>(() => base.TestRevertToCommitPoint());
        }

48. Example

View license
public void TestConstructorThrowsOnNullInput()
        {
            Assert.Throws<ArgumentNullException>(() => new StoreResponseModel(null));
        }

49. Example

Project: BrightstarDB
Source File: SimpleContextTests.cs
View license
[Test]
        [NUnit.Framework.Ignore("Behaviour is changed - an entity can be created, but will not be tracked or saved until its identity is set")]
        public void TestCannotCreateEntityWithKey()
        {
            string storeName = "CannotCreateEntityWithKey_" + DateTime.UtcNow.Ticks;
            using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
            {
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    Assert.Throws<EntityKeyRequiredException>(() =>
                    {
                        // Should throw an exception as the Name property is required to generate the key
                        context.StringKeyEntities.Create();
                        context.SaveChanges();
                    });
                }
            }
        }

50. Example

View license
[Test]
        public void TestHttpWithoutEndpoint()
        {
            Assert.Throws<FormatException>(() =>
            {
                var cs = new ConnectionString("type=http");
            });
        }