I have to test a projection that handle a given events and persist it on a read only Mongo database (I'm using official c# Mongo Driver):
public class MyObjectProjection : IHandleMessages<RegisteredEvent>
{
private MongoCollection<MyObjectView> _collection;
public MyObjectProjection (MongoDatabase db)
{
_collection = db.GetCollection<MyObjectView>("my-object");
}
public void Handle(RegisteredEvent message)
{
var item = new MyObjectView();
item.Id = message.Id;
// some code omitted
_collection.Save(item);
}
}
I need to unit test the Handle
method, given that:
- I don't want an integration test. Database and collection are mocked, so the save is not real
- I just want to test the item-message mapping
- the members are hidden and I don't want to make them more visibile
Should I use alternative solution rather than reflection? What is the best practice in a case like this? Right now my test look like this:
[TestMethod]
public void TestMethod1()
{
// ARRANGE - some code omitted
databaseMock
.Setup(x => x.GetCollection<MyObjectView>(It.IsAny<string>()))
.Returns(collection);
collectionMock
.Setup(x => x.Save(It.IsAny<MyObjectView>()))
.Returns(It.IsAny<WriteConcernResult>);
// ACT
var handler = new MyObjectProjection(database);
handler.Handle(evt);
// ASSERT
// nothin' to assert here!
}
this works, but i have nothing to assert when Handle
method is completed.
Aucun commentaire:
Enregistrer un commentaire