Exemplo n.º 1
0
        public void Preserve_given_precomputed_results()
        {
            // Arrange
            var result            = new WorkItemResult(WorkStatus.Successful);
            var preComputedResult = new [] { DummyData };
            var testBatch         = new TestWorkBatch(BatchId);
            var workBatch         = new WorkBatch(1, testBatch, preComputedResult);

            // Act
            workBatch.DoFinally(result, CancellationToken.None);

            // Assert
            testBatch.Result.Data.Should().Contain(DummyData);
        }
Exemplo n.º 2
0
        public void Fail_when_workitems_failed()
        {
            // Arrange
            var results   = _failedBatch;
            var testBatch = new TestWorkBatch(BatchId);
            var workBatch = new WorkBatch(results.Length, testBatch);

            // Act
            foreach (var result in results)
            {
                workBatch.DoFinally(result, CancellationToken.None);
            }

            // Assert
            testBatch.Result.Status.Should().Be(WorkStatus.Failed);
        }
Exemplo n.º 3
0
        public void Execute_doFinally_only_once(bool successful)
        {
            // Arrange
            var results   = successful ? _successfulBatch :_failedBatch;
            var testBatch = new TestWorkBatch(BatchId);
            var workBatch = new WorkBatch(results.Length, testBatch);

            // Act
            foreach (var result in results)
            {
                workBatch.DoFinally(result, CancellationToken.None);
            }

            // Assert
            testBatch.Executions.Should().Be(1);
        }
Exemplo n.º 4
0
        public void Store_results(bool successful)
        {
            // Arrange
            var results   = successful ? _successfulBatch : _failedBatch;
            var testBatch = new TestWorkBatch(BatchId);
            var workBatch = new WorkBatch(results.Length, testBatch);

            // Act
            foreach (var result in results)
            {
                workBatch.DoFinally(result, CancellationToken.None);
            }

            // Assert
            testBatch.Result.Data.Should()
            .Contain(results.Where(x => x.Data != null)
                     .Select(y => y.Data.Cast <string>().First()));
        }
Exemplo n.º 5
0
        public void Error_when_trying_to_add_a_result_to_a_completed_batch()
        {
            // Arrange
            var results = new[]
            {
                new WorkItemResult(WorkStatus.Successful),
                new WorkItemResult(WorkStatus.Failed),
                new WorkItemResult(WorkStatus.Successful)
            };
            var testBatch = new TestWorkBatch(BatchId);
            var workBatch = new WorkBatch(results.Length, testBatch);

            foreach (var result in results)
            {
                workBatch.DoFinally(result, CancellationToken.None);
            }

            Action addToClosedBatch = () => workBatch.DoFinally(new WorkItemResult(WorkStatus.Successful), CancellationToken.None);

            // Act & Assert
            addToClosedBatch.ShouldThrow <ApplicationException>();
        }