Example #1
0
        public void GetBuildArtifact()
        {
            var pipeline = new TestBuildPipelineWithBuildArtifact();
            var config   = BuildConfiguration.CreateInstance(c => c.SetComponent(new TestBuildPipelineComponent {
                Pipeline = pipeline
            }));
            var context = new TestContextBase(pipeline, config);

            Assert.That(context.GetBuildArtifact <TestBuildArtifactA>(), Is.Null);
            Assert.That(context.GetBuildArtifact <TestBuildArtifactB>(), Is.Null);

            config.Build();
            Assert.That(context.GetBuildArtifact <TestBuildArtifactA>(), Is.Not.Null);
            Assert.That(context.GetBuildArtifact <TestBuildArtifactB>(), Is.Null);
            Assert.That(config.Run().Succeeded, Is.True);

            config.CleanBuildArtifact();
            Assert.That(context.GetBuildArtifact <TestBuildArtifactA>(), Is.Null);
            Assert.That(context.GetBuildArtifact <TestBuildArtifactB>(), Is.Null);

            Assert.Throws <ArgumentNullException>(() => context.GetBuildArtifact(null));
            Assert.Throws <InvalidOperationException>(() => context.GetBuildArtifact(typeof(object)));
            Assert.Throws <InvalidOperationException>(() => context.GetBuildArtifact(typeof(TestBuildArtifactInvalidA)));
            Assert.Throws <InvalidOperationException>(() => context.GetBuildArtifact(typeof(TestBuildArtifactInvalidB)));
        }
Example #2
0
        public void SetValue_SkipObjectType()
        {
            var context = new TestContextBase();

            Assert.DoesNotThrow(() => context.SetValue(new object()));
            Assert.That(context.Values.Length, Is.Zero);
        }
Example #3
0
 public TestResult(TestContextBase context, bool succeeded, DateTime startTime, DateTime endTime)
 {
     this.Succeeded = succeeded;
     this.StartTime = startTime;
     this.EndTime   = endTime;
     this.Context   = context;
 }
Example #4
0
        public void GetValueOrDefault()
        {
            var context = new TestContextBase();

            Assert.That(context.GetValueOrDefault <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.False);
        }
Example #5
0
        public void SetValue_SkipNullValues()
        {
            var context = new TestContextBase();

            Assert.DoesNotThrow(() => context.SetValue <object>(null));
            Assert.That(context.Values.Length, Is.Zero);
        }
Example #6
0
        public void GetOrCreateValue_WhenValueExist_DoesNotThrow()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.DoesNotThrow(() => context.GetOrCreateValue <TestValueA>());
        }
Example #7
0
        public void GetValue()
        {
            var context = new TestContextBase();
            var value   = new TestValueA();

            context.SetValue(value);
            Assert.That(context.GetValue <TestValueA>(), Is.EqualTo(value));
        }
Example #8
0
        public void HasValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.HasValue <TestValueB>(), Is.False);
        }
Example #9
0
        public void GetValueOrDefault()
        {
            var context = new TestContextBase();

            Assert.That(context.GetValueOrDefault <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.False);
            Assert.Throws <InvalidOperationException>(() => context.GetValueOrDefault <object>());
        }
Example #10
0
        public void GetOrCreateValue()
        {
            var context = new TestContextBase();

            Assert.That(context.GetOrCreateValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(1));
        }
Example #11
0
        public void RemoveValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.That(context.Values.Length, Is.EqualTo(1));
            Assert.That(context.RemoveValue <TestValueA>(), Is.True);
            Assert.That(context.Values.Length, Is.Zero);
        }
Example #12
0
        public void GetValue()
        {
            var context = new TestContextBase();
            var value   = new TestValueA();

            context.SetValue(value);
            Assert.That(context.GetValue <TestValueA>(), Is.EqualTo(value));
            Assert.Throws <InvalidOperationException>(() => context.GetValue <object>());
        }
Example #13
0
        public void HasValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.HasValue <TestValueB>(), Is.False);
            Assert.Throws <InvalidOperationException>(() => context.HasValue <object>());
        }
Example #14
0
        public void RemoveValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.That(context.Values.Length, Is.EqualTo(1));
            Assert.That(context.RemoveValue <TestValueA>(), Is.True);
            Assert.That(context.Values.Length, Is.Zero);
            Assert.Throws <InvalidOperationException>(() => context.RemoveValue <object>());
        }
Example #15
0
        public void GetOrCreateValue()
        {
            var context = new TestContextBase();

            Assert.That(context.GetOrCreateValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(1));
            Assert.Throws <InvalidOperationException>(() => context.GetOrCreateValue <object>());
        }
Example #16
0
        public void SetValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            context.SetValue <TestValueB>();
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueB>(), Is.True);
            Assert.That(context.GetValue <TestValueB>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(2));
        }
Example #17
0
        public void SetValue_WhenValueExist_OverrideValue()
        {
            var context   = new TestContextBase();
            var instance1 = new TestValueA();
            var instance2 = new TestValueA();

            context.SetValue(instance1);
            Assert.That(context.Values, Is.EqualTo(new[] { instance1 }));

            context.SetValue(instance2);
            Assert.That(context.Values, Is.EqualTo(new[] { instance2 }));
        }
Example #18
0
        public void TryGetComponent()
        {
            var pipeline = new TestBuildPipelineWithUsedComponents();
            var config   = BuildConfiguration.CreateInstance(c => c.SetComponent <TestBuildComponentA>());
            var context  = new TestContextBase(pipeline, config);

            Assert.That(context.TryGetComponent <TestBuildComponentA>(out _), Is.True);
            Assert.That(context.TryGetComponent <TestBuildComponentB>(out _), Is.False);
            Assert.Throws <InvalidOperationException>(() => context.TryGetComponent <TestBuildComponentC>(out _));
            Assert.Throws <ArgumentNullException>(() => context.TryGetComponent(null, out _));
            Assert.Throws <InvalidOperationException>(() => context.TryGetComponent(typeof(object), out _));
            Assert.Throws <InvalidOperationException>(() => context.TryGetComponent(typeof(TestBuildComponentInvalid), out _));
        }
Example #19
0
        public void GetComponentTypes()
        {
            var pipeline = new TestBuildPipelineWithUsedComponents();
            var configB  = BuildConfiguration.CreateInstance(c => c.SetComponent <TestBuildComponentB>());
            var configA  = BuildConfiguration.CreateInstance(c =>
            {
                c.SetComponent <TestBuildComponentA>();
                c.AddDependency(configB);
            });
            var context = new TestContextBase(pipeline, configA);

            Assert.That(context.GetComponentTypes(), Is.EquivalentTo(new[] { typeof(TestBuildComponentA), typeof(TestBuildComponentB) }));
        }
Example #20
0
        public void GetComponentOrDefault()
        {
            var pipeline = new TestBuildPipelineWithUsedComponents();
            var config   = BuildConfiguration.CreateInstance();
            var context  = new TestContextBase(pipeline, config);

            Assert.That(context.HasComponent <TestBuildComponentA>(), Is.False);
            Assert.That(context.GetComponentOrDefault <TestBuildComponentA>(), Is.Not.Null);
            Assert.Throws <InvalidOperationException>(() => context.GetComponentOrDefault <TestBuildComponentC>());
            Assert.Throws <ArgumentNullException>(() => context.GetComponentOrDefault(null));
            Assert.Throws <InvalidOperationException>(() => context.GetComponentOrDefault(typeof(object)));
            Assert.Throws <InvalidOperationException>(() => context.GetComponentOrDefault(typeof(TestBuildComponentInvalid)));
        }
Example #21
0
        public void SetValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            context.SetValue <TestValueB>();
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueB>(), Is.True);
            Assert.That(context.GetValue <TestValueB>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(2));
            Assert.Throws <ArgumentNullException>(() => context.SetValue <TestValueA>(null));
            Assert.Throws <InvalidOperationException>(() => context.SetValue(new object()));
        }
Example #22
0
        public void GetAllBuildArtifacts()
        {
            var pipeline = new TestBuildPipelineWithBuildArtifact();
            var config   = BuildConfiguration.CreateInstance(c => c.SetComponent(new TestBuildPipelineComponent {
                Pipeline = pipeline
            }));
            var context = new TestContextBase(pipeline, config);

            Assert.That(context.GetAllBuildArtifacts(), Is.Empty);

            config.Build();
            Assert.That(context.GetAllBuildArtifacts().Select(a => a.GetType()), Is.EquivalentTo(new[] { typeof(TestBuildArtifactA) }));
            Assert.That(config.Run().Succeeded, Is.True);

            config.CleanBuildArtifact();
            Assert.That(context.GetAllBuildArtifacts(), Is.Empty);
        }
Example #23
0
        public async Task RunAsync(Func <Task> next)
        {
            var testContext = new TestContextBase();

            Console.WriteLine("With dependency injection framework and generic type implementation:");
            var iocManager = new IocManager();

            iocManager.Builder
            .RegisterGeneric(typeof(AsyncPipelineAggregator <>))
            .AsImplementedInterfaces()
            .InstancePerDependency();
            iocManager.RegisterByConvention(typeof(Program).Assembly);

            IIocResolver resolver = iocManager;

            var aggregator = resolver.Resolve <IAsyncPipelineAggregator <TestContextBase> >();

            await aggregator.AggregateAsync(testContext, next);
        }
Example #24
0
        public void GetComponents()
        {
            var pipeline = new TestBuildPipelineWithUsedComponents();
            var configB  = BuildConfiguration.CreateInstance(c => c.SetComponent <TestBuildComponentB>());
            var configA  = BuildConfiguration.CreateInstance(c =>
            {
                c.SetComponent <TestBuildComponentA>();
                c.AddDependency(configB);
            });
            var context = new TestContextBase(pipeline, configA);

            var components = context.GetComponents();

            Assert.That(components.Count, Is.EqualTo(2));
            Assert.That(components.Select(c => c.GetType()), Is.EquivalentTo(new[] { typeof(TestBuildComponentA), typeof(TestBuildComponentB) }));

            configA.SetComponent <TestBuildComponentC>();
            Assert.Throws <InvalidOperationException>(() => context.GetComponents());
        }
Example #25
0
        public void IsComponentInherited()
        {
            var pipeline = new TestBuildPipelineWithUsedComponents();
            var configB  = BuildConfiguration.CreateInstance(c => c.SetComponent <TestBuildComponentB>());
            var configA  = BuildConfiguration.CreateInstance(c =>
            {
                c.SetComponent <TestBuildComponentA>();
                c.AddDependency(configB);
            });
            var context = new TestContextBase(pipeline, configA);

            Assert.That(context.IsComponentInherited <TestBuildComponentA>(), Is.False);
            Assert.That(context.IsComponentInherited <TestBuildComponentB>(), Is.True);
            Assert.Throws <InvalidOperationException>(() => context.IsComponentInherited <TestBuildComponentC>());

            Assert.Throws <ArgumentNullException>(() => context.IsComponentInherited(null));
            Assert.Throws <InvalidOperationException>(() => context.IsComponentInherited(typeof(object)));
            Assert.Throws <InvalidOperationException>(() => context.IsComponentInherited(typeof(TestBuildComponentInvalid)));
        }
Example #26
0
 public TestResultWithValue(TestContextBase context, T instance, TValue value, bool isSuccess, DateTime startTime, DateTime endTime) : base(context, instance, isSuccess, startTime, endTime)
 {
     this.Value = value;
 }
Example #27
0
 public TestResultWithException(TestContextBase context, T instance, TException exception, DateTime startTime, DateTime endTime) : base(context, instance, exception != null, startTime, endTime)
 {
     this.Exception = exception;
 }
Example #28
0
        public void GetValue_WhenValueDoesNotExist_IsNull()
        {
            var context = new TestContextBase();

            Assert.That(context.GetValue <TestValueA>(), Is.Null);
        }