Exemplo n.º 1
0
        public void Given_CreatedVotingPairFromDictionary_When_NullDictionary_Then_Exception()
        {
            Dictionary <string, int> values = null;
            Action result = () => VotingPair.CreateFrom(values);

            Assert.ThrowsAny <ArgumentNullException>(result);
        }
Exemplo n.º 2
0
        public void Given_CreatedVotingPair_When_VotingForOne_Then_OneWinner()
        {
            var result = VotingPair.Create("C#", "F#").VoteForTopic("C#").GetWinners();

            Assert.Equal(result.Count(), 1);
            Assert.Equal(result.First(), "C#");
        }
Exemplo n.º 3
0
        public void Given_CreatedVotingPair_When_VoteForTopic_Then_NewVotingPair()
        {
            var result = VotingPair.Create("C#", "F#").VoteForTopic("C#");

            Assert.Equal(result.TopicA, ("C#", 1));
            Assert.Equal(result.TopicB, ("F#", 0));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void Given_CreatedVotingPairFromDictionary_When_OnlyTwoTopics_Then_NewVotingPair()
        {
            var result = VotingPair.CreateFrom(new Dictionary <string, int>()
            {
                { "C#", 1 },
                { "F#", 2 }
            });

            Assert.Equal(result.TopicA, ("C#", 1));
            Assert.Equal(result.TopicB, ("F#", 2));
        }
Exemplo n.º 6
0
        public void Given_CreatedVotingPairFromDictionary_When_MoreThanTwoTopics_Then_Empty()
        {
            var result = VotingPair.CreateFrom(new Dictionary <string, int>()
            {
                { "C#", 0 },
                { "F#", 1 },
                { "Haskell", 2 }
            });

            Assert.Equal(result.IsEmpty, true);
        }
Exemplo n.º 7
0
 public VotingStartedEvent(Guid votingId, string[] remainingTopics, VotingPair votingPair)
 {
     VotingId        = votingId;
     RemainingTopics = remainingTopics;
     VotingPair      = votingPair;
 }
Exemplo n.º 8
0
        public void Given_NullVotingPair_When_VoteForTopic_Then_Exception()
        {
            Action result = () => VotingPair.Create(null, null).VoteForTopic("C#");

            Assert.ThrowsAny <InvalidOperationException>(result);
        }
Exemplo n.º 9
0
        public void Given_NullVotingPair_When_GetWinners_Then_Empty()
        {
            var result = VotingPair.Create(null, null).GetWinners();

            Assert.Equal(result.Count(), 0);
        }
Exemplo n.º 10
0
        public void Given_EmptyVotingPair_When_GetWinners_Then_Empty()
        {
            var result = VotingPair.Empty().GetWinners();

            Assert.Equal(result.Count(), 0);
        }
Exemplo n.º 11
0
        public void Given_EmptyVotingPair_When_VoteForTopic_Then_Exception()
        {
            Action result = () => VotingPair.Empty().VoteForTopic("C#");

            Assert.ThrowsAny <InvalidOperationException>(result);
        }
Exemplo n.º 12
0
        public void Given_CreatedVotingPair_When_MoreThanTwoTopics_Then_Exception()
        {
            Action result = () => VotingPair.Create("C#", "F#", "Haskell");

            Assert.ThrowsAny <InvalidOperationException>(result);
        }
Exemplo n.º 13
0
        public void Given_CreatedVotingPair_When_NotEmpty_Then_IsNotEmpty()
        {
            var result = VotingPair.Create("not", "empty").IsEmpty;

            Assert.Equal(result, false);
        }
Exemplo n.º 14
0
        public void Given_CreatedVotingPair_When_Empty_Then_IsEmpty()
        {
            var result = VotingPair.Empty().IsEmpty;

            Assert.Equal(result, true);
        }
Exemplo n.º 15
0
        public async Task Given_CreatedVoting_When_StartAndVoteAndFinish_Then_SameSnapshots()
        {
            var sut = new VotingReadModelService(new FakeRepo());
            await sut.AddOrUpdate(GetCreatedEvent());

            var snapshot = await sut.AddOrUpdate(new VotingStartedEvent(votingId, new string[] { }, VotingPair.Create("C#", "F#")));

            var result = await sut.Get(votingId);

            Assert.Equal(result.Topics, snapshot.Topics);

            snapshot = await sut.AddOrUpdate(new TopicVotedEvent(votingId, "C#"));

            result = await sut.Get(votingId);

            Assert.Equal(result.Topics, snapshot.Topics);

            snapshot = await sut.AddOrUpdate(new VotingFinishedEvent(votingId, "C#"));

            result = await sut.Get(votingId);

            Assert.Equal(result.Topics, snapshot.Topics);
            Assert.Equal(result.Winner, snapshot.Winner);
        }