public void TestEventMultipleEmitSourcing_AfterManyMultiCommand_TestStateSignalled() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var test = new TestEntity(TestId.New); var testSourceId = SourceId.New; var testCommand = new AddFourTestsCommand(aggregateId, test).WithSourceId(testSourceId); var poisonCommand = new PoisonTestAggregateCommand(aggregateId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command, testCommand, poisonCommand) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectState( x => x.TestCollection.Count == 4); }
public void FixtureArrangerWithSnapshot_CanBeLoaded() { using (var testKit = new TestKit(_config, "fixture-tests-4")) { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(testKit); var aggregateIdentity = TestAggregateId.New; var snapshot = new TestAggregateSnapshot(Enumerable.Range(0, 10) .Select(x => new TestAggregateSnapshot.TestModel(Guid.NewGuid())).ToList()); var snapshotStore = Persistence.Instance.Apply(testKit.Sys).SnapshotStoreFor(null); var receiverProbe = testKit.CreateTestProbe("snapshot-probe"); var snapshotSequenceNumber = 1L; fixture .For(aggregateIdentity) .Given(snapshot, snapshotSequenceNumber); snapshotStore.Tell(new LoadSnapshot(aggregateIdentity.Value, new SnapshotSelectionCriteria(long.MaxValue, DateTime.MaxValue), long.MaxValue), receiverProbe.Ref); receiverProbe.ExpectMsg <LoadSnapshotResult>(x => x.Snapshot.Snapshot is ComittedSnapshot <TestAggregate, TestAggregateId, IAggregateSnapshot <TestAggregate, TestAggregateId> > && x.Snapshot.Metadata.SequenceNr == snapshotSequenceNumber && x.Snapshot.Metadata.PersistenceId == aggregateIdentity.Value && x.Snapshot.Snapshot .As <ComittedSnapshot <TestAggregate, TestAggregateId, IAggregateSnapshot <TestAggregate, TestAggregateId> > >().AggregateSnapshot .As <TestAggregateSnapshot>().Tests.Count == snapshot.Tests.Count && x.ToSequenceNr == long.MaxValue); } }
public void FixtureArrangerWithEvents_CanBeReplayed() { using (var testKit = new TestKit(_config, "fixture-tests-3")) { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(testKit); var aggregateIdentity = TestAggregateId.New; var events = new List <IAggregateEvent <TestAggregate, TestAggregateId> >(); events.Add(new TestCreatedEvent(aggregateIdentity)); events.AddRange(Enumerable.Range(0, 10).Select(x => new TestAddedEvent(new Test(TestId.New)))); var journal = Persistence.Instance.Apply(testKit.Sys).JournalFor(null); var receiverProbe = testKit.CreateTestProbe("journal-probe"); fixture .For(aggregateIdentity) .Given(events.ToArray()); journal.Tell(new ReplayMessages(1, long.MaxValue, long.MaxValue, aggregateIdentity.ToString(), receiverProbe.Ref)); var from = 1; foreach (var _ in events) { var index = from; receiverProbe.ExpectMsg <ReplayedMessage>(x => x.Persistent.SequenceNr == index && x.Persistent.Payload is ICommittedEvent <TestAggregate, TestAggregateId, IAggregateEvent <TestAggregate, TestAggregateId> >); from++; } receiverProbe.ExpectMsg <RecoverySuccess>(); } }
public void TestCommandTwice_AfterAggregateCreation_TestEventEmitted() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var testId = TestId.New; var test = new TestEntity(testId); var nextCommandId = SourceId.New; var nextCommand = new AddTestCommand(aggregateId, test).WithSourceId(nextCommandId); var test2Id = TestId.New; var test2 = new TestEntity(test2Id); var nextCommandId2 = SourceId.New; var nextCommand2 = new AddTestCommand(aggregateId, test2).WithSourceId(nextCommandId2); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command, nextCommand, nextCommand2) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>( x => x.AggregateEvent.Test.Equals(test)) .ThenExpectDomainEvent <TestAddedEvent>( x => x.AggregateEvent.Test.Equals(test2)); }
public void With_Test_Kit_InitialSnapshot_After_TestCreatedEventEmitted() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; fixture .For(aggregateId) .Given(new TestAggregateSnapshot(Enumerable.Range(0, 10).Select(x => new TestAggregateSnapshot.TestModel(Guid.NewGuid())).ToList()), 10) .When(new PublishTestStateCommand(aggregateId)) .ThenExpect <TestStateSignalEvent>(x => x.AggregateState.FromHydration); }
public void With_Test_Kit_InitialState_AfterAggregateCreation_TestCreatedEventEmitted() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; fixture .For(aggregateId) .GivenNothing() .When(new CreateTestCommand(aggregateId)) .ThenExpect <TestCreatedEvent>(x => x.TestAggregateId == aggregateId); }
public void With_Test_Kit_InitialCommand_AfterAggregateCreation_TestCreatedEventEmitted() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; var testId = TestId.New; fixture .For(aggregateId) .Given(new CreateTestCommand(aggregateId)) .When(new AddTestCommand(aggregateId, new Test(testId))) .ThenExpect <TestAddedEvent>(x => x.Test.Id == testId); }
public void InitialState_TestingForbidden3() { var aggregateId = TestAggregateId.New; var command = new TestForbiddenCommand(aggregateId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenUser("test", "Test User", new [] { "Admin" }) .When(command) .ThenExpectResult(r => r.Should().BeEquivalentTo(Result.Success).And.Ok()); }
public void InitialState_TestingForbidden2() { var aggregateId = TestAggregateId.New; var command = new TestForbiddenCommand2(aggregateId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectResult(r => r.Should().BeOfType <ForbiddenResult>().And.Ok()); }
public void FixtureArrangerWithIdentity_CreatesAggregateRef() { //TODO - https://dev.azure.com/lutando/EventFly/_workitems/edit/23/ using var testKit = new TestKit(Configuration.Default, "fixture-tests-1"); var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(testKit); var aggregateIdentity = TestAggregateId.New; fixture .For(aggregateIdentity) .GivenNothing(); fixture.AggregateId.Should().Be(aggregateIdentity); }
public void With_Test_Kit_TestCommand_AfterAggregateCreation_TestEventEmitted() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; var testId = TestId.New; var test = new Test(testId); fixture .For(aggregateId) .GivenNothing() .When(new CreateTestCommand(aggregateId), new AddTestCommand(aggregateId, test)) .ThenExpect <TestAddedEvent>(x => x.Test.Equals(test)); }
public void InitialState_TestingBadCommand_SuccessResultReplied() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new BadCommand(aggregateId).WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectResult(r => !r.IsSuccess); }
public void With_Test_Kit_InitialState_AfterAggregateCreation_TestStateSignalled() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; fixture .For(aggregateId) .GivenNothing() .When(new CreateTestCommand(aggregateId), new PublishTestStateCommand(aggregateId)) .ThenExpectDomainEvent <TestStateSignalEvent>( x => x.AggregateEvent.LastSequenceNr == 1 && x.AggregateEvent.Version == 1 && x.AggregateEvent.AggregateState.TestCollection.Count == 0); }
public void SendingCommand_ToAggregateRoot_ShouldReplyWithProperMessage() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectResult(result => result.IsSuccess); }
public void InitialState_AfterAggregateCreation_TestCreatedEventEmitted() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectDomainEvent <TestCreatedEvent>( x => x.AggregateEvent.Id.Equals(aggregateId) && x.Metadata.ContainsKey("some-key")); }
public void FixtureArrangerWithIdentity_CreatesAggregateRef() { //Issue - https://dev.azure.com/lutando/Akkatecture/_workitems/edit/23/ using (var testKit = new TestKit(_config, "fixture-tests-1")) { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(testKit); var aggregateIdentity = TestAggregateId.New; fixture .For(aggregateIdentity) .GivenNothing(); fixture.AggregateRef.Path.Name.Should().Be(aggregateIdentity.Value); fixture.AggregateId.Should().Be(aggregateIdentity); } }
public void InitialState_AfterAggregateCreation_TestStateSignalled() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectState( x => x.TestCollection.Count == 0); }
public void With_Test_Kit_EventContainerMetadata_AfterAggregateCreation_TestCreatedEventEmitted() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; fixture .For(aggregateId) .GivenNothing() .When(new CreateTestCommand(aggregateId)) .ThenExpectDomainEvent <TestCreatedEvent>( x => x.AggregateIdentity.Equals(aggregateId) && x.IdentityType == typeof(TestAggregateId) && x.AggregateType == typeof(TestAggregate) && x.EventType == typeof(TestCreatedEvent) && x.Metadata.EventName == "TestCreated" && x.Metadata.AggregateId == aggregateId.Value && x.Metadata.EventVersion == 1 && x.Metadata.AggregateSequenceNumber == 1); }
public void TestEventMultipleEmitSourcing_AfterManyMultiCreateCommand_EventsEmitted() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var firstTest = new TestEntity(TestId.New); var secondTest = new TestEntity(TestId.New); var command = new CreateAndAddTwoTestsCommand(aggregateId, firstTest, secondTest) .WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>(); }
public void TestCommandTwice_AfterAggregateCreation_TestEventEmitted() { var fixture = new AggregateFixture <TestAggregate, TestAggregateId>(this); var aggregateId = TestAggregateId.New; var commandId = CommandId.New; var commandId2 = CommandId.New; var commandId3 = CommandId.New; var testId = TestId.New; var test = new Test(testId); var test2Id = TestId.New; var test2 = new Test(test2Id); fixture .For(aggregateId) .GivenNothing() .When(new CreateTestCommand(aggregateId, commandId), new AddTestCommand(aggregateId, commandId2, test), new AddTestCommand(aggregateId, commandId3, test2)) .ThenExpectDomainEvent <TestAddedEvent>(x => x.AggregateEvent.Test.Equals(test) && x.AggregateSequenceNumber == 2) .ThenExpectDomainEvent <TestAddedEvent>(x => x.AggregateEvent.Test.Equals(test2) && x.AggregateSequenceNumber == 3); }
public void EventContainerMetadata_AfterAggregateCreation_TestCreatedEventEmitted() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new CreateTestCommand(aggregateId).WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectDomainEvent <TestCreatedEvent>( x => x.AggregateEvent.Id.Equals(aggregateId) && x.IdentityType == typeof(TestAggregateId) && x.EventType == typeof(TestCreatedEvent) && x.Metadata.EventName == "TestCreated" && x.Metadata.EventVersion == 1 && x.Metadata.SourceId.Value == commandId.Value); }
public void TestEventSourcing_AfterManyTests_TestStateSignalled() { IEnumerable <ICommand> GetCommands(TestAggregateId testAggregateId, ISourceId commandId1) { var command = new CreateTestCommand(testAggregateId).WithSourceId(commandId1); yield return(command); for (var i = 0; i < 5; i++) { var test = new TestEntity(TestId.New); var testCommandId = SourceId.New; var testCommand = new AddTestCommand(testAggregateId, test).WithSourceId(testCommandId); yield return(testCommand); } var poisonCommand = new PoisonTestAggregateCommand(testAggregateId); yield return(poisonCommand); } var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(GetCommands(aggregateId, commandId).ToArray()) .ThenExpectDomainEvent <TestCreatedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectDomainEvent <TestAddedEvent>() .ThenExpectState( x => x.TestCollection.Count == 5); }
public void UpdateMemoTest() { //Создаем заготовку для теста var fixture = new AggregateFixture <MemoId, MemoAggregate, IMemoState, MemoState>(this); var id = MemoId.New; //Параметры документа var docId = Guid.NewGuid().ToString(); var docNumber = new DocumentNumber("100"); var docAddress = new Address("12700", "Россия", "Москва", "проспект Мира", "1"); //BDD тест (сценарий) fixture.For(id) //Допустим (предусловия) .GivenNothing() //Когда (тестируемые действия) .When(new UpdateMemo(id, new MemoDocument(docId, docNumber, docAddress))) //Тогда (проверка результатов) .ThenExpectResult(e => e.IsSuccess) .ThenExpectDomainEvent <MemoUpdated>(e => e.AggregateEvent.Id == id && e.AggregateEvent.Document != null && e.AggregateEvent.Document.Id == docId && e.AggregateEvent.Document.Number == docNumber && e.AggregateEvent.Document.CustomerAddress == docAddress) .ThenExpectState(s => s.Status == MemoStatus.Undefined && s.Document != null && s.Document.Id == docId && s.Document.Number == docNumber && s.Document.CustomerAddress == docAddress); }