Exemplo n.º 1
0
        static void Main(string[] args)
        {
            PersistentList<int> pl = new PersistentList<int>(new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }));
            Console.WriteLine("Añadiendo nodo con valor 22");
            Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode);
            pl.Add(22);
            Console.WriteLine("Añadiendo nodo con valor 42");
            Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode);
            pl.Add(42);
            Console.WriteLine("Añadiendo nodo con valor 62");
            Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode);
            pl.Add(62);
            Console.WriteLine("Añadiendo nodo con valor 82");
            Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode);
            pl.Add(82);

            Print(pl);
            Console.WriteLine("Last Node : {0}", pl.LastNode);

            Console.WriteLine(" ===================================================== ");

            Console.WriteLine("Deshaciendo ultima operacion ( eliminar nodo con valor 82 )");
            pl.Undo();
            Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode);
            Console.WriteLine("Deshaciendo ultima operacion ( eliminar nodo con valor 62 )");
            pl.Undo();
            Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode);

            Print(pl);
            Console.WriteLine("Last Node : {0}", pl.LastNode);
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public async void Should_save_async()
        {
            _list.Add(new Tweet());
            await _list.SaveAsync();

            Assert.AreEqual("[{\"Username\":null,\"Message\":null,\"DateTime\":\"0001-01-01T00:00:00\"}]", _store.Json);
        }
Exemplo n.º 3
0
 public void TestList()
 {
     var a = new PersistentList<string>();
     a.Add("one");
     a.Store();
     a.Add("two");
     a.Undo();
     Assert.True(a.Count == 1);
     Assert.True(a[0] == "one");
     a.Redo();
     Assert.True(a.Count == 2);
     Assert.True(a[0] == "one");
     Assert.True(a[1] == "two");
 }
Exemplo n.º 4
0
 public void TestIgnoreRepetitiveActions()
 {
     var list = new PersistentList<string>();
     var undoRedo = new UndoRedo<PersistentList<string>>(list);
     undoRedo.NewAction("add");
     list.Add("1");
     undoRedo.NewAction("add");
     list.Add("2");
     undoRedo.Undo();
     Assert.True(list.Count == 1);
     undoRedo.IgnoreRepetitiveActions = true;
     undoRedo.NewAction("add");
     list.Add("2");
     undoRedo.Undo();
     Assert.True(list.Count == 0);
 }
Exemplo n.º 5
0
        public void Should_throw_when_saving_is_not_possible()
        {
            var tweet = new Tweet {
                Username = "******"
            };

            _list.Add(tweet);
            _list.Save();
            FileStream fs = null;

            try {
                fs = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.None);
                _list.Add(tweet);
                _list.Save();
                Assert.True(false, "Should throw exception!");
            }
            catch (Exception) {}
            finally {
                fs?.Dispose();
            }
        }
Exemplo n.º 6
0
        public async Task Should_save_async()
        {
            _list.Add(new Tweet());
            await _list.SaveAsync();

            Assert.Equal("[{\"$id\":\"1\",\"Username\":null,\"Message\":null,\"DateTime\":\"0001-01-01T00:00:00\"}]", Encoding.UTF8.GetString(_store.Json));
        }
        protected override void AddToCollection(ICollection collection, Person person)
        {
            PersistentList concrete = collection as PersistentList;

            if (concrete != null)
            {
                concrete.Add(person);
            }
            else
            {
                ((ArrayList)collection).Add(person);
            }
        }
        protected virtual void process_construct(ShipConstruct construct)
        {
            var kit = new VesselKit(this, construct, false);
            var selected_space_module = selected_space as PartModule;

            if (selected_space_module != null)
            {
                float ratio;
                if (!selected_space.Empty)
                {
                    Utils.Message("Selected assembly space is occupied");
                }
                else if (!selected_space.CheckKit(kit, kit_part, out ratio))
                {
                    if (ratio > 0)
                    {
                        Utils.Message("Selected assembly space is too small");
                    }
                    else
                    {
                        Utils.Message("Selected container is not suitable for construction of this kit");
                    }
                }
                else
                {
                    selected_space.SetKit(kit, kit_part);
                }
            }
            else if (find_assembly_space(kit, false) != null)
            {
                kit.Host = this;
                Kits.Add(kit);
                Queue.Enqueue(new AssemblyKitInfo(kit));
            }
            else
            {
                Utils.Message("No suitable assembly space was found.");
            }
            construct.Unload();
        }
 PersistentList<IdentifiableForTesting> BuildTestList()
 {
     var list = new PersistentList<IdentifiableForTesting>(editGroup);
     list.Add(new IdentifiableForTesting("1"));
     list.Add(new IdentifiableForTesting("2"));
     list.Add(new IdentifiableForTesting("3"));
     return list;
 }
Exemplo n.º 10
0
 public void TestList3()
 {
     var a = new Persistent<string>("one");
     var b = new Persistent<string>("two");
     var persistent = new PersistentList<Persistent<string>>();
     persistent.Add(a);
     persistent.Add(b);
     persistent.Store();
     a.Value = "1";
     b.Value = "2";
     persistent.Store();
     persistent[0] = b;
     persistent[1] = a;
     persistent.Store();
     persistent.Undo();
     Assert.True(persistent[0] == b);
     Assert.True(persistent[1] == a);
     persistent.Undo();
     Assert.True(persistent[0] == a);
     Assert.True(persistent[1] == b);
 }
Exemplo n.º 11
0
 public void TestPersistentStructureList()
 {
     var a = new PersistentList<Persistent<string>>();
     a.Add(new Persistent<string>("one"));
     a.Store();
     a[0].Value = "two";
     a.Undo();
     Assert.True(a[0].Value == "one");
     a.Redo();
     Assert.True(a[0].Value == "two");
 }