コード例 #1
0
        public async void RemoveElectionUnitTest()
        {
            // Arrange
            var mockElectionRepository = GetElectionRepositoryMock();
            var deleteElectionSetup    = new RemoveElectionSetup();

            var election = new Election
            {
                Id             = 1,
                Ballots        = new[] { new Ballot() },
                CreatedDate    = DateTime.Now,
                ElectionQr     = Guid.NewGuid(),
                ExpirationDate = DateTime.Now.Add(new TimeSpan(7, 0, 0, 0))
            };

            deleteElectionSetup.SetupMock(mockElectionRepository);
            var electionService = new ElectionService(mockElectionRepository.Object);

            mockElectionRepository.Verify(repo => repo.RemoveAsync(It.IsAny <Election>()), Times.AtMostOnce);

            // Act
            await electionService.RemoveAsync(election);

            // Assert

            //Verify if repository is called. see the code above
        }