public void StartSharing_should_throw_if_SharingContext_already_exist() { var existingContext = A.Dummy <SharingContext>(); A.CallTo(() => _repository.GetSharingContextForUserByInfoHash(A <string> .Ignored, A <string> .Ignored)) .Returns(existingContext); var request = ShareRequestFactory.CreateCompleteRequestForSingleFile(); Func <Task> act = async() => await _operation.StartSharing(request); act.Should().ThrowExactly <DuplicateSharingContextException>(); }
public async Task StartSharing(ShareRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } await _shareRequestValidator.ValidateAndThrowAsync(request, "default,write"); var context = SharingContext.Create(request); var existing = await _sharingRepository.GetSharingContextForUserByInfoHash(request.User.Id, context.InfoHash); if (existing != default) { throw new DuplicateSharingContextException(); } SanitizeSharingContext(context); await _sharingRepository.CreateSharingContext(context); }