Exemple #1
0
        public async Task ToTheLimit()
        {
            for (int i = 0; i < MaxStores; i++)
            {
                IDatabaseCandidate candidate = new MockDatabaseCandidate
                {
                    FileName = $"{i,10:D4}.kdbx"
                };

                Assert.IsTrue(
                    await this.credentialProvider.TryStoreRawKeyAsync(candidate.FileName, this.mockPasswordBuffer),
                    "Storing up to the credential limit should be fine"
                    );
            }

            IReadOnlyCollection <string> allCredsEnum = await this.credentialProvider.GetAllEntriesAsync();

            IList <string> allCreds = allCredsEnum.OrderBy(s => s).ToList();

            Assert.AreEqual(MaxStores, allCreds.Count, $"{MaxStores} credentials should have been stored");
            for (int i = 0; i < allCreds.Count; i++)
            {
                Assert.AreEqual($"{i,10:D4}.kdbx", allCreds[i]);
            }

            IDatabaseCandidate finalCandidate = new MockDatabaseCandidate
            {
                FileName = $"{MaxStores}.kdbx"
            };

            Assert.IsFalse(
                await this.credentialProvider.TryStoreRawKeyAsync(finalCandidate.FileName, this.mockPasswordBuffer),
                "Storing past the credential limit should fail"
                );
        }
        /// <summary>
        /// Initializes the design data.
        /// </summary>
        public DesignDatabaseUnlockViewModel()
        {
            CandidateFile = new MockDatabaseCandidate
            {
                FileName     = "My Database.kdbx",
                LastModified = new DateTimeOffset(DateTime.UtcNow),
                Size         = 12345,
            };

            Password = "******";

            UnlockCommand = new AsyncActionCommand(
                () => HasGoodHeader,
                () => Task.CompletedTask
                );

            UseSavedCredentialsCommand = new AsyncActionCommand(
                () => true,
                () => Task.CompletedTask
                );

            HasGoodHeader    = true;
            ParseResult      = new ReaderResult(KdbxParserCode.Success);
            RememberDatabase = true;
        }