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);
        }
        public void When_file_locked_by_its_owner_then_lock_owner_is_correct_and_proper_event_published()
        {
            // Arrange
            FakeFileLockingService fileLockingService = new FakeFileLockingService();
            FakeFileRepository     fileRepository     = new FakeFileRepository();
            FakeEventPublisher     eventPublisher     = new FakeEventPublisher();
            FakeCurrentUserSource  currentUserSource  = new FakeCurrentUserSource();

            File file = new ExampleFileFactory().CreateFile();

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

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

            var command = new AcquireFileLockCommand("fileId");

            // Act
            commandHandler.Handle(command);

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

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

            Assert.AreEqual("fileId", publishedEvent.FileId);
        }