Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 测试我的MVC2控制器 [CompanyAuthorizationFilter] [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] 公共类控制器:System.Web_C#_Unit Testing_Asp.net Mvc 2_Controller - Fatal编程技术网

C# 测试我的MVC2控制器 [CompanyAuthorizationFilter] [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] 公共类控制器:System.Web

C# 测试我的MVC2控制器 [CompanyAuthorizationFilter] [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] 公共类控制器:System.Web,c#,unit-testing,asp.net-mvc-2,controller,C#,Unit Testing,Asp.net Mvc 2,Controller,测试我的MVC2控制器 [CompanyAuthorizationFilter] [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] 公共类控制器:System.Web.Mvc.Controller { 公共操作结果注释(Guid?id,字符串notesText) { if(isModelValid(id)) { 返回视图(@“~\Views\Indications\showstringpartial.asp

测试我的MVC2控制器
[CompanyAuthorizationFilter]
[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
公共类控制器:System.Web.Mvc.Controller
{
公共操作结果注释(Guid?id,字符串notesText)
{
if(isModelValid(id))
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”,“notesText”);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果摘要信息(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(model)+“SummaryInformation.aspx”,model);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果ProductLegs(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“ProductLegs.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果摊销选项(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“amorizationOptions.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果值(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“Values.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共行动结果率(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“Rates.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
public ActionResult RatesSpecific(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“RatesSpecific.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共行动结果摊销计划(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“amorizationSchedule.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果赞助商信息(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getBaseViewPath()+“SponsorInfo.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果借阅者信息(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getBaseViewPath()+“BorrowerInfo.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共操作结果赞助商联系人(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getBaseViewPath()+“SponsorContacts.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共行动结果现金流(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
返回视图(getSpecificViewPath(模型)+“CashFlows.aspx”,模型);
}
其他的
{
返回视图(@“~\Views\Indications\showstringpartial.aspx”、“”和“”结构未处于有效状态。无法呈现术语表视图。“);
}
}
公共行动结果预付款(Guid?id)
{
if(isModelValid(id))
{
ModelBase model=getModel(id.Value);
if(string.IsNull)
[CompanyAuthorizationFilter]
    [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class TermSheetController : System.Web.Mvc.Controller
    {
        public ActionResult Notes(Guid? id, string notesText)
        {
            if (isModelValid(id))
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", notesText);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult SummaryInformation(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "SummaryInformation.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult ProductLegs(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "ProductLegs.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult AmortizationOptions(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "AmortizationOptions.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult Values(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "Values.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult Rates(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "Rates.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult RatesSpecific(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "RatesSpecific.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult AmortizationSchedule(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "AmortizationSchedule.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult SponsorInfo(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getBaseViewPath() + "SponsorInfo.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult BorrowerInfo(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getBaseViewPath() + "BorrowerInfo.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult SponsorContacts(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getBaseViewPath() + "SponsorContacts.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult CashFlows(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "CashFlows.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult PrePayment(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                if (string.IsNullOrEmpty(model.PrepaymentExport))
                {
                    return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Prepayment has not been calculated yet.");
                }
                else
                {
                    return Json(model.PrepaymentExport);
                }
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult FutureExposure(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                if (string.IsNullOrEmpty(model.ExposureExport))
                {
                    return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Potential Future Exposure has not been calculated yet.");
                }
                else
                {
                    return Json(model.ExposureExport);
                }
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult FutureExposureSpecific(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                if (string.IsNullOrEmpty(model.ExposureExport))
                {
                    return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Potential Future Exposure has not been calculated yet.");
                }
                else
                {
                    return Json(model.ExposureExport);
                }
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult History(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getBaseViewPath() + "History.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        public ActionResult ValuationHistoryGrid(Guid? id)
        {
            if (isModelValid(id))
            {
                ModelBase model = getModel(id.Value);
                return View(getSpecificViewPath(model) + "ValuationHistoryGrid.aspx", model);
            }
            else
            {
                return View(@"~\Views\Indications\ShowAStringPartial.aspx", "", "Structure is not in a valid state. Could not render Term Sheet View.");
            }
        }

        private bool isModelValid(Guid? id)
        {
            try
            {
                if (id.HasValue)
                {
                    IndicationBase indication = CachedTransactionManager<IndicationBase>.GetCachedTransactions(id.Value);
                    if (indication.Model == null)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }

        private ModelBase getModel(Guid id)
        {
            IndicationBase indication = CachedTransactionManager<IndicationBase>.GetCachedTransactions(id);
            return indication.Model;
        }

        private string getSpecificViewPath(ModelBase model)
        {
            var viewPath = "";
            if (model.GetType() == typeof(Chatham.Web.Models.Indications.SwapModel))
            {
                viewPath = @"~\Views\Indications\TermSheetViews\Swap\";
            }
            if (model.GetType() == typeof(Chatham.Web.Models.Indications.OptionModel))
            {
                viewPath = @"~\Views\Indications\TermSheetViews\Option\";
            }
            if (model.GetType() == typeof(Chatham.Web.Models.Indications.CollarModel))
            {
                viewPath = @"~\Views\Indications\TermSheetViews\Collar\";
            }
            if (model.GetType() == typeof(Chatham.Web.Models.Indications.CompoundSwapModel))
            {
                viewPath = @"~\Views\Indications\TermSheetViews\CompoundSwap\";
            }

            return viewPath;
        }

        private string getBaseViewPath()
        {
            return @"~\Views\Indications\TermSheetViews\";
        }
    }
ActionResult action = _myControllerToTest.Notes(null, null);
Assert.IsNotNull(action);

ViewResult viewResult = action as ViewResult;
Assert.IsNotNull(viewResult);

// Check viewResult for correct view path and model data