在vs2012单元测试框架中测试行为

时间:2012-10-29 11:51:17

标签: c# unit-testing visual-studio-2012 stub

以下是我的测试:

   [TestMethod]
    public void GetSubscribers()
    {

        stubSubscriptionMng.GetModelSubscribersInt32String = (mgr, i) => new List<IModel>() { modelStub };
        var dispatcher = UnitySingleton.Instance.UnityContainer.Resolve<Dispatcher>();
        IDispatchingMessage message = new DispatchingMessage(Guid.NewGuid().ToString(), "MessageName", "MessageVal", 1);
        dispatcher.Publish(message);

    }

这是正在测试的方法:

  if (message.UniverseId > 0 && !string.IsNullOrEmpty(message.EntityId) && !string.IsNullOrWhiteSpace(message.MessageName))
            {
                //the modelMgr will forword the the relevant Data to the relevant Models
                IList<IModel> models = subscriptionService.GetModelSubscribers(message.UniverseId, message.MessageName);
                Parallel.ForEach(models, (model) =>
                {
                    try
                    {
                        model.Update(message);
                    }
                    catch (Exception ex)
                    {
                        ResourceManager.Instance.Logger.LogException(ex);
                    }
                });
            }

使用void Update()方法调用每个模型。有没有办法验证这种行为?验证方法已被调用? 在Rhino mocks中等同于Expect()verifyAllExpectations()的东西?


我在following post找到了一个解决方法。

0 个答案:

没有答案