dimanche 24 janvier 2016

How can i write unit test for this actionfilter

       public MyContext _db;
       public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
           if (_db == null || !_db.ChangeTracker.HasChanges())
                {
                    return;
                }
                try
                {
                    _db.SaveChanges();
                }
                catch
                {

                }
              }
       }

This is my action filter for my wep api project. _db context object injected to this filter by per request. My point is here to call SaveChanges() method once after all processing done in service layers. My problem is how can test this filter? How can i mimic exception case that can happen in any controler or service layer and when exception throwns saveChanges() never called? How can i setup the case that exception occurred in any place inside application?

Aucun commentaire:

Enregistrer un commentaire