Ejemplo n.º 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));
        }
Ejemplo n.º 2
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>();
        }
Ejemplo n.º 3
0
        public async Task StartBeginShutdownAsync_ProcessSupplied(Func <Bootstrapper, Task <bool> > testDelegate, bool shouldBeStared)
        {
            // arrange
            if (shouldBeStared)
            {
                await _sut.BeginStartupAsync(CancellationToken.None);
            }

            var processToRun = A.Fake <IProcess>();

            A.CallTo(() => processToRun.RunAsync(CancellationToken.None))
            .Returns(Task.CompletedTask);

            A.CallTo(() => _fakeProcessConstructor.BuildStartupProcess(A <IReadOnlyCollection <IInitializer> > ._))
            .Returns(processToRun);

            // act
            var result = await testDelegate(_sut);

            // assert
            Assert.True(result);
        }