예제 #1
0
    protected void Ex01()
    {
        var result = Fixture.Run(null, Substitute.For <IFixtureStepRunnerFactory>());

        Expect("the fixture method should be called", () => TestFixtures.CalledFixtureMethods.Count == 1 && TestFixtures.CalledFixtureMethods.Contains(TargetFixtureType));
        Expect("the Dispose method should be called", () => TestFixtures.DisposeCalled);

        ExpectedFixtureDescriptor = FixtureDescriptorAssertion.Of(TargetFixtureDescription, TargetMethodDescription, TargetMethodFullName, typeof(ExampleAttribute));
        Expect($"the descriptor of the result should be as follows:{ExpectedFixtureDescriptor.ToDescription()}", () => result != null && FixtureDescriptorAssertion.Of(result.FixtureDescriptor) == ExpectedFixtureDescriptor);
        ExpectedFixtureResult = FixtureResultAssertion.ForNullException(true, true, true, 0, 0, FixtureStatus.Passed);
        Expect($"the result should be as follows:{ExpectedFixtureResult.ToDescription()}", () => result != null && FixtureResultAssertion.Of(result) == ExpectedFixtureResult);

        Expect("FixtureRunning event should be raised", () => FixtureRunningResult != null);

        ExpectedFixtureRunningDescriptor = FixtureDescriptorAssertion.Of(TargetFixtureDescription, TargetMethodDescription, TargetMethodFullName, typeof(ExampleAttribute));
        Expect($"the descriptor of the result on FixtureRunning event should be as follows:{ExpectedFixtureRunningDescriptor.ToDescription()}", () => FixtureRunningResult != null && FixtureDescriptorAssertion.Of(FixtureRunningResult.FixtureDescriptor) == ExpectedFixtureRunningDescriptor);
        ExpectedFixtureRunningResult = FixtureResultAssertion.ForNullException(true, false, false, 0, 0, FixtureStatus.Running);
        Expect($"the result on FixtureRunning event should be as follows:{ExpectedFixtureRunningResult.ToDescription()}", () => FixtureRunningResult != null && FixtureResultAssertion.Of(FixtureRunningResult) == ExpectedFixtureRunningResult);

        Expect("FixtureRun event should be raised", () => FixtureRunResult != null);

        Expect("the result on FixtureRun event should be the result that is returned by Run method", () => FixtureRunResult == result);

        Expect("FixtureStepRunning event should not be raised", () => FixtureStepRunningResult == null);
        Expect("FixtureStepRun event should not be raised", () => FixtureStepRunResult == null);
    }
    protected void Ex04()
    {
        TestFixtures.RaiseException = true;

        var result = Fixture.Run(null, new TestFixtures.SimpleFixtureStepRunnerFactory());

        ExpectedFixtureDescriptor = FixtureDescriptorAssertion.Of(TargetFixtureDescription, TargetMethodDescription, TargetMethodFullName, typeof(ExampleAttribute));
        Expect($"the descriptor of the result should be as follows:{ExpectedFixtureDescriptor.ToDescription()}", () => result != null && FixtureDescriptorAssertion.Of(result.FixtureDescriptor) == ExpectedFixtureDescriptor);
        ExpectedFixtureResult = FixtureResultAssertion.ForNotNullException(true, true, true, 0, 0, FixtureStatus.Failed);
        Expect($"the result should be as follows:{ExpectedFixtureResult.ToDescription()}", () => result != null && FixtureResultAssertion.Of(result) == ExpectedFixtureResult);

        Expect("FixtureRunning event should be raised", () => FixtureRunningResult != null);

        ExpectedFixtureRunningDescriptor = FixtureDescriptorAssertion.Of(TargetFixtureDescription, TargetMethodDescription, TargetMethodFullName, typeof(ExampleAttribute));
        Expect($"the descriptor of the result on FixtureRunning event should be as follows:{ExpectedFixtureRunningDescriptor.ToDescription()}", () => FixtureRunningResult != null && FixtureDescriptorAssertion.Of(FixtureRunningResult.FixtureDescriptor) == ExpectedFixtureRunningDescriptor);
        ExpectedFixtureRunningResult = FixtureResultAssertion.ForNullException(true, false, false, 0, 0, FixtureStatus.Running);
        Expect($"the result on FixtureRunning event should be as follows:{ExpectedFixtureRunningResult.ToDescription()}", () => FixtureRunningResult != null && FixtureResultAssertion.Of(FixtureRunningResult) == ExpectedFixtureRunningResult);

        Expect("FixtureRun event should be raised", () => FixtureRunResult != null);

        Expect("the result on FixtureRun event should be the result that is returned by Run method", () => FixtureRunResult == result);
    }
    protected void Ex01()
    {
        var result = Fixture.Run(null, new TestFixtures.SimpleFixtureStepRunnerFactory());

        Expect("the fixture method should be called", () => TestFixtures.CalledFixtureMethods.Count == 1 && TestFixtures.CalledFixtureMethods.Contains(TargetFixtureType));

        ExpectedFixtureDescriptor = FixtureDescriptorAssertion.Of(TargetFixtureDescription, TargetMethodDescription, TargetMethodFullName, typeof(ExampleAttribute));
        Expect($"the descriptor of the result should be as follows:{ExpectedFixtureDescriptor.ToDescription()}", () => result != null && FixtureDescriptorAssertion.Of(result.FixtureDescriptor) == ExpectedFixtureDescriptor);
        ExpectedFixtureResult = FixtureResultAssertion.ForNullException(true, true, true, 1, 0, FixtureStatus.Passed);
        Expect($"the result should be as follows:{ExpectedFixtureResult.ToDescription()}", () => result != null && FixtureResultAssertion.Of(result) == ExpectedFixtureResult);

        if (result is null)
        {
            return;
        }

        var stepResult = result.StepResults.ElementAt(0);

        ExpectedFixtureStepResult = FixtureStepResultAssertion.Of("Description", null, FixtureStepStatus.Passed, typeof(ExpectStep));
        Expect($"the the result of the step should be as follows:{ExpectedFixtureStepResult.ToDescription()}", () => FixtureStepResultAssertion.Of(stepResult) == ExpectedFixtureStepResult);

        Expect("FixtureRunning event should be raised", () => FixtureRunningResult != null);

        ExpectedFixtureRunningDescriptor = FixtureDescriptorAssertion.Of(TargetFixtureDescription, TargetMethodDescription, TargetMethodFullName, typeof(ExampleAttribute));
        Expect($"the descriptor of the result on FixtureRunning event should be as follows:{ExpectedFixtureRunningDescriptor.ToDescription()}", () => FixtureRunningResult != null && FixtureDescriptorAssertion.Of(FixtureRunningResult.FixtureDescriptor) == ExpectedFixtureRunningDescriptor);
        ExpectedFixtureRunningResult = FixtureResultAssertion.ForNullException(true, false, false, 0, 0, FixtureStatus.Running);
        Expect($"the result on FixtureRunning event should be as follows:{ExpectedFixtureRunningResult.ToDescription()}", () => FixtureRunningResult != null && FixtureResultAssertion.Of(FixtureRunningResult) == ExpectedFixtureRunningResult);

        Expect("FixtureRun event should be raised", () => FixtureRunResult != null);

        Expect("the result on FixtureRun event should be the result that is returned by Run method", () => FixtureRunResult == result);

        Expect("FixtureStepRunning event should be raised", () => FixtureStepRunningResult != null);

        ExpectedFixtureStepRunningResult = FixtureStepRunningResultAssertion.Of(stepResult.Step, true, false, false, null, FixtureStepStatus.Running);
        Expect($"the result of the step on FixtureRunning event should be as follows:{ExpectedFixtureStepRunningResult.ToDescription()}", () => FixtureStepRunningResult != null && FixtureStepRunningResultAssertion.Of(FixtureStepRunningResult) == ExpectedFixtureStepRunningResult);

        Expect("FixtureStepRun event should be raised", () => FixtureStepRunResult != null);

        Expect("the result on FixtureStepRun event should be the result that is returned by Run method", () => FixtureStepRunResult == stepResult);
    }
    void Ex02()
    {
        Filter.Accept(Arg.Any <FixtureDescriptor>()).Returns(true);

        var result = Container.Run(Filter, new FixtureStepRunnerFactory());

        Expect(
            "all inner fixture methods should be called",
            () => TestFixtures.CalledFixtureMethods.Count == 3 &&
            TestFixtures.CalledFixtureMethods.Contains(typeof(TestFixtures.SimpleFixture)) &&
            TestFixtures.CalledFixtureMethods.Contains(typeof(TestFixtures.SimpleDisposableFixture)) &&
            TestFixtures.CalledFixtureMethods.Contains(typeof(TestFixtures.SimpleFixtureSteppable))
            );

        ExpectedFixtureDescriptor = FixtureDescriptorWithBackgroundAssertion.Of("Simple Fixture", "SimpleFixture", "Carna.TestFixtures+SimpleFixture", typeof(ContextAttribute), "Simple Fixture Background");
        Expect($"the descriptor of the result should be as follows:{ExpectedFixtureDescriptor.ToDescription()}", () => result != null && FixtureDescriptorWithBackgroundAssertion.Of(result.FixtureDescriptor) == ExpectedFixtureDescriptor);
        ExpectedFixtureResult = FixtureResultAssertion.ForNullException(true, true, true, 0, 3, FixtureStatus.Passed);
        Expect($"the result should be as follows:{ExpectedFixtureResult.ToDescription()}", () => result != null && FixtureResultAssertion.Of(result) == ExpectedFixtureResult);

        Expect("FixtureRunning event should be raised", () => FixtureRunningResult != null);

        ExpectedFixtureRunningDescriptor = FixtureDescriptorAssertion.Of("Simple Fixture", "SimpleFixture", "Carna.TestFixtures+SimpleFixture", typeof(ContextAttribute));
        Expect($"the descriptor of the result on FixtureRunning should be as follows:{ExpectedFixtureRunningDescriptor.ToDescription()}", () => FixtureRunningResult != null && FixtureDescriptorAssertion.Of(FixtureRunningResult.FixtureDescriptor) == ExpectedFixtureRunningDescriptor);
        ExpectedFixtureRunningResult = FixtureResultAssertion.ForNullException(true, false, false, 0, 0, FixtureStatus.Running);
        Expect($"the result on FixtureRunning should be as follows:{ExpectedFixtureRunningResult.ToDescription()}", () => FixtureRunningResult != null && FixtureResultAssertion.Of(FixtureRunningResult) == ExpectedFixtureRunningResult);

        Expect("FixtureRun event should be raised", () => FixtureRunResult != null);

        Expect("the result on FixtureRun event should be the result that is returned by Run method", () => FixtureRunResult == result);
    }