Exemplo n.º 1
0
        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>();
        }
Exemplo n.º 2
0
        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);
        }