Exemplo n.º 1
0
 public void TestNoAssertion_DoNotThrowException()
 {
     Assert.DoesNotThrow(() =>
     {
         AssertionHelper.DoAssert(a =>
         {
             // no exception
         });
     });
 }
Exemplo n.º 2
0
 public void TestSingleAssertionSuccess_DoNotThrowException()
 {
     Assert.DoesNotThrow(() =>
     {
         AssertionHelper.DoAssert(a =>
         {
             a.Add(true);
         });
     });
 }
Exemplo n.º 3
0
 public void TestSingleAssertionFails_ThrowsException()
 {
     Assert.Throws <MultiException>(() =>
     {
         AssertionHelper.DoAssert(a =>
         {
             a.Add(false);
         });
     });
 }
Exemplo n.º 4
0
 public void TestAnyOfMultiAssertionsFails_ButNoThrowFlag_DoNoThrowException()
 {
     Assert.DoesNotThrow(() =>
     {
         AssertionHelper.DoAssert(a =>
         {
             a.Add(true);
             a.Add(() => false);
         }, false);
     });
 }
Exemplo n.º 5
0
 public void TestAnyOfMultiAssertionsFails_ThrowsException()
 {
     Assert.Throws <MultiException>(() =>
     {
         AssertionHelper.DoAssert(a =>
         {
             a.Add(true);
             a.Add(() => false);
         });
     });
 }
Exemplo n.º 6
0
 public void TestMultiAssertionsSuccess_DoNotThrowException()
 {
     Assert.DoesNotThrow(() =>
     {
         AssertionHelper.DoAssert(a =>
         {
             a.Add(true);
             a.Add(() => true);
         });
     });
 }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            ExecStatus worstStatus = default(ExecStatus);

            try
            {
                var writer = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                logger.LogError += writer.ErrorFormat;
                logger.LogFatal += writer.FatalFormat;
                logger.LogInfo  += writer.InfoFormat;
                logger.LogWarn  += writer.WarnFormat;

                logger.Info("Start Application");
                logger.Info("Arguments: {0}", args.Select(_ => _.DoubleQuote()).Join(","));
                AssertionHelper.DoAssert(helper => helper.Add(args.Length >= 2, "should have at least 2 arguments"));

                var targetDllPath  = args[0];
                var targetExecName = args[1];
                var otherArgs      = args.Skip(2);
                AssertionHelper.DoAssert(helper =>
                {
                    helper.AddNotNull(targetDllPath, "TargetDllPath");
                    helper.AddNotNull(targetExecName, "TargetExecName");
                });
                var typ = LoadType(targetDllPath, targetExecName);
                AssertionHelper.DoAssert(helper => helper.Add(typ != null, "Cannot load {0} at {1}".Format2(targetExecName, targetDllPath)));

                var cls = Activator.CreateInstance(typ) as IExecutable;
                AssertionHelper.DoAssert(helper => helper.Add(cls != null, "Loaded class[{0}] is not an IExecutable".Format2(targetExecName)));

                var setupResult = cls.Setup(otherArgs.ToArray());
                setupResult.PrettyLog(logger, "[Setup] Result" + Environment.NewLine);

                var result = cls.Execute();
                result.PrettyLog(logger, "[Execute] Result" + Environment.NewLine);

                var teardownResult = cls.Teardown();
                teardownResult.PrettyLog(logger, "[Teardown] Result" + Environment.NewLine);

                worstStatus = new[] { setupResult.Status, result.Status, teardownResult.Status }.WorstStatus();
            }
            catch (Exception e)
            {
                logger.Error("Error occurred\n{0}", e.PrettyPrint());
                worstStatus = ExecStatus.Error;
            }
            finally
            {
                logger.Info("Exit with exit code [{0}]", worstStatus);
            }
            Environment.Exit((int)worstStatus);
        }