Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Competition" /> class.
 /// </summary>
 public Competition()
 {
     CreatedDate = DateTime.Now;
     PossibleAnswers = new PossibleAnswers();
     State = new OpenState();
     _entrants = new List<Entrant>();
 }
        public void PickWinnerWithNoCorrectAnswers()
        {
            // Arrange
            Competition competition = Stubs.StubCompetition(includeCorrectAnswers: false);
            var competitionState = new OpenState();
            WinnerSelectedEvent winnerSelectedEvent = null;
            DomainEvents.Register<WinnerSelectedEvent>(evt => winnerSelectedEvent = evt);

            // Act
            competitionState.PickWinner(competition);

            // Assert
            Assert.IsNull(winnerSelectedEvent.Competition.Winner);
            Assert.AreEqual(CompetitionStatus.Closed, competition.State.Status);
        }
        public void PickWinnerWhenTheCloseDateHasNotPassed()
        {
            // Arrange
            Competition competition = Stubs.StubCompetition(includeCorrectAnswers: false);
            competition.ClosingDate = DateTime.Now.AddMonths(1); // always ensure the data is in the future

            var competitionState = new OpenState();
            WinnerSelectedEvent winnerSelectedEvent = null;
            DomainEvents.Register<WinnerSelectedEvent>(evt => winnerSelectedEvent = evt);

            // Act
            competitionState.PickWinner(competition);

            // Assert
            Assert.IsNull(winnerSelectedEvent);
            Assert.AreEqual(CompetitionStatus.Open, competition.State.Status);
        }