public async Task HandleShouldReturnOk() { // Arrange var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <SiteModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <SiteModel>()); var mapper = mapperMock.Object; var siteReadRepositoryMock = new Mock <ISiteReadRepository>(); siteReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Site, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <Site>())); var siteReadRepository = siteReadRepositoryMock.Object; var siteOdataProviderMock = new Mock <ISiteOdataProvider>(); siteOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <Site, bool> >)null); var SiteOdataProvider = siteOdataProviderMock.Object; var query = new ListSiteQuery(null, null, null); var handler = new ListSiteQueryHandler(mapper, siteReadRepository, SiteOdataProvider); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result <SitesModel>)); }
public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs() { // Arrange var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <IEnumerable <SiteModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <SiteModel>()); var mapper = mapperMock.Object; var siteReadRepositoryMock = new Mock <ISiteReadRepository>(); siteReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <Site, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>(); var siteReadRepository = siteReadRepositoryMock.Object; var siteOdataProviderMock = new Mock <ISiteOdataProvider>(); siteOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <Site, bool> >)null); var siteOdataProvider = siteOdataProviderMock.Object; var query = new ListSiteQuery(null, null, null); var handler = new ListSiteQueryHandler(mapper, siteReadRepository, siteOdataProvider); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListSiteFailure); }
public ListSiteQuery Map(ListSiteRequest request) { var filter = request.Filter; var top = request.Top; var skip = request.Skip; var result = new ListSiteQuery(filter, top, skip); return(result); }
public void ShouldContainNoTopErrorWhenTopIsNotSet(string top) { // Arrange string filter = null; string skip = null; var query = new ListSiteQuery(filter, top, skip); // Act var validationResult = _validator.Validate(query); var exists = validationResult.Errors.Any(a => a.PropertyName.Equals("$top")); // Assert exists.Should().BeFalse(); }
public void ShouldContainNoErrors() { // Arrange string filter = null; string top = null; string skip = null; var query = new ListSiteQuery(filter, top, skip); // Act var validationResult = _validator.Validate(query); var exists = validationResult.Errors.Count > 0; // Assert exists.Should().BeFalse(); }
public void ShouldHaveTopInvalidCustomFailureWhenTopInvalid(string top) { // Arrange string filter = null; string skip = null; var query = new ListSiteQuery(filter, top, skip); // Act var validationResult = _validator.Validate(query); var exists = validationResult.Errors.Any( a => a.PropertyName.Equals("$top") && a.ErrorMessage.Contains(CustomFailures.TopInvalid)); // Assert exists.Should().BeTrue(); }
public void ShouldHaveSkipRangeCustomFailure(string skip) { // Arrange string filter = null; string top = null; var query = new ListSiteQuery(filter, top, skip); // Act var validationResult = _validator.Validate(query); var exists = validationResult.Errors.Any( a => a.PropertyName.Equals("$skip") && a.ErrorMessage.Contains(string.Format(CustomFailures.SkipRange, Consts.CqsValidation.SkipMaxValue))); // Assert exists.Should().BeTrue(); }