public void Upcasting_UnsupportedEvent_ThrowsException()
        {
            var aggregateEventUpcaster = new TestAggregateEventUpcaster();
            var aggregateEvent         = new TestAddedEvent(Test.New);

            this.Invoking(test => aggregateEventUpcaster.Upcast(aggregateEvent))
            .Should().Throw <ArgumentException>();
        }
Example #2
0
        public void InstantiatingDomainEvent_WithNullMetadata_ThrowsException()
        {
            var aggregateSequenceNumber = 3;
            var aggregateId             = TestAggregateId.New;
            var entityId       = TestId.New;
            var entity         = new Test(entityId);
            var aggregateEvent = new TestAddedEvent(entity);
            var now            = DateTimeOffset.UtcNow;

            this.Invoking(test => new DomainEvent <TestAggregateId, TestAddedEvent>(
                              aggregateId,
                              aggregateEvent,
                              null,
                              now,
                              aggregateSequenceNumber))
            .Should().Throw <ArgumentNullException>().And.Message.Contains("metadata").Should().BeTrue();
        }
Example #3
0
        public bool 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.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.SourceId));
            }

            return(true);
        }
Example #4
0
        public async Task <Result> Do(CreateAndAddTwoTestsCommand command)
        {
            if (IsNew)
            {
                var createdEvent         = new TestCreatedEvent(command.Id);
                var firstTestAddedEvent  = new TestAddedEvent(command.Id, command.FirstTest);
                var secondTestAddedEvent = new TestAddedEvent(command.Id, command.SecondTest);
                await Emit(createdEvent);
                await Emit(firstTestAddedEvent);
                await Emit(secondTestAddedEvent);

                return(Result.Success);
            }

            TestErrors++;
            await Emit(new TestedErrorEvent(Id, TestErrors));

            return(Result.Fail("TestedErrorEvent"));
        }
Example #5
0
        public void InstantiatingCommittedEvent_WithNullMetadata_ThrowsException()
        {
            var aggregateSequenceNumber = 3;
            var aggregateId             = TestAggregateId.New;
            var entityId       = TestId.New;
            var entity         = new Test(entityId);
            var aggregateEvent = new TestAddedEvent(entity);
            var now            = DateTimeOffset.UtcNow;
            var eventId        = EventId.NewDeterministic(
                GuidFactories.Deterministic.Namespaces.Events,
                $"{aggregateId.Value}-v{aggregateSequenceNumber}");

            this.Invoking(test =>
                          new CommittedEvent <TestAggregate, TestAggregateId, TestAddedEvent>(
                              aggregateId,
                              aggregateEvent,
                              null,
                              now,
                              aggregateSequenceNumber))
            .Should().Throw <ArgumentNullException>().And.Message.Contains("metadata");
        }
Example #6
0
        private bool Execute(CreateAndAddTwoTestsCommand command)
        {
            if (IsNew)
            {
                var createdEvent         = new TestCreatedEvent(command.AggregateId);
                var firstTestAddedEvent  = new TestAddedEvent(command.FirstTest);
                var secondTestAddedEvent = new TestAddedEvent(command.SecondTest);
                var events = Events(createdEvent, firstTestAddedEvent, secondTestAddedEvent);
                //EmitAll(events, new Metadata {{"some-key","some-value"}});
                EmitAll(createdEvent, firstTestAddedEvent, secondTestAddedEvent);
                Reply(TestExecutionResult.SucceededWith(command.SourceId));
            }
            else
            {
                TestErrors++;
                Throw(new TestedErrorEvent(TestErrors));
                ReplyFailure(TestExecutionResult.FailedWith(command.SourceId));
            }

            return(true);
        }
Example #7
0
        public void CommittedEvent_WhenTagged_ContainsAggregateEventAsTaggedElement()
        {
            var aggregateEventTagger    = new AggregateEventTagger();
            var aggregateSequenceNumber = 3;
            var aggregateId             = TestAggregateId.New;
            var entityId       = TestId.New;
            var entity         = new Test(entityId);
            var aggregateEvent = new TestAddedEvent(entity);
            var now            = DateTimeOffset.UtcNow;
            var eventId        = EventId.NewDeterministic(
                GuidFactories.Deterministic.Namespaces.Events,
                $"{aggregateId.Value}-v{3}");
            var eventMetadata = new Metadata
            {
                Timestamp = now,
                AggregateSequenceNumber = aggregateSequenceNumber,
                AggregateName           = typeof(TestAggregate).GetAggregateName().Value,
                AggregateId             = aggregateId.Value,
                EventId = eventId
            };
            var committedEvent =
                new CommittedEvent <TestAggregate, TestAggregateId, TestAddedEvent>(
                    aggregateId,
                    aggregateEvent,
                    eventMetadata,
                    now,
                    aggregateSequenceNumber);

            var taggedEvent = aggregateEventTagger.ToJournal(committedEvent);

            if (taggedEvent is Tagged a)
            {
                a.Tags.Should().Contain("TestAdded");
            }
            else
            {
                false.Should().BeTrue();
            }
        }
Example #8
0
        public void InstantiatingCommittedEvent_WithDefaultTimeOffset_ThrowsException()
        {
            var aggregateSequenceNumber = 3;
            var aggregateId             = TestAggregateId.New;
            var entityId       = TestId.New;
            var entity         = new Test(entityId);
            var aggregateEvent = new TestAddedEvent(entity);
            var now            = DateTimeOffset.UtcNow;
            var eventId        = EventId.NewDeterministic(GuidFactories.Deterministic.Namespaces.Events, $"{aggregateId.Value}-v{aggregateSequenceNumber}");

            var eventMetadata = new EventMetadata
            {
                Timestamp = now,
                AggregateSequenceNumber = aggregateSequenceNumber,
                AggregateName           = typeof(TestAggregate).GetAggregateName().Value,
                AggregateId             = aggregateId.Value,
                EventId = eventId
            };

            this.Invoking(test => new CommittedEvent <TestAggregateId, TestAddedEvent>(
                              aggregateId,
                              aggregateEvent,
                              eventMetadata,
 public void Apply(TestAddedEvent aggregateEvent)
 {
     TestCollection.Add(aggregateEvent.Test);
 }
 public TestAddedEventV2 Upcast(TestAddedEvent aggregateEvent)
 {
     return(new TestAddedEventV2(aggregateEvent.Test, "default upcasted string"));
 }