Example #1
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"));
        }
Example #2
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());
        }
Example #3
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());
        }
Example #4
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);
        }
Example #5
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());
        }
Example #6
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");
        }