public async Task HandleShouldReturnOk() { // Arrange var checklistReadRepositoryMock = new Mock <IChecklistReadRepository>(); checklistReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Checklist, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <Checklist>())); var checklistReadRepository = checklistReadRepositoryMock.Object; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <ChecklistModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <ChecklistModel>()); var mapper = mapperMock.Object; var query = new ListChecklistQuery(null, null, null); var handler = new ListChecklistQueryHandler(mapper, checklistReadRepository); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result <ChecklistsModel>)); }
public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs() { // Arrange var checklistReadRepositoryMock = new Mock <IChecklistReadRepository>(); checklistReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Checklist, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>(); var checklistReadRepository = checklistReadRepositoryMock.Object; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <ChecklistModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <ChecklistModel>()); var mapper = mapperMock.Object; var query = new ListChecklistQuery(null, null, null); var handler = new ListChecklistQueryHandler(mapper, checklistReadRepository); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListChecklistFailure); }