问题描述
你好,
我刚刚从Visual Studio 2015迁移到Visual Studio 2017.我的单元测试不再被发现。当我搜索如何让我的单元测试被发现时,我发现了一些有用的命中,告诉我通过NuGet安装nunit 3.7.0。这适用于
77测试。但总的来说,我有784个测试。为什么nunit 3.7.0只发现77个测试,而不是完整的784?
b
这是nunit 3.7.0发现的测试示例:
[代码]
[TestFixture]
 公共类Consequence_MF_Tests:CalculationTestBase
  {
      [测试]
      public void Calculation_Consequence_MitigatedFrequency_Test0()
      {
          _consequences [0] .DoCalculations();
          Assert.AreEqual(_consequences [0] .MitigatedFrequency,0.0003);
      }
      [测试]
      public void Calculation_Consequence_MitigatedFrequency_Test1()
      {
          _consequences [1] .DoCalculations();
          Assert.AreEqual(_consequences [1] .MitigatedFrequency,0);
      }
      [测试]
      public void Calculation_Consequence_MitigatedFrequency_Test2()
      {
          _consequences [2] .DoCalculations();
          Assert.AreEqual(_consequences [2] .MitigatedFrequency,2.0);
      }
      [测试]
      public void Calculation_Consequence_MitigatedFrequency_Test3()
      {
          _consequences [3] .DoCalculations();
          Assert.AreEqual(_consequences [3] .MitigatedFrequency,null);
      }
      [测试]
      public void Calculation_Consequence_MitigatedFrequency_Test4()
      {
          var errors = _consequences [4] .DoCalculations();
          Assert.IsTrue(errors.Count == 1);
          Assert.IsTrue(errors [0] .Description.Contains(" Safeguard Credit null));
      }
      [测试]
      public void Calculation_Consequence_MitigatedFrequency_Test5()
      {
          var errors = _consequences [5] .DoCalculations();
          Assert.IsTrue(errors.Count == 1);
          Assert.IsTrue(errors [0] .Description.Contains(" Value not not null));
      }¥b $ b   }
[/ code]
这是nunit 3.7.0未发现的测试示例:
[代码]
  [TestFixture]
 公共课ETReportCardSpecs
  {
      #region测试数据为InitiatingEventBreakdowns
      #region私人会员
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDto> _result1;
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDto> _result2;
$
&NBSP; &NBSP; &NBSP; #region H& S InitiatingEventBreakdowns
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_HAndS_human_5 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Human,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 5
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_HAndS_equipment_10 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Equipment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 10
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_HAndS_external_15 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.External,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 15
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_HAndS_undetermined_20 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Undetermined,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 20
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; #region ENV InitiatingEventBreakdowns
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ENV_human_5 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Environment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Human,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 5
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ENV_equipment_10 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Environment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Equipment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 10
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ENV_external_15 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Environment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.External,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 15
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ENV_undetermined_20 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Environment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Undetermined,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 20
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; #region ENC InitiatingEventBreakdowns
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ECN_human_5 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Human,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 5
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ECN_equipment_10 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Equipment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 10
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ECN_external_15 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.External,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 15
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static InitiatingEventBreakdown _ieb_ECN_undetermined_20 = new InitiatingEventBreakdown()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Code = CauseCodes.Undetermined,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;总计= 20
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; private static IEnumerable< InitiatingEventBreakdown> GetTestInitiatingEventBreakdowns(int projectId)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;开关(projectId)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例1:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< InitiatingEventBreakdown>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_equipment_10,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_external_15,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_undetermined_20,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //设备:10/50
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ENV_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ENV_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ENV_equipment_10,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ENV_external_15,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ENV_undetermined_20,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //设备:10/55
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_equipment_10,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_equipment_10,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_external_15,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ECN_undetermined_20,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //设备:20/70
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例2:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< InitiatingEventBreakdown>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_human_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_external_15,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_HAndS_undetermined_20,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //设备:0/40
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ieb_ENV_equipment_10
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //设备:10/10
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回null;
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP;公共类When_getting_equipment_threat_by_category:SpecsFor< PromComService>
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; protected override void Given()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetInitiatingEventBreakdown(1))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestInitiatingEventBreakdowns(1));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetInitiatingEventBreakdown(2))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestInitiatingEventBreakdowns(2));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; protected override void当()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result1 = SUT.GetEquipmentThreatsByReceptor(1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result2 = SUT.GetEquipmentThreatsByReceptor(2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_result1_should_have_3_elements()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result1.Count()。ShouldEqual(3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_consequence_categories_should_be_ordered_by_descending()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result1.ElementAt(0).Label.ShouldEqual(ConsequenceCodes.HealthAndSafety);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result1.ElementAt(1).Label.ShouldEqual(ConsequenceCodes.Environment);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result1.ElementAt(2).Label.ShouldEqual(ConsequenceCodes.Economic);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_HAndS_for_result1_should_be_20_percent()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result1.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.2M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_ENV_for_result1_should_be_18_percent()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var envValue = _result1.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison .CurrentCultureIgnoreCase)))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; double envValueRounded = Math.Round((double)envValue.Value,2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; envValueRounded.ShouldEqual(0.18d);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_ECN_for_result1_should_be_29_percent()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var ecnValue = _result1.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison .CurrentCultureIgnoreCase)))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; double ecnValueRounded = Math.Round((double)ecnValue.Value,2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ecnValueRounded.ShouldEqual(0.29d);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_result2_should_have_3_elements()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result2.Count()。ShouldEqual(3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_HAndS_for_result2_should_be_0_percent()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result2.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_ECN_should_have_0_value_for_result2()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result2.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Count()。ShouldEqual(1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result2.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_EVN_for_result2_should_be_100_percent()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result2.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison。 CurrentCultureIgnoreCase)))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(1.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP;针对平均设备威胁的#region测试数据
&NBSP; &NBSP; &NBSP; #region私人会员
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDtoWithStandardDeviation> _result3;
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDtoWithStandardDeviation> _no_ECN_result;
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDtoWithStandardDeviation> _no_ENV_result;
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDtoWithStandardDeviation> _no_HAndS_result;
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDtoWithStandardDeviation> _no_ECN_ENV_result;
&NBSP; &NBSP; &NBSP; private static IEnumerable< ChartDataDtoWithStandardDeviation> _0_stddev_result;
$
&NBSP; &NBSP; &NBSP; #region H& S
$
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _HAndS_equipment_threat_0_5 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.5M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.6455M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1502M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _HAndS_equipment_threat_0_6364 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.6364M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.6455M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1502M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _HAndS_equipment_threat_0_8 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.8M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.6455M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1502M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; #region ENV
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ENV_equipment_threat_0_7 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Environment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.7M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.6147M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1206M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ENV_equipment_threat_0_5294 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Environment,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.5294M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.6147M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1206M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; #region ENC
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ECN_equipment_threat_0_4783 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.4783M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.5746M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1137M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ECN_equipment_threat_0_7 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.7M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.5746M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1137M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ECN_equipment_threat_0_5455 = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.5455M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.5746M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.1137M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; //用于测试案例,当只有一个项目传入"其他人"时为
&NBSP; &NBSP; &NBSP; #region 0标准差
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _HAndS_return_on_investment_0_stddev = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.2308M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.2308M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.0M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ENV_return_on_investment_0_stddev = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.2759M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.2759M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.0M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; private static AverageMetricByCategory _ECN_return_on_investment_0_stddev = new AverageMetricByCategory()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ConsequenceCategory = ConsequenceCodes.Economic,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;比率= 0.875M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;平均值= 0.875M,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StandardDeviation = 0.0M
&NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; private static IEnumerable< AverageMetricByCategory> GetTestAverageEquipmentThreatsByCategory(int projectId)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;开关(projectId)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例1:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< AverageMetricByCategory>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_6364,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_8,
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_equipment_threat_0_7,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_equipment_threat_0_5294,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_4783,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_7,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_5455
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例2:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< AverageMetricByCategory>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_6364,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_8,
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_equipment_threat_0_7,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_equipment_threat_0_5294
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例3:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< AverageMetricByCategory>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_6364,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_8,
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_4783,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_7,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_5455
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例4:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< AverageMetricByCategory>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_equipment_threat_0_7,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_equipment_threat_0_5294,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_4783,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_7,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_equipment_threat_0_5455
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例5:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< AverageMetricByCategory>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_5,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_6364,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_equipment_threat_0_8
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }; b
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例6:
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新列表< AverageMetricByCategory>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _HAndS_return_on_investment_0_stddev,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ENV_return_on_investment_0_stddev,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _ECN_return_on_investment_0_stddev
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回null;
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; #endregion
&NBSP; &NBSP; &NBSP; public class When_getting_average_equipment_threat_by_receptor:SpecsFor< PromComService>
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; protected override void Given()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory(" 26,27,28"))//< - 硬编码项目ID
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestAverageEquipmentThreatsByCategory(1));
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory(" NoECNTest"))//< - 临时值,直到我们停止硬编码项目ID列表。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestAverageEquipmentThreatsByCategory(2));
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory(" NoENVTest"))//< - 临时值,直到我们停止硬编码项目ID列表。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestAverageEquipmentThreatsByCategory(3));
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory(" NoHAndSTest"))//< - 临时值,直到我们停止硬编码项目ID列表。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestAverageEquipmentThreatsByCategory(4));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory(" NoECN_ENVTest"))//< - 临时值,直到我们停止硬编码项目ID列表。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestAverageEquipmentThreatsByCategory(5));
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; GetMockFor< IRiskAliveContext>()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory(" 0"))//< - 临时值,直到我们停止硬编码项目ID列表。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .Returns(GetTestAverageEquipmentThreatsByCategory(6));
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; protected override void当()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3 = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SUT.ChangeProjectIdListForUnitTests(" NoECNTest");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SUT.ChangeProjectIdListForUnitTests(" NoENVTest");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ENV_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SUT.ChangeProjectIdListForUnitTests(" NoHAndSTest");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_HAndS_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SUT.ChangeProjectIdListForUnitTests(" NoECN_ENVTest");
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_ENV_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SUT.ChangeProjectIdListForUnitTests(" 0");
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _0_stddev_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SUT.RevertProjectIdListForUnitTests();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_result3_should_have_3_elements()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Count()。ShouldEqual(3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_consequence_categories_should_be_ordered_by_descending()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.ElementAt(0).Label.ShouldEqual(ConsequenceCodes.HealthAndSafety);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.ElementAt(1).Label.ShouldEqual(ConsequenceCodes.Environment);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.ElementAt(2).Label.ShouldEqual(ConsequenceCodes.Economic);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_avg_HAndS_should_be_0_6455()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.6455M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_avg_ENV_should_be_0_6147()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.6147M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_avg_ECN_should_be_0_5746()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.5746M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_StdDev_HAndS_should_be_0_1502()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.1502M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_StdDev_ENV_should_be_0_1206()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.1206M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_StdDev_ECN_should_be_0_1137()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _result3.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.1137M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_ECN_should_exist_with_0_values_for_no_ECN_result()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_ENV_should_exist_with_0_values_for_no_ENV_result()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ENV_result.Where(x => x.Label.Equals(
$
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ENV_result.Where(x => x.Label.Equals(
$
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_HAndS_should_exist_with_0_values_for_no_HAndS_result()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_HAndS_result.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_HAndS_result.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_ECN_and_ENV_should_exist_with_0_values_for_no_ECN_ENV_result()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).Value.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [测试]
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void then_stddev_should_ebe_0_for_0_stddev_result()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _0_stddev_result.Where(x => x.Label.Equals(&
ConsequenceCodes.HealthAndSafety,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _0_stddev_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _0_stddev_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic,StringComparison.CurrentCultureIgnoreCase) )
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; }
[/ code]
我看到的唯一区别是后者涉及when / given / then结构。
Hello,
I just migrated from Visual Studio 2015 to Visual Studio 2017. My unit tests are no longer being discovered. When I googled how to get my unit tests to be discovered I found some useful hits that told me to install nunit 3.7.0 through NuGet. That worked for 77 tests. But all together, I have 784 tests. Why would nunit 3.7.0 discover only 77 tests and not the full 784?
Here's an example of test that nunit 3.7.0 discovered:
[code]
[TestFixture]
public class Consequence_MF_Tests : CalculationTestBase
{
[Test]
public void Calculation_Consequence_MitigatedFrequency_Test0()
{
_consequences[0].DoCalculations();
Assert.AreEqual(_consequences[0].MitigatedFrequency, 0.0003);
}
[Test]
public void Calculation_Consequence_MitigatedFrequency_Test1()
{
_consequences[1].DoCalculations();
Assert.AreEqual(_consequences[1].MitigatedFrequency, 0);
}
[Test]
public void Calculation_Consequence_MitigatedFrequency_Test2()
{
_consequences[2].DoCalculations();
Assert.AreEqual(_consequences[2].MitigatedFrequency, 2.0);
}
[Test]
public void Calculation_Consequence_MitigatedFrequency_Test3()
{
_consequences[3].DoCalculations();
Assert.AreEqual(_consequences[3].MitigatedFrequency, null);
}
[Test]
public void Calculation_Consequence_MitigatedFrequency_Test4()
{
var errors = _consequences[4].DoCalculations();
Assert.IsTrue(errors.Count == 1);
Assert.IsTrue(errors[0].Description.Contains("Safeguard Credit null"));
}
[Test]
public void Calculation_Consequence_MitigatedFrequency_Test5()
{
var errors = _consequences[5].DoCalculations();
Assert.IsTrue(errors.Count == 1);
Assert.IsTrue(errors[0].Description.Contains("Value cannot be null"));
}
}
[/code]
Here's an example of test that nunit 3.7.0 did not discover:
[code]
[TestFixture]
public class ETReportCardSpecs
{
#region test data for InitiatingEventBreakdowns
#region private members
private static IEnumerable<ChartDataDto> _result1;
private static IEnumerable<ChartDataDto> _result2;
#region H&S InitiatingEventBreakdowns
private static InitiatingEventBreakdown _ieb_HAndS_human_5 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Code = CauseCodes.Human,
Total = 5
};
private static InitiatingEventBreakdown _ieb_HAndS_equipment_10 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Code = CauseCodes.Equipment,
Total = 10
};
private static InitiatingEventBreakdown _ieb_HAndS_external_15 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Code = CauseCodes.External,
Total = 15
};
private static InitiatingEventBreakdown _ieb_HAndS_undetermined_20 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Code = CauseCodes.Undetermined,
Total = 20
};
#endregion
#region ENV InitiatingEventBreakdowns
private static InitiatingEventBreakdown _ieb_ENV_human_5 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Environment,
Code = CauseCodes.Human,
Total = 5
};
private static InitiatingEventBreakdown _ieb_ENV_equipment_10 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Environment,
Code = CauseCodes.Equipment,
Total = 10
};
private static InitiatingEventBreakdown _ieb_ENV_external_15 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Environment,
Code = CauseCodes.External,
Total = 15
};
private static InitiatingEventBreakdown _ieb_ENV_undetermined_20 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Environment,
Code = CauseCodes.Undetermined,
Total = 20
};
#endregion
#region ENC InitiatingEventBreakdowns
private static InitiatingEventBreakdown _ieb_ECN_human_5 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Code = CauseCodes.Human,
Total = 5
};
private static InitiatingEventBreakdown _ieb_ECN_equipment_10 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Code = CauseCodes.Equipment,
Total = 10
};
private static InitiatingEventBreakdown _ieb_ECN_external_15 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Code = CauseCodes.External,
Total = 15
};
private static InitiatingEventBreakdown _ieb_ECN_undetermined_20 = new InitiatingEventBreakdown()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Code = CauseCodes.Undetermined,
Total = 20
};
#endregion
#endregion
private static IEnumerable<InitiatingEventBreakdown> GetTestInitiatingEventBreakdowns(int projectId)
{
switch (projectId)
{
case 1:
return new List<InitiatingEventBreakdown>()
{
_ieb_HAndS_human_5,
_ieb_HAndS_equipment_10,
_ieb_HAndS_external_15,
_ieb_HAndS_undetermined_20,
// equipment: 10/50
_ieb_ENV_human_5,
_ieb_ENV_human_5,
_ieb_ENV_equipment_10,
_ieb_ENV_external_15,
_ieb_ENV_undetermined_20,
// equipment: 10/55
_ieb_ECN_human_5,
_ieb_ECN_human_5,
_ieb_ECN_human_5,
_ieb_ECN_equipment_10,
_ieb_ECN_equipment_10,
_ieb_ECN_external_15,
_ieb_ECN_undetermined_20,
// equipment: 20/70
};
case 2:
return new List<InitiatingEventBreakdown>()
{
_ieb_HAndS_human_5,
_ieb_HAndS_external_15,
_ieb_HAndS_undetermined_20,
// equipment: 0/40
_ieb_ENV_equipment_10
// equipment: 10/10
};
}
return null;
}
#endregion
public class When_getting_equipment_threat_by_category : SpecsFor<PromComService>
{
protected override void Given()
{
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetInitiatingEventBreakdown(1))
.Returns(GetTestInitiatingEventBreakdowns(1));
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetInitiatingEventBreakdown(2))
.Returns(GetTestInitiatingEventBreakdowns(2));
}
protected override void When()
{
_result1 = SUT.GetEquipmentThreatsByReceptor(1);
_result2 = SUT.GetEquipmentThreatsByReceptor(2);
}
[Test]
public void then_result1_should_have_3_elements()
{
_result1.Count().ShouldEqual(3);
}
[Test]
public void then_consequence_categories_should_be_ordered_by_descending()
{
_result1.ElementAt(0).Label.ShouldEqual(ConsequenceCodes.HealthAndSafety);
_result1.ElementAt(1).Label.ShouldEqual(ConsequenceCodes.Environment);
_result1.ElementAt(2).Label.ShouldEqual(ConsequenceCodes.Economic);
}
[Test]
public void then_HAndS_for_result1_should_be_20_percent()
{
_result1.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.2M);
}
[Test]
public void then_ENV_for_result1_should_be_18_percent()
{
var envValue = _result1.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value;
double envValueRounded = Math.Round((double)envValue.Value, 2);
envValueRounded.ShouldEqual(0.18d);
}
[Test]
public void then_ECN_for_result1_should_be_29_percent()
{
var ecnValue = _result1.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value;
double ecnValueRounded = Math.Round((double)ecnValue.Value, 2);
ecnValueRounded.ShouldEqual(0.29d);
}
[Test]
public void then_result2_should_have_3_elements()
{
_result2.Count().ShouldEqual(3);
}
[Test]
public void then_HAndS_for_result2_should_be_0_percent()
{
_result2.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
}
[Test]
public void then_ECN_should_have_0_value_for_result2()
{
_result2.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.Count().ShouldEqual(1);
_result2.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
}
[Test]
public void then_EVN_for_result2_should_be_100_percent()
{
_result2.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(1.0M);
}
}
#region test data for average equipment threats
#region private members
private static IEnumerable<ChartDataDtoWithStandardDeviation> _result3;
private static IEnumerable<ChartDataDtoWithStandardDeviation> _no_ECN_result;
private static IEnumerable<ChartDataDtoWithStandardDeviation> _no_ENV_result;
private static IEnumerable<ChartDataDtoWithStandardDeviation> _no_HAndS_result;
private static IEnumerable<ChartDataDtoWithStandardDeviation> _no_ECN_ENV_result;
private static IEnumerable<ChartDataDtoWithStandardDeviation> _0_stddev_result;
#region H&S
private static AverageMetricByCategory _HAndS_equipment_threat_0_5 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Ratio = 0.5M,
Average = 0.6455M,
StandardDeviation = 0.1502M
};
private static AverageMetricByCategory _HAndS_equipment_threat_0_6364 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Ratio = 0.6364M,
Average = 0.6455M,
StandardDeviation = 0.1502M
};
private static AverageMetricByCategory _HAndS_equipment_threat_0_8 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Ratio = 0.8M,
Average = 0.6455M,
StandardDeviation = 0.1502M
};
#endregion
#region ENV
private static AverageMetricByCategory _ENV_equipment_threat_0_7 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Environment,
Ratio = 0.7M,
Average = 0.6147M,
StandardDeviation = 0.1206M
};
private static AverageMetricByCategory _ENV_equipment_threat_0_5294 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Environment,
Ratio = 0.5294M,
Average = 0.6147M,
StandardDeviation = 0.1206M
};
#endregion
#region ENC
private static AverageMetricByCategory _ECN_equipment_threat_0_4783 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Ratio = 0.4783M,
Average = 0.5746M,
StandardDeviation = 0.1137M
};
private static AverageMetricByCategory _ECN_equipment_threat_0_7 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Ratio = 0.7M,
Average = 0.5746M,
StandardDeviation = 0.1137M
};
private static AverageMetricByCategory _ECN_equipment_threat_0_5455 = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Ratio = 0.5455M,
Average = 0.5746M,
StandardDeviation = 0.1137M
};
#endregion
// for testing case when only 1 project passed in for "others"
#region 0 standard deviation
private static AverageMetricByCategory _HAndS_return_on_investment_0_stddev = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.HealthAndSafety,
Ratio = 0.2308M,
Average = 0.2308M,
StandardDeviation = 0.0M
};
private static AverageMetricByCategory _ENV_return_on_investment_0_stddev = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Ratio = 0.2759M,
Average = 0.2759M,
StandardDeviation = 0.0M
};
private static AverageMetricByCategory _ECN_return_on_investment_0_stddev = new AverageMetricByCategory()
{
ConsequenceCategory = ConsequenceCodes.Economic,
Ratio = 0.875M,
Average = 0.875M,
StandardDeviation = 0.0M
};
#endregion
#endregion
private static IEnumerable<AverageMetricByCategory> GetTestAverageEquipmentThreatsByCategory(int projectId)
{
switch (projectId)
{
case 1:
return new List<AverageMetricByCategory>()
{
_HAndS_equipment_threat_0_5,
_HAndS_equipment_threat_0_6364,
_HAndS_equipment_threat_0_8,
_ENV_equipment_threat_0_7,
_ENV_equipment_threat_0_5294,
_ECN_equipment_threat_0_4783,
_ECN_equipment_threat_0_7,
_ECN_equipment_threat_0_5455
};
case 2:
return new List<AverageMetricByCategory>()
{
_HAndS_equipment_threat_0_5,
_HAndS_equipment_threat_0_6364,
_HAndS_equipment_threat_0_8,
_ENV_equipment_threat_0_7,
_ENV_equipment_threat_0_5294
};
case 3:
return new List<AverageMetricByCategory>()
{
_HAndS_equipment_threat_0_5,
_HAndS_equipment_threat_0_6364,
_HAndS_equipment_threat_0_8,
_ECN_equipment_threat_0_4783,
_ECN_equipment_threat_0_7,
_ECN_equipment_threat_0_5455
};
case 4:
return new List<AverageMetricByCategory>()
{
_ENV_equipment_threat_0_7,
_ENV_equipment_threat_0_5294,
_ECN_equipment_threat_0_4783,
_ECN_equipment_threat_0_7,
_ECN_equipment_threat_0_5455
};
case 5:
return new List<AverageMetricByCategory>()
{
_HAndS_equipment_threat_0_5,
_HAndS_equipment_threat_0_6364,
_HAndS_equipment_threat_0_8
};
case 6:
return new List<AverageMetricByCategory>()
{
_HAndS_return_on_investment_0_stddev,
_ENV_return_on_investment_0_stddev,
_ECN_return_on_investment_0_stddev
};
}
return null;
}
#endregion
public class When_getting_average_equipment_threat_by_receptor : SpecsFor<PromComService>
{
protected override void Given()
{
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory("26,27,28")) // <-- Hard coded project IDs
.Returns(GetTestAverageEquipmentThreatsByCategory(1));
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory("NoECNTest")) // <-- Temporary value until we stop hardcoding project ID list.
.Returns(GetTestAverageEquipmentThreatsByCategory(2));
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory("NoENVTest")) // <-- Temporary value until we stop hardcoding project ID list.
.Returns(GetTestAverageEquipmentThreatsByCategory(3));
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory("NoHAndSTest")) // <-- Temporary value until we stop hardcoding project ID list.
.Returns(GetTestAverageEquipmentThreatsByCategory(4));
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory("NoECN_ENVTest")) // <-- Temporary value until we stop hardcoding project ID list.
.Returns(GetTestAverageEquipmentThreatsByCategory(5));
GetMockFor<IRiskAliveContext>()
.Setup(ctx => ctx.GetAvgEquipmentThreatsByCategory("0")) // <-- Temporary value until we stop hardcoding project ID list.
.Returns(GetTestAverageEquipmentThreatsByCategory(6));
}
protected override void When()
{
_result3 = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
SUT.ChangeProjectIdListForUnitTests("NoECNTest");
_no_ECN_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
SUT.ChangeProjectIdListForUnitTests("NoENVTest");
_no_ENV_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
SUT.ChangeProjectIdListForUnitTests("NoHAndSTest");
_no_HAndS_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
SUT.ChangeProjectIdListForUnitTests("NoECN_ENVTest");
_no_ECN_ENV_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
SUT.ChangeProjectIdListForUnitTests("0");
_0_stddev_result = SUT.GetAverageMetricByCategory(ReportCardIcon.ET);
SUT.RevertProjectIdListForUnitTests();
}
[Test]
public void then_result3_should_have_3_elements()
{
_result3.Count().ShouldEqual(3);
}
[Test]
public void then_consequence_categories_should_be_ordered_by_descending()
{
_result3.ElementAt(0).Label.ShouldEqual(ConsequenceCodes.HealthAndSafety);
_result3.ElementAt(1).Label.ShouldEqual(ConsequenceCodes.Environment);
_result3.ElementAt(2).Label.ShouldEqual(ConsequenceCodes.Economic);
}
[Test]
public void then_avg_HAndS_should_be_0_6455()
{
_result3.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.6455M);
}
[Test]
public void then_avg_ENV_should_be_0_6147()
{
_result3.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.6147M);
}
[Test]
public void then_avg_ECN_should_be_0_5746()
{
_result3.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.5746M);
}
[Test]
public void then_StdDev_HAndS_should_be_0_1502()
{
_result3.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.1502M);
}
[Test]
public void then_StdDev_ENV_should_be_0_1206()
{
_result3.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.1206M);
}
[Test]
public void then_StdDev_ECN_should_be_0_1137()
{
_result3.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.1137M);
}
[Test]
public void then_ECN_should_exist_with_0_values_for_no_ECN_result()
{
_no_ECN_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
_no_ECN_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
}
[Test]
public void then_ENV_should_exist_with_0_values_for_no_ENV_result()
{
_no_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
_no_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
}
[Test]
public void then_HAndS_should_exist_with_0_values_for_no_HAndS_result()
{
_no_HAndS_result.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
_no_HAndS_result.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
}
[Test]
public void then_ECN_and_ENV_should_exist_with_0_values_for_no_ECN_ENV_result()
{
_no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
_no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
_no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).Value.ShouldEqual(0.0M);
_no_ECN_ENV_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
}
[Test]
public void then_stddev_should_ebe_0_for_0_stddev_result()
{
_0_stddev_result.Where(x => x.Label.Equals(
ConsequenceCodes.HealthAndSafety, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
_0_stddev_result.Where(x => x.Label.Equals(
ConsequenceCodes.Environment, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
_0_stddev_result.Where(x => x.Label.Equals(
ConsequenceCodes.Economic, StringComparison.CurrentCultureIgnoreCase))
.ElementAt(0).StandardDeviation.ShouldEqual(0.0M);
}
}
}
[/code]
The only difference I see is that the latter involves the when/given/then structure.
推荐答案
感谢您的帖子。
我可以问一下如果在VS2015中可以发现所有测试?
May I ask if all the tests could be discovered in VS2015?
要在VS2017中进行Nunit测试,我们需要安装以下软件包:
To Nunit test in VS2017 we need install the below packages:
确保已安装所有内容并再试一次。
Make sure you've installed them all and give it try again.
祝你好运,
Fletcher
这篇关于nunit不会发现我的所有测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!