public void File_can_be_locked_by_authorized_user()
        {
            // Arrange
            FakeFileLockingService fileLockingService = new FakeFileLockingService();
            FakeFileRepository     fileRepository     = new FakeFileRepository();
            FakeEventPublisher     eventPublisher     = new FakeEventPublisher();
            FakeCurrentUserSource  currentUserSource  = new FakeCurrentUserSource();

            File file      = new ExampleFileFactory().CreateFile();
            User otherUser = new User("someRandomUserId", "someRandomUser");

            file.ShareWith(otherUser);

            fileRepository.Save(file);
            currentUserSource.CurrentUser = otherUser;

            var commandHandler = new AcquireFileLockCommandHandler(
                fileLockingService, fileRepository, eventPublisher, currentUserSource);

            var command = new AcquireFileLockCommand("fileId");

            // Act
            commandHandler.Handle(command);

            // Assert
            Assert.AreEqual(otherUser.Id, fileLockingService.GetLockOwner(file).Id);

            FileLockChangedMessage publishedEvent = eventPublisher.VerifyPublishedOnce <FileLockChangedMessage>();

            Assert.AreEqual("fileId", publishedEvent.FileId);
            Assert.AreEqual(otherUser.Id, publishedEvent.NewLock.LockOwner.Id);
        }
Exemplo n.º 2
0
        public void File_cannot_be_shared_with_its_owner()
        {
            // Arrange
            File file = new ExampleFileFactory().CreateFile();

            //Assert
            Assert.Throws <PermissionException>(() => file.ShareWith(file.Owner));
        }
Exemplo n.º 3
0
        public void File_can_be_modified_by_authorized_user()
        {
            // Arrange
            File file           = new ExampleFileFactory().CreateFile();
            var  someRandomUser = new User("f10b5f27-5470-49aa-af83-754dfffa7c2c", "otherUser");

            file.ShareWith(someRandomUser);

            // Act
            bool canBeModifiedBySomeRandom = file.CanBeModifiedBy(someRandomUser);

            // Assert
            Assert.True(canBeModifiedBySomeRandom);
        }
Exemplo n.º 4
0
        public void File_cannot_be_modified_after_unsharing()
        {
            // Arrange
            File file           = new ExampleFileFactory().CreateFile();
            var  someRandomUser = new User("f10b5f27-5470-49aa-af83-754dfffa7c2c", "otherUser");

            file.ShareWith(someRandomUser);
            file.Unshare(someRandomUser);

            // Act
            bool canBeModifiedBySomeRandom = file.CanBeModifiedBy(someRandomUser);

            // Assert
            Assert.False(canBeModifiedBySomeRandom);
        }
        public void File_cannot_be_shared_by_user_which_has_access_but_is_not_owner()
        {
            // Arrange
            FakeFileRepository fileRepository = new FakeFileRepository();
            FakeUserRepository userRepository = new FakeUserRepository();
            FakeEventPublisher eventPublisher = new FakeEventPublisher();
            FakeCurrentUser    currentUser    = new FakeCurrentUser();

            File file      = new ExampleFileFactory().CreateFile();
            User shareWith = new User("shareWithUserId", "username");

            fileRepository.Save(file);
            userRepository.Save(shareWith);
            file.ShareWith(shareWith);
            currentUser.Id = shareWith.Id;

            var commandHandler = new ShareFileCommandHandler(
                currentUser, fileRepository, userRepository, eventPublisher);

            var command = new ShareFileCommand("fileId", shareWith.Id);

            // Act & Assert
            Assert.Throws <PermissionException>(() => commandHandler.Handle(command));
        }