/// <summary> /// Initializes a new instance of the /// <see cref="T:CSF.FlexDi.Resolution.Proxies.CircularDependencyPreventingResolverProxy"/> class. /// </summary> /// <param name="proxiedResolver">Proxied resolver.</param> /// <param name="circularDependencyDetector">Circular dependency detector.</param> public CircularDependencyPreventingResolverProxy(IResolver proxiedResolver, IDetectsCircularDependencies circularDependencyDetector) : base(proxiedResolver) { if (circularDependencyDetector == null) { throw new ArgumentNullException(nameof(circularDependencyDetector)); } this.circularDependencyDetector = circularDependencyDetector; }
public void Resolve_calls_throw_on_circular_dependency_from_detector_service(IDetectsCircularDependencies detector, [ResolvesToFailure] IResolver proxiedResolver, ResolutionPath path, [Registration] IServiceRegistration registration) { // Arrange var request = new ResolutionRequest(typeof(ISampleService), path); Mock.Get(proxiedResolver).Setup(x => x.GetRegistration(request)).Returns(registration); var sut = new CircularDependencyPreventingResolverProxy(proxiedResolver, detector); // Act sut.Resolve(request); // Assert Mock.Get(detector).Verify(x => x.ThrowOnCircularDependency(registration, path), Times.Once); }
public void GetRulesWithDependenciesShouldThrowValidationExceptionWithCorrectMessageIfThereAreCircularDependencies([Frozen] IGetsAllExecutableRulesWithDependencies wrapped, [Frozen] IDetectsCircularDependencies circularDependencyDetector, CircularDependencyPreventingRulesWithDependenciesDecorator sut, [ManifestModel] ManifestValue manifestValue, object objectToBeValidated, ResolvedValidationOptions validationOptions) { var circularDependencies = GetSomeCircularDependencies(manifestValue); var expectedMessage = @"Validation rules may not have circular dependencies. Following is a list of the circular dependencies found, to a maximum of the first 10. Type = System.String Name = Foo Validated type = System.Int32 Validated identity = Identity 1 -> Type = System.DateTime Validated type = System.Int64 -> Type = System.String Name = Foo Validated type = System.Int32 Validated identity = Identity 1 Type = System.String Name = Bar Validated type = System.Int32 Validated identity = Identity 2 -> Type = System.Object Validated type = System.Int64 -> Type = System.String Name = Bar Validated type = System.Int32 Validated identity = Identity 2 "; Mock.Get(wrapped) .Setup(x => x.GetRulesWithDependencies(It.IsAny <ManifestValue>(), It.IsAny <object>(), validationOptions)) .Returns(new ExecutableRuleAndDependencies[0]); Mock.Get(circularDependencyDetector) .Setup(x => x.GetCircularDependencies(It.IsAny <IEnumerable <ExecutableRuleAndDependencies> >())) .Returns(circularDependencies); Assert.That(() => sut.GetRulesWithDependencies(manifestValue, objectToBeValidated, validationOptions), Throws.InstanceOf <ValidationException>().And.Message.EqualTo(expectedMessage)); }
public void GetRulesWithDependenciesShouldNotThrowIfThereAreNoCircularDependencies([Frozen] IGetsAllExecutableRulesWithDependencies wrapped, [Frozen] IDetectsCircularDependencies circularDependencyDetector, CircularDependencyPreventingRulesWithDependenciesDecorator sut, [ManifestModel] ManifestValue manifestValue, object objectToBeValidated, ResolvedValidationOptions validationOptions) { Mock.Get(wrapped) .Setup(x => x.GetRulesWithDependencies(It.IsAny <ManifestValue>(), It.IsAny <object>(), validationOptions)) .Returns(new ExecutableRuleAndDependencies[0]); Mock.Get(circularDependencyDetector) .Setup(x => x.GetCircularDependencies(It.IsAny <IEnumerable <ExecutableRuleAndDependencies> >())) .Returns(Enumerable.Empty <CircularDependency>()); Assert.That(() => sut.GetRulesWithDependencies(manifestValue, objectToBeValidated, validationOptions), Throws.Nothing); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:CSF.FlexDi.Resolution.Proxies.CircularDependencyPreventingResolverProxyFactory"/> class. /// </summary> /// <param name="detector">Detector.</param> public CircularDependencyPreventingResolverProxyFactory(IDetectsCircularDependencies detector = null) { this.detector = detector ?? new CircularDependencyDetector(); }
/// <summary> /// Initialises a new instance of <see cref="CircularDependencyPreventingRulesWithDependenciesDecorator"/> /// </summary> /// <param name="wrapped">The wrapped implementation.</param> /// <param name="circularDependencyDetector">A circular dependency detector.</param> /// <exception cref="ArgumentNullException">If <paramref name="circularDependencyDetector"/> or <paramref name="wrapped"/> are <see langword="null"/>.</exception> public CircularDependencyPreventingRulesWithDependenciesDecorator(IGetsAllExecutableRulesWithDependencies wrapped, IDetectsCircularDependencies circularDependencyDetector) { this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped)); this.circularDependencyDetector = circularDependencyDetector ?? throw new ArgumentNullException(nameof(circularDependencyDetector)); }