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

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

24 Examples 7

1. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Empty_Defined_NotStatic_TargetNull_Exception()
        {
            var p = new Parser<Sample_15>();

            Expect(() => p.RunStatic(new string[] {}),
                   Throws.InstanceOf<ParserExecutionTargetException>());
        }

2. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void RegisterHelpHandler_MoreThanOnce_SameKey_Exception()
        {
            var p = new Parser<Sample_25>();

            p.Register.HelpHandler("a", delegate { });
            p.Register.HelpHandler("b", delegate { });
            Expect(() => p.Register.HelpHandler("a", delegate { }), Throws.InstanceOf<InvalidOperationException>());
        }

3. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Run_Verb_NoMatchingMethod_Exception()
        {
            var p = new Parser<Sample_25>();

            Expect(() => p.RunStatic(new[] { "boo!" }), Throws.InstanceOf<VerbNotFoundException>());
        }

4. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Help_MoreThanOneParameter_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_24 { Printer = mock.Object };

            var p = new Parser<Sample_24>();

            Expect(() => p.Run(new[] {"-?"}, sample),
                   Throws.InstanceOf<InvalidHelpHandlerException>());
        }

5. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void RegisterHelpHandler_MoreThanOnce_Exception()
        {
            var p = new Parser<Sample_25>();

            p.Register.EmptyHandler(delegate { });
            Expect(() => p.Register.EmptyHandler(delegate { }), Throws.InstanceOf<MoreThanOneEmptyHandlerException>());
        }

6. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void RegisterEmptyHelpHandler_MoreThanOnce_Exception()
        {
            var p = new Parser<Sample_25>();

            p.Register.EmptyHelpHandler(delegate { });
            Expect(() => p.Register.EmptyHelpHandler(delegate { }), Throws.InstanceOf<MoreThanOneEmptyHandlerException>());
        }

7. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void RegisterError_MoreThanOne_Exception()
        {
            var p = new Parser<Sample_02>();

            p.Register.ErrorHandler(delegate { });
            Expect(() => p.Register.ErrorHandler(delegate { }),
                   Throws.InstanceOf<MoreThanOneErrorHandlerException>());
        }

8. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Empty_Defined_Static_TargetNotNull_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_14 { Printer = mock.Object };

            var p = new Parser<Sample_14>();

            Expect(() => p.Run(new string[] {}, sample),
                   Throws.InstanceOf<ParserExecutionTargetException>());
        }

9. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Run_NoVerb_NoDefaultVerb_Exception()
        {
            var p = new Parser<Sample_25>();

            Expect(() => p.RunStatic(new[] { "-x" }), Throws.InstanceOf<MissingDefaultVerbException>());
        }

10. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Help_IntParameter_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_25 { Printer = mock.Object };

            var p = new Parser<Sample_25>();

            Expect(() => p.Run(new[] { "-?" }, sample),
                   Throws.InstanceOf<InvalidHelpHandlerException>());
        }

11. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Global_Defined_BadConvertion()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_10 { Printer = mock.Object };

            var p = new Parser<Sample_10>();

            Expect(() => p.Run("print -abra1:cadabra".Split(' '), sample),
                   Throws.InstanceOf<TypeConvertionException>());
        }

12. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Register_EmptyHandler_Null_Exception()
        {
            var p = new Parser<Sample_02>();

            Expect(() => p.Register.EmptyHandler(null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.EmptyHelpHandler(null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.ErrorHandler(null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.HelpHandler("help", null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.ParameterHandler("p", null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.ParameterHandler<int>("p", null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.ParameterHandler("p", null, "description"), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.ParameterHandler<string>("p", null, new ParameterOptions { Description = "description" }), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.PreVerbInterceptor(null), Throws.InstanceOf<ArgumentNullException>());
            Expect(() => p.Register.PostVerbInterceptor(null), Throws.InstanceOf<ArgumentNullException>());
        }

13. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Execute_HandleError_Registered_Rethrow()
        {
            var p = new Parser<Sample_39>();
            var handled = false;

            p.Register.ErrorHandler(ex =>
            {
                handled = true;

                ex.ReThrow = true;
            });

            Expect(() => p.RunStatic(new string[] {}),
                   Throws.InstanceOf<Exception>());
            Expect(handled, Is.True);
        }

14. Example

View license
[Test]
        public void BaselineThrowsIfMigrationsHaveAlreadyBeenApplied()
        {
            this.LoadMigrator(1);

            Expect(() => this.migrator.Baseline(1), Throws.InstanceOf<InvalidOperationException>());
        }

15. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Global_Defined_MoreThanOneParameter_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_12 { Printer = mock.Object };

            var p = new Parser<Sample_12>();

            Expect(() => p.Run("print -foo".Split(' '), sample),
                   Throws.InstanceOf<NotSupportedException>());
        }

16. Example

View license
[Test]
        public void LoadThrowsIfMigrationProviderDoesNotFindAnyMigrations()
        {
            this.migrationProvider.Setup(x => x.LoadMigrations()).Returns<List<MigrationData>>(null);
            Expect(() => this.migrator.Load(), Throws.InstanceOf<MigrationException>());

            this.migrationProvider.Setup(x => x.LoadMigrations()).Returns(new List<MigrationData>());
            Expect(() => this.migrator.Load(), Throws.InstanceOf<MigrationException>());
        }

17. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Unhandled_Exception_Some()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_02 { Printer = mock.Object };

            var p = new Parser<Sample_02>();

            Expect(() => p.Run(new[]
                {
                    "-count:1",
                    "-who:me",
                    "-foo:bar",
                    "-message:a",
                    "-prefix:p",
                    "-upper",
                    "-what:x"
                }, sample),
                   Throws.InstanceOf<UnhandledParametersException>()
                       .With.Property("UnhandledParameters").EqualTo(new Dictionary<string, string>
                                                                         {
                                                                             { "who", "me" },
                                                                             { "foo", "bar" },
                                                                             { "what", "x" },
                                                                         }));
        }

18. Example

View license
[Test]
        public void BaselineThrowsIfRequestedVersionDoesNotExist()
        {
            this.databaseProvider.Object.CurrentVersion = 0;
            this.migrator.Load();

            Expect(() => this.migrator.Baseline(3), Throws.InstanceOf<MigrationNotFoundException>().With.Property("Version").EqualTo(3));
        }

19. Example

View license
[Test]
        public void LoadThrowsIfTwoMigrationsHaveTheSameVersion()
        {
            var migrations = new List<MigrationData>()
            {
                new MigrationData(2, "Migration", typeof(ValidMigration1).GetTypeInfo()),
                new MigrationData(2, "Migration", typeof(ValidMigration2).GetTypeInfo()),
            };
            this.migrationProvider.Setup(x => x.LoadMigrations()).Returns(migrations);

            Expect(() => this.migrator.Load(), Throws.InstanceOf<MigrationException>());
        }

20. Example

View license
[Test]
        public void LoadThrowsIfMigrationProviderProvidesATypeNotDerivedFromTMigration()
        {
            var migrations = new List<MigrationData>()
            {
                new MigrationData(1, "Migration", typeof(MigrationNotDerivedFromBase).GetTypeInfo()),
            };
            this.migrationProvider.Setup(x => x.LoadMigrations()).Returns(migrations);

            Expect(() => this.migrator.Load(), Throws.InstanceOf<MigrationException>());
        }

21. Example

View license
[Test]
        public void LoadThrowsIfAnyMigrationHasAnInvalidVersion()
        {
            var migrations = new List<MigrationData>()
            {
                new MigrationData(0, "Migration", typeof(ValidMigration1).GetTypeInfo()),
            };
            this.migrationProvider.Setup(x => x.LoadMigrations()).Returns(migrations);

            Expect(() => this.migrator.Load(), Throws.InstanceOf<MigrationException>());
        }

22. Example

Project: CLAP
Source File: Tests.cs
View license
[Test]
        public void Unhandled_Exception_One()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_02 { Printer = mock.Object };

            var p = new Parser<Sample_02>();

            Expect(() => p.Run(new[]
                                   {
                                       "-count:1",
                                       "-message:a",
                                       "-prefix:p",
                                       "-upper",
                                       "-what:x"
                                   }, sample),
                   Throws.InstanceOf<UnhandledParametersException>()
                       .With.Property("UnhandledParameters").EqualTo(new Dictionary<string, string>
                                                                         {
                                                                             {"what", "x"}
                                                                         }));
        }

23. Example

View license
[Test]
        public void MigrateToThrowsIfVersionNotFound()
        {
            this.LoadMigrator(0);

            Expect(() => this.migrator.MigrateTo(3), Throws.InstanceOf<MigrationNotFoundException>().With.Property("Version").EqualTo(3));
        }

24. Example

View license
[Test]
        public void MigrateToPropagatesExceptionFromMigration()
        {
            this.LoadMigrator(0);

            var e = new Exception("BOOM");
            Migration1.Exception = e;

            Expect(() => this.migrator.MigrateTo(2), Throws.Exception.EqualTo(e));

            this.databaseProvider.Verify(x => x.UpdateVersion(It.IsAny<long>(), It.IsAny<long>(), It.IsAny<string>()), Times.Never());
            Expect(this.migrator.CurrentMigration.Version, EqualTo(0));
            Expect(Migration1.DownCalled, False);
        }