Exemplo n.º 1
0
        public async Task Status_JobWithStatusResult_ReturnsStatusResult()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            var fakeServiceScope = Substitute.For <IServiceScope>();

            var fakeServiceProvider = Substitute.For <IServiceProvider>();

            fakeServiceProvider
            .GetService(typeof(IMediator))
            .Returns(fakeMediator);

            fakeServiceScope.ServiceProvider.Returns(fakeServiceProvider);

            var fakeProvisioningStateFlow = Substitute.For <IProvisioningStateFlow>();

            var provisioningJob = new ProvisioningJob(
                fakeProvisioningStateFlow,
                fakeServiceScope)
            {
                Exception = new StateUpdateException("dummy", new ConflictResult())
            };
            await provisioningJob.InitializeAsync();

            var fakeProvisioningService = Substitute.For <IProvisioningService>();

            fakeProvisioningService
            .GetJobByIdAsync("some-job-id")
            .Returns(provisioningJob);

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new JobsController(
                mapper,
                fakeProvisioningService);

            //Act
            var status = await controller.Status("some-job-id");

            //Assert
            Assert.IsNotNull(status);
            Assert.AreEqual(StatusCodes.Status409Conflict, status.GetStatusCode());
        }
Exemplo n.º 2
0
        public async Task Initialize_FlowGiven_SetsInitialStateFromFlow()
        {
            //Arrange
            var fakeInitialState = Substitute.For <IProvisioningState>();

            var fakeFlow = Substitute.For <IProvisioningStateFlow>();

            fakeFlow
            .GetInitialStateAsync(Arg.Any <InitialStateContext>())
            .Returns(fakeInitialState);

            var provisioningJob = new ProvisioningJob(
                fakeFlow,
                Substitute.For <IServiceScope>());

            //Act
            await provisioningJob.InitializeAsync();

            //Assert
            Assert.AreSame(provisioningJob.CurrentState, fakeInitialState);
        }
Exemplo n.º 3
0
        public async Task Status_JobExists_ReturnsJobStatus()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            var fakeServiceScope = Substitute.For <IServiceScope>();

            var fakeServiceProvider = Substitute.For <IServiceProvider>();

            fakeServiceProvider
            .GetService(typeof(IMediator))
            .Returns(fakeMediator);

            fakeServiceScope.ServiceProvider.Returns(fakeServiceProvider);

            var fakeProvisioningStateFlow = Substitute.For <IProvisioningStateFlow>();

            var provisioningJob = new ProvisioningJob(
                fakeProvisioningStateFlow,
                fakeServiceScope);
            await provisioningJob.InitializeAsync();

            var fakeProvisioningService = Substitute.For <IProvisioningService>();

            fakeProvisioningService
            .GetJobByIdAsync("some-job-id")
            .Returns(provisioningJob);

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new JobsController(
                mapper,
                fakeProvisioningService);

            //Act
            var status = await controller.Status("some-job-id");

            //Assert
            Assert.IsNotNull(status);
        }
Exemplo n.º 4
0
        public async Task Initialize_FlowGiven_CallsInitializeOnInitialState()
        {
            //Arrange
            var fakeInitialState = Substitute.For <IProvisioningState>();

            var fakeFlow = Substitute.For <IProvisioningStateFlow>();

            fakeFlow
            .GetInitialStateAsync(Arg.Any <InitialStateContext>())
            .Returns(fakeInitialState);

            var provisioningJob = new ProvisioningJob(
                fakeFlow,
                Substitute.For <IServiceScope>());

            //Act
            await provisioningJob.InitializeAsync();

            //Assert
            await fakeInitialState
            .Received(1)
            .InitializeAsync();
        }