3 using System.Collections.Generic;
5 using Microsoft.VisualStudio.TestTools.UnitTesting;
14 private IEnumerable<FileManager> EnumerateStorages()
22 const string testFileName =
"x0emxujnhp.jhc";
24 foreach ( var storage
in EnumerateStorages() )
26 storage.Delete( testFileName );
27 Assert.IsFalse( storage.Exists( testFileName ),
"Test file still exists after deletion (#1) for " + storage.GetType().Name );
31 Assert.IsTrue( storage.Exists( testFileName ),
"Test file does not exist after creation for " + storage.GetType().Name );
33 storage.Delete( testFileName );
34 Assert.IsFalse( storage.Exists( testFileName ),
"Test file still exists after deletion (#2) for " + storage.GetType().Name );
41 const string testDir =
"akjfhyshkl";
43 foreach ( var storage
in EnumerateStorages() )
45 storage.RmDir( testDir );
46 Assert.IsFalse( storage.Exists( testDir ),
"Test directory still exists after deletion (#1) for " + storage.GetType().Name );
48 storage.MkDir( testDir );
49 Assert.IsTrue( storage.Exists( testDir ),
"Test directory does not exist after creation for " + storage.GetType().Name );
51 storage.RmDir( testDir );
52 Assert.IsFalse( storage.Exists( testDir ),
"Test directory still exists after deletion (#2) for " + storage.GetType().Name );
59 [Save]
public int Attr1;
60 [Save]
public char Attr2 {
get;
set; }
61 [Save]
internal string NonPublic1;
62 [Save]
internal string NonPublic2 {
get;
set; }
63 public short DoNotSave1;
64 public double DoNotSave2 {
get;
set; }
66 public TestClass(
int a1,
string np1,
string np2 )
73 public string GetNonPublic1() {
return NonPublic1; }
74 public string GetNonPublic2() {
return NonPublic2; }
80 const string testFileName =
"wiropopipoi";
81 const short notSaved1 = 9;
82 const double notSaved2 = Math.PI;
84 TestClass testObj =
new TestClass( 47,
"C#",
"Jypeli" );
86 testObj.DoNotSave1 = 6;
87 testObj.DoNotSave2 = 2.41;
89 foreach ( var storage
in EnumerateStorages() )
91 storage.Delete( testFileName );
92 Assert.IsFalse( storage.Exists( testFileName ),
"Test file still exists after deletion (#1) for " + storage.GetType().Name );
94 storage.Save<TestClass>( testObj, testFileName );
95 Assert.IsTrue( storage.Exists( testFileName ),
"Test file does not exist after creation for " + storage.GetType().Name );
97 TestClass loaded =
new TestClass( -1,
"vanha1",
"vanha2" );
98 loaded.DoNotSave1 = notSaved1;
99 loaded.DoNotSave2 = notSaved2;
100 storage.Load<TestClass>( loaded, testFileName );
101 Assert.AreEqual( testObj.Attr1, loaded.Attr1,
"Attr1 value mismatch in " + storage.GetType().Name );
102 Assert.AreEqual( testObj.Attr2, loaded.Attr2,
"Attr2 value mismatch in " + storage.GetType().Name );
103 Assert.AreEqual( testObj.GetNonPublic1(), loaded.GetNonPublic1(),
"NonPublic1 value mismatch in " + storage.GetType().Name );
104 Assert.AreEqual( testObj.GetNonPublic2(), loaded.GetNonPublic2(),
"NonPublic2 value mismatch in " + storage.GetType().Name );
105 Assert.AreEqual( notSaved1, loaded.DoNotSave1,
"DoNotSave1 value mismatch in " + storage.GetType().Name );
106 Assert.AreEqual( notSaved2, loaded.DoNotSave2,
"DoNotSave2 value mismatch in " + storage.GetType().Name );
108 storage.Delete( testFileName );
109 Assert.IsFalse( storage.Exists( testFileName ),
"Test file still exists after deletion (#2) for " + storage.GetType().Name );
static readonly string MyDocuments
Omat tiedostot.
void TestCreateExistsRemove()
Usein käytettyjä polkuja Windowsissa.