public void When_file_unlocked_then_lock_owner_is_null_and_proper_event_published() { // Arrange FakeFileLockingService fileLockingService = new FakeFileLockingService(); FakeFileRepository fileRepository = new FakeFileRepository(); FakeEventPublisher eventPublisher = new FakeEventPublisher(); FakeCurrentUser currentUser = new FakeCurrentUser(); File file = new ExampleFileFactory().CreateFile(); fileRepository.Save(file); currentUser.Id = "currentUserId"; fileLockingService.Lock(file, new User(currentUser.Id, currentUser.Username)); var commandHandler = new RemoveFileLockCommandHandler( fileLockingService, fileRepository, currentUser, eventPublisher); var command = new RemoveFileLockCommand("fileId"); // Act commandHandler.Handle(command); // Assert Assert.IsFalse(fileLockingService.IsLocked(file)); Assert.IsNull(fileLockingService.GetLockOwner(file)); var publishedEvent = eventPublisher.VerifyPublishedOnce <FileLockChangedMessage>(); Assert.IsFalse(publishedEvent.NewLock.IsLockPresent); }
public void Not_locked_file_cannot_be_unlocked() { // Arrange FakeFileLockingService fileLockingService = new FakeFileLockingService(); FakeFileRepository fileRepository = new FakeFileRepository(); FakeEventPublisher eventPublisher = new FakeEventPublisher(); FakeCurrentUser currentUser = new FakeCurrentUser(); File file = new ExampleFileFactory().CreateFile(); fileRepository.Save(file); currentUser.Id = "currentUserId"; var commandHandler = new RemoveFileLockCommandHandler( fileLockingService, fileRepository, currentUser, eventPublisher); var command = new RemoveFileLockCommand("fileId"); // Act Assert.Throws <NotFoundException>(() => commandHandler.Handle(command)); }
public void File_cannot_be_unlocked_by_user_other_than_lock_owner() { // Arrange FakeFileLockingService fileLockingService = new FakeFileLockingService(); FakeFileRepository fileRepository = new FakeFileRepository(); FakeEventPublisher eventPublisher = new FakeEventPublisher(); FakeCurrentUser currentUser = new FakeCurrentUser(); File file = new ExampleFileFactory().CreateFile(); fileRepository.Save(file); currentUser.Id = "currentUserId"; fileLockingService.Lock(file, new User("someRandomUserId", "someRandomUser")); var commandHandler = new RemoveFileLockCommandHandler( fileLockingService, fileRepository, currentUser, eventPublisher); var command = new RemoveFileLockCommand("fileId"); // Act Assert.Throws <PermissionException>(() => commandHandler.Handle(command)); }