public void UpdateItemDataAsync_EnsureCurrentUserCanAccessThisItem() { const int itemId = 4; var executionContext = new NaheulbookExecutionContext(); var item = new Item(); _unitOfWorkFactory.GetUnitOfWork().Items.GetWithOwnerAsync(itemId) .Returns(item); _authorizationUtil.When(x => x.EnsureItemAccess(executionContext, item)) .Throw(new TestException()); Func <Task> act = () => _service.UpdateItemDataAsync(executionContext, itemId, new ItemData()); act.Should().Throw <TestException>(); _unitOfWorkFactory.GetUnitOfWork().DidNotReceive().SaveChangesAsync(); }
public void CreateLootAsync_EnsureUserAccessToLoot() { const int groupId = 42; var naheulbookExecutionContext = new NaheulbookExecutionContext { UserId = 10 }; var group = new Group { Id = groupId }; _unitOfWorkFactory.GetUnitOfWork().Groups.GetAsync(groupId) .Returns(group); _authorizationUtil.When(x => x.EnsureIsGroupOwner(naheulbookExecutionContext, group)) .Throw(new TestException()); Func <Task> act = () => _service.CreateLootAsync(naheulbookExecutionContext, groupId, new CreateLootRequest()); act.Should().Throw <TestException>(); }
public void GetGroupDetailsAsync_ShouldEnsureIsGroupOwner() { const int groupId = 4; var naheulbookExecutionContext = new NaheulbookExecutionContext(); var group = new Group(); _unitOfWorkFactory.GetUnitOfWork().Groups.GetGroupsWithDetailsAsync(groupId) .Returns(group); _authorizationUtil.When(x => x.EnsureIsGroupOwner(naheulbookExecutionContext, group)) .Throw(new TestException()); Func <Task> act = () => _service.GetGroupDetailsAsync(naheulbookExecutionContext, groupId); act.Should().Throw <TestException>(); }
public void CreateCharacterAsync_WhenGroupIdIsGiven_CheckIsGroupOwner() { const int groupId = 8; var createCharacterRequest = new CreateCharacterRequest { Name = "some-name", GroupId = groupId }; var naheulbookExecutionContext = new NaheulbookExecutionContext(); var createdCharacter = new Character(); var group = new Group(); _characterFactory.CreateCharacter(createCharacterRequest) .Returns(createdCharacter); _unitOfWorkFactory.GetUnitOfWork().Groups.GetAsync(groupId) .Returns(group); _authorizationUtil.When(x => x.EnsureIsGroupOwner(naheulbookExecutionContext, group)) .Throw(new ForbiddenAccessException()); Func <Task> act = () => _service.CreateCharacterAsync(naheulbookExecutionContext, createCharacterRequest); act.Should().Throw <ForbiddenAccessException>(); }