Пример #1
0
        public void Trim()
        {
            using (session.BeginTransaction())
            {
                AnotherEntity ae1 = new AnotherEntity {
                    Input = " hi "
                };
                AnotherEntity ae2 = new AnotherEntity {
                    Input = "hi"
                };
                AnotherEntity ae3 = new AnotherEntity {
                    Input = "heh"
                };
                session.Save(ae1);
                session.Save(ae2);
                session.Save(ae3);
                session.Flush();

                Assert.AreEqual(2, session.Query <AnotherEntity>().Where(e => e.Input.Trim() == "hi").Count());
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.TrimEnd() == " hi").Count());

                // Emulated trim does not support multiple trim characters, but for many databases it should work fine anyways.
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.Trim('h') == "e").Count());
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.TrimStart('h') == "eh").Count());
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.TrimEnd('h') == "he").Count());

                // Let it rollback to get rid of temporary changes.
            }
        }
Пример #2
0
        public void Trim()
        {
            using (session.BeginTransaction())
            {
                AnotherEntity ae1 = new AnotherEntity {
                    Input = " hi "
                };
                AnotherEntity ae2 = new AnotherEntity {
                    Input = "hi"
                };
                AnotherEntity ae3 = new AnotherEntity {
                    Input = "heh"
                };
                session.Save(ae1);
                session.Save(ae2);
                session.Save(ae3);
                session.Flush();

                Assert.AreEqual(2, session.Query <AnotherEntity>().Count(e => e.Input.Trim() == "hi"));
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.TrimEnd() == " hi"));

                // Emulated trim does not support multiple trim characters, but for many databases it should work fine anyways.
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.Trim('h') == "e"));
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.TrimStart('h') == "eh"));
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.TrimEnd('h') == "he"));

                // Check when passed as array
                // (the single character parameter is a new overload in .netcoreapp2.0, but not net461 or .netstandard2.0).
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.Trim(new [] { 'h' }) == "e"));
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.TrimStart(new[] { 'h' }) == "eh"));
                Assert.AreEqual(1, session.Query <AnotherEntity>().Count(e => e.Input.TrimEnd(new[] { 'h' }) == "he"));

                // Let it rollback to get rid of temporary changes.
            }
        }
Пример #3
0
 public JsonConverterTests()
 {
     _converter = new JilJsonConverter();
     _id = Guid.NewGuid();
     _description = "xxx";
     _entityToSerialize = new AnotherEntity {Id = _id,Description = _description};
 }
Пример #4
0
 public JsonConverterTests()
 {
     _converter = new JilJsonConverter();
     _id = DateTime.Now.Ticks;
     _description = "xxx";
     _entityToSerialize = new AnotherEntity {Id = _id,Description = _description};
 }
Пример #5
0
        public void SomeOperation(AnotherEntityId id)
        {
            AnotherEntity entity = _anotherEntityRepository.GetById(id);

            entity.SomeLogic();

            _anotherEntityRepository.Update(entity);
        }
Пример #6
0
        public void SetUp()
        {
            _simpleEntity = new SimpleEntity();

            _anotherEntity = new AnotherEntity();

            _compoundEntity = new CompoundEntity();
        }
Пример #7
0
 public JsonConverterTests()
 {
     _converter         = new JilJsonConverter();
     _id                = Guid.NewGuid();
     _description       = "xxx";
     _entityToSerialize = new AnotherEntity {
         Id = _id, Description = _description
     };
 }
        protected override void Seed(ThingieContext context)
        {
            var entity1 = new AThingAsEntity("This is MY thing", 42, "That is the meaning of life");
            var entity2 = new AnotherEntity
            {
                Id = 41
            };

            entity1.Relationship = entity2;
            context.Things.Add(entity1);
            context.Another.Add(entity2);
            base.Seed(context);
        }
Пример #9
0
        public CompoundEntity Create(DateTime date, SimpleEntity simpleEntity, AnotherEntity anotherEntity, decimal a, decimal b)
        {
            var compoundEntity = new CompoundEntity();

            compoundEntity.Date = date;

            compoundEntity.SimpleEntity = simpleEntity;

            compoundEntity.AnotherEntity = anotherEntity;

            compoundEntity.B = b;

            compoundEntity.A = a;

            return(compoundEntity);
        }
Пример #10
0
        public void an_exception_is_thrown_if_id_null()
        {
            var metadataFactory      = new AttributeMetadataFactory(new NullLogger());
            var queryExecutorFactory = new Mock <IQueryExecutorFactory>();
            var repositoryFactory    = new Mock <IRepositoryFactory>();
            var stateTracker         = new EntityStateCache();
            var proxyFactory         = new DynamicProxyFactory(metadataFactory, new NullLogger());

            using (var session = new GraphSession(new UnitOfWork(stateTracker), new List <IListener>(), queryExecutorFactory.Object, repositoryFactory.Object, stateTracker, proxyFactory))
            {
                Assert.Throws <PropertyNotSetException>(() =>
                {
                    var factory = new DynamicProxyFactory(metadataFactory, new NullLogger());
                    var notSet  = new AnotherEntity();
                    factory.Create(notSet, session);
                });
            }
        }
        public void CompositeProperty()
        {
            AnotherEntity e1 = new AnotherEntity()
            {
                Name = "2", Entity = new AnEntity()
                {
                    Name = "Test1"
                }
            };
            AnotherEntity e2 = new AnotherEntity()
            {
                Name = "2", Entity = new AnEntity()
                {
                    Name = "Test2"
                }
            };
            ObjectComparer comparer = new ObjectComparer();
            var            res      = comparer.FindDifferencies(e1, e2);

            Assert.That(res[0], Text.Contains("Entity.Name"));
        }
Пример #12
0
        public void Trim()
        {
            List <int> idsToDelete = new List <int>();

            try
            {
                AnotherEntity ae1 = new AnotherEntity {
                    Input = " hi "
                };
                AnotherEntity ae2 = new AnotherEntity {
                    Input = "hi"
                };
                AnotherEntity ae3 = new AnotherEntity {
                    Input = "heh"
                };
                session.Save(ae1);
                idsToDelete.Add(ae1.Id);
                session.Save(ae2);
                idsToDelete.Add(ae2.Id);
                session.Save(ae3);
                idsToDelete.Add(ae3.Id);
                session.Flush();

                Assert.AreEqual(2, session.Query <AnotherEntity>().Where(e => e.Input.Trim() == "hi").Count());
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.TrimEnd() == " hi").Count());

                // Emulated trim does not support multiple trim characters, but for many databases it should work fine anyways.
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.Trim('h') == "e").Count());
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.TrimStart('h') == "eh").Count());
                Assert.AreEqual(1, session.Query <AnotherEntity>().Where(e => e.Input.TrimEnd('h') == "he").Count());
            }
            finally
            {
                foreach (int idToDelete in idsToDelete)
                {
                    session.Delete(session.Get <AnotherEntity>(idToDelete));
                }
                session.Flush();
            }
        }
Пример #13
0
 private string Key(AnotherEntity e)
 {
     return("Input=" + (e.Input ?? "NULL") + ", Output=" + (e.Output ?? "NULL"));
 }
Пример #14
0
        public void Test_Ef_Inheritance()
        {
            var guid = Guid.NewGuid().ToString();
            var evs  = new List <EntityFrameworkEvent>();

            Audit.Core.Configuration.Setup().UseDynamicProvider(x => x.OnInsertAndReplace(ev =>
            {
                evs.Add(ev.GetEntityFrameworkEvent());
            }));
            using (DataBaseContext dbContext = new DataBaseContext())
            {
                dbContext.Database.Initialize(false);
            }
            int id;

            using (DataBaseContext context = new DataBaseContext())
            {
                var another = new AnotherEntity();
                another.AnotherColumn = guid;
                context.AnotherEntities.Add(another);
                context.SaveChanges();

                DBEntity ent = new DBEntity();
                ent.Name    = "Base";
                ent.Name2   = "Inherited";
                ent.Ticks   = 123;
                ent.Timeout = TimeSpan.FromMinutes(5);

                context.Entities.Add(ent);
                context.SaveChanges();
                id = ent.ID;
            }
            using (DataBaseContext context = new DataBaseContext())
            {
                DBEntityBase bse = context.Entities.First(x => x.ID == id);

                if (!(bse is DBEntity))
                {
                    throw new Exception("1");
                }

                DBEntity ent = (DBEntity)bse;

                ent.Name    = "Base 2";
                ent.Name2   = "Inherited 2";
                ent.Ticks   = 456;
                ent.Timeout = TimeSpan.FromMinutes(10);

                context.SaveChanges();
            }
            using (DataBaseContext context = new DataBaseContext())
            {
                DBEntityBase bse = context.Entities.First(x => x.ID == id);

                context.Entities.Remove(bse);
                context.SaveChanges();
            }

            // add another, add, update, delete
            Assert.AreEqual(4, evs.Count);

            Assert.AreEqual("Insert", evs[0].Entries[0].Action);
            Assert.AreEqual("Another", evs[0].Entries[0].Table);
            Assert.AreEqual(guid, (evs[0].Entries[0].Entity as dynamic).AnotherColumn);

            Assert.AreEqual("Insert", evs[1].Entries[0].Action);
            Assert.AreEqual("Entities", evs[1].Entries[0].Table);
            Assert.AreEqual("Inherited", (evs[1].Entries[0].Entity as dynamic).Name2);

            Assert.AreEqual("Update", evs[2].Entries[0].Action);
            Assert.AreEqual("Entities", evs[2].Entries[0].Table);

            Assert.AreEqual(4, evs[2].Entries[0].Changes.Count);
            Assert.IsTrue(evs[2].Entries[0].Changes.Any(ch =>
                                                        ch.ColumnName == "Timeout" && ((TimeSpan)ch.OriginalValue) == TimeSpan.FromMinutes(5) && ((TimeSpan)ch.NewValue) == TimeSpan.FromMinutes(10)));
            Assert.IsFalse(evs[2].Entries[0].Changes.Any(ch => ch.ColumnName == null));
            Assert.AreEqual("Inherited 2", (evs[2].Entries[0].Entity as dynamic).Name2);

            Assert.AreEqual("Delete", evs[3].Entries[0].Action);
        }
Пример #15
0
 public void Update(AnotherEntity entity)
 {
     throw new NotImplementedException();
 }