Ejemplo n.º 1
0
        public void SetValueFormattingService_should_allow_using_custom_formatter()
        {
            var expected    = Fake.Int();
            var actualValue = expected + 1;
            Verifiable <int> expectation = expected;

            ((IComplexParameter)expectation).SetValueFormattingService(new ValueFormattingServiceStub(CultureInfo.InvariantCulture, "--{0}--"));
            expectation.SetActual(() => actualValue);

            Assert.That(expectation.ToString(), Is.EqualTo($"expected: equals '--{expected}--', but got: '--{actualValue}--'"));
        }
Ejemplo n.º 2
0
        public void SetActual_should_be_allowed_once()
        {
            Verifiable <int> expectation = Fake.Int();

            expectation.SetActual(() => Fake.Int());
            var ex = Assert.Throws <InvalidOperationException>(() => expectation.SetActual(() => Fake.Int()));

            Assert.That(ex.Message, Is.EqualTo("Actual value has been already specified"));
            ex = Assert.Throws <InvalidOperationException>(() => expectation.SetActual(Fake.Int()));
            Assert.That(ex.Message, Is.EqualTo("Actual value has been already specified"));
        }
Ejemplo n.º 3
0
        public async Task SetActualAsync_should_capture_exception_during_actual_value_evaluation_and_expose_it_with_GetActual()
        {
            var expected = Fake.Int();

            Verifiable <int> expectation = expected;
            await expectation.SetActualAsync(() => throw new DivideByZeroException());

            Assert.That(expectation.Status, Is.EqualTo(ParameterVerificationStatus.Exception));
            Assert.That(expectation.ToString(), Is.EqualTo($"expected: equals '{expected}', but got: '<{nameof(DivideByZeroException)}>'"));
            Assert.Throws <DivideByZeroException>(() => expectation.GetActual());
        }
Ejemplo n.º 4
0
        public async Task SetActualAsync_should_verify_expectation_and_update_formatting(int expected, int actual, bool shouldMatch, string message)
        {
            Verifiable <int> expectation = expected;
            await expectation.SetActualAsync(async() =>
            {
                await Task.Yield();
                return(actual);
            });

            Assert.That(expectation.Status, Is.EqualTo(shouldMatch ? ParameterVerificationStatus.Success : ParameterVerificationStatus.Failure));
            Assert.That(expectation.ToString(), Is.EqualTo(message));
        }
Ejemplo n.º 5
0
        private void Filter_results_should_be(Verifiable <bool> expected)
        {
            var evidence = GetEvidence(whenCondition, evaluationContext);

            if (evidence != null)
            {
                StepExecution.Current.Comment($"Evidence\n{evidence.FormatObject()}\n");
            }

            var actual = filter(evaluationContext);

            expected.SetActual(actual);
        }
Ejemplo n.º 6
0
        private void Evaluation_results_should_be(Verifiable <bool> expected)
        {
            var  builder = new ExpressionEvaluator();
            bool actual  = false;

            if (evaluationContext is Location location)
            {
                var lambda = builder.Evaluate <Location>(conditionExpression);
                actual = lambda(location);
            }
            else if (evaluationContext is Person person)
            {
                var lambda = builder.Evaluate <Person>(conditionExpression);
                actual = lambda(person);
            }
            else
            {
                Assert.Fail($"context type '{evaluationContext.GetType().Name}' is not supported");
            }

            expected.SetActual(actual);
        }
Ejemplo n.º 7
0
        private void Evaluation_results_should_be(Verifiable <bool> expected)
        {
            var    builder  = new ExpressionEvaluator();
            bool   actual   = false;
            JArray evidence = null;

            if (evaluationContext is Location location)
            {
                var lambda = builder.Evaluate <Location>(conditionExpression);
                actual   = lambda(location);
                evidence = GetEvidence(conditionExpression, location);
            }
            else if (evaluationContext is Person person)
            {
                var lambda = builder.Evaluate <Person>(conditionExpression);
                actual   = lambda(person);
                evidence = GetEvidence(conditionExpression, person);
            }
            else if (evaluationContext is TreeNode treeNode)
            {
                var lambda = builder.Evaluate <TreeNode>(conditionExpression);
                actual   = lambda(treeNode);
                evidence = GetEvidence(conditionExpression, treeNode);
            }
            else
            {
                Assert.Fail($"context type '{evaluationContext.GetType().Name}' is not supported");
            }

            if (evidence != null)
            {
                StepExecution.Current.Comment($"Evidence\n{evidence.FormatObject()}\n");
            }

            expected.SetActual(actual);
        }
Ejemplo n.º 8
0
 private void Then_dividing_X_by_Y_should_give_RESULT(int x, int y, Verifiable <int> result)
 {
     result.SetActual(() => _calculator.Divide(x, y));
 }
Ejemplo n.º 9
0
 private void Then_adding_X_to_Y_should_give_RESULT(int x, int y, Verifiable <int> result)
 {
     result.SetActual(() => _calculator.Add(x, y));
 }
Ejemplo n.º 10
0
 public MainEngine()
 {
     InitializeComponent();
     DataContext = this;
     mainEngine  = new MainEngineBarcode();
 }
Ejemplo n.º 11
0
 public Injectors()
 {
     InitializeComponent();
     DataContext = this;
     mainEngine  = new InjectorDataMatrix();
 }