Skip to content

Instantly share code, notes, and snippets.

@JamesTryand
Created January 23, 2023 10:45
Show Gist options
  • Save JamesTryand/3ac5b5816446ea5e2cacc655aa6cfeea to your computer and use it in GitHub Desktop.
Save JamesTryand/3ac5b5816446ea5e2cacc655aa6cfeea to your computer and use it in GitHub Desktop.
example of tests in BDD style for eventsourcing library
public class DomainModelTests {
[Fact]
public void ANewModelWillHaveNoUncommittedChangesTest() {
new SimpleDomainModel().Changes().ShouldBeEmpty();
}
[Fact]
public void ANewModelDoingNothingWIllHaveNoUncommittedChanges() {
TestResult<SimpleDomainModel> test = new TestHarness<SimpleDomainModel>().
Given(TestHelpers.NoEvents).
When(TestHelpers.NothingHappensWith<SimpleDomainModel>()).
Then(
events => events.Count() == 0
);
test.Result.ShouldBeTrue(test.Message);
}
[Fact]
public void AModelWithASingleEntryTest() {
TestResult<SimpleDomainModel> test = new TestHarness<SimpleDomainModel>().
Given(new ThingamajigCreated()).
When(subject => subject.AddItem("Hello")).
Then(
events => events.Count() == 1,
events => events.First() is ItemAddedEvent
);
test.Result.ShouldBeTrue(test.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment