public async void CreateSession_Throws_UnauthorizedAccessException(string userId) { var studio = new StudioDto { OwnerUserId = Guid.NewGuid() }; var room = new RoomDto { StudioId = studio.Id }; var session = new SessionDto { Id = Guid.NewGuid() }; _studioService .Setup(s => s.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(studio)); _roomService .Setup(r => r.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(room)); var isAuthenticated = userId != null; _identity.Setup(i => i.IsAuthenticated).Returns(isAuthenticated); _identity.Setup(i => i.Name).Returns(userId); var ex = await Assert.ThrowsAsync <UnauthorizedAccessException>( () => _roomsController.CreateSession(room.Id, session)); Assert.NotNull(ex); }