public void Resolve_resolves_unregistered_service_when_resolution_is_unsuccesful([Frozen, ResolvesToFailure] IResolver proxiedResolver, [Frozen] IResolvesRegistrations registrationResolver, [Frozen] IServiceRegistrationProvider unregisteredRegistrationProvider, UnregisteredServiceResolverProxy sut, ResolutionPath path, ResolutionRequest request, ResolutionResult resolutionResult, IServiceRegistration registration) { // Arrange Mock.Get(proxiedResolver) .Setup(x => x.Resolve(request)) .Returns(ResolutionResult.Failure(path)); Mock.Get(unregisteredRegistrationProvider) .Setup(x => x.Get(request)) .Returns(registration); Mock.Get(registrationResolver) .Setup(x => x.Resolve(request, registration)) .Returns(resolutionResult); // Act var result = sut.Resolve(request); // Assert Assert.That(result, Is.SameAs(resolutionResult)); }
public void Customize(IFixture fixture) { fixture.Customize <IResolver>(c => { return(c .FromFactory(() => Mock.Of <IResolver>()) .Do(r => { Mock.Get(r) .Setup(x => x.Resolve(It.IsAny <ResolutionRequest>())) .Returns(ResolutionResult.Failure(new ResolutionPath())); })); }); }
/// <summary> /// Attempts to fulfil the given resolution request, using the given registration, from the cache. /// </summary> /// <returns>A resolution result.</returns> /// <param name="registration">Registration.</param> /// <param name="request">Request.</param> protected virtual ResolutionResult ResolveFromCache(IServiceRegistration registration, ResolutionRequest request) { if (registration == null) { return(ResolutionResult.Failure(request.ResolutionPath)); } object resolved; if (TryGetFromCache(registration, out resolved)) { return(ResolutionResult.Success(request.ResolutionPath, resolved)); } return(ResolutionResult.Failure(request.ResolutionPath)); }
public void Resolve_does_not_add_anything_to_the_cache_if_resolution_fails(IResolver proxiedResolver, [Registration] IServiceRegistration registration, ICachesResolvedServiceInstances cache, ResolutionRequest request, ResolutionPath resolutionPath) { // Arrange object cachedItem = null; Mock.Get(proxiedResolver).Setup(x => x.GetRegistration(request)).Returns(registration); Mock.Get(proxiedResolver).Setup(x => x.Resolve(request)).Returns(ResolutionResult.Failure(resolutionPath)); Mock.Get(cache).Setup(x => x.TryGet(registration, out cachedItem)).Returns(false); var sut = new CachingResolverProxy(proxiedResolver, cache); // Act var result = sut.Resolve(request); // Assert Mock.Get(cache).Verify(x => x.Add(registration, It.IsAny <object>()), Times.Never); }