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

101. 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");
		}

102. 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");
		}

103. Example

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

104. 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");
		}

105. Example

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

106. Example

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

107. Example

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

108. Example

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

109. Example

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

110. 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");
        }

111. 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");
        }

112. 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.");
        }

113. Example

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

114. 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."
                );
        }

115. 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."
                );
        }

116. Example

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

117. 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."
                );
        }

118. 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"
                );
        }

119. 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"
                );
        }

120. 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.");
        }

121. 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");
        }

122. 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.");
        }

123. 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.");
        }

124. 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");
        }

125. 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");
		}

126. 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");
		}

127. Example

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

128. 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.");
		}

129. 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.");
        }

130. 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");
        }

131. 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].");
        }

132. 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.");
		}

133. Example

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

134. 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'");
        }

135. 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'.");
		}

136. 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.");
		}

137. 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.");
		}

138. 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.");
		}

139. 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'");
        }

140. 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.");
        }

141. Example

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

142. Example

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

143. 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.");
		}

144. 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.");
		}

145. 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");
        }

146. 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.");
		}

147. Example

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

148. Example

Project: spring-net
Source File: ServiceExporterTests.cs
View license
[Test(Description = "http://jira.springframework.org/browse/SPRNET-1179")]
        public void ProxiesOnlyContractInterfaceFailsIfNoContractInterface()
        {
            se.ObjectName = "ProxiesOnlyContractInterface";
            se.TargetName = "serviceWithMultipleInterfaces";
            // se.ContractInterface = typeof (IContract);
            Assert.Throws<ArgumentException>(() => se.AfterPropertiesSet(), "ServiceExporter cannot export service type 'Spring.ServiceModel.ServiceExporterTests+ServiceWithMultipleInterfaces' as a WCF service because it implements multiple interfaces. Specify the contract interface to expose via the ContractInterface property.");
        }

149. Example

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

150. Example

View license
[Test]
		public void GetSupertypesTooManyArgs()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "Supertypes2";
			mcfo.Arguments = new Object[] {new ArrayList(), new ArrayList(), "hello", "bogus"};
            Assert.Throws<ArgumentException>(() => mcfo.AfterPropertiesSet(), "Unable to determine which exact method to call; found '2' matches.");
		}