I have a unit test that has two calls to SaveChanges() when the first attempt to call SaveChanges() throws an OptimisticVerificationException, a refresh of the object occurs and then a second attempt is made. When writing my unit test I arranged the following expectations:
What is interesting is that the call to: Mock.Arrange(() => _mockModel.SaveChanges()).Occurs(2); actually breaks the next two lines (the one that throws on the first SaveChanges() in sequence). Regardless of where Occurs(n) appears in the arrange, it breaks the throw. Simply commenting it out allows the test to run as expected.
Am I doing something wrong or is there a defect here?
Mock.Arrange(() => _mockModel.SaveChanges()).Occurs(2);
Mock.Arrange(() => _mockModel.SaveChanges()).Throws<OptimisticVerificationException>(
string
.Empty).InSequence();
Mock.Arrange(() => _mockModel.SaveChanges()).InSequence();
Mock.Arrange(() => _mockModel.Users.SingleOrDefault(p => p.Guid == userGuid)).Returns(
new
User());
Mock.Arrange(() => _mockModel.Refresh(RefreshMode.OverwriteChangesFromStore, Arg.IsAny<User>())).MustBeCalled();
What is interesting is that the call to: Mock.Arrange(() => _mockModel.SaveChanges()).Occurs(2); actually breaks the next two lines (the one that throws on the first SaveChanges() in sequence). Regardless of where Occurs(n) appears in the arrange, it breaks the throw. Simply commenting it out allows the test to run as expected.
Am I doing something wrong or is there a defect here?