Skip to content

Commit 4b61cba

Browse files
committed
Update test to verify that AM.Collection is using for the mapping and updating the existing entity instead of replacing it.
1 parent 126d5ec commit 4b61cba

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/AutoMapper.Collection.Tests/NotExistingTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Should_not_throw_exception_for_nonexisting_types()
1717
});
1818
IMapper mapper = new Mapper(configuration);
1919

20-
var system = new System
20+
var originalModel = new System
2121
{
2222
Name = "My First System",
2323
Contacts = new List<Contact>
@@ -36,10 +36,16 @@ public void Should_not_throw_exception_for_nonexisting_types()
3636
}
3737
};
3838

39-
var model = mapper.Map<SystemViewModel>(system);
40-
model.Name.Should().Be(system.Name);
41-
model.Contacts.Single().Name.Should().Be(system.Contacts.Single().Name);
42-
model.Contacts.Single().Emails.Single().Address.Should().Be(system.Contacts.Single().Emails.Single().Address);
39+
var originalEmail = originalModel.Contacts.Single().Emails.Single();
40+
41+
var assertModel = mapper.Map<SystemViewModel>(originalModel);
42+
assertModel.Name.Should().Be(originalModel.Name);
43+
assertModel.Contacts.Single().Name.Should().Be(originalModel.Contacts.Single().Name);
44+
assertModel.Contacts.Single().Emails.Single().Address.Should().Be(originalModel.Contacts.Single().Emails.Single().Address);
45+
46+
mapper.Map(assertModel, originalModel);
47+
// This tests if equality was found and mapped to pre-existing object and not defaulting to AM and clearing and regenerating the list
48+
originalModel.Contacts.Single().Emails.Single().Should().Be(originalEmail);
4349
}
4450

4551
public class System

0 commit comments

Comments
 (0)