public void Contains_returns_false_when_a_registration_has_not_been_added(Registry sut, [Registration] IServiceRegistration registration) { // Act var result = sut.Contains(ServiceRegistrationKey.ForRegistration(registration)); // Assert Assert.That(result, Is.False); }
public void Get_returns_null_for_a_registration_which_has_not_been_added(Registry sut, [Registration] IServiceRegistration registration) { // Act var result = sut.Get(ServiceRegistrationKey.ForRegistration(registration)); // Assert Assert.That(result, Is.Null); }
void DoNotPermitReRegisteringAServiceWhichIsAlreadyCached(IServiceRegistration registration) { var key = ServiceRegistrationKey.ForRegistration(registration); if (cache.Has(key)) { var message = String.Format(Resources.ExceptionFormats.CannotReRegisterAfterResolution, registration); throw new ServiceReRegisteredAfterResolutionException(message); } }
/// <summary> /// Attempts to get a service/component instance from the cache, matching a given registration. /// </summary> /// <returns> /// <c>true</c>, if a component was found and retrieved, <c>false</c> otherwise.</returns> /// <param name="registration">The registration for which to get a component.</param> /// <param name="instance">Exposes the component instance found (only if this method returns <c>true</c>).</param> public bool TryGet(IServiceRegistration registration, out object instance) { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } var key = ServiceRegistrationKey.ForRegistration(registration); return(TryGet(key, out instance)); }
/// <summary> /// Gets a value indicating whether or not the cache contains a component which matches the given registration. /// </summary> /// <returns> /// <c>true</c> if the cache contains a matching component; <c>false</c> otherwise.</returns> /// <param name="registration">Registration.</param> public bool Has(IServiceRegistration registration) { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } var key = ServiceRegistrationKey.ForRegistration(registration); return(Has(key)); }
public void Get_returns_a_registration_which_has_been_added(Registry sut, [Registration] IServiceRegistration registration) { // Arrange sut.Add(registration); // Act var result = sut.Get(ServiceRegistrationKey.ForRegistration(registration)); // Assert Assert.That(result, Is.SameAs(registration)); }
public void Contains_returns_true_when_a_registration_has_been_added(Registry sut, [Registration] IServiceRegistration registration) { // Arrange sut.Add(registration); // Act var result = sut.Contains(ServiceRegistrationKey.ForRegistration(registration)); // Assert Assert.That(result, Is.True); }
/// <summary> /// Adds a component to the cache. /// </summary> /// <param name="registration">Registration.</param> /// <param name="instance">Instance.</param> public void Add(IServiceRegistration registration, object instance) { if (registration == null) { throw new ArgumentNullException(nameof(registration)); } var key = ServiceRegistrationKey.ForRegistration(registration); var cacheKeys = ServiceCacheKey.CreateFromRegistrationKeyAndInstance(key, instance); foreach (var cacheKey in cacheKeys) { instances.TryAdd(cacheKey, instance); } }