Esempio n. 1
0
        public void AppendFile()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new DefaultWriter <User>(new UserBasicSerializer());//take default serializer

            writer.Write <UserList>(users, TxtFile);

            ListSerializable <User> OtherUsers = new UserList();

            OtherUsers.Add(new User("lala", "lala"));
            OtherUsers.Add(new User("test", "test"));

            writer.Append <UserList>(OtherUsers, TxtFile, "users");

            StringList lines = FileReader.ReadLines(TxtFile);

            Assert.AreEqual("Toto Titi", lines[0]);
            Assert.AreEqual("Tata Roro", lines[1]);
            Assert.AreEqual("lala lala", lines[2]);
            Assert.AreEqual("test test", lines[3]);
        }
Esempio n. 2
0
        public void AppendFileWithInvalidFile()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new DefaultWriter <User>(new UserBasicSerializer());//take default serializer

            writer.Write <UserList>(users, TxtFile);

            ListSerializable <User> OtherUsers = new UserList();

            OtherUsers.Add(new User("lala", "lala"));
            OtherUsers.Add(new User("test", "test"));

            writer.Append <UserList>(OtherUsers, "invalid.json", "users");
        }