public async Task HandleShouldReturnOk() { // Arrange var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <OperatorModel> >(It.IsAny <object>())).Returns(new List <OperatorModel>()); var mapper = mapperMock.Object; var teamReadRepositoryMock = new Mock <ITeamReadRepository>(); teamReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(new List <Team>() as IEnumerable <Team>)); var teamReadRepository = teamReadRepositoryMock.Object; var operatorReadRepository = new Mock <IOperatorReadRepository>().Object; var query = new ListTeamQuery(null, null, null); var handler = new ListTeamQueryHandler(mapper, teamReadRepository, operatorReadRepository); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result <TeamsModel>)); }
public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs() { // Arrange var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <OperatorModel> >(It.IsAny <object>())).Returns(new List <OperatorModel>()); var mapper = mapperMock.Object; var teamReadRepositoryMock = new Mock <ITeamReadRepository>(); teamReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>(); var teamReadRepository = teamReadRepositoryMock.Object; var operatorReadRepository = new Mock <IOperatorReadRepository>().Object; var query = new ListTeamQuery(null, null, null); var handler = new ListTeamQueryHandler(mapper, teamReadRepository, operatorReadRepository); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListTeamFailure); }