예제 #1
0
        public async Task EstimateEventByParticipantAsyncSuccessTest()
        {
            //Arrange
            var estimate    = 1.0;
            var collection  = new List <Participant>();
            var participant = new Participant {
                UserId = "1", EventId = 1
            };

            _repoWrapper.Setup(x => x.Participant.GetFirstAsync(It.IsAny <Expression <Func <Participant, bool> > >(), null))
            .ReturnsAsync(participant);
            participant.Estimate = estimate;
            _repoWrapper.Setup(x => x.Participant.Update(participant));
            _repoWrapper.Setup(x => x.SaveAsync());
            _repoWrapper.Setup(x => x.Participant.GetAllAsync(a => a.UserId == participant.UserId, null))
            .ReturnsAsync(collection);
            var eventRating = Math.Round(collection.Sum(p => p.Estimate) / collection.Count(), 2, MidpointRounding.AwayFromZero);

            //Act
            var participantManager = new ParticipantManager(_repoWrapper.Object, _eventStatusManager.Object, _participantStatusManager.Object);
            var methodResult       = await participantManager.EstimateEventByParticipantAsync(participant.EventId, participant.UserId, estimate);

            //Assert
            Assert.Equal(eventRating, methodResult);
        }
예제 #2
0
        public async Task ChangeStatusToRejectedSuccessTest()
        {
            //Arrange
            int participantId     = 1;
            int participantStatus = 3;
            var participant       = new Participant {
                ID = 1, ParticipantStatusId = 2, EventId = 1, UserId = "abc-1"
            };
            var testEvent = new Event {
                ID = 1, EventStatusID = 1
            };

            _repoWrapper.Setup(x => x.Participant.GetFirstAsync(It.IsAny <Expression <Func <Participant, bool> > >(), null))
            .ReturnsAsync(participant);
            _repoWrapper.Setup(x => x.Event.GetFirstAsync(It.IsAny <Expression <Func <Event, bool> > >(), null)).ReturnsAsync(testEvent);
            _participantStatusManager.Setup(x => x.GetStatusIdAsync(It.IsAny <string>()))
            .ReturnsAsync(participantStatus);
            //Act
            var participantManager = new ParticipantManager(_repoWrapper.Object, _eventStatusManager.Object, _participantStatusManager.Object);
            var methodResult       = await participantManager.ChangeStatusToRejectedAsync(participantId);

            //Assert
            _repoWrapper.Verify(r => r.Participant.Update(It.IsAny <Participant>()), Times.Once());
            _repoWrapper.Verify(r => r.SaveAsync(), Times.Once());
            Assert.Equal(StatusCodes.Status200OK, methodResult);
        }
예제 #3
0
        public async Task GetParticipantsByUserIdAsyncSuccessTest()
        {
            //Arrange
            var collection  = new List <Participant>();
            var participant = new Participant {
                UserId = "1", Event = new Event()
            };

            _repoWrapper.Setup(x => x.Participant.GetAllAsync(a => a.UserId == participant.UserId, null))
            .ReturnsAsync(collection);

            //Act
            var participantManager = new ParticipantManager(_repoWrapper.Object, _eventStatusManager.Object, _participantStatusManager.Object);
            var methodResult       = await participantManager.GetParticipantsByUserIdAsync(participant.UserId);

            //Assert
            Assert.Equal(collection, methodResult);
        }
예제 #4
0
        public async Task ChangeStatusToRejectedFailStatusidTest()
        {
            //Arrange
            int participantId     = 1;
            int participantStatus = 3;
            var participant       = new Participant {
                ID = 1, ParticipantStatusId = 3, EventId = 1, UserId = "abc-1"
            };
            var testEvent = new Event {
                ID = 1, EventStatusID = 1
            };

            _repoWrapper.Setup(x => x.Participant.GetFirstAsync(It.IsAny <Expression <Func <Participant, bool> > >(), null))
            .ReturnsAsync(participant);
            _repoWrapper.Setup(x => x.Event.GetFirstAsync(It.IsAny <Expression <Func <Event, bool> > >(), null)).ReturnsAsync(testEvent);
            _participantStatusManager.Setup(x => x.GetStatusIdAsync(It.IsAny <string>()))
            .ReturnsAsync(participantStatus);
            //Act
            var participantManager = new ParticipantManager(_repoWrapper.Object, _eventStatusManager.Object, _participantStatusManager.Object);
            var methodResult       = await participantManager.ChangeStatusToRejectedAsync(participantId);

            //Assert
            Assert.Equal(StatusCodes.Status409Conflict, methodResult);
        }