SimpleTaskContextFixture class definition.
Depending on which is simpler, this class can either be inherited by test classes or created and disposed inside test. In the first instance XUnit will automatically dispose of the instance but in the second you should use a using or finally block to ensure correct disposal.
Наследование: IDisposable
Пример #1
0
            public void FailedTaskShouldRaiseStartThenFailedEvents()
            {
                this.task.ExecuteFunction =
                    c => { throw new InvalidOperationException(); };

                using (var fixture = new SimpleContextFixture(
                    b => b.RegisterInstance(this.log).As<IExecutionLog>()))
                {
                    try
                    {
                        this.task.Execute(fixture.Context);
                    }
                    catch (AggregateException)
                    {
                        // This exception type is thrown because we are executing in
                        // an asynchronous context.
                    }
                }

                this.log.Received(1).TaskStarted(this.task);
                this.log.Received(1).TaskFailed(this.task, Arg.Any<string>());

                this.log.DidNotReceiveWithAnyArgs().TaskSucceeded(null);
            }
Пример #2
0
            public void SucceedingTaskShouldRaiseStartThenSuccessEvents()
            {
                using (var fixture = new SimpleContextFixture(
                    b => b.RegisterInstance(this.log).As<IExecutionLog>()))
                {
                    this.task.Execute(fixture.Context);
                }

                this.log.Received(1).TaskStarted(this.task);
                this.log.Received(1).TaskSucceeded(this.task);

                this.log.DidNotReceiveWithAnyArgs().TaskFailed(null, Arg.Any<string>());
            }