public void Get_ShouldFail_GivenRoleDoesntExist() { // Given // RolesController over a mock service that would alway throw exceptions on GetAsync var accountManager = Substitute.For <IRestrictedAccountManager>(); var roleService = Substitute.For <IRestrictedRoleService>(); var claimsService = Substitute.For <IClaimsService>(); var authorizationService = Substitute.For <IAuthorizationService>(); roleService.When(s => s.GetRoleByIdAsync(Arg.Any <Guid>())) .Do(v => throw new ItemNotFoundException(v[0].ToString(), "tenant")); var logger = Substitute.For <Microsoft.Extensions.Logging.ILogger <RolesController> >(); var tenantIdProvider = Substitute.For <ITenantIdProvider>(); var roleController = new RolesController( accountManager, roleService, claimsService, authorizationService, tenantIdProvider, new AutoMapperConfig()); var roleId = Guid.NewGuid(); // When // Get is called on the controller AsyncTestDelegate action = async() => await roleController.GetRoleById(roleId); // Then // The controller should thrown ItemNotFoundException Assert.ThrowsAsync <ItemNotFoundException>(action); }