Exemple #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"));
        }
Exemple #2
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;
            }
        }