public async Task AddBonus_ShouldReturnServiceAndBonus() { var controller = new ServiceController(_service); var serviceDto = GetServiceDto(); var service = (await controller.GetAll(serviceDto.Name))[0]; var user = await _context.Users.FirstOrDefaultAsync(); var bonusDto = new AddBonusDto { PromoCode = "itpromocodes", ServiceId = Guid.Parse(service.Id), }; // mock current user user var claims = new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) } ); var claimsPrincipal = new ClaimsPrincipal(claims); var httpContext = new DefaultHttpContext(); httpContext.User = claimsPrincipal; var controllerContext = new ControllerContext() { HttpContext = httpContext }; controller.ControllerContext = controllerContext; // Add bonus var result = await controller.AddBonus(bonusDto) as OkObjectResult; // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Value, typeof(ServiceResponse)); }