public WhenUpdatingAConstructionContext() { string extra = Guid.NewGuid().ToString("D").ToUpperInvariant(); IContainer <string> container = new Mock <IContainer <string> >().Object; _initialValue = ConstructionContext <string> .Default.Initialize(container, extra); }
public void ItShouldUpdateRecipientTypeIfSpecified() { // Act ConstructionContext <string> context = _initialValue.Update(recipientType: GetType()); // Assert context.ImplementationType.Should().Be(typeof(void)); context.ServiceType.Should().Be(typeof(void)); context.RecipientType.Should().Be(GetType()); context.Container.Should().Be(_initialValue.Container); context.Extra.Should().Be(_initialValue.Extra); }
/// <summary> /// Creates a <see cref="ConstructionContext{TExtra}"/> updated with the specified parameters. /// </summary> /// <typeparam name="TExtra"> /// The type of the <see cref="ConstructionContext{TExtra}.Extra"/> construction context information. /// </typeparam> /// <param name="context">The source <see cref="ConstructionContext{TExtra}"/>.</param> /// <param name="implementationType">The <see cref="ConstructionContext{TExtra}.ImplementationType"/>.</param> /// <param name="serviceType">The <see cref="ConstructionContext{TExtra}.ServiceType"/>.</param> /// <param name="recipientType">The <see cref="ConstructionContext{TExtra}.RecipientType"/>.</param> /// <returns>An updated <see cref="ConstructionContext{TExtra}"/>.</returns> public static ConstructionContext <TExtra> Update <TExtra>( this ConstructionContext <TExtra> context, Type implementationType = null, Type serviceType = null, Type recipientType = null) { implementationType = implementationType ?? context.ImplementationType; serviceType = serviceType ?? context.ServiceType; recipientType = recipientType ?? context.RecipientType; return(new ConstructionContext <TExtra>( implementationType, serviceType, recipientType, context.Container, context.Extra)); }
/// <summary> /// Creates a <see cref="ConstructionContext{TExtra}"/> updated with the <paramref name="extra"/> information. /// </summary> /// <typeparam name="TExtra"> /// The type of the <see cref="ConstructionContext{TExtra}.Extra"/> construction context information. /// </typeparam> /// <param name="context">The source <see cref="ConstructionContext{TExtra}"/>.</param> /// <param name="container"> /// The abioc <see cref="IContainer{TExtra}"/> used for this construction request. /// </param> /// <param name="extra"> /// The <see cref="ConstructionContext{TExtra}.Extra"/> construction context information. /// </param> /// <returns>An updated <see cref="ConstructionContext{TExtra}"/>.</returns> public static ConstructionContext <TExtra> Initialize <TExtra>( this ConstructionContext <TExtra> context, IContainer <TExtra> container, TExtra extra) { if (container == null) { throw new ArgumentNullException(nameof(container)); } return(new ConstructionContext <TExtra>( context.ImplementationType, context.ServiceType, context.RecipientType, container, extra)); }