NUnit.Framework.AssertionHelper.Expect(NUnit.Framework.TestDelegate, NUnit.Framework.Constraints.IResolveConstraint)

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

176 Examples 7

1. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Array_Numbers_NoInput()
        {
            var printer = new Printer();
            var sample = new Sample_08 { Printer = printer };

            Parser.Run(new[]
            {
                "printnumbers",
                "/prefix:test_",
            }, sample);

            Expect(printer.PrintedTexts, Is.Empty);
        }

2. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Error_Handled_Empty()
        {
            var sample = new Sample_34();

            Expect(sample.Handled, Is.False);

            Expect(() => Parser.Run(new[] {"foo"}, sample), Throws.Exception);

            Expect(sample.Handled, Is.True);
        }

3. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Array_Enum_NoInput()
        {
            var printer = new Printer();
            var sample = new Sample_08 { Printer = printer };

            Parser.Run(new[]
            {
                "printenums",
                "/prefix:test_",
            }, sample);

            Expect(printer.PrintedTexts, Is.Empty);
        }

4. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Array_Strings_NoInput()
        {
            var printer = new Printer();
            var sample = new Sample_08 { Printer = printer };

            Parser.Run(new[]
            {
                "print",
                "/prefix:test_",
            }, sample);

            Expect(printer.PrintedTexts, Is.Empty);
        }

5. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void HandlePreMatureError_DefinedHandler()
        {
            var s = new Sample_64();

            Expect(s.Handled, Is.False);

            Parser.Run(new[] { "." }, s);

            Expect(s.Handled, Is.True);
        }

6. Example

View license
[Test]
        public void get_nullable_datetime()
        {
            var collection = new Dictionary<string, DateTime?> { { "startDate", null } };

            var value = collection.GetValue<DateTime?>("startDate");

            Expect(value, Is.Null);
        }

7. Example

View license
[Test]
        public void get_null_string_from_hashtable_for_missing_value()
        {
            var table = new Hashtable { { "app id", "abc123" } };

            var value = table.GetValueOrDefault<string>("cat id");

            Expect(value, Is.Null);
        }

8. Example

View license
[Test]
        public void get_null_string_with_default()
        {
            var collection = new Dictionary<string, string> { { "app id", null } };

            var value = collection.GetValueOrDefault("app id", "a default value");

            Expect(value, Is.Null);
        }

9. Example

View license
[Test]
        public void get_false_from_hashtable_for_missing_value()
        {
            var table = new Hashtable { { "app id", "abc123" } };

            var value = table.GetValueOrDefault<bool>("Allow Windows Live Writer");

            Expect(value, Is.False);
        }

10. Example

View license
[Test]
        public void does_not_throw_invalidcastexception_when_value_is_null_for_reference_type()
        {
            var dictionary = new Dictionary<string, string> { { "length", null } };

            var value = dictionary.GetValueOrDefault<ApplicationException>("length");

            Expect(value, Is.Null);
        }

11. Example

View license
[Test]
        public void can_get_boolean_from_form()
        {
            var collection = new NameValueCollection { { "radio", "on" } };

            var value = collection.GetValueOrDefault("radio", CollectionExtensions.GetFlexibleBooleanParsingFunction());

            Expect(value, Is.True);
        }

12. Example

View license
[Test]
        public void get_bool_from_hashtable_when_default_is_provided()
        {
            var table = new Hashtable { { "app id", "true" } };

            var value = table.GetValueOrDefault("app id", false);

            Expect(value, Is.True);
        }

13. Example

View license
[Test]
        public void can_get_empty_string_rather_than_default()
        {
            var dictionary = new Hashtable { { "question", string.Empty } };

            var value = dictionary.GetValueOrDefault("question", "yes");

            Expect(value, Is.Empty);
        }

14. Example

View license
[Test]
        public void get_null_string_without_default()
        {
            var collection = new Dictionary<string, string> { { "app id", null } };

            var value = collection.GetValue<string>("app id");

            Expect(value, Is.Null);
        }

15. Example

View license
[Test]
        public void throws_invalidoperationexception_when_lookup_has_multiple_values()
        {
            var collection = new NameValueCollection { { "state", "CA" }, { "state", "BC" } };

            Expect(() => collection.GetValueOrDefault<string>("state"), Throws.InvalidOperationException);
        }

16. Example

View license
[Test]
        public void can_get_bool_from_hashtable()
        {
            var table = new Hashtable { { "app id", "true" } };

            var value = table.GetValueOrDefault<bool>("app id");

            Expect(value, Is.True);
        }

17. Example

View license
[Test]
        public void can_get_null_value_rather_than_default()
        {
            var dictionary = new Hashtable { { "question", null } };

            var value = dictionary.GetValueOrDefault("question", "yes");

            Expect(value, Is.Null);
        }

18. Example

View license
[Test]
        public void can_get_empty_boolean_from_form()
        {
            var collection = new NameValueCollection { { "text", "blah" } };

            var value = collection.GetValueOrDefault("radio", CollectionExtensions.GetFlexibleBooleanParsingFunction());

            Expect(value, Is.False);
        }

19. Example

View license
[Test]
        public void flexible_boolean_parsing_is_case_insensitive()
        {
            var collection = new NameValueCollection { { "question", "YES" } };

            var value = collection.GetValueOrDefault("question", CollectionExtensions.GetFlexibleBooleanParsingFunction("yes"));

            Expect(value, Is.True);
        }

20. Example

View license
[Test]
		public void AddMongoStores_WithCustomTypes_ThisShouldLookReasonableForUsers()
		{
			// this test is just to make sure I consider the interface for using custom types
			// so that it's not a horrible experience even though it should be rarely used
			var services = new ServiceCollection();
			services.AddIdentityWithMongoStoresUsingCustomTypes<CustomUser, CustomRole>(FakeConnectionStringWithDatabase);
			services.AddLogging();

			var provider = services.BuildServiceProvider();
			var resolvedUserStore = provider.GetService<IUserStore<CustomUser>>();
			Expect(resolvedUserStore, Is.Not.Null, "User store did not resolve");

			var resolvedRoleStore = provider.GetService<IRoleStore<CustomRole>>();
			Expect(resolvedRoleStore, Is.Not.Null, "Role store did not resolve");

			var resolvedUserManager = provider.GetService<UserManager<CustomUser>>();
			Expect(resolvedUserManager, Is.Not.Null, "User manager did not resolve");

			var resolvedRoleManager = provider.GetService<RoleManager<CustomRole>>();
			Expect(resolvedRoleManager, Is.Not.Null, "Role manager did not resolve");
		}

21. Example

View license
[Test]
		public void Create_NullLists_DoesNotSerializeNullLists()
		{
			// serialized nulls can cause havoc in deserialization, overwriting the constructor's initial empty list 
			var user = new IdentityUser();
			user.Roles = null;
			user.Tokens = null;
			user.Logins = null;
			user.Claims = null;

			var document = user.ToBsonDocument();

			Expect(document.Contains("Roles"), Is.False);
			Expect(document.Contains("Tokens"), Is.False);
			Expect(document.Contains("Logins"), Is.False);
			Expect(document.Contains("Claims"), Is.False);
		}

22. Example

View license
[Test]
		public void GetToken_NoTokens_ReturnsNull()
		{
			var user = new IdentityUser();

			var value = user.GetTokenValue("loginProvider", "tokenName");

			Expect(value, Is.Null);
		}

23. Example

View license
[Test]
		public void ReplaceClaim_NoExistingClaim_Ignores()
		{
			// note: per EF implemention - only existing claims are updated by looping through them so that impl ignores too
			var user = new IdentityUser();
			var newClaim = new Claim("newType", "newValue");

			user.ReplaceClaim(newClaim, newClaim);

			Expect(user.Claims, Is.Empty);
		}

24. Example

View license
[Test]
		public void AddMongoStores_WithDefaultTypes_ResolvesStoresAndManagers()
		{
			var services = new ServiceCollection();
			services.AddIdentityWithMongoStores(FakeConnectionStringWithDatabase);
			// note: UserManager and RoleManager use logging
			services.AddLogging();

			var provider = services.BuildServiceProvider();
			var resolvedUserStore = provider.GetService<IUserStore<IdentityUser>>();
			Expect(resolvedUserStore, Is.Not.Null, "User store did not resolve");

			var resolvedRoleStore = provider.GetService<IRoleStore<IdentityRole>>();
			Expect(resolvedRoleStore, Is.Not.Null, "Role store did not resolve");

			var resolvedUserManager = provider.GetService<UserManager<IdentityUser>>();
			Expect(resolvedUserManager, Is.Not.Null, "User manager did not resolve");

			var resolvedRoleManager = provider.GetService<RoleManager<IdentityRole>>();
			Expect(resolvedRoleManager, Is.Not.Null, "Role manager did not resolve");
		}

25. Example

View license
[Test]
		public void Create_NoPassword_DoesNotSerializePasswordField()
		{
			// if a particular consuming application doesn't intend to use passwords, there's no reason to store a null entry except for padding concerns, if that is the case then the consumer may want to create a custom class map to serialize as desired.

			var user = new IdentityUser();

			var document = user.ToBsonDocument();

			Expect(document.Contains("PasswordHash"), Is.False);
		}

26. Example

View license
[Test]
		public void Create_NewIdentityUser_ListsNotNull()
		{
			var user = new IdentityUser();

			Expect(user.Logins, Is.Empty);
			Expect(user.Tokens, Is.Empty);
			Expect(user.Roles, Is.Empty);
			Expect(user.Claims, Is.Empty);
		}

27. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Parameter_WithDefault_BadDefaultProvider()
        {
            var t = new ParameterWithDefaults_3();

            Expect(() => Parser.Run(new[] { "foo" }, t), Throws.InstanceOf<InvalidParameterDefaultProviderException>());
        }

28. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void NonArrayWithInvalidSeparator_Exception()
        {
            Expect(() => Parser.Run<Sample_70>(new[] {"foo", "-enums=aaa bbb ccc"}),
                   Throws.InstanceOf<InvalidSeparatorException>());

            Expect(() => Parser.Run<Sample_71>(new[] { "foo", "-enums=aaa bbb ccc" }),
                   Throws.InstanceOf<InvalidSeparatorException>());

            Expect(() => Parser.Run<Sample_72>(new[] { "foo", "-enums=aaa bbb ccc" }),
                   Throws.InstanceOf<InvalidSeparatorException>());

            Expect(() => Parser.Run<Sample_73>(new[] { "foo", "-enums=aaa bbb ccc" }),
                   Throws.InstanceOf<InvalidSeparatorException>());
        }

29. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void EmptyDefined_WithParameters_Exception()
        {
            Expect(() => new Parser<Sample_20>(),
                   Throws.InstanceOf<ArgumentMismatchException>());
        }

30. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void DefaultVerb_MoreThanOnce_Exception()
        {
            Expect(() => new Parser<Sample_38>(), Throws.InstanceOf<MoreThanOneDefaultVerbException>());
        }

31. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void NonArrayWithSeparator_Exception()
        {
            Expect(() => Parser.Run<Sample_68>(new[] {"foo", "-x=aaa"}),
                   Throws.InstanceOf<NonArrayParameterWithSeparatorException>());
        }

32. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void ValidateExpression_TwoInts_TwoValidators_Fail()
        {
            Expect(() => Parser.Run<Sample_40>(new[]
                                                   {
                                                       "foo2",
                                                       "-p1:8",
                                                       "-p2:3",
                                                   }),
                   Throws.InstanceOf<ValidationException>());
        }

33. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Validation_MoreThan()
        {
            var sample = new ValidationSample_01();
            Parser.Run(new[]
            {
                "morethan5",
                "/n=10",
            }, sample);

            Expect(() => Parser.Run(new[]
                                  {
                                      "morethan5",
                                      "/n=1",
                                  }, sample),
                   Throws.InstanceOf<ValidationException>());
        }

34. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void PreVerbExecution_MismatchArgs_Exception_2()
        {
            Expect(() => Parser.Run<Sample_58>(new[] { "" }), Throws.InstanceOf<ArgumentMismatchException>());
            Expect(() => Parser.Run<Sample_59>(new[] { "" }), Throws.InstanceOf<ArgumentMismatchException>());
        }

35. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Parameters_WithAutoPrefixes()
        {
            var s = new Sample_62();
            Parser.Run(new[]
            {
                "foo","-c=5","-n=bar"
            }, s);

            Expect(s.Count, Is.EqualTo(5));
            Expect(s.Name, Is.EqualTo("bar"));
        }

36. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void ValidateExpression_String_Like_Fail()
        {
            Expect(() => Parser.Run<Sample_40>(new[]
                                                   {
                                                       "foo4",
                                                       "-str:blah",
                                                   }),
                   Throws.InstanceOf<ValidationException>());
        }

37. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void DeserializeComplexTypeWithCollection_Xml_ValidationError()
        {
            var s = new Sample_66();

            var xml = "<Person><Age>34</Age><Name>Adrian</Name><Email>[email protected]</Email><PhoneNumbers><PhoneNumber><Type>Home</Type><Number>001-2232322</Number></PhoneNumber><PhoneNumber><Type>Mobile</Type><Number>002-7787787</Number></PhoneNumber><PhoneNumber><Type>Office</Type><Number>003-4463565</Number></PhoneNumber></PhoneNumbers></Person>";

            Expect(() => Parser.Run(new[] { "foo", "-p=" + xml }, s),
                   Throws.InstanceOf<ValidationException>());
        }

38. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Validation_MoreOrEqualTo()
        {
            var sample = new ValidationSample_01();

            Parser.Run(new[]
            {
                "moreorequalto10",
                "/n=10",
            }, sample);

            Parser.Run(new[]
            {
                "moreorequalto10",
                "/n=11",
            }, sample);

            Expect(() => Parser.Run(new[]
                                        {
                                            "moreorequalto10",
                                            "/n=9",
                                        }, sample),
                   Throws.InstanceOf<ValidationException>());
        }

39. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void DeserializeComplexTypeWithCollection_Json_ValidationError()
        {
            var s = new Sample_66();

            var json = "{Age: 34,Name: 'Adrian',Email: '[email protected]',PhoneNumbers:[{Type:'Home',Number:'001-2232322'},{Type:'Mobile',Number:'002-7787787'},{Type: 'Office',Number: '003-4463565'}]}";

            Expect(() => Parser.Run(new[] {"foo", "-p=" + json}, s),
                   Throws.InstanceOf<ValidationException>());
        }

40. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void ValidateExpression_TwoInts_Fail()
        {
            Expect(() => Parser.Run<Sample_40>(new[]
                                                   {
                                                       "foo1",
                                                       "-p1:1",
                                                       "-p2:3",
                                                   }),
                   Throws.InstanceOf<ValidationException>());
        }

41. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Validation_PathExists()
        {
            var sample = new Validation/n ..... /n //View Source file for more details /n }

42. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Execute_Verb()
        {
            var printer = new Printer();
            var sample = new Sample_02 { Printer = printer };

            Parser.Run(new[]
            {
                "print",
                "/c=5",
                "/msg=test",
                "/prefix=hello_",
            }, sample);

            Expect(printer.PrintedTexts, Count.EqualTo(5));
            Expect(printer.PrintedTexts, All.EqualTo("hello_test"));
        }

43. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Validation_DirectoryExists()
        {
            var sample = new Valid/n ..... /n //View Source file for more details /n }

44. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Error_DefinedWithInt_Exception()
        {
            Expect(() => Parser.Run<Sample_35>(null),
                   Throws.InstanceOf<ArgumentMismatchException>());
        }

45. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void EmptyHelp_Defined_TwoParameters_Exception()
        {
            Expect(() => new Parser<Sample_19>(),
                   Throws.InstanceOf<InvalidHelpHandlerException>());
        }

46. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void EmptyHelp_Defined_IntParameter_Exception()
        {
            Expect(() => new Parser<Sample_18>(),
                   Throws.InstanceOf<InvalidHelpHandlerException>());
        }

47. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Execute_DefaultVerb()
        {
            var printer = new Printer();
            var sample = new Sample_02 { Printer = printer };

            Parser.Run(new[]
            {
                "/c=5",
                "/msg=test",
                "/prefix=hello_",
            }, sample);

            Expect(printer.PrintedTexts, Count.EqualTo(5));
            Expect(printer.PrintedTexts, All.EqualTo("hello_test"));
        }

48. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Error_MoreThanOne_Exception()
        {
            Expect(() => new Parser<Sample_32>(),
                   Throws.InstanceOf<MoreThanOneErrorHandlerException>());
        }

49. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Error_DefinedWithMoreThanOneParameter_Exception()
        {
            Expect(() => Parser.Run<Sample_37>(null),
                   Throws.InstanceOf<ArgumentMismatchException>());
        }

50. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Validation_LessOrEqualTo()
        {
            var sample = new ValidationSample_01();

            Parser.Run(new[]
            {
                "lessorequalto30",
                "/n=10",
            }, sample);

            Parser.Run(new[]
            {
                "lessorequalto30",
                "/n=30",
            }, sample);

            Expect(() => Parser.Run(new[]
                                        {
                                            "lessorequalto30",
                                            "/n=40",
                                        }, sample),
                   Throws.InstanceOf<ValidationException>());
        }