コード例 #1
0
        public void RegistrationLookupOperatorEqualsTest()
        {
            var target1 = new TestEntity()
            {
                Name = "vm",
            };
            var target2 = new TestEntity()
            {
                Name = "vm",
            };
            var target3 = new TestEntity()
            {
                Name = "vm",
            };
            var target4 = new TestEntity()
            {
                Name = "vm1",
            };

            Assert.IsTrue(!(target1 == (TestEntity)null), "target1 must not be equal to null.");
            Assert.IsTrue(!((TestEntity)null == target1), "target1 must not be equal to obj1.");

            // reflexitivity
            var t = target1;

            Assert.IsTrue(target1 == t, "The operator == must be reflexive.");
            Assert.IsFalse(target1 != t, "The operator == must be reflexive.");

            // symmetricity
            Assert.AreEqual(target1 == target2, target2 == target1, "The operator == must be symmetric.");
            Assert.AreEqual(target1 != target4, target4 != target1, "The operator != must be symmetric.");

            // transityvity
            Assert.IsTrue(target1 == target2 && target2 == target3 && target3 == target1, "The operator == must be transitive.");
            Assert.IsTrue(target1 == target2 && target1 != target4 && target2 != target4, "The operator != must be transitive.");
        }
コード例 #2
0
        public virtual void AttachDeletedNonExistingTest()
        {
            long        id;
            IRepository target;
            TestEntity  entity;

            using (target = GetInitializedRepository())
            {
                id     = target.GetStoreId <TestEntity, long>();
                entity = target.CreateEntity <TestEntity>();

                entity.Id   = id;
                entity.Name = "test" + id;

                target.Add(entity);
                target.CommitChanges();

                // the store may have generated it
                id = entity.Id;
            }

            entity.StringProperty = "testValue";

            var entity1 = new TestEntity
            {
                Name    = "test101",
                Created = Facility.Clock.UtcNow,
                Updated = Facility.Clock.UtcNow,
            };

            entity1.SetUpdated();

            Type targetType = null;

            try
            {
                using (target = GetInitializedRepository())
                {
                    targetType = target.GetType();

                    var id1 = target.GetStoreId <TestEntity, long>();

                    entity1.Id = id1;

                    target.AttachEntity(entity1, EntityState.Deleted);
                    target.CommitChanges();

                    Assert.IsNull(target.GetByStoreId <TestEntity, long>(id1));
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                Assert.IsTrue(typeof(EFRepositoryBase).IsAssignableFrom(targetType));
            }
            // Add here more similar exception handlers for expected exceptions from different types of repositories.
            catch (Exception x)
            {
                TestContext.WriteLine("{0}", x.DumpString());
                throw;
            }
        }