Esempio n. 1
0
        public void TestDeleteAll()
        {
            Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList());
            _queryable.Delete();

            Assert.ScriptsCalled(_databaseFixture, () => _queryable.Save(), 2, Query.Delete);
        }
Esempio n. 2
0
        public virtual void TestDifferentWritabilityLevels()
        {
            E.DifferentWritabilityLevels entity = _databaseFixture.ObjectProvider.CreateObject <E.DifferentWritabilityLevels>();

            entity.Writeable  = 5;
            entity.Insertable = 10;
            entity.Updateable = 15;

            Assert.ScriptCalled(_databaseFixture, Query.InsertDifferentWritabilityLevels, () => _databaseFixture.ObjectProvider.GetQueryable <E.DifferentWritabilityLevels>().Save());

            Assert.Equal(5, entity.Writeable);
            Assert.Equal(10, entity.Insertable);
            Assert.Equal(1, entity.Updateable);
            Assert.Equal(1, entity.Readonly);

            entity = Assert.ScriptCalled(_databaseFixture, Query.SelectDifferentWritabilityLevels, () => _databaseFixture.ObjectProvider.GetQueryable <E.DifferentWritabilityLevels>().ToList().First());

            entity.Writeable  = 20;
            entity.Insertable = 25;
            entity.Updateable = 30;

            Assert.ScriptCalled(_databaseFixture, Query.UpdateDifferentWritabilityLevels, () => _databaseFixture.ObjectProvider.GetQueryable <E.DifferentWritabilityLevels>().Save());

            Assert.Equal(20, entity.Writeable);
            Assert.Equal(10, entity.Insertable);
            Assert.Equal(30, entity.Updateable);
            Assert.Equal(2, entity.Readonly);
        }
Esempio n. 3
0
        public void TestOrderBy()
        {
            E.Test t = Assert.Single(Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList().Where(x => x.Id == 1)));

            Assert.ScriptCalled(_databaseFixture, Query.OrderBy, () =>
                                Assert.Collection(_subQueryable.Where(x => x.Test == t).OrderBy(x => x.Second),
                                                  x => Assert.Equal(10, x.Id),
                                                  x => Assert.Equal(9, x.Id),
                                                  x => Assert.Equal(8, x.Id),
                                                  x => Assert.Equal(7, x.Id),
                                                  x => Assert.Equal(6, x.Id),
                                                  x => Assert.Equal(5, x.Id),
                                                  x => Assert.Equal(4, x.Id),
                                                  x => Assert.Equal(3, x.Id),
                                                  x => Assert.Equal(2, x.Id),
                                                  x => Assert.Equal(1, x.Id)));

            Assert.ScriptCalled(_databaseFixture, Query.OrderByDescending, () =>
                                Assert.Collection(_subQueryable.Where(x => x.Test == t).OrderByDescending(x => x.Second),
                                                  x => Assert.Equal(1, x.Id),
                                                  x => Assert.Equal(2, x.Id),
                                                  x => Assert.Equal(3, x.Id),
                                                  x => Assert.Equal(4, x.Id),
                                                  x => Assert.Equal(5, x.Id),
                                                  x => Assert.Equal(6, x.Id),
                                                  x => Assert.Equal(7, x.Id),
                                                  x => Assert.Equal(8, x.Id),
                                                  x => Assert.Equal(9, x.Id),
                                                  x => Assert.Equal(10, x.Id)));
        }
Esempio n. 4
0
        public void TestSimpleExpression(Query query, Expression <Func <E.SubTest, bool> > expression)
        {
            _output.WriteLine($"Test {query} expression");
            List <E.SubTest> subResult = Assert.ScriptCalled(_databaseFixture, query, () => _subQueryable.Where(expression).ToList());

            Assert.Equal(GetDefaultResult(query).Count(), subResult.Count);
            _output.WriteLine("... Done");
        }
Esempio n. 5
0
        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"));
        }
Esempio n. 6
0
        public void TestDeleteForeignObjectKeyEntities()
        {
            E.Test testKey = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().ForceLoad().ToList()).Where(x => x.Id == 1).First();

            E.ForeignObjectKey entity = _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKey>().Where(x => x.Test == testKey).FirstOrDefault();
            Assert.NotNull(entity);
            _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKey>().Where(x => x == entity).Delete();

            Assert.ScriptCalled(_databaseFixture, Query.DeleteForeignObjectKeyEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKey>().Where(x => x == entity).Save());
        }
Esempio n. 7
0
        public void TestForeignObjectExpression(Query query, Func <IQueryable <E.SubTest>, E.Test, IQueryable <E.SubTest> > function, string queryPattern, IEnumerable <object[]> values)
        {
            _output.WriteLine($"Test {query} expression");

            E.Test t = Assert.Single(Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList().Where(x => x.Id == 1)));

            List <E.SubTest> subResult = Assert.ScriptCalled(_databaseFixture, query, () => function(_subQueryable, t).ToList());

            Assert.Equal(values.Count(), subResult.Count);
            _output.WriteLine("... Done");
        }
Esempio n. 8
0
        public void TestUpdateForeignObjectKeyEntities()
        {
            E.Test testKey = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().ForceLoad().ToList()).Where(x => x.Id == 1).First();
            string text    = FirstRandomText;

            _databaseFixture.SetResult(Query.UpdateForeignObjectKeyEntity, new[] { new object[] { testKey.Id, text } });

            E.ForeignObjectKey entity = _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKey>().Where(x => x.Test == testKey).ForceLoad().FirstOrDefault();
            Assert.NotNull(entity);
            entity.Value = text;

            Assert.ScriptCalled(_databaseFixture, Query.UpdateForeignObjectKeyEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKey>().Where(x => x == entity).Save());
        }
Esempio n. 9
0
        public void TestDeleteSingle()
        {
            E.Test entity = Assert.ScriptCalled(_databaseFixture, Query.Select, () => Assert.Single(_queryable.ToList().Where(x => x.Id == 1)));

            // Quick fix to prevent the test to run in to issue #14 problem, needs to be removed in the future.
            entity.SubTests.ToList().Select(x => x.Test).ToList();

            IQueryable <E.Test> queryable = _databaseFixture.ObjectProvider.GetQueryable <E.Test>().Where(x => x == entity);

            queryable.Delete();

            Assert.ScriptCalled(_databaseFixture, Query.Delete, () => queryable.Save());
        }
Esempio n. 10
0
        public void TestUpdate()
        {
            E.Test entity = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList().First());

            string oldString = entity.Description;
            string newString = oldString == FirstRandomText ? SecondRandomText : FirstRandomText;

            _databaseFixture.SetResult(Query.Update, new[] { new object[] { entity.Id, entity.Name, newString } });

            Assert.PropertyChanged((INotifyPropertyChanged)entity, nameof(E.Test.Description),
                                   () => entity.Description = newString);

            Assert.ScriptCalled(_databaseFixture, Query.Update, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().Where(x => x == entity).Save());
        }
Esempio n. 11
0
        public void TestInsertNonAutoInitializedKey()
        {
            List <E.NonInitializedKey> cachedItems = Assert.ScriptCalled(_databaseFixture, Query.SelectNonInitializedKeyEntitiy, () => _databaseFixture.ObjectProvider.GetQueryable <E.NonInitializedKey>().ForceLoad().ToList());
            int newId = cachedItems.Count == 0 ? 1 : cachedItems.Max(x => x.Id) + 1;

            _databaseFixture.SetResult(Query.InsertNonInitializedKeyEntitiy, new[] { new object[] { newId } });

            E.NonInitializedKey entity = _databaseFixture.ObjectProvider.CreateObject <E.NonInitializedKey>();
            Assert.NotNull(entity);
            entity.Id = newId;

            Assert.ScriptCalled(_databaseFixture, Query.InsertNonInitializedKeyEntitiy, () => _databaseFixture.ObjectProvider.GetQueryable <E.NonInitializedKey>().Where(x => x == entity).Save());
            Assert.Equal(entity.Id, newId);
        }
Esempio n. 12
0
        public void TestCheckChanged()
        {
            List <string> recordedPropertyChanged = new List <string>();
            List <E.Test> elements = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList());

            PropertyChangedEventHandler propertyChangedHandler = (s, e) =>
            {
                recordedPropertyChanged.Add(e.PropertyName);
            };

            ((INotifyPropertyChanged)elements[0]).PropertyChanged += propertyChangedHandler;

            try
            {
                string originalDescription = elements[0].Description;
                string newDescription      = elements[0].Description == FirstRandomText ? SecondRandomText : FirstRandomText;

                Assert.False(_queryable.CheckChanged());

                elements[0].Description = newDescription;

                Assert.True(_queryable.CheckChanged());

                elements[0].Description = originalDescription;

                Assert.False(_queryable.CheckChanged());

                elements[0].Description = newDescription;

                Assert.True(_queryable.CheckChanged());

                _queryable.DropChanges();

                Assert.False(_queryable.CheckChanged());


                Assert.Collection(recordedPropertyChanged,
                                  x => Assert.Equal(nameof(E.Test.Description), x),
                                  x => Assert.Equal(nameof(E.Test.Description), x),
                                  x => Assert.Equal(nameof(E.Test.Description), x),
                                  x => Assert.True(string.IsNullOrEmpty(x)),
                                  x => Assert.True(string.IsNullOrEmpty(x)));
            }
            finally
            {
                ((INotifyPropertyChanged)elements[0]).PropertyChanged -= propertyChangedHandler;
            }
        }
Esempio n. 13
0
        public void TestTake()
        {
            List <E.SubTest> subResult = Assert.ScriptCalled(_databaseFixture, Query.SelectSubTake10, () => _subQueryable.OrderBy(x => x.Id).Take(10).ToList());

            Assert.Collection(subResult,
                              x => Assert.Equal(1, x.Id),
                              x => Assert.Equal(2, x.Id),
                              x => Assert.Equal(3, x.Id),
                              x => Assert.Equal(4, x.Id),
                              x => Assert.Equal(5, x.Id),
                              x => Assert.Equal(6, x.Id),
                              x => Assert.Equal(7, x.Id),
                              x => Assert.Equal(8, x.Id),
                              x => Assert.Equal(9, x.Id),
                              x => Assert.Equal(10, x.Id));
        }
Esempio n. 14
0
        public void TestInsertForeignObjectKeyChainEntity()
        {
            E.Test             testKey          = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().ForceLoad().ToList()).Where(x => x.Id == 1).First();
            E.SubTest          subTestKey       = _subQueryable.Where(x => x.Test == testKey).ToList().FirstOrDefault();
            E.ForeignObjectKey foreignObjectKey = Assert.ScriptCalled(_databaseFixture, Query.SelectForeignObjectKeyEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKey>().Where(x => x.Test == testKey).ForceLoad().ToList()).First();
            string             text             = FirstRandomText;

            _databaseFixture.SetResult(Query.InsertForeignObjectKeyChainEntity, new[] { new object[] { foreignObjectKey.Test.Id, subTestKey.Id, text } });

            E.ForeignObjectKeyChain entity = _databaseFixture.ObjectProvider.CreateObject <E.ForeignObjectKeyChain>();
            Assert.NotNull(entity);
            entity.ForeignObjectKey = foreignObjectKey;
            entity.SubTest          = subTestKey;
            entity.Value            = text;

            Assert.ScriptCalled(_databaseFixture, Query.InsertForeignObjectKeyChainEntity, () => _databaseFixture.ObjectProvider.GetQueryable <E.ForeignObjectKeyChain>().Where(x => x == entity).Save());
        }
Esempio n. 15
0
        public void TestInsert()
        {
            List <E.Test> cachedItems = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().ForceLoad().ToList());
            int           newId       = cachedItems.Count == 0 ? 1 : cachedItems.Max(x => x.Id) + 1;
            string        name        = $"Testname {DateTime.Now:g}";
            string        description = FirstRandomText;

            _databaseFixture.SetResult(Query.Insert, new[] { new object[] { newId, name, description } });

            E.Test entity = _databaseFixture.ObjectProvider.CreateObject <E.Test>();
            Assert.NotNull(entity);
            entity.Name        = name;
            entity.Description = description;

            _output.WriteLine($"Entity created, Name: {entity.Name}");

            Assert.PropertyChanged((INotifyPropertyChanged)entity, nameof(E.Test.Id),
                                   () => Assert.ScriptCalled(_databaseFixture, Query.Insert, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().Where(x => x == entity).Save()));

            Assert.Equal(entity.Id, newId);
            _output.WriteLine($"First entity saved, new Id: {entity.Id} -> passed");
        }
Esempio n. 16
0
        public void TestSelect()
        {
            List <E.Test> result = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList()).OrderBy(x => x.Id).ToList();

            E.Test t = result.First();

            IQueryable <E.SubTest> queryable       = _subQueryable.Where(x => x.Test == t);
            IQueryable <string>    selectQueryable = queryable.Select(x => x.Name);

            List <string>    selectResult = selectQueryable.ToList();
            List <E.SubTest> subResult    = queryable.ToList();

            selectResult.Sort();

            Assert.Collection(selectResult,
                              x => Assert.Equal("SubEntity0", x),
                              x => Assert.Equal("SubEntity10", x),
                              x => Assert.Equal("SubEntity12", x),
                              x => Assert.Equal("SubEntity14", x),
                              x => Assert.Equal("SubEntity16", x),
                              x => Assert.Equal("SubEntity18", x),
                              x => Assert.Equal("SubEntity2", x),
                              x => Assert.Equal("SubEntity4", x),
                              x => Assert.Equal("SubEntity6", x),
                              x => Assert.Equal("SubEntity8", x));

            int removeCount = 0;

            NotifyCollectionChangedEventHandler collectionChangedHandler = (s, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    removeCount++;
                }
            };

            try
            {
                ((INotifyCollectionChanged)selectQueryable).CollectionChanged += collectionChangedHandler;

                subResult.First().Test = result[1];

                Assert.Equal(1, removeCount);

                selectResult = selectQueryable.ToList();
                selectResult.Sort();

                Assert.Collection(selectResult,
                                  x => Assert.Equal("SubEntity10", x),
                                  x => Assert.Equal("SubEntity12", x),
                                  x => Assert.Equal("SubEntity14", x),
                                  x => Assert.Equal("SubEntity16", x),
                                  x => Assert.Equal("SubEntity18", x),
                                  x => Assert.Equal("SubEntity2", x),
                                  x => Assert.Equal("SubEntity4", x),
                                  x => Assert.Equal("SubEntity6", x),
                                  x => Assert.Equal("SubEntity8", x));

                _subQueryable.DropChanges();
            }
            finally
            {
                ((INotifyCollectionChanged)selectQueryable).CollectionChanged -= collectionChangedHandler;
            }
        }