public async Task HandleShouldReturnOk() { // Arrange var inputReadRepositoryMock = new Mock <IInputReadRepository>(); inputReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Input, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <Input>())); var inputReadRepository = inputReadRepositoryMock.Object; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <InputModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <InputModel>()); var mapper = mapperMock.Object; var query = new ListInputQuery(null, null, null); var handler = new ListInputQueryHandler(mapper, inputReadRepository); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result <InputsModel>)); }
public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs() { // Arrange var inputReadRepositoryMock = new Mock <IInputReadRepository>(); inputReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Input, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>(); var inputReadRepository = inputReadRepositoryMock.Object; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <InputModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <InputModel>()); var mapper = mapperMock.Object; var query = new ListInputQuery(null, null, null); var handler = new ListInputQueryHandler(mapper, inputReadRepository); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListInputFailure); }