Skip to content

Commit 9f15765

Browse files
committed
.
1 parent e8db770 commit 9f15765

6 files changed

Lines changed: 43 additions & 4 deletions

File tree

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public async Task Queryable()
190190
await Verify(queryable);
191191
}
192192
```
193-
<sup><a href='/src/Tests/Tests.cs#L113-L122' title='File snippet `queryable` was extracted from'>snippet source</a> | <a href='#snippet-queryable' title='Navigate to start of snippet `queryable`'>anchor</a></sup>
193+
<sup><a href='/src/Tests/Tests.cs#L134-L143' title='File snippet `queryable` was extracted from'>snippet source</a> | <a href='#snippet-queryable' title='Navigate to start of snippet `queryable`'>anchor</a></sup>
194194
<!-- endsnippet -->
195195

196196
Will result in the following verified file:

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;CS8632</NoWarn>
5-
<Version>0.1.1</Version>
5+
<Version>0.1.2</Version>
66
<PackageTags>EntityFramework, Verify</PackageTags>
77
<Description>Extends Verify (https://github.com/SimonCropp/Verify) to allow verification of EntityFramework bits.</Description>
88
</PropertyGroup>

src/Tests/Tests.DateTimeOffsetProp.verified.txt

Whitespace-only changes.

src/Tests/Tests.UpdateEntity.verified.txt

Whitespace-only changes.

src/Tests/Tests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,27 @@ public async Task SomePropsModified()
109109
await Verify(context);
110110
}
111111
}
112+
[Fact]
113+
public async Task UpdateEntity()
114+
{
115+
var options = DbContextOptions();
116+
117+
await using (var context = new SampleDbContext(options))
118+
{
119+
context.Add(new Employee
120+
{
121+
Content = "before",
122+
});
123+
context.SaveChanges();
124+
}
125+
126+
await using (var context = new SampleDbContext(options))
127+
{
128+
var employee = context.Employees.Single();
129+
context.Update(employee).Entity.Content = "after";
130+
await Verify(context);
131+
}
132+
}
112133

113134
#region Queryable
114135
[Fact]

src/Verify.EntityFramework/Extensions.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,26 @@ public static class Extensions
77
public static IEnumerable<PropertyEntry> ChangedProperties(this EntityEntry entry)
88
{
99
return entry.Properties
10-
.Where(x => x.IsModified &&
11-
x.OriginalValue != x.CurrentValue);
10+
.Where(x =>
11+
{
12+
if (!x.IsModified)
13+
{
14+
return false;
15+
}
16+
17+
var original = x.OriginalValue;
18+
var current = x.CurrentValue;
19+
if (ReferenceEquals(original, current))
20+
{
21+
return false;
22+
}
23+
24+
if (original == null)
25+
{
26+
return true;
27+
}
28+
return !original.Equals(current);
29+
});
1230
}
1331

1432
public static IEnumerable<(string name, object value)> FindPrimaryKeyValues(this EntityEntry entry)

0 commit comments

Comments
 (0)