Example #1
0
        public Bootstrapper(ILogger <Bootstrapper> logger, IEnumerable <IInitializer> initializers, IInitializersValidator validator, IProcessConstructor builder)
        {
            Logger = logger ?? throw new ArgumentNullException(nameof(logger));
            var immutableInitializers = initializers?.ToImmutableArray() ?? throw new ArgumentNullException(nameof(initializers));

            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }

            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var result = validator.Validate(immutableInitializers);

            if (!result.IsValid)
            {
                throw new ValidationException(result);
            }

            AdditionalTime = TimeSpan.FromSeconds(5);

            StartProcess = new Lazy <IProcess>(() => builder.BuildStartupProcess(immutableInitializers));
            StopProcess  = new Lazy <IProcess>(() => builder.BuildShutdownProcess(immutableInitializers));
        }
Example #2
0
        public async Task BeginStartupAsync_StopIsRunning_ExceptionThrown()
        {
            // arrange
            var shutdownProcess = A.Fake <IProcess>();

            A.CallTo(() => _fakeProcessConstructor.BuildShutdownProcess(A <IReadOnlyCollection <IInitializer> > ._)).Returns(shutdownProcess);
            var canEnd    = new TaskCompletionSource <bool>();
            var isStarted = new TaskCompletionSource <bool>();

            A.CallTo(() => shutdownProcess.RunAsync(CancellationToken.None)).ReturnsLazily(() =>
            {
                isStarted.SetResult(true);
                return(canEnd.Task);
            });

            await _sut.BeginStartupAsync(CancellationToken.None);

            // act
            var stopTask = Task.Factory.StartNew(async() => await _sut.BeginShutdownAsync(CancellationToken.None), TaskCreationOptions.LongRunning);
            await isStarted.Task;
            var sutMethod = _sut.BeginStartupAsync(CancellationToken.None);

            // assert
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await sutMethod);

            //// finishing the stop method so no task are left running after all tests are finished
            canEnd.SetResult(true);
            await stopTask;
        }
Example #3
0
        public BootstrapperTests()
        {
            _fakeProcess            = A.Fake <IProcess>();
            _fakeProcessConstructor = A.Fake <IProcessConstructor>();
            A.CallTo(() => _fakeProcessConstructor.BuildStartupProcess(A <IReadOnlyCollection <IInitializer> > ._)).Returns(_fakeProcess);
            A.CallTo(() => _fakeProcessConstructor.BuildShutdownProcess(A <IReadOnlyCollection <IInitializer> > ._)).Returns(_fakeProcess);

            _fixture = new Fixture();
            _fixture.Customize(new AutoFakeItEasyCustomization {
                ConfigureMembers = true
            });
            _fixture.Inject(_fakeProcessConstructor);
            _sut = _fixture.Create <Bootstrapper>();
        }