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); }
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); }
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); }
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); }