И CreatedBy
, и LastUpdatedBy
должны быть точно и точно определены в ваших тестовых примерах. Следовательно, я считаю, что оба могут быть утверждены в тестовых примерах.
Точно так же, если у вас нет каких-то странных временных требований, должно быть довольно легко наложить ограничения на поля CreatedAt
и LastUpdatedAt
.
Я бы также предложил, чтобы, если вы находитесь на EFCore, используйте базу данных в памяти для упрощения обратного просмотра и подтверждаете здесь.
var now = DateTime.Now;
repository.Insert(entity);
// At this point, I think both the entity itself and if you can read it back from the store should have acceptable values or the test fails.
Assert.IsTrue(entity.CreatedBy == "me");
Assert.IsTrue(entity.LastUpdatedBy == "me");
Assert.IsTrue((now - entity.CreatedAt).TotalMilliseconds <= tolerance);
Assert.IsTrue((now - entity.LastUpdatedAt).TotalMilliseconds <= tolerance);
var newEntity = repository.Get(entity.Id);
// same tests here.
// Repeat similarly for update, and ensure created attributes don't change.