Exemplo n.º 1
0
        public Task <IExecutionResult> Execute(ReceiveTestCommand command)
        {
            if (!IsNew)
            {
                Emit(new TestReceivedEvent(command.SenderAggregateId, command.TestToReceive));
                Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult(ExecutionResult.Success()));
        }
Exemplo n.º 2
0
        public Task <IExecutionResult> Execute(AddTestCommand command)
        {
            if (!IsNew)
            {
                Emit(new TestAddedEvent(command.Test));
                Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult((IExecutionResult) new SuccessTestExecutionResult(command.Metadata.SourceId)));
        }
Exemplo n.º 3
0
        public Task <IExecutionResult> Execute(CreateTestCommand command)
        {
            if (IsNew)
            {
                Emit(new TestCreatedEvent(command.AggregateId), new EventMetadata {
                    { "some-key", "some-value" }
                });
                Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult((IExecutionResult) new SuccessTestExecutionResult(command.Metadata.SourceId)));
        }
Exemplo n.º 4
0
        public Task <IExecutionResult> Execute(CreateAndAddTwoTestsCommand command)
        {
            if (IsNew)
            {
                var createdEvent         = new TestCreatedEvent(command.AggregateId);
                var firstTestAddedEvent  = new TestAddedEvent(command.FirstTest);
                var secondTestAddedEvent = new TestAddedEvent(command.SecondTest);
                EmitAll(createdEvent, firstTestAddedEvent, secondTestAddedEvent);
                Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult(ExecutionResult.Success()));
        }
Exemplo n.º 5
0
        public Task <IExecutionResult> Execute(GiveTestCommand command)
        {
            if (!IsNew)
            {
                if (State.TestCollection.Any(x => x.Id == command.TestToGive.Id))
                {
                    Emit(new TestSentEvent(command.TestToGive, command.ReceiverAggregateId));
                    Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId));
                }
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult(ExecutionResult.Success()));
        }
Exemplo n.º 6
0
        public Task <IExecutionResult> Execute(AddFourTestsCommand command)
        {
            if (!IsNew)
            {
                var events = Enumerable.Range(0, 4).Select(x => new TestAddedEvent(command.Test));

                // ReSharper disable once CoVariantArrayConversion
                EmitAll(events.ToArray());
                Reply(TestExecutionResult.SucceededWith(command.Metadata.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.Metadata.SourceId));
            }

            return(Task.FromResult(ExecutionResult.Success()));
        }