Пример #1
0
        public async Task GetVotesForPlaceAsyncTest()
        {
            Guid  eId = new Guid();
            Event e   = new Event {
                Id = eId
            };
            Place p1 = new Place {
                Id = new Guid("00000000-0000-0000-0000-000000000001"), EventId = eId, Event = e
            };
            Place p2 = new Place {
                Id = new Guid("00000000-0000-0000-0000-000000000002"), EventId = eId, Event = e
            };
            VoteForPlace vp1 = new VoteForPlace {
                Id = new Guid("00000000-0000-0000-0000-000000000000"), PlaceId = p1.Id, Place = p1
            };
            VoteForPlace vp2 = new VoteForPlace {
                Id = new Guid("00000000-0000-0000-0000-000000000002"), PlaceId = p1.Id, Place = p1
            };
            VoteForPlace vp3 = new VoteForPlace {
                Id = new Guid("00000000-0000-0000-0000-000000000003"), PlaceId = p2.Id, Place = p2
            };
            var tcs = new TaskCompletionSource <List <VoteForPlace> >();

            tcs.SetResult(new List <VoteForPlace> {
                vp1, vp2, vp3
            });
            _voteForPlaceRepository.Setup(mock => mock.GetAll()).Returns(tcs.Task);
            var task = await _votingService.GetVotesForPlaceAsync(eId, p1.Id);

            _voteForPlaceRepository.Verify(mock => mock.GetAll(), Times.Once(), "Method GetAll was not called or was called more than once (or its parameters were wrong).");

            CollectionAssert.AreEqual(new List <VoteForPlace> {
                vp1, vp2
            }, task.ToList(), "Returned list of votes is not correct");
        }