What is the easies way to ensure UpdateDatabase is called in unit tests?
Better would be to know the objects that are going to be updated.
100% working solution is implementing IPersistenceService and chain the calls
to the original one.
Are there any ideas to implement it with ~<50 lines of code plus <=3 lines
per test?
The aim is 2-3 lines of code per test to ensure object is going to be persisted.
It should not break the IPersistenceService itself (so mocking is tricky).
.NET 3.5
I can buy some beer for an elegant solution or can promise discount at http://www.argocomputing.com.au/Services/DCPortal.aspx
I expect to write the code like this:
[TestMethod]
public void Save_PersistsObject() {
PsAssert<User>()
.Saved()
.With(new { Username="test"} );
// Should save User with Username
Controller.Save(new UserData {
Username= "test"
});
}
:)
Cheers,
Dmitriy.
> Check there are no dirty objects?
>
<=3 Lines of code per test.
Absence of dirty objects doesn't guaranty objects were persisted. They could
just never beeing created.
This what I've came up for now:
[TestMethod]
public void Save_PersistsDatabase() {
string name = Unique;
Controller.Save(new PersonController.EditData {
FirstName = name
});
var person = WorkSpace.Query<Person>().Where(p=>p.FirstName == name).Single();
Assert.IsTrue(person.IsFullyPersisted());
}
Query is extension method over IEcoServiceProvider that just return IQuaryable.
IsFullyPersisted is extension method over ILoopBack that return true if object
is NOT (New | Dirty | Deleted).
Disadvantage here - using IQuryable which is not performant for ECO (might
run lots of SQL, XPath or just in memory).
But while I don't run tests agains DB I don't care about it. For now.
=========================================================
Looking at this code I've just realised tha it can be simplified:
[TestMethod]
public void Save_PersistsObject() {
var newId = Controller.Save(new PersonController.EditData {
FirstName = Unique
}).Data.As<PersonController.SaveData>().Id;
var person = WorkSpace.GetObject<Person>(newId);
Assert.IsNotNull(person);
Assert.IsTrue(person.IsFullyPersisted(), "Not saved.");
}
It only relies on IsFullePersisted (StateService.IsNew,IsDirty, IObject.Deleted).
==========================================================
It is not what I wanted but works for now very good.
It seems my initial idea were to record what should happen with ECO objects
and then verify it.
It'd involve stages like:
1. Record actions and conditions.
2. Save current ECO state.
3. Exercise.
4. Save current ECO state.
5. Compare 2 and 4 and veryfy conditions.
Looks like common implementation of Mocking Frameworks.
Not sure I really need it.
Pete
> Expect.Call for UpdateDatabaseWithList
>
How do you know what exactly has been saved?
Pete