public virtual void TestUsingDifferentDataTypes() { E.DifferentTypes entity = _databaseFixture.ObjectProvider.CreateObject <E.DifferentTypes>(); entity.Text = FirstRandomText; entity.Boolean = true; entity.Int = int.MaxValue; entity.Byte = byte.MaxValue; entity.Short = short.MaxValue; entity.Long = long.MaxValue; entity.DateTime = DateTime.MaxValue; entity.Guid = FirstRandomGuid; entity.Binary = FirstRandomGuid.ToByteArray(); entity.Decimal = 1234567890.12345m; entity.Xml = new XElement("root", new XElement("sub1", "Value")); Assert.ScriptCalled(_databaseFixture, Query.InsertDifferentTypesEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.DifferentTypes>().Save()); Assert.Equal(FirstRandomText, entity.Text); Assert.True(entity.Boolean); Assert.Equal(int.MaxValue, entity.Int); Assert.Equal(byte.MaxValue, entity.Byte); Assert.Equal(short.MaxValue, entity.Short); Assert.Equal(long.MaxValue, entity.Long); Assert.InRange(entity.DateTime, DatabaseMaxDate, DateTime.MaxValue); Assert.Equal(FirstRandomGuid, entity.Guid); Assert.Equal(FirstRandomGuid.ToByteArray(), entity.Binary); Assert.Equal(1234567890.12345m, entity.Decimal); Assert.NotNull(entity.Xml.Element("sub1")); entity = Assert.ScriptCalled(_databaseFixture, Query.SelectDifferentTypesEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.DifferentTypes>().ForceLoad().ToList().First()); entity.Text = SecondRandomText; entity.Boolean = false; entity.Int = int.MinValue; entity.Byte = byte.MinValue; entity.Short = short.MinValue; entity.Long = long.MinValue; entity.DateTime = DateTime.MinValue; entity.Guid = SecondRandomGuid; entity.Binary = SecondRandomGuid.ToByteArray(); entity.Decimal = 9876543210.54321m; entity.Xml = new XElement("root", new XElement("sub2", "Value")); Assert.ScriptCalled(_databaseFixture, Query.UpdateDifferentTypesEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.DifferentTypes>().Save()); Assert.Equal(SecondRandomText, entity.Text); Assert.False(entity.Boolean); Assert.Equal(int.MinValue, entity.Int); Assert.Equal(byte.MinValue, entity.Byte); Assert.Equal(short.MinValue, entity.Short); Assert.Equal(long.MinValue, entity.Long); Assert.InRange(entity.DateTime, DateTime.MinValue, DatabaseMinDate); Assert.Equal(SecondRandomGuid, entity.Guid); Assert.Equal(SecondRandomGuid.ToByteArray(), entity.Binary); Assert.Equal(9876543210.54321m, entity.Decimal); Assert.NotNull(entity.Xml.Element("sub2")); }
public async Task TestBeginFetch() { int collectionChangedCounter = 0; List <Query> hittedCommands = new List <Query>(); ManualResetEvent manualResetEvent = new ManualResetEvent(false); ManualResetEvent manualResetEvent2 = new ManualResetEvent(false); EventHandler <HitCommandEventArgs> blockHandler = (s, e) => { hittedCommands.Add(e.Key); manualResetEvent2.Set(); manualResetEvent.WaitOne(); }; NotifyCollectionChangedEventHandler collectionChangedHandler = (s, e) => { lock (this) { collectionChangedCounter++; } }; IQueryable <E.Test> testQueryable = _databaseFixture.ObjectProvider.GetQueryable <E.Test>(); IQueryable <E.SubTest> subTestQueryable = _databaseFixture.ObjectProvider.GetQueryable <E.SubTest>(); _databaseFixture.HitCommand += blockHandler; try { ((INotifyCollectionChanged)testQueryable).CollectionChanged += collectionChangedHandler; ((INotifyCollectionChanged)subTestQueryable).CollectionChanged += collectionChangedHandler; Task[] tasks = new Task[] { subTestQueryable.FetchAsync(), testQueryable.FetchAsync(), subTestQueryable.FetchAsync() }; manualResetEvent2.WaitOne(); Assert.Collection(hittedCommands, x => Assert.Equal(Query.SelectSub, x)); manualResetEvent.Set(); await tasks[0]; await tasks[1]; await tasks[2]; Assert.Collection(hittedCommands, x => Assert.Equal(Query.SelectSub, x), x => Assert.Equal(Query.Select, x), x => Assert.Equal(Query.SelectSub, x)); Assert.InRange(collectionChangedCounter, 20, int.MaxValue); } finally { _databaseFixture.HitCommand -= blockHandler; ((INotifyCollectionChanged)testQueryable).CollectionChanged -= collectionChangedHandler; ((INotifyCollectionChanged)subTestQueryable).CollectionChanged -= collectionChangedHandler; } }