public async Task CreateRoleHandler_BusinessValidationPasses_DoesNotThrowException() { //Setup var repository = new Mock <IApplicationRepository>(); repository.Setup(o => o.Find(It.IsAny <Expression <Func <Application, bool> > >())).ReturnsAsync(new List <Application>().AsQueryable()); var handler = new CreateApplicationBusinessRuleValidationHandler(repository.Object); //Act var result = await Record.ExceptionAsync(async() => await handler.Validate(new CreateApplicationCommand(new CreateApplicationDto { ApplicationName = "Test" }))); //Assert Assert.Null(result); }
public async Task CreateApplicationHandler_BusinessValidationFails_BusinessRuleIsBroken() { //Setup var repository = new Mock <IApplicationRepository>(); repository.Setup(o => o.Find(It.IsAny <Expression <Func <Application, bool> > >())).ReturnsAsync(new List <Application> { new Application { ApplicationId = Guid.Empty, ApplicationName = "Test" } }.AsQueryable()); var handler = new CreateApplicationBusinessRuleValidationHandler(repository.Object); //Act var result = await handler.Validate(new CreateApplicationCommand(new CreateApplicationDto { ApplicationName = "Test" })); //Assert Assert.True(result.IsBroken()); }