public void Given_VotingSnapshot_When_CreateSnaphotFromVotingAggregate_Then_SameSnapshot() { var snapshot = new VotingSnapshot(Guid.NewGuid(), VotingPair.Empty(), string.Empty); var result = VotingAggregate.CreateFrom(snapshot).CreateSnapshot(); Assert.Equal(result.Topics, snapshot.Topics); Assert.Equal(result.Winner, snapshot.Winner); }
public async Task <Guid> Create([FromBody] string[] topics) { var voting = new VotingAggregate(); voting.CreateVoting(topics); await _repository.Save(voting); return(voting.Id); }
public void Given_NoTopics_When_CreateVoting_Then_Exception() { // Arrange var sut = new VotingAggregate(); // Act Action result = () => sut.CreateVoting(null); // Assert Assert.ThrowsAny <ArgumentNullException>(result); }
public void Given_DuplicatedTopics_When_CreateVoting_Then_Exception() { // Arrange var sut = new VotingAggregate(); var topics = new[] { "C#", "F#", "F#", "JS" }; // Act Action result = () => sut.CreateVoting(topics); // Assert Assert.ThrowsAny <InvalidOperationException>(result); }
public void Given_StartedVoting_When_VoteForNonExistingTopic_Then_Exception() { // Arrange var sut = new VotingAggregate(); sut.CreateVoting("C#", "F#"); sut.StartNextVoting(); // Act Action result = () => sut.VoteTopic("Haskell"); // Assert Assert.ThrowsAny <InvalidOperationException>(result); }
public void Given_Topics_When_CreateVoting_Then_VotingCreated() { // Arrange var sut = new VotingAggregate(); var topics = new[] { "C#", "F#", "Java", "JS" }; // Act sut.CreateVoting(topics); // Assert var result = sut.GetPendingEvents().OfType <VotingCreatedEvent>().First(); Assert.NotNull(result); Assert.Equal(result.Topics, topics); }
public void Given_CreatedVoting_WithOneTopic_When_StartVoting_Then_VotingFinished() { // Arrange var sut = new VotingAggregate(); sut.CreateVoting("C#"); // Act sut.StartNextVoting(); // Assert var result = sut.GetPendingEvents().OfType <VotingFinishedEvent>().First(); Assert.NotNull(result); Assert.Equal(result.Winner, "C#"); }
public void Given_CreatedVoting_When_StartNextVoting_Then_VotingStarted() { // Arrange var sut = new VotingAggregate(); sut.CreateVoting("C#", "F#", "VB.NET", "PowerShell"); // Act sut.StartNextVoting(); // Assert var result = sut.GetPendingEvents().OfType <VotingStartedEvent>().First(); Assert.NotNull(result); Assert.Equal(result.VotingPair.TopicA, ("C#", 0)); Assert.Equal(result.VotingPair.TopicB, ("F#", 0)); Assert.Equal(result.RemainingTopics, new[] { "VB.NET", "PowerShell" }); }
public void Given_StartedVoting_When_VoteManyTimes_Then_VotingStarted() { // Arrange var sut = new VotingAggregate(); sut.CreateVoting("C#", "F#"); sut.StartNextVoting(); // Act sut.VoteTopic("C#"); sut.VoteTopic("F#"); sut.StartNextVoting(); // Assert var result = sut.GetPendingEvents().OfType <VotingStartedEvent>().First(); Assert.NotNull(result); Assert.Equal(result.VotingPair.TopicA, ("C#", 0)); Assert.Equal(result.VotingPair.TopicB, ("F#", 0)); }