public async Task TestForEach()
        {
            using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt")))
            {
                ActiveFile activeFile;
                activeFile = new ActiveFile(New <IDataStore>(_encrypted1AxxPath), New <IDataStore>(_decrypted1TxtPath), new LogOnIdentity("passphrase1"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId);
                state.Add(activeFile);
                activeFile = new ActiveFile(New <IDataStore>(_encrypted2AxxPath), New <IDataStore>(_decrypted2TxtPath), new LogOnIdentity("passphrase2"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId);
                state.Add(activeFile);
                activeFile = new ActiveFile(New <IDataStore>(_encrypted3AxxPath), New <IDataStore>(_decrypted3TxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId);
                state.Add(activeFile);

                Assert.That(state.ActiveFiles.Count(), Is.EqualTo(3), "There should be three.");
                int i = 0;
                await state.ForEach((ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(Task.FromResult(activeFileArgument));
                });

                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");

                i = 0;
                await state.ForEach((ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(Task.FromResult(new ActiveFile(activeFileArgument, activeFile.Status | ActiveFileStatus.Error)));
                });

                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");
            }
        }
Ejemplo n.º 2
0
        public static void TestForEach()
        {
            bool changedEventWasRaised = false;

            using (FileSystemState state = new FileSystemState())
            {
                state.Load(OS.Current.FileInfo(_mystateXmlPath));
                state.Changed += ((object sender, ActiveFileChangedEventArgs e) =>
                {
                    changedEventWasRaised = true;
                });

                ActiveFile activeFile;
                activeFile = new ActiveFile(OS.Current.FileInfo(_encrypted1AxxPath), OS.Current.FileInfo(_decrypted1TxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, null);
                state.Add(activeFile);
                activeFile = new ActiveFile(OS.Current.FileInfo(_encrypted2AxxPath), OS.Current.FileInfo(_decrypted2TxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, null);
                state.Add(activeFile);
                activeFile = new ActiveFile(OS.Current.FileInfo(_encrypted3AxxPath), OS.Current.FileInfo(_decrypted3TxtPath), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, null);
                state.Add(activeFile);
                Assert.That(changedEventWasRaised, Is.True, "The change event should have been raised by the adding of active files.");

                changedEventWasRaised = false;
                Assert.That(state.ActiveFiles.Count(), Is.EqualTo(3), "There should be three.");
                int i = 0;
                state.ForEach(ChangedEventMode.RaiseOnlyOnModified, (ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(activeFileArgument);
                });
                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");
                Assert.That(changedEventWasRaised, Is.False, "No change event should have been raised.");

                i = 0;
                state.ForEach(ChangedEventMode.RaiseAlways, (ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(activeFileArgument);
                });
                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");
                Assert.That(changedEventWasRaised, Is.True, "The change event should have been raised.");

                changedEventWasRaised = false;
                i = 0;
                state.ForEach(ChangedEventMode.RaiseAlways, (ActiveFile activeFileArgument) =>
                {
                    ++i;
                    return(new ActiveFile(activeFileArgument, activeFile.Status | ActiveFileStatus.Error));
                });
                Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files.");
                Assert.That(changedEventWasRaised, Is.True, "The change event should have been raised.");
            }
        }
        public void TestArgumentNull()
        {
            using (FileSystemState state = new FileSystemState())
            {
                ActiveFile nullActiveFile = null;
                string     nullPath       = null;
                Func <ActiveFile, Task <ActiveFile> > nullAction = null;
                IDataStore nullFileInfo = null;

                Assert.Throws <ArgumentNullException>(() => { state.RemoveActiveFile(nullActiveFile); });
                Assert.Throws <ArgumentNullException>(() => { state.Add(nullActiveFile); });
                Assert.Throws <ArgumentNullException>(() => { state.FindActiveFileFromEncryptedPath(nullPath); });
                Assert.ThrowsAsync <ArgumentNullException>(async() => { await state.ForEach(nullAction); });
                Assert.Throws <ArgumentNullException>(() => { FileSystemState.Create(nullFileInfo); });
            }
        }
Ejemplo n.º 4
0
        public static void TestArgumentNull()
        {
            using (FileSystemState state = new FileSystemState())
            {
                ActiveFile nullActiveFile = null;
                string     nullPath       = null;
                Func <ActiveFile, ActiveFile> nullAction = null;
                IRuntimeFileInfo nullFileInfo            = null;

                Assert.Throws <ArgumentNullException>(() => { state.Remove(nullActiveFile); });
                Assert.Throws <ArgumentNullException>(() => { state.Add(nullActiveFile); });
                Assert.Throws <ArgumentNullException>(() => { state.FindEncryptedPath(nullPath); });
                Assert.Throws <ArgumentNullException>(() => { state.FindDecryptedPath(nullPath); });
                Assert.Throws <ArgumentNullException>(() => { state.ForEach(ChangedEventMode.RaiseAlways, nullAction); });
                Assert.Throws <ArgumentNullException>(() => { state.Load(nullFileInfo); });
            }
        }