コード例 #1
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
        }
コード例 #2
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
        }