Exemple #1
0
        public void SaveAndLoad()
        {
            new LocalStorageManager().Add(new EcKeyPair(), this.storageName1);

            Console.Out.WriteLine(File.ReadAllText(LocalStorageManager.GetStoragePath(false)));

            var result = new LocalStorageManager().GetAll <EcKeyPair>(this.storageName1);

            Assert.That(result.Count(), Is.EqualTo(1));
        }
Exemple #2
0
        public void Setup()
        {
            var tryDelete = new Action <string>(s =>
            {
                if (File.Exists(s))
                {
                    File.Delete(s);
                }
            });

            tryDelete(LocalStorageManager.GetStoragePath(false));
            tryDelete(LocalStorageManager.GetStoragePath(true));

            this.storageName1 = Guid.NewGuid().ToString();
            this.storageName2 = Guid.NewGuid().ToString();
            this.storageName3 = Guid.NewGuid().ToString();
        }
Exemple #3
0
        public void SaveAndLoad_DifferentTypeDifferentValues()
        {
            #region Arrange

            new LocalStorageManager().Add(new EcKeyPair()
            {
                Version = 1
            }, this.storageName1);
            new LocalStorageManager().Add(new EcKeyPair()
            {
                Version = 2
            }, this.storageName1);
            new LocalStorageManager().Add(new EcIdentifier(), this.storageName2);
            new LocalStorageManager().Add(new EcIdentifier(), this.storageName2);
            new LocalStorageManager().Add(new EcIdentifier(), this.storageName2);
            new LocalStorageManager().Add(new EcKeyPairInfo(), this.storageName3);

            Console.Out.WriteLine(File.ReadAllText(LocalStorageManager.GetStoragePath(false)));

            #endregion

            #region Act

            var result1 = new LocalStorageManager().GetAll <EcKeyPair>(this.storageName1);
            var result2 = new LocalStorageManager().GetAll <EcIdentifier>(this.storageName2);
            var result3 = new LocalStorageManager().GetAll <EcKeyPairInfo>(this.storageName3);

            #endregion

            #region Assert

            Assert.That(result1.Count(), Is.EqualTo(2));
            Assert.That(result2.Count(), Is.EqualTo(3));
            Assert.That(result3.Count(), Is.EqualTo(1));

            Assert.That(result1.ToArray()[0].Version, Is.EqualTo(1));
            Assert.That(result1.ToArray()[1].Version, Is.EqualTo(2));

            #endregion
        }
Exemple #4
0
        public void RemoveAll()
        {
            #region Arrange

            var data = new[] { new EcKeyPair()
                               {
                                   Version = 1
                               }, new EcKeyPair()
                               {
                                   Version = 2
                               } };
            var storageName = Guid.NewGuid().ToString();

            #endregion

            #region Act

            new LocalStorageManager().AddRange(data, storageName);
            Console.Out.WriteLine(File.ReadAllText(LocalStorageManager.GetStoragePath(false)));

            new LocalStorageManager().RemoveAll(storageName);
            Console.Out.WriteLine(File.ReadAllText(LocalStorageManager.GetStoragePath(false)));

            new LocalStorageManager().AddRange(data.Take(1), storageName);
            Console.Out.WriteLine(File.ReadAllText(LocalStorageManager.GetStoragePath(false)));


            var result1 = new LocalStorageManager().GetAll <EcKeyPair>(storageName);

            #endregion

            #region Assert

            Assert.That(result1.Count(), Is.EqualTo(1));
            Assert.That(result1.ToArray()[0].Version, Is.EqualTo(1));

            #endregion
        }