Пример #1
0
        public async Task GetTotalNumberOfVotersForEventTest()
        {
            Guid  eId = new Guid();
            Event e   = new Event {
                Id = eId
            };
            VoteForPlace vp1 = new VoteForPlace {
                Id = new Guid("00000000-0000-0000-0000-000000000000"), UserId = "0"
            };
            VoteForPlace vp2 = new VoteForPlace {
                Id = new Guid("00000000-0000-0000-0000-000000000001"), UserId = "1"
            };
            Place p1 = new Place {
                Id = new Guid("00000000-0000-0000-0000-000000000000"), Event = e, EventId = eId, VotesForPlace = new List <VoteForPlace> {
                    vp1, vp2
                }
            };
            Place p2 = new Place {
                Id = new Guid("00000000-0000-0000-0000-000000000001"), Event = e, EventId = eId
            };
            List <Place> places = new List <Place> {
                p1, p2
            };
            VoteForDate vd1 = new VoteForDate {
                Id = new Guid("00000000-0000-0000-0000-000000000000"), UserId = "1"
            };
            VoteForDate vd2 = new VoteForDate {
                Id = new Guid("00000000-0000-0000-0000-000000000001"), UserId = "2"
            };
            TimeSlot t1 = new TimeSlot {
                Id = new Guid("00000000-0000-0000-0000-000000000000"), Event = e, EventId = eId, VotesForDate = new List <VoteForDate> {
                    vd1, vd2
                }
            };
            TimeSlot t2 = new TimeSlot {
                Id = new Guid("00000000-0000-0000-0000-000000000001"), Event = e, EventId = eId
            };
            List <TimeSlot> timeslots = new List <TimeSlot> {
                t1, t2
            };
            var tcs1 = new TaskCompletionSource <IList <Place> >();

            tcs1.SetResult(places);
            var tcs2 = new TaskCompletionSource <IList <TimeSlot> >();

            tcs2.SetResult(timeslots);

            _eventDetailsService.Setup(mock => mock.GetPlacesWithVotes(eId)).Returns(tcs1.Task);
            _eventDetailsService.Setup(mock => mock.GetDatesWithVotes(eId)).Returns(tcs2.Task);
            var task = await _votingService.GetTotalNumberOfVotersForEvent(eId);

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

            Assert.AreEqual(3, task, "Returned number of voters is different to the actual value");
        }