public void There_are_no_behavior_factories_by_default()
        {
            var sut = new FakeWorkflowConfiguration();

            Assert.NotNull(sut.BehaviorFactories);
            Assert.Equal(0, sut.BehaviorFactories.Count);
        }
        public void There_are_no_retry_exception_types_by_default()
        {
            var sut = new FakeWorkflowConfiguration();

            Assert.NotNull(sut.RetryExceptionTypes);
            Assert.Equal(0, sut.RetryExceptionTypes.Count);
        }
        public void Fluently_assigning_workflow_logger_returns_configuration()
        {
            var sut = new FakeWorkflowConfiguration();

            var result = sut.WithLogger(new FakeWorkflowLogger());

            Assert.Equal(sut, result);
        }
        public void You_can_fluently_assign_the_workflow_logger(IWorkflowLogger logger)
        {
            var sut = new FakeWorkflowConfiguration();

            sut.WithLogger(logger);

            Assert.Equal(logger, sut.Logger);
        }
        public void Fluently_assigning_operation_resolver_returns_configuration(IOperationResolver resolver)
        {
            var sut = new FakeWorkflowConfiguration();

            var result = sut.WithResolver(resolver);

            Assert.Equal(sut, result);
        }
        public void You_can_fluently_assign_the_operation_resolver(IOperationResolver resolver)
        {
            var sut = new FakeWorkflowConfiguration();

            sut.WithResolver(resolver);

            Assert.Equal(resolver, sut.Resolver);
        }
        public void When_workflow_configuration_does_not_have_retry_exception_types_no_behaviors_are_created(IOperation operation)
        {
            var configuration = new FakeWorkflowConfiguration();
            var sut = new WorkflowRetryBehaviorFactory();

            var result = sut.CreateBehaviors(operation, configuration);

            Assert.Equal(0, result.Count);
        }
        public void When_workflow_configuration_has_retry_exception_types_a_retry_behavior_is_added_to_every_operation_with_those_exception_types(IOperation operation)
        {
            var configuration = new FakeWorkflowConfiguration().WithGlobalRetryBehavior(3, TimeSpan.FromSeconds(5), typeof(Exception));
            var sut = new WorkflowRetryBehaviorFactory();

            var result = sut.CreateBehaviors(operation, configuration);

            Assert.Equal(1, result.Count);
            Assert.IsType<RetryBehavior>(result[0]);
        }
        public void The_logging_behaviors_are_created_when_the_log_is_defined_on_the_configuration(IWorkflowLogger logger, IOperation operation)
        {
            var sut = new OperationLoggingBehaviorFactory();
            var configuration = new FakeWorkflowConfiguration { Logger = logger };

            var result = sut.CreateBehaviors(operation, configuration);

            Assert.Equal(2, result.Count);
            Assert.IsType<OperationExecutionLoggingBehavior>(result[0]);
            Assert.IsType<OperationErrorLoggingBehavior>(result[1]);
        }
        public void Retry_behaviors_are_created_with_the_settings_from_the_workflow_configuration(IOperation operation)
        {
            var configuration = new FakeWorkflowConfiguration().WithGlobalRetryBehavior(3, TimeSpan.FromSeconds(5), typeof(Exception));
            var sut = new WorkflowRetryBehaviorFactory();

            var result = sut.CreateBehaviors(operation, configuration);

            var retryBehavior = (RetryBehavior)result[0];
            Assert.Equal(new[] { typeof(Exception) }, retryBehavior.RetryExceptionTypes);
            Assert.Equal(3, retryBehavior.TimesToRetry);
            Assert.Equal(TimeSpan.FromSeconds(5), retryBehavior.RetryDelay);
        }
        public void You_can_fluently_assign_behavior_factories(IOperationBehaviorFactory factory)
        {
            var sut = new FakeWorkflowConfiguration();

            sut.WithBehaviorFactory(factory);

            Assert.Equal(1, sut.BehaviorFactories.Count);
            Assert.Equal(factory, sut.BehaviorFactories[0]);
        }
        public void You_cannot_assign_a_retry_exception_type_that_is_not_an_exception_type()
        {
            var sut = new FakeWorkflowConfiguration();

            Assert.Throws<ArgumentException>(() => sut.WithGlobalRetryBehavior(3, TimeSpan.FromSeconds(5), typeof(object)));
        }
        public void Fluently_assigning_retry_exception_types_returns_configuration()
        {
            var sut = new FakeWorkflowConfiguration();

            var result = sut.WithGlobalRetryBehavior(3, TimeSpan.FromSeconds(5), typeof(Exception));

            Assert.Equal(sut, result);
        }
        public void You_can_fluently_assign_retry_behavior()
        {
            var sut = new FakeWorkflowConfiguration();

            sut.WithGlobalRetryBehavior(3, TimeSpan.FromSeconds(5), typeof(Exception));

            Assert.Equal(3, sut.TimesToRetry);
            Assert.Equal(TimeSpan.FromSeconds(5), sut.RetryDelay);
            Assert.Equal(1, sut.RetryExceptionTypes.Count);
            Assert.Equal(typeof(Exception), sut.RetryExceptionTypes[0]);
        }
        public void Fluently_assigning_behavior_factories_returns_configuration()
        {
            var sut = new FakeWorkflowConfiguration();

            var result = sut.WithBehaviorFactory(new FakeOperationBehaviorFactory());

            Assert.Equal(sut, result);
        }