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

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

142 Examples 7

1. Example

View license
[TestCase(null)]
        [TestCase("")]
        [TestCase("  ")]
        public void Test_Empty_Key_Throws_KeyException(string key)
        {
            Assert.Throws<MissingKeyException>(() => new FakeSubDocumentOperation<dynamic>(null, key, null, null, 0), "Key cannot be empty.");
        }

2. Example

View license
[TestCase(null)]
        [TestCase("")]
        [TestCase("  ")]
        public void Test_Empty_Key_Throws_KeyException(string key)
        {
            Assert.Throws<MissingKeyException>(() => new FakeMultiLookupOperation<dynamic>(key, null, null, null, 0), "Key cannot be empty.");
        }

3. Example

View license
[TestCase(null)]
        [TestCase("")]
        [TestCase("  ")]
        public void Test_Empty_Key_Throws_KeyException(string key)

        {
            Assert.Throws<MissingKeyException>(() => new FakeMultiMutationOperation<dynamic>(key, null, null, null, 0), "Key cannot be empty.");
        }

4. Example

View license
[Test]
		public void UnderlyingSetter ()
		{
			var i = new XamlMemberInvoker (new MyXamlMember (str_len, sctx));
			// call XamlMember's UnderlyingSetter.
			Assert.Throws<MyException> (() => { var t = i.UnderlyingSetter; }, "#1");
		}

5. Example

View license
[Test]
		public void UnderlyingGetter ()
		{
			var i = new XamlMemberInvoker (new MyXamlMember (str_len, sctx));
			// call XamlMember's UnderlyingGetter.
			Assert.Throws<MyException> (() => { var t = i.UnderlyingGetter; }, "#1");
		}

6. Example

View license
[Test]
		public void SetHandleTypeConverterInvalid ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (TestClassTypeConverter1), sctx));
			Assert.Throws<ArgumentException> (() => { var t = i.SetTypeConverterHandler; }, "#1");
		}

7. Example

View license
[Test]
		public void InconsistentConverterType ()
		{
			var c = new XamlValueConverter<TypeConverter> (typeof (int), XamlLanguage.String, null);
			Assert.Throws<XamlSchemaException> (() => { var t = c.ConverterInstance; }, "#1");
		}

8. Example

View license
[Test]
		public void SetHandleMarkupExtensionInvalid ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (TestClassMarkupExtension1), sctx));
			Assert.Throws<ArgumentException> (() => { var t = i.SetMarkupExtensionHandler; }, "#1");
		}

9. Example

View license
[Test]
		public void SetHandleTypeConverterInvalid3 ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (TestClassTypeConverter3), sctx));
			Assert.Throws<ArgumentException> (() => { var t = i.SetTypeConverterHandler; }, "#1");
		}

10. Example

View license
[Test]
		public void SetHandleTypeConverterInvalid2 ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (TestClassTypeConverter2), sctx));
			Assert.Throws<ArgumentException> (() => { var t = i.SetTypeConverterHandler; }, "#1");
		}

11. Example

View license
[Test]
		public void SetHandleMarkupExtensionInvalid3 ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (TestClassMarkupExtension3), sctx));
			Assert.Throws<ArgumentException> (() => { var t = i.SetMarkupExtensionHandler; }, "#1");
		}

12. Example

View license
[Test]
		public void SetHandleMarkupExtensionInvalid2 ()
		{
			var i = new XamlTypeInvoker (new XamlType (typeof (TestClassMarkupExtension2), sctx));
			Assert.Throws<ArgumentException> (() => { var t = i.SetMarkupExtensionHandler; }, "#1");
		}

13. Example

Project: DotSpatial
Source File: ExtentTests.cs
View license
[Test(Description = "This checks whether setting a null value as Center throws an ArgumentNullException.")]
        public void ExtentSetCenterNullCoordinateTest()
        {
            Extent e = new Extent();

            Assert.Throws<ArgumentNullException>(delegate { e.SetCenter(null); }, "ExtentSetCenter throws on null Coordinate");
            Assert.Throws<ArgumentNullException>(delegate { e.SetCenter(null, 3, 4); }, "ExtentSetCenter with height and width throws on null Coordinate");
        }

14. Example

Project: NsqSharp
Source File: ConfigTest.cs
View license
[Test]
        public void TestConfigSet()
        {
            var c = new Config();

            Assert.Throws<Exception>(() => c.Set("not a real config value", new object()),
                "No error when setting an invalid value");
        }

15. Example

Project: msbuildtasks
Source File: ScriptTest.cs
View license
[Test]
        public void ThrowActualExceptionInsteadOfTargetInvocationException()
        {
            Script task = new Script();
            task.BuildEngine = new MockBuild();
            task.Code = @"public static void ScriptMain(){
throw new InvalidOperationException(""This is the actual exception."");
}";
            Assert.Throws<InvalidOperationException>(() =>task.Execute(), "Task should have succeeded.");
        }

16. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void FieldOptionalPlusFieldOrderWrong1()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOptionalPlusFieldOrderTypeWrong1>(),
                    ""
                );
        }

17. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void PartialFieldOrderAppliedMiddle()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOrderPartialAppliedMiddle>(),
                    "The field: Field3 must be marked with FielOrder because if you use this attribute in one field you must also use it in all."
                );
        }

18. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void PartialFieldOrderAppliedFirst()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOrderPartialAppliedFirst>(),
                    "The field: Field1 must be marked with FielOrder because if you use this attribute in one field you must also use it in all."
                );
        }

19. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void FieldOptionalPlusFieldOrderWrong2()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOptionalPlusFieldOrderTypeWrong2>(),
                    ""
                );
        }

20. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void PartialFieldOrderAppliedLast()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOrderPartialAppliedLast>(),
                    "The field: Field5 must be marked with FielOrder because if you use this attribute in one field you must also use it in all."
                );
        }

21. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void FieldOrderWithSameNumber2()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOrderSameNumber2>(),
                    "The field: Field2 has the same FieldOrder that: Field1 you must use different values"
                );
        }

22. Example

Project: FileHelpers
Source File: FieldOrderTests.cs
View license
[Test]
        public void FieldOrderWithSameNumber1()
        {
            Assert.Throws<BadUsageException>
                (
                    () => new FileHelperEngine<FieldOrderSameNumber1>(),
                    "The field: Field5 has the same FieldOrder that: Field3 you must use different values"
                );
        }

23. Example

Project: FileHelpers
Source File: Optional.cs
View license
[Test]
        public void OptionalWithAutoProps()
        {
            Assert.Throws<BadUsageException>(() =>
                new FileHelperEngine<OptionalWithAutoPropsType>(),
                "You must only use all standard fields or all automatic properties, but you can't mix them like in the OptionalWithAutoPropsType class.");
        }

24. Example

Project: nant
Source File: PropertyDictionaryTest.cs
View license
[Test]
        public void Test_NullPropertyTest()
        {
            const string xml = "<project><property name='temp.var' value='some.value'/></project>";
            Project p = CreateFilebasedProject(xml);
            PropertyDictionary d = new PropertyDictionary(p);
            TestDelegate assn = delegate() { d["temp.var"] = null; };

            Assert.Throws<BuildException>(assn,
                "Null values should not be allowed in PropertyDictionary");
        }

25. Example

Project: Regalo
Source File: AggregateTests.cs
View license
[Test]
        public void InvokingBehaviour_GivenAggregateWithInvariantLogic_ShouldFailIfInvariantIsNotSatisfied()
        {
            // Arrange
            var user = new User();
            user.Register();
            user.ChangePassword("newpassword");

            // Act / Assert
            Assert.Throws<InvalidOperationException>(() => user.ChangePassword("newpassword"), "Expected exception stating the new password must be different the the previous one.");
        }

26. Example

Project: Regalo
Source File: AggregateTests.cs
View license
[Test]
        public void ApplyingPreviouslyGeneratedEvents_GivenNewAggregateObject_ShouldBringAggregateBackToPreviousState()
        {
            // Arrange
            var user = new User();
            user.Register();
            var events = new object[] {new UserRegistered(user.Id), new UserChangedPassword("newpassword"), new UserChangedPassword("newerpassword") };

            // Act
            user.ApplyAll(events);

            // Assert
            Assert.Throws<InvalidOperationException>(() => user.ChangePassword("newerpassword"), "Expected exception stating the new password must be different the the previous one, indicating that previous events have replayed successfully.");
        }

27. Example

Project: nunit
Source File: PlatformDetectionTests.cs
View license
[Test]
        public void PlatformAttribute_InvalidPlatform()
        {
            PlatformAttribute attr = new PlatformAttribute( "Net-1.0,Net11,Mono" );
            Assert.Throws<InvalidPlatformException>(
                () => winXPHelper.IsPlatformSupported(attr), 
                "Invalid platform name Net11");
        }

28. Example

View license
[Test]
		public void DisassociatePublication_BadArgsTests()
		{
			Assert.Throws<ArgumentNullException>(() => _controller.DisassociatePublication(null, null), "No configuration to disassociate. No publication to disassociate from.");
			Assert.Throws<ArgumentNullException>(() => _controller.DisassociatePublication("publicationA", null), "No configuration");
			Assert.Throws<ArgumentNullException>(() => _controller.DisassociatePublication(null, _configurations[0]), "No publication");

			Assert.Throws<ArgumentOutOfRangeException>(() => _controller.DisassociatePublication("unknown publication", _configurations[0]), "Don't try to operate using an invalid/unknown publication");
		}

29. Example

View license
[Test]
		public void AssociatePublication_BadArgsTests()
		{
			Assert.Throws<ArgumentNullException>(() => _controller.AssociatePublication(null, null), "No configuration to associate with");
			Assert.Throws<ArgumentNullException>(() => _controller.AssociatePublication("publicationA", null), "No configuration to associate with");
			Assert.Throws<ArgumentNullException>(() => _controller.AssociatePublication(null, _configurations[0]), "Don't allow trying to add null");

			Assert.Throws<ArgumentOutOfRangeException>(() => _controller.AssociatePublication("unknown publication", _configurations[0]), "Don't associate with an invalid/unknown publication");
		}

30. Example

View license
[Test]
		public void DeleteConfigurationCrashesOnNullArgument()
		{
			Assert.Throws<ArgumentNullException>(() => _controller.DeleteConfiguration(null), "Failed to throw");
		}

31. Example

Project: spring-net
Source File: MethodInvokerTests.cs
View license
[Test]
		public void InvokeWithArgumentOfWrongType()
		{
			Foo foo = new Foo();
			foo.Age = 88;
			MethodInvoker vkr = new MethodInvoker();
			vkr.TargetObject = foo;
			vkr.TargetMethod = "growolder";
			vkr.AddNamedArgument("years", "Bingo");
			vkr.Prepare();
            Assert.Throws<MethodInvocationException>(() => vkr.Invoke(), "At least one of the arguments passed to this MethodInvoker was incompatible with the signature of the invoked method.");
		}

32. Example

View license
[Test]
        public void ConvertFromBadKeyString()
        {
            RegistryKeyConverter rkc = new RegistryKeyConverter();
            Assert.Throws<ArgumentException>(() => rkc.ConvertFrom(@"HKEY_CURRENT_USER\sdgsdfgsdfgxadas\Xyz\Abc"), @"Registry key [HKEY_CURRENT_USER\sdgsdfgsdfgxadas] does not exist.");
        }

33. Example

View license
[Test]
        public void DefinitionInvalidPropagationState()
        {
            MockTxnDefinition def = new MockTxnDefinition();
            def.PropagationBehavior = TransactionPropagation.Mandatory;
            Assert.Throws<IllegalTransactionStateException>(() => _mockTxnMgr.GetTransaction(def), "Transaction propagation 'mandatory' but no existing transaction found");
        }

34. Example

View license
[Test]
        public void ConvertFromBadHiveString()
        {
            RegistryKeyConverter rkc = new RegistryKeyConverter();
            Assert.Throws<ArgumentException>(() => rkc.ConvertFrom(@"HKEY_ERROR\sdgsdfgsdfgxadas"), "Invalid root hive name [HKEY_ERROR].");
        }

35. Example

Project: spring-net
Source File: MethodInvokerTests.cs
View license
[Test]
		public void PrepareWithOnlyTargetMethodSet()
		{
			MethodInvoker vkr = new MethodInvoker();
			vkr.TargetMethod = "Foo";
            Assert.Throws<ArgumentException>(() => vkr.Prepare(), "One of either the 'TargetType' or 'TargetObject' properties is required.");
		}

36. Example

View license
[Test]
        public void BailsWhenNotConfigured()
        {
            RemoteObjectFactory factory = new RemoteObjectFactory();
            Assert.Throws<ArgumentException>(() => factory.AfterPropertiesSet(), "The Target property is required.");
        }

37. Example

View license
[Test]
        public void MergeNotAllowedWhenMergeNotEnabled()
        {
            ManagedNameValueCollection child = new ManagedNameValueCollection();
            Assert.Throws<InvalidOperationException>(() => child.Merge(null), "Not allowed to merge when the 'MergeEnabled' property is set to 'false'");
        }

38. Example

View license
[Test]
		public void WithUnresolvableEnvironmentProperty()
		{
			StaticApplicationContext ac = new StaticApplicationContext();
			MutablePropertyValues pvs = new MutablePropertyValues();
			pvs.Add("touchy", "${PROCESSOR_ARCHITECTURE}");
			ac.RegisterSingleton("to", typeof (TestObject), pvs);

			pvs = new MutablePropertyValues();
			pvs.Add("environmentVariableMode", EnvironmentVariableMode.Never);
			ac.RegisterSingleton("configurer", typeof (PropertyPlaceholderConfigurer), pvs);
            Assert.Throws<ObjectDefinitionStoreException>(() => ac.Refresh(), "Error registering object with name 'to' defined in '' : Could not resolve placeholder 'PROCESSOR_ARCHITECTURE'.");
		}

39. Example

View license
[Test]
		public void SetTargetListTypeToDerivedIListInterfaceType()
		{
			ListFactoryObject lfo = new ListFactoryObject();
            Assert.Throws<ArgumentException>(() => lfo.TargetListType = typeof (IExtendedList), "The Type passed to the TargetListType property cannot be an interface; it must be a concrete class that implements the 'System.Collections.IList' interface.");
		}

40. Example

Project: spring-net
Source File: SetFactoryObjectTests.cs
View license
[Test]
		public void SetTargetSetTypeToDerivedISetInterfaceType()
		{
			SetFactoryObject lfo = new SetFactoryObject();
            Assert.Throws<ArgumentException>(() => lfo.TargetSetType = typeof (IExtendedSet), "The Type passed to the TargetSetType property cannot be an interface; it must be a concrete class that implements the 'Spring.Collections.ISet' interface.");
		}

41. Example

Project: spring-net
Source File: SetFactoryObjectTests.cs
View license
[Test]
		public void SetTargetSetTypeToNonSetType()
		{
			SetFactoryObject lfo = new SetFactoryObject();
            Assert.Throws<ArgumentException>(() => lfo.TargetSetType = typeof (ICollection), "The Type passed to the TargetSetType property must implement the 'Spring.Collections.ISet' interface.");
		}

42. Example

Project: spring-net
Source File: ManagedSetTests.cs
View license
[Test]
        public void MergeNotAllowedWhenMergeNotEnabled()
        {
            ManagedSet child = new ManagedSet();
            Assert.Throws<InvalidOperationException>(() => child.Merge(null), "Not allowed to merge when the 'MergeEnabled' property is set to 'false'");
        }

43. Example

View license
[Test]
        public void IntroductionMustImplementIntroducedInterfaces()
        {
            DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new TestIntroductionAdvice(), typeof(ICloneable));
            Assert.Throws<ArgumentException>(() => advisor.ValidateInterfaces(), "Introduction [Spring.Aop.Support.DefaultIntroductionAdvisorTests+TestIntroductionAdvice] does not implement interface 'System.ICloneable' specified in introduction advice.");
        }

44. Example

View license
[Test]
		public void BailsIfTheTargetMethodPropertyAintSet()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
            Assert.Throws<ArgumentException>(() => mcfo.AfterPropertiesSet(), "The 'TargetMethod' property is required.");
		}

45. Example

View license
[Test]
        public void NullConfig()
        {
            wse.ObjectName = "NullConfig";
            Assert.Throws<ArgumentException>(() => wse.AfterPropertiesSet(), "The TargetName property is required.");
        }

46. Example

Project: spring-net
Source File: SetFactoryObjectTests.cs
View license
[Test]
		public void SetTargetSetTypeToAbstractISetInterfaceType()
		{
			SetFactoryObject lfo = new SetFactoryObject();
            Assert.Throws<ArgumentException>(() => lfo.TargetSetType = typeof (AbstractSet), "The Type passed to the TargetSetType property cannot be abstract (MustInherit in VisualBasic.NET); it must be a concrete class that implements the 'Spring.Collections.ISet' interface.");
		}

47. Example

View license
[Test]
		public void BailsWhenNotConfigured()
		{
			PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();
            Assert.Throws<ArgumentException>(() => fac.AfterPropertiesSet(), "One of the TargetType or TargetObject properties must be set.");
		}

48. Example

View license
[Test, Ignore("obsolete test, defaultMessageQueueName is used to obtain a queue from MessageQueueFactory")]
        public void MessageQueueNameNotInContext()
        {
            MessageQueueTemplate q = new MessageQueueTemplate("noqueuename");
            q.ApplicationContext = applicationContext;
            Assert.Throws<ArgumentException>(() => q.AfterPropertiesSet(), "No object named noqueuename is defined in the Spring container");
        }

49. Example

View license
[Test]
		public void SetTargetDictionaryTypeToDerivedIDictionaryInterfaceType()
		{
			DictionaryFactoryObject dfo = new DictionaryFactoryObject();
            Assert.Throws<ArgumentException>(() => dfo.TargetDictionaryType = typeof (IExtendedDictionary), "The Type passed to the TargetDictionaryType property cannot be an interface; it must be a concrete class that implements the 'System.Collections.IDictionary' interface.");
		}

50. Example

View license
[Test]
		public void WithMissingObjectName()
		{
			ObjectFactoryCreatingFactoryObject factory
				= new ObjectFactoryCreatingFactoryObject();
            Assert.Throws<ArgumentException>(() => factory.AfterPropertiesSet(), "The 'TargetObjectName' property must have a value.");
		}