public void File_can_be_shared_and_allows_for_modifications_by_authorized_user()
        {
            // 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);
            currentUser.Id = file.Owner.Id;

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

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

            // Act
            commandHandler.Handle(command);

            // Assert
            Assert.IsTrue(file.CanBeModifiedBy(shareWith));
            FileSharesChangedMessage publishedEvent = eventPublisher.VerifyPublishedOnce <FileSharesChangedMessage>();

            Assert.AreEqual(file, publishedEvent.File);
        }
Пример #2
0
        public void File_can_be_modified_by_owner()
        {
            // Arrange
            File file      = new ExampleFileFactory().CreateFile();
            User fileOwner = file.Owner;

            // Act
            bool canBeModifiedByOwner = file.CanBeModifiedBy(fileOwner);

            // Assert
            Assert.True(canBeModifiedByOwner);
        }
Пример #3
0
        public void File_cannnot_be_modified_by_random_user()
        {
            // Arrange
            File file           = new ExampleFileFactory().CreateFile();
            var  someRandomUser = new User("f10b5f27-5470-49aa-af83-754dfffa7c2c", "otherUser");

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

            // Assert
            Assert.False(canBeModifiedBySomeRandom);
        }