public void Collate()
        {
            var obj = new TestObj
                          {
                              CollateDefault = "Alpha ",
                              CollateBinary = "Alpha ",
                              CollateRTrim = "Alpha ",
                              CollateNoCase = "Alpha ",
                          };

            var db = new OrmTestSession();
            db.CreateTable<TestObj>();
            db.Insert(obj);

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
        }
示例#2
0
        public void Collate()
        {
            var obj = new TestObj
            {
                CollateDefault = "Alpha ",
                CollateBinary = "Alpha ",
                CollateRTrim = "Alpha ",
                CollateNoCase = "Alpha ",
            };

            var db = new TestDb(new SQLitePlatformTest(), TestPath.GetTempFileName());

            db.Insert(obj);

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
        }
示例#3
0
 public static int Main()
 {
     TestObj
     obj
     =
     new
     TestObj
     ();
     TestObj
     clone;
     if
     (sbah
     +
     obj.bah
     +
     obj.amethod
     ()
     !=
     8)
     return
     1;
     clone
     =
     (TestObj)obj.MemberwiseClone
     ();
     if
     (clone.boh
     !=
     2)
     return
     1;
     return
     0;
 }
        public void IsKeyPrivate_Defaults_To_Expected_Convention()
        {
            PrivateKeySetter setter = new PrivateKeySetter();

            TestObj test = new TestObj();

            Assert.IsTrue(setter.IsKeyPrivate(test));
        }
        public void IsKeyPrivate_Returns_True()
        {
            PrivateKeySetter setter = new PrivateKeySetter();

            TestObj test = new TestObj();

            Assert.IsTrue(setter.IsKeyPrivate(test, "PrivateSetter"));
        }
        public void IsKeyPrivate_Throws_If_Property_Not_Found()
        {
            PrivateKeySetter setter = new PrivateKeySetter();

            TestObj test = new TestObj();

            setter.IsKeyPrivate(test, "NotFound");
        }
示例#7
0
        public void testobj_get_set_BSTR_prop()
        {
            const string expected = "Test set string";

              var obj = new TestObj();
              obj.TestStringProp2 = expected;

              Assert.Equal(expected, obj.TestStringProp2);
        }
示例#8
0
        public void testobj_get_set_testprop()
        {
            const int expected = 2;

              var obj = new TestObj();
              obj.TestProp = expected;

              Assert.Equal(expected, obj.TestProp);
        }
示例#9
0
		//[Test]
		public void ObjToDicTest()
		{
			var obj  = new TestObj { Country = CountryCodeEnum1.DZ, Other = OtherEnum1.EnumValue2 };
			var sh   = new MappingSchema { Extensions = TypeExtension.GetExtensions("Map.xml") };
			var pars = sh.MapObjectToDictionary(obj);

			Assert.AreEqual("DZ", pars["country_code"]);
			Assert.AreEqual(101,  pars["other"]);
		}
        public void SetId_Defaults_To_Expected_Convention()
        {
            PrivateKeySetter setter = new PrivateKeySetter();

            TestObj test = new TestObj();
            const string idValue = "10";

            Assert.IsTrue(setter.SetKey(test, idValue));
            Assert.IsTrue(test.PrivateSetter == 0);
            Assert.IsTrue(test.PublicSetter == Guid.Empty);
        }
        public void SetId_Returns_True_And_Sets_Property_With_Private_Setter()
        {
            PrivateKeySetter setter = new PrivateKeySetter();

            TestObj test = new TestObj();
            const int idValue = 10;

            Assert.IsTrue(setter.SetKey(test, "PrivateSetter", idValue));
            Assert.IsTrue(test.Id == null);
            Assert.IsTrue(test.PrivateSetter == idValue);
            Assert.IsTrue(test.PublicSetter == Guid.Empty);
        }
 public void TestGetGUID()
 {
     var testObj = new TestObj("This is a simple test hope shit does not go wrong!!", 666);
     var record = database.Save(testObj);
     Assert.IsTrue(Object.ReferenceEquals(testObj, record.Value), "IObjectDatabase.Save failed to return the same object that was passed to it in the returned record");
     record = database.Get<TestObj>(record.UniqueId);
     Assert.IsTrue(Object.ReferenceEquals(testObj, record.Value), "IObjectDatabase.Get(GUID) failed to return an object from memory");
     database.Dispose();
     database = new SQLiteObjectDatabase(databaseFile);
     var newRecord = database.Get<TestObj>(record.UniqueId);
     Assert.IsTrue(record.UniqueId == newRecord.UniqueId && testObj.Value1 == newRecord.Value.Value1 && testObj.Value2 == newRecord.Value.Value2, "IObjectDatabase.Get(GUID) failed to return an object from storage");
 }
        public void StringContains()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestObj>();

            var testObj = new TestObj { Name = "This is a Good name" };
            db.Insert(testObj);

            var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains("Good") select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
            var finder = "good";
            stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains(finder) select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
        }
示例#14
0
		public void InsertSucceeds ()
		{
			var db = new TestDb ();
			db.CreateTable<TestObj> ();

			var o = new TestObj {
				Text = "Hello",
				IgnoredText = "World",
			};

			db.Insert (o);

			Assert.AreEqual (1, o.Id);
		}
        public void StringStartsWith()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestObj>();

            var testObj = new TestObj { Name = "This is a Good name" };
            db.Insert(testObj);

            var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.StartsWith("This") select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
            var finder = "name";
            stringContainsTest = (from n in db.Table<TestObj>() where n.Name.StartsWith(finder) select n).SingleOrDefault();
            Assert.IsNull(stringContainsTest);
        }
        public void can_deserialize_id_with_private_setter()
        {
            using (var documentStore = NewDocumentStore())
            using (var session = documentStore.OpenSession())
            {
                var testObj = new TestObj(1000, 123);
                session.Store(testObj);
                session.SaveChanges();
                session.Advanced.Clear();
                var load = session.Load<TestObj>(1000);

                Assert.Equal(123, load.AnotherLong);
                Assert.Equal(1000, load.Id);
            }
        }
示例#17
0
        void TestDateTime(TestDb db)
        {
            db.CreateTable<TestObj> ();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj {
                ModifiedTime = new DateTime (2012, 1, 14, 3, 2, 1, 234),
            };
            db.Insert (o);
            o2 = db.Get<TestObj> (o.Id);
            Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
        }
示例#18
0
        void TestAsyncDateTime(SQLiteAsyncConnection db)
        {
            db.CreateTableAsync<TestObj> ().Wait ();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj {
                ModifiedTime = new DateTime (2012, 1, 14, 3, 2, 1, 234),
            };
            db.InsertAsync (o).Wait ();
            o2 = db.GetAsync<TestObj> (o.Id).Result;
            Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
        }
示例#19
0
        public void InsertIntoTwoTables()
        {
            var obj1 = new TestObj() { Text = "GLaDOS loves testing!" };
            var obj2 = new TestObj2() { Text = "Keep testing, just keep testing" };

            var numIn1 = _db.Insert(obj1);
            Assert.AreEqual(1, numIn1);
            var numIn2 = _db.Insert(obj2);
            Assert.AreEqual(1, numIn2);

            var result1 = _db.Query<TestObj>("select * from TestObj").ToList();
            Assert.AreEqual(numIn1, result1.Count);
            Assert.AreEqual(obj1.Text, result1.First().Text);

            var result2 = _db.Query<TestObj>("select * from TestObj2").ToList();
            Assert.AreEqual(numIn2, result2.Count);
        }
示例#20
0
		public void GetDoesntHaveIgnores ()
		{
			var db = new TestDb ();
			db.CreateTable<TestObj> ();

			var o = new TestObj {
				Text = "Hello",
				IgnoredText = "World",
			};

			db.Insert (o);

			var oo = db.Get<TestObj> (o.Id);

			Assert.AreEqual ("Hello", oo.Text);
			Assert.AreEqual (null, oo.IgnoredText);
		}
示例#21
0
        private async Task TestAsyncDateTime(SQLiteAsyncConnection db)
        {
            await db.CreateTableAsync<TestObj>();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj
            {
                ModifiedTime = new DateTime(2012, 1, 14, 3, 2, 1),
            };
            await db.InsertAsync(o);
            o2 = await db.GetAsync<TestObj>(o.Id);
            Assert.AreEqual(o.ModifiedTime, o2.ModifiedTime);
        }
示例#22
0
        private async Task TestAsyncDateTime(SQLiteAsyncConnection db, bool storeDateTimeAsTicks)
        {
            await db.CreateTableAsync<TestObj>();

            var org = new TestObj
            {
                Time1 = DateTime.UtcNow,
                Time2 = DateTime.Now,
            };
            await db.InsertAsync(org);
            var fromDb = await db.GetAsync<TestObj>(org.Id);
            Assert.AreEqual(fromDb.Time1.ToUniversalTime(), org.Time1.ToUniversalTime());
            Assert.AreEqual(fromDb.Time2.ToUniversalTime(), org.Time2.ToUniversalTime());

            Assert.AreEqual(fromDb.Time1.ToLocalTime(), org.Time1.ToLocalTime());
            Assert.AreEqual(fromDb.Time2.ToLocalTime(), org.Time2.ToLocalTime());
        }
示例#23
0
        public void It_Should_Create_A_Dictionary_From_An_Object()
        {
            // Arrange
            var testObj = new TestObj();
            var reflector = new Reflector();

            // Act

            var exprObject = (DictionaryValue) reflector.GenerateExpressionConstant(testObj);

            // Assert
            Assert.That(exprObject, Is.Not.Null);
            Assert.That(exprObject.ValueAt("MyProperty").Value, Is.EqualTo(testObj.MyProperty));
            Assert.That(exprObject.ValueAt("MyPropertyWithPrivateSetter").Value, Is.EqualTo(testObj.MyPropertyWithPrivateSetter));
            Assert.That(exprObject.ValueAt("MyPublicField").Value, Is.EqualTo(testObj.MyPublicField));
            Assert.That(exprObject.ValueAt("MyPrivateProperty").HasValue, Is.False);
            Assert.That(exprObject.ValueAt("MyPrivateField").HasValue, Is.False);
        }
示例#24
0
        public void AutoGuid_HasGuid()
        {
            var db = new SQLiteConnection(TestPath.GetTempFileName());
            db.CreateTable<TestObj>(CreateFlags.AutoIncPK);

            var guid1 = new Guid("36473164-C9E4-4CDF-B266-A0B287C85623");
            var guid2 = new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6");

            var obj1 = new TestObj() { Id = guid1, Text = "First Guid Object" };
            var obj2 = new TestObj() { Id = guid2, Text = "Second Guid Object" };

            db.Insert(obj1);
            db.Insert(obj2);

            Assert.AreEqual(guid1, obj1.Id);
            Assert.AreEqual(guid2, obj2.Id);

            db.Close();
        }
示例#25
0
        public void AutoGuid_EmptyGuid()
        {
            var db = new SQLiteConnection(TestPath.GetTempFileName());
            db.CreateTable<TestObj>(CreateFlags.AutoIncPK);

            var obj1 = new TestObj() { Text = "First Guid Object" };
            var obj2 = new TestObj() { Text = "Second Guid Object" };

            Assert.AreEqual(Guid.Empty, obj1.Id);
            Assert.AreEqual(Guid.Empty, obj2.Id);

            db.Insert(obj1);
            db.Insert(obj2);

            Assert.AreNotEqual(Guid.Empty, obj1.Id);
            Assert.AreNotEqual(Guid.Empty, obj2.Id);
            Assert.AreNotEqual(obj1.Id, obj2.Id);

            db.Close();
        }
示例#26
0
        private async Task TestAsyncDateTime(SQLiteAsyncConnection db, bool storeDateTimeAsTicks)
        {
            await db.CreateTableAsync<TestObj>();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj
            {
                ModifiedTime = DateTime.UtcNow,
            };
            await db.InsertAsync(o);
            o2 = await db.GetAsync<TestObj>(o.Id);
            Assert.AreEqual(o.ModifiedTime, o2.ModifiedTime.ToUniversalTime());

            var expectedTimeZone = storeDateTimeAsTicks ? DateTimeKind.Utc : DateTimeKind.Local;
            Assert.AreEqual(o2.ModifiedTime.Kind, expectedTimeZone);
        }
示例#27
0
        private void TestDateTime(TestDb db)
        {
            db.CreateTable<TestObj>();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj
            {
                ModifiedTime = DateTime.UtcNow,
            };
            db.Insert(o);
            o2 = db.Get<TestObj>(o.Id);
            Assert.AreEqual(o.ModifiedTime, o2.ModifiedTime.ToUniversalTime());

            var expectedTimeZone = db.StoreDateTimeAsTicks ? DateTimeKind.Utc : DateTimeKind.Local;
            Assert.AreEqual(o2.ModifiedTime.Kind, expectedTimeZone);
        }
示例#28
0
        private void TestDateTime(TestDb db)
        {
            db.CreateTable<TestObj>();

            //
            // Ticks
            //
            var org = new TestObj
            {
                Time1 = DateTime.UtcNow,
                Time2 = DateTime.Now,
            };
            db.Insert(org);
            var fromDb = db.Get<TestObj>(org.Id);
            Assert.AreEqual(fromDb.Time1.ToUniversalTime(), org.Time1.ToUniversalTime());
            Assert.AreEqual(fromDb.Time2.ToUniversalTime(), org.Time2.ToUniversalTime());

            Assert.AreEqual(fromDb.Time1.ToLocalTime(), org.Time1.ToLocalTime());
            Assert.AreEqual(fromDb.Time2.ToLocalTime(), org.Time2.ToLocalTime());
        }
示例#29
0
        public void ShouldPersistAndReadGuid() {
            var db = new TestDb(TestPath.GetTempFileName());

            var obj1 = new TestObj() { Id=new Guid("36473164-C9E4-4CDF-B266-A0B287C85623"), Text = "First Guid Object" };
            var obj2 = new TestObj() {  Id=new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6"), Text = "Second Guid Object" };

            var numIn1 = db.Insert(obj1);
            var numIn2 = db.Insert(obj2);
            Assert.AreEqual(1, numIn1);
            Assert.AreEqual(1, numIn2);

            var result = db.Query<TestObj>("select * from TestObj").ToList();
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(obj1.Text, result[0].Text);
            Assert.AreEqual(obj2.Text, result[1].Text);

            Assert.AreEqual(obj1.Id, result[0].Id);
            Assert.AreEqual(obj2.Id, result[1].Id);

            db.Close();
        }
示例#30
0
        private void TestDateTime(TestDb db)
        {
            db.CreateTable <TestObj>();

            //
            // Ticks
            //
            var org = new TestObj
            {
                Time1 = DateTime.UtcNow,
                Time2 = DateTime.Now,
            };

            db.Insert(org);
            var fromDb = db.Get <TestObj>(org.Id);

            Assert.AreEqual(fromDb.Time1.ToUniversalTime(), org.Time1.ToUniversalTime());
            Assert.AreEqual(fromDb.Time2.ToUniversalTime(), org.Time2.ToUniversalTime());

            Assert.AreEqual(fromDb.Time1.ToLocalTime(), org.Time1.ToLocalTime());
            Assert.AreEqual(fromDb.Time2.ToLocalTime(), org.Time2.ToLocalTime());
        }
示例#31
0
        public void InsertTraces()
        {
            var oldTracer = _db.Tracer;
            var oldTrace  = _db.Trace;

            var traces = new List <string> ();

            _db.Tracer = traces.Add;
            _db.Trace  = true;

            var obj1 = new TestObj()
            {
                Text = "GLaDOS loves tracing!"
            };
            var numIn1 = _db.Insert(obj1);

            Assert.AreEqual(1, numIn1);
            Assert.AreEqual(1, traces.Count);

            _db.Tracer = oldTracer;
            _db.Trace  = oldTrace;
        }
        public void TestGetPropertyName()
        {
            var o = new TestObj();

            Assert.Equal("PropertyOne", o.GetPropertyName(() => o.PropertyOne));
            Assert.Equal("PropertyOne", o.GetPropertyName(() => - o.PropertyOne));

            Assert.Throws <ArgumentNullException>(() => o.GetPropertyName <int>(null));
            var ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => o.MethodOne()));

            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => - o.MethodOne()));
            Assert.Equal("Expression unaire invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => o.FieldOne));
            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            int varOne = o.MethodOne();

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => varOne));
            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => - varOne));
            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            var anony = new {
                PropertyOne = 1
            };

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => anony.PropertyOne));
            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => TestObj.StaticPropertyOne));
            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);

            ex = Assert.Throws <ArgumentException>(() => o.GetPropertyName(() => 123));
            Assert.Equal("Expression invalide. Doit être appelé avec une expression de type\r\nn() => PropertyName\r\nNom du paramètre : expression", ex.Message);
        }
示例#33
0
        public void can_deserialize_id_with_private_setter()
        {
            using (var documentStore = new EmbeddableDocumentStore
            {
                RunInMemory = true
            })
            {
                documentStore.Initialize();

                using (var session = documentStore.OpenSession())
                {
                    var testObj = new TestObj(1000, 123);
                    session.Store(testObj);
                    session.SaveChanges();
                    session.Advanced.Clear();
                    var load = session.Load <TestObj>(1000);

                    Assert.Equal(123, load.AnotherLong);
                    Assert.Equal(1000, load.Id);
                }
            }
        }
示例#34
0
        public async Task ClusterWideTransaction_WhenImportThenLoadAndUpdateWhileDeleted_ShouldFailUpdate()
        {
            var(nodes, leader) = await CreateRaftCluster(3);

            using var documentStore = GetDocumentStore(new Options { Server = leader, ReplicationFactor = nodes.Count });

            var entity = new TestObj();

            using (var source = GetDocumentStore())
            {
                using var session = source.OpenAsyncSession(new SessionOptions { TransactionMode = TransactionMode.ClusterWide });
                await session.StoreAsync(entity);

                await session.SaveChangesAsync();

                var operation = await source.Smuggler.ExportAsync(new DatabaseSmugglerExportOptions(), documentStore.Smuggler);

                await operation.WaitForCompletionAsync(TimeSpan.FromMinutes(1));
            }

            await LoadAndUpdateWhileDeleted(nodes, documentStore.Database, entity.Id);
        }
示例#35
0
        public async Task ClusterWideTransaction_WhenStore_ShouldCreateCompareExchange()
        {
            var(nodes, leader) = await CreateRaftCluster(3);

            using var store = GetDocumentStore(new Options { Server = leader, ReplicationFactor = nodes.Count });

            var entity = new TestObj();

            using (var session = store.OpenAsyncSession(new SessionOptions {
                TransactionMode = TransactionMode.ClusterWide
            }))
            {
                await session.StoreAsync(entity);

                await session.SaveChangesAsync();
            }

            var result = await store.Operations.SendAsync(new GetCompareExchangeValuesOperation <TestObj>(""));

            Assert.Single(result);
            Assert.EndsWith(entity.Id, result.Single().Key, StringComparison.OrdinalIgnoreCase);
        }
示例#36
0
        public void HashTable_find_items_with_contains()
        {
            var ht = new HashTable();

            var objs = new TestObj[] {
                new TestObj {
                    Number = 5
                },
                new TestObj {
                    Number = 1
                }
            };

            Assert.False(ht.Contains(objs[0]));

            ht.Add(objs[0], objs[0].Number);
            ht.Add(objs[1], objs[1].Number);

            Assert.True(ht.Contains(objs[0]));

            Assert.True(ht.ContainsValue((int)5));
        }
示例#37
0
        public void StringColumnContainsStringFunctionTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();

            var testObj = new TestObj {
                Name = "This is a Good name"
            };

            db.Insert(testObj);

            var finderObj = new TestObj {
                Name = "good"
            };
            Func <string> finder             = () => finderObj.Name;
            var           stringContainsTest = (from n in db.Table <TestObj>()
                                                where n.Name.Contains(finder())
                                                select n).Single();

            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
        }
示例#38
0
        public void InsertUsingSavePointsOnACommittedTransaction()
        {
            var obj = new TestObj {
                Text = "Matthew"
            };

            using (var db = new OrmTestSession())
            {
                db.CreateTable <TestObj>();

                var trans = db.BeginTransaction();
                trans.CreateSavepoint("First");
                trans.Commit();

#if SILVERLIGHT || MS_TEST
                ExceptionAssert.Throws <SqliteException>(() => trans.RollbackSavepoint("First"));
#elif NETFX_CORE
                Assert.ThrowsException <SqliteException>(() => trans.RollbackSavepoint("First"));
#else
                Assert.Catch <SqliteException>(() => trans.RollbackSavepoint("First"));
#endif
            }
        }
示例#39
0
        private async Task TestAsyncDateTime(SQLiteAsyncConnection db, bool storeDateTimeAsTicks)
        {
            await db.CreateTableAsync <TestObj>();

            TestObj o, o2;

            //
            // Ticks
            //
            o = new TestObj
            {
                ModifiedTime = DateTime.UtcNow,
            };
            await db.InsertAsync(o);

            o2 = await db.GetAsync <TestObj>(o.Id);

            Assert.AreEqual(o.ModifiedTime, o2.ModifiedTime.ToUniversalTime());

            var expectedTimeZone = storeDateTimeAsTicks ? DateTimeKind.Utc : DateTimeKind.Local;

            Assert.AreEqual(o2.ModifiedTime.Kind, expectedTimeZone);
        }
示例#40
0
        public void DifferShouldDiffObjectArrayElementsByIndexWhenUsingIndexEnumerableDiffer()
        {
            var differ = GetDiffer(true);
            var obj1   = new TestObj
            {
                Id = 1
            };
            var obj2 = new TestObj
            {
                Id = 2
            };
            IEnumerable <TestObj> array = new List <TestObj>
            {
                obj1, obj2
            };

            // should return 2 child diffs, one for each array element, even though the elements in each array are equal
            var diff = differ.Diff(array, array.Reverse());

            Assert.AreEqual(2, diff.ChildDiffs.Count());
            Assert.IsTrue(diff.ChildDiffs.Any(d => d.NewValue == obj1 && d.OldValue == obj2));
            Assert.IsTrue(diff.ChildDiffs.Any(d => d.NewValue == obj2 && d.OldValue == obj1));
        }
示例#41
0
        public void InsertAllWithinATransactionSucceeds()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();

            var first = new TestObj {
                Text = "First"
            };
            var second = new TestObj {
                Text = "Second"
            };
            var third = new TestObj {
                Text = "Third"
            };

            using (var trans = db.BeginTransaction())
            {
                var inObjs = db.InsertAll(new[] { first, second, third }, false);
                trans.Commit();
            }

            Assert.AreEqual(3, db.Table <TestObj>().Count());
        }
示例#42
0
        public void AutoGuid_HasGuid()
        {
            var db = GetConnection(CreateFlags.AutoIncPK);

            var guid1 = new Guid("36473164-C9E4-4CDF-B266-A0B287C85623");
            var guid2 = new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6");

            var obj1 = new TestObj()
            {
                Id = guid1, Text = "First Guid Object"
            };
            var obj2 = new TestObj()
            {
                Id = guid2, Text = "Second Guid Object"
            };

            var numIn1 = db.Insert(obj1);
            var numIn2 = db.Insert(obj2);

            Assert.AreEqual(guid1, obj1.Id);
            Assert.AreEqual(guid2, obj2.Id);

            db.Close();
        }
示例#43
0
            public void NonNullNullableValueNestedInObject_ExpectJsonUnaffected()
            {
                var testObj = new TestObj
                {
                    NullableFrequency    = Frequency.FromHertz(10),
                    NonNullableFrequency = Frequency.FromHertz(10)
                };
                // Ugly manually formatted JSON string is used because string literals with newlines are rendered differently
                //  on the build server (i.e. the build server uses '\r' instead of '\n')
                string expectedJson = "{\n" +
                                      "  \"NullableFrequency\": {\n" +
                                      "    \"Unit\": \"FrequencyUnit.Hertz\",\n" +
                                      "    \"Value\": 10.0\n" +
                                      "  },\n" +
                                      "  \"NonNullableFrequency\": {\n" +
                                      "    \"Unit\": \"FrequencyUnit.Hertz\",\n" +
                                      "    \"Value\": 10.0\n" +
                                      "  }\n" +
                                      "}";

                string json = SerializeObject(testObj);

                Assert.Equal(expectedJson, json);
            }
示例#44
0
        public void InsertTwoTimes()
        {
            var obj1 = new TestObj()
            {
                Text = "GLaDOS loves testing!"
            };
            var obj2 = new TestObj()
            {
                Text = "Keep testing, just keep testing"
            };


            var numIn1 = _db.Insert(obj1);
            var numIn2 = _db.Insert(obj2);

            Assert.AreEqual(1, numIn1);
            Assert.AreEqual(1, numIn2);

            var result = _db.Query <TestObj>("select * from TestObj").ToList();

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(obj1.Text, result[0].Text);
            Assert.AreEqual(obj2.Text, result[1].Text);
        }
示例#45
0
        public void InsertOrReplace()
        {
            _db.TraceListener = DebugTraceListener.Instance;
            _db.InsertAll(from i in Enumerable.Range(1, 20)
                          select new TestObj
            {
                Text = "#" + i
            });

            Assert.AreEqual(20, _db.Table <TestObj>().Count());

            var t = new TestObj
            {
                Id   = 5,
                Text = "Foo",
            };

            _db.InsertOrReplace(t);

            List <TestObj> r = (from x in _db.Table <TestObj>() orderby x.Id select x).ToList();

            Assert.AreEqual(20, r.Count);
            Assert.AreEqual("Foo", r[4].Text);
        }
示例#46
0
            public Task Run()
            {
                var t = Task.Run(() =>
                {
                    try
                    {
                        while (true)
                        {
                            using (var dbConnection = new DbConnection(SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.ReadWrite))
                            {
                                System.Diagnostics.Debug.WriteLine($"{Environment.CurrentManagedThreadId} Start insert");

                                for (var i = 0; i < 50; i++)
                                {
                                    var newRecord = new TestObj()
                                    {
                                    };

                                    dbConnection.Insert(newRecord);
                                }

                                System.Diagnostics.Debug.WriteLine($"{Environment.CurrentManagedThreadId} Inserted records");
                            }

                            // No await so we stay on the same thread
                            Task.Delay(1).GetAwaiter().GetResult();
                            cancellationToken.ThrowIfCancellationRequested();
                        }
                    }
                    catch (OperationCanceledException)
                    {
                    }
                });

                return(t);
            }
示例#47
0
    void Spawn()
    {
        TestObj obj = (TestObj)Poolers.Ins.GetObject(pre);

        obj.OnSpawn();
    }
        static List <long> RunSerializer(IJsonSerializer jsonSerializer, int iterations, TestObj testObj)
        {
            var timing = new List <long>();
            var sw     = new Stopwatch();

            for (int i = 0; i < iterations; i++)
            {
                sw.Start();
                var serialised = jsonSerializer.SerializeToString(testObj);
                sw.Stop();
                timing.Add(sw.ElapsedTicks);
                sw.Reset();
            }

            return(timing);
        }
示例#49
0
 public static void AssignNewInstance(TestObj testObj)
 {
     testObj = new TestObj {
         Val = "Changed in AssignNewInstance"
     };
 }
示例#50
0
 public void LoadObj()
 {
     testObj = ObjectHandler.ReadObject <TestObj>("testObj.json", fileType: FileType.Json);
 }
示例#51
0
        public void MultiplePkOperations()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();

            // insert
            const int n = 10, m = 5;
            var       objs = new TestObj[n * m];

            for (int j = 0; j != n; ++j)
            {
                for (int i = 0; i != m; ++i)
                {
                    objs[j * m + i] = new TestObj {
                        Id = j, SubId = i, Text = "I am (" + j + "," + i + ")"
                    };
                }
            }

            int numIn = db.InsertAll(objs);

            Assert.AreEqual(numIn, n * m, "Num inserted must = num objects");

            var obj = db.Get <TestObj>(5, 3);

            Assert.AreEqual(5, obj.Id);
            Assert.AreEqual(3, obj.SubId);
            Assert.AreEqual("I am (5,3)", obj.Text);

            try
            {
                db.Insert(obj);
            }
            catch (SqliteException ex)
            {
                Assert.AreEqual(SQLiteErrorCode.Constraint, ex.ErrorCode);
            }

            // update
            obj.Text = "I've been changed";
            db.Update(obj);
            db.Update <TestObj>("Text", "I've been changed also", 8, 2);

            obj = db.Get <TestObj>(5, 3);
            Assert.AreEqual("I've been changed", obj.Text);

            obj = db.Get <TestObj>(8, 2);
            Assert.AreEqual("I've been changed also", obj.Text);

            db.UpdateAll <TestObj>("Text", "All changed");
            IEnumerable <TestObj> q1 = from o in db.Table <TestObj>() select o;

            foreach (TestObj o in q1)
            {
                Assert.AreEqual("All changed", o.Text);
            }

            TestObj[] q2 = (from o in db.Table <TestObj>() where o.SubId == 3 select o).ToArray();
            Assert.AreEqual(10, q2.Length);
            for (int i = 0; i != 10; ++i)
            {
                Assert.AreEqual(i, q2[i].Id);
            }

            object numCount = db.Table <TestObj>().Count();

            Assert.AreEqual(numCount, objs.Length, "Num counted must = num objects");

            // delete
            obj = db.Get <TestObj>(8, 2);
            db.Delete(obj);

            ExceptionAssert.Throws <InvalidOperationException>(() => db.Get <TestObj>(8, 2));

            db.Execute("delete from TestObj where SubId=2");
            numCount = db.ExecuteScalar <int>("select count(*) from TestObj");
            Assert.AreEqual(numCount, objs.Length - 10);
            foreach (TestObj o in (from o in db.Table <TestObj>() select o))
            {
                Assert.AreNotEqual(2, o.SubId);
            }
        }
示例#52
0
        public static void Main()
        {
            // This test suite does not use the Test Runner infrastructure as it requires a
            // reboot of the physical device to verify the references have been saved.  It relies
            // on the test harness to time it out if it fails to complete because of issues with
            // EWR persistence.

            // Skip test on Emulator
            if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
            {
                StartTestLog("Emulator, skipping...");
                EndTestLog(0, 0, 1);
            }

            else
            {
                ewrs[0] = ExtendedWeakReference.Recover(typeof(TestRunTracker), 0);
                if (ewrs[0] == null)
                {
                    ewrs[0] = ExtendedWeakReference.RecoverOrCreate(
                        typeof(TestRunTracker),
                        0,
                        ExtendedWeakReference.c_SurviveBoot | ExtendedWeakReference.c_SurvivePowerdown);
                    runTracker = new TestRunTracker()
                    {
                        RebootCount = -1, TestState = TestRunTracker.State.Initialize
                    };
                }
                else
                {
                    runTracker = (TestRunTracker)ewrs[0].Target;
                }

                Log.Comment("State: " + runTracker.TestState + ", Reboot Count: " + runTracker.RebootCount);

                switch (runTracker.TestState)
                {
                // Initial state
                case TestRunTracker.State.Initialize:
                    if (runTracker.RebootCount == -1)
                    {
                        StartTestLog("No EWR found, initializing for first run...");
                    }
                    else
                    {
                        StartTestLog("Previous EWR found.  Re-initializing...");
                    }

                    runTracker.TestState   = TestRunTracker.State.HardReboot;
                    runTracker.RebootCount = 0;
                    runTracker.TestState   = TestRunTracker.State.HardReboot;
                    for (uint i = 1; i < 10; i++)
                    {
                        ewrs[i] = ExtendedWeakReference.RecoverOrCreate(typeof(TestObj), i,
                                                                        ExtendedWeakReference.c_SurvivePowerdown |
                                                                        ExtendedWeakReference.c_SurviveBoot);
                        TestObj obj = new TestObj();
                        ewrs[i].Target          = obj;
                        runTracker.objHashes[i] = obj.GetHashCode();
                    }
                    break;

                // HardReboot cases - Reboots 1 - 3
                case TestRunTracker.State.HardReboot:
                    Debug.Print("<TestMethod name=\"HardReboot" + runTracker.RebootCount + "\">");

                    // Validate objects
                    if (ValidateEWR(true))
                    {
                        Debug.Print("    <TestMethodResult Result=\"Pass\">");
                        runTracker.PassCount++;
                    }
                    else
                    {
                        Debug.Print("    <TestMethodResult Result=\"Fail\">");
                        runTracker.FailCount++;
                    }
                    Debug.Print("        <Text><![CDATA[TEST: HardReboot" + runTracker.RebootCount + "]]></Text>" + TimeStamp());
                    Debug.Print("    </TestMethodResult>");
                    Debug.Print("</TestMethod>");

                    // End test
                    if (runTracker.RebootCount >= 3)
                    {
                        runTracker.TestState = TestRunTracker.State.SoftReboot;
                    }

                    break;

                // SoftReboot cases - Reboots 4 - 6
                case TestRunTracker.State.SoftReboot:
                    Debug.Print("<TestMethod name=\"SoftReboot" + runTracker.RebootCount + "\">");

                    // Validate objects
                    if (ValidateEWR(true))
                    {
                        Debug.Print("    <TestMethodResult Result=\"Pass\">");
                        runTracker.PassCount++;
                    }
                    else
                    {
                        Debug.Print("    <TestMethodResult Result=\"Fail\">");
                        runTracker.FailCount++;
                    }
                    Debug.Print("        <Text><![CDATA[TEST: SoftReboot" + runTracker.RebootCount + "]]></Text>" + TimeStamp());
                    Debug.Print("    </TestMethodResult>");
                    Debug.Print("</TestMethod>");

                    // End test
                    if (runTracker.RebootCount >= 6)
                    {
                        runTracker.TestState = TestRunTracker.State.Restore;
                    }
                    break;

                // Restore cases - Reboots 7 - 8
                case TestRunTracker.State.Restore:
                    Debug.Print("<TestMethod name=\"Restore" + runTracker.RebootCount + "\">");
                    if (runTracker.RebootCount == 7)
                    {
                        Log.Comment("Restore and Pushback with Soft Reboot");
                    }
                    else
                    {
                        Log.Comment("Restore and Pushback with Hard Reboot");
                    }

                    // Validate objects
                    if (ValidateEWR(false))
                    {
                        Debug.Print("    <TestMethodResult Result=\"Pass\">");
                        runTracker.PassCount++;
                    }
                    else
                    {
                        Debug.Print("    <TestMethodResult Result=\"Fail\">");
                        runTracker.FailCount++;
                    }
                    Debug.Print("        <Text><![CDATA[TEST: SoftReboot" + runTracker.RebootCount + "]]></Text>" + TimeStamp());
                    Debug.Print("    </TestMethodResult>");
                    Debug.Print("</TestMethod>");

                    if (runTracker.RebootCount > 8)
                    {
                        runTracker.TestState = TestRunTracker.State.Complete;
                    }
                    break;

                // Tests complete
                case TestRunTracker.State.Complete:
                    runTracker.TestState = TestRunTracker.State.Initialize;
                    // Close logs
                    EndTestLog(runTracker.PassCount, runTracker.FailCount, 0);
                    break;
                }
                runTracker.RebootCount++;
                ewrs[0].Target = runTracker;
                // Need to sleep to make sure debug buffer has chance to flush before rebooting
                // This should not be needed for EWR any longer
                System.Threading.Thread.Sleep(15000);

                switch (runTracker.TestState)
                {
                case TestRunTracker.State.HardReboot:
                    PowerState.RebootDevice(false);
                    break;

                case TestRunTracker.State.SoftReboot:
                    PowerState.RebootDevice(true);
                    break;

                case TestRunTracker.State.Restore:
                    if (runTracker.RebootCount == 8)
                    {
                        PowerState.RebootDevice(true);
                    }
                    else
                    {
                        PowerState.RebootDevice(false);
                    }
                    break;
                }
                // fall through to end test suite
            }
        }
 public void GetMapMarkers(TestObj t)
 {
     // ..
 }
示例#54
0
 public IActionResult Test(TestObj model)
 {
     return(View(model));
 }
示例#55
0
 private void DeserializeCallback(System.IO.BinaryReader reader, StatusInstance <TestObj> instance, TestObj obj)
 {
     Assert.AreEqual("hello", reader.ReadString());
     Assert.AreEqual(true, reader.ReadBoolean());
     if (instance.GetStatus <TestStatus>() == TestStatus.A)
     {
         deserializedInstanceA = instance;
     }
 }
示例#56
-1
        public void AutoGuid_EmptyGuid()
        {
            var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.GetTempFileName());
            db.CreateTable<TestObj>(CreateFlags.AutoIncPK);

            var guid1 = new Guid("36473164-C9E4-4CDF-B266-A0B287C85623");
            var guid2 = new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6");

            var obj1 = new TestObj
            {
                Text = "First Guid Object"
            };
            var obj2 = new TestObj
            {
                Text = "Second Guid Object"
            };

            Assert.AreEqual(Guid.Empty, obj1.Id);
            Assert.AreEqual(Guid.Empty, obj2.Id);

            int numIn1 = db.Insert(obj1);
            int numIn2 = db.Insert(obj2);
            Assert.AreNotEqual(Guid.Empty, obj1.Id);
            Assert.AreNotEqual(Guid.Empty, obj2.Id);
            Assert.AreNotEqual(obj1.Id, obj2.Id);

            db.Close();
        }