public void ConditionDefaultsToTrueWhenNotProvided()
        {
            var service = new DecoratorService(typeof(string));

            var context = DecoratorContext.Create(typeof(string), typeof(string), "A");

            Assert.True(service.Condition(context));
        }
Example #2
0
        public void CreateSetsContextToPreDecoratedState()
        {
            const string implementationInstance = "Initial";

            var context = DecoratorContext.Create(typeof(string), typeof(string), implementationInstance);

            Assert.Equal(typeof(string), context.ServiceType);
            Assert.Equal(typeof(string), context.ImplementationType);
            Assert.Equal(implementationInstance, context.CurrentInstance);
            Assert.Empty(context.AppliedDecoratorTypes);
            Assert.Empty(context.AppliedDecorators);
        }
Example #3
0
        public void UpdateAddsDecoratorStateToContext()
        {
            const string implementationInstance = "Initial";
            var          context = DecoratorContext.Create(typeof(string), typeof(string), implementationInstance);

            const string decoratorA = "DecoratorA";

            context = context.UpdateContext(decoratorA);

            Assert.Equal(decoratorA, context.CurrentInstance);
            Assert.Equal(context.AppliedDecoratorTypes, new[] { typeof(string) });
            Assert.Equal(context.AppliedDecorators, new[] { decoratorA });

            const string decoratorB = "DecoratorB";

            context = context.UpdateContext(decoratorB);

            Assert.Equal(decoratorB, context.CurrentInstance);
            Assert.Equal(context.AppliedDecoratorTypes, new[] { typeof(string), typeof(string) });
            Assert.Equal(context.AppliedDecorators, new[] { decoratorA, decoratorB });
        }