Пример #1
0
        public void LoggableEntity_CreatesPropertiesForAttachedEntity()
        {
            context.Dispose();
            String roleName = model.Name;

            context = new TestingContext();
            context.Set <Role>().Attach(model);

            entry = context.Entry <BaseModel>(model);
            entry.OriginalValues["Name"] = "Role";
            entry.CurrentValues["Name"]  = "Role";
            entry.State = EntityState.Modified;

            IEnumerator <LoggableProperty> expected = new List <LoggableProperty>()
            {
                new LoggableProperty(entry.Property("Name"), roleName)
            }.GetEnumerator();
            IEnumerator <LoggableProperty> actual = new LoggableEntity(entry).Properties.GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.AreEqual(expected.Current.IsModified, actual.Current.IsModified);
                Assert.AreEqual(expected.Current.ToString(), actual.Current.ToString());
            }
        }
        private void AsssertProperties(DbPropertyValues originalValues)
        {
            IEnumerable <String> properties = originalValues.PropertyNames;

            IEnumerator <LoggableProperty> actual   = new LoggableEntity(entry).Properties.GetEnumerator();
            IEnumerator <LoggableProperty> expected = properties.Where(property => property != "Id")
                                                      .Select(name => new LoggableProperty(entry.Property(name), originalValues[name])).GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.Equal(expected.Current.IsModified, actual.Current.IsModified);
                Assert.Equal(expected.Current.ToString(), actual.Current.ToString());
            }
        }
        public void LoggableEntity_CreatesPropertiesForModifiedEntity()
        {
            String title = model.Title;

            entry.State = EntityState.Modified;
            entry.CurrentValues["Title"]  = "Role";
            entry.OriginalValues["Title"] = "Role";

            IEnumerator <LoggableProperty> expected = new List <LoggableProperty> {
                new LoggableProperty(entry.Property("Title"), title)
            }.GetEnumerator();
            IEnumerator <LoggableProperty> actual = new LoggableEntity(entry).Properties.GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.Equal(expected.Current.IsModified, actual.Current.IsModified);
                Assert.Equal(expected.Current.ToString(), actual.Current.ToString());
            }
        }