public void DuplicateKeyTest()
        {
            var t1 = new InterfaceTester {
                A = "Hello", B = 10, C = 5.135f
            };
            var t2 = new InterfaceTester {
                A = "Goodbye", B = 44, C = 1897.01f
            };

            var filePath = Path.GetTempFileName();

            try
            {
                using (var settingsWriter = new ObjectStatePersister("TestSettings", filePath))
                {
                    settingsWriter.Add("t1", t1);
                    Assert.Throws <ArgumentException>(() => settingsWriter.Add("t1", t2));
                }
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
        }
示例#2
0
 public void TestVirtualIndirectCallInNative()
 {
     using (Inter i = new Inter())
     {
         using (InterfaceTester tester = new InterfaceTester())
         {
             tester.SetInterface(i);
             Assert.That(tester.Get(10), Is.EqualTo(IntPtr.Zero));
         }
     }
 }
示例#3
0
    static int Test()
    {
        int result;

        result = CollectionTester.Test();
        if (result != 0)
        {
            return(result);
        }
        result = InterfaceTester.Test();
        if (result != 0)
        {
            return(10000 + result);
        }
        return(0);
    }
        public void AddNewItemTest()
        {
            var t1 = new InterfaceTester {
                A = "Hello", B = 10, C = 5.135f
            };
            var t2 = new InterfaceTester {
                A = "Goodbye", B = 44, C = 1897.01f
            };
            var t3 = new InterfaceTester {
                A = "wb", B = 24, C = 1234.3f
            };

            var             retT1 = new InterfaceTester();
            var             retT2 = new InterfaceTester();
            InterfaceTester retT3;

            var filePath = Path.GetTempFileName();

            try
            {
                using (var settingsWriter = new ObjectStatePersister("TestSettings", filePath))
                {
                    settingsWriter.Add("t1", t1);
                    settingsWriter.Add("t2", t2);
                }

                using (var settingsReader = new ObjectStatePersister("TestSettings", filePath))
                {
                    settingsReader.Add("t3", t3);
                    settingsReader.Add("t1", retT1);
                    settingsReader.Add("t2", retT2);
                    retT3 = t3;
                }
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }

            Assert.IsTrue(t1.HaveSameValues(retT1));
            Assert.IsTrue(t2.HaveSameValues(retT2));
            Assert.IsTrue(t3.HaveSameValues(retT3));
        }
        public void WriteTonsOfCrapReadOnlySomeTest()
        {
            const int iterations = 10000;

            var items = new List <InterfaceTester>(iterations);

            for (var i = 0; i < iterations; i++)
            {
                items.Add(GetRandomInterfaceTester());
            }

            var filePath = Path.GetTempFileName();

            try
            {
                using (var settingsWriter = new ObjectStatePersister("TestSettings", filePath))
                {
                    for (var i = 0; i < items.Count; i++)
                    {
                        settingsWriter.Add("item" + Parser.Invariant.ToString(i), items[i]);
                    }
                }

                using (var settingsReader = new ObjectStatePersister("TestSettings", filePath))
                {
                    for (var i = items.Count - 1; i > 0; i -= 22)
                    {
                        var newItem = new InterfaceTester();
                        settingsReader.Add("item" + Parser.Invariant.ToString(i), newItem);
                        Assert.IsTrue(items[i].HaveSameValues(newItem), "Index: {0}", i);
                    }
                }
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
        }
示例#6
0
        public void AddNewItemTest()
        {
            var t1 = new InterfaceTester { A = "Hello", B = 10, C = 5.135f };
            var t2 = new InterfaceTester { A = "Goodbye", B = 44, C = 1897.01f };
            var t3 = new InterfaceTester { A = "wb", B = 24, C = 1234.3f };

            var retT1 = new InterfaceTester();
            var retT2 = new InterfaceTester();
            InterfaceTester retT3;

            var filePath = Path.GetTempFileName();

            try
            {
                using (var settingsWriter = new ObjectStatePersister("TestSettings", filePath))
                {
                    settingsWriter.Add("t1", t1);
                    settingsWriter.Add("t2", t2);
                }

                using (var settingsReader = new ObjectStatePersister("TestSettings", filePath))
                {
                    settingsReader.Add("t3", t3);
                    settingsReader.Add("t1", retT1);
                    settingsReader.Add("t2", retT2);
                    retT3 = t3;
                }
            }
            finally
            {
                if (File.Exists(filePath))
                    File.Delete(filePath);
            }

            Assert.IsTrue(t1.HaveSameValues(retT1));
            Assert.IsTrue(t2.HaveSameValues(retT2));
            Assert.IsTrue(t3.HaveSameValues(retT3));
        }
示例#7
0
 static bool HaveSameValues(InterfaceTester l, InterfaceTester r)
 {
     return (l.A == r.A) && (l.B == r.B) && (l.C == r.C);
 }
示例#8
0
 public bool HaveSameValues(InterfaceTester other)
 {
     return HaveSameValues(this, other);
 }
示例#9
0
        public void WriteTonsOfCrapReadOnlySomeTest()
        {
            const int iterations = 10000;

            var items = new List<InterfaceTester>(iterations);

            for (var i = 0; i < iterations; i++)
            {
                items.Add(GetRandomInterfaceTester());
            }

            var filePath = Path.GetTempFileName();

            try
            {
                using (var settingsWriter = new ObjectStatePersister("TestSettings", filePath))
                {
                    for (var i = 0; i < items.Count; i++)
                    {
                        settingsWriter.Add("item" + Parser.Invariant.ToString(i), items[i]);
                    }
                }

                using (var settingsReader = new ObjectStatePersister("TestSettings", filePath))
                {
                    for (var i = items.Count - 1; i > 0; i -= 22)
                    {
                        var newItem = new InterfaceTester();
                        settingsReader.Add("item" + Parser.Invariant.ToString(i), newItem);
                        Assert.IsTrue(items[i].HaveSameValues(newItem), "Index: {0}", i);
                    }
                }
            }
            finally
            {
                if (File.Exists(filePath))
                    File.Delete(filePath);
            }
        }
示例#10
0
        public void DuplicateKeyTest()
        {
            var t1 = new InterfaceTester { A = "Hello", B = 10, C = 5.135f };
            var t2 = new InterfaceTester { A = "Goodbye", B = 44, C = 1897.01f };

            var filePath = Path.GetTempFileName();

            try
            {
                using (var settingsWriter = new ObjectStatePersister("TestSettings", filePath))
                {
                    settingsWriter.Add("t1", t1);
                    Assert.Throws<ArgumentException>(() => settingsWriter.Add("t1", t2));
                }
            }
            finally
            {
                if (File.Exists(filePath))
                    File.Delete(filePath);
            }
        }
 static bool HaveSameValues(InterfaceTester l, InterfaceTester r)
 {
     return((l.A == r.A) && (l.B == r.B) && (l.C == r.C));
 }
 public bool HaveSameValues(InterfaceTester other)
 {
     return(HaveSameValues(this, other));
 }