Пример #1
0
        bool Assert(bool condition, string toThrow, AssertType type)
        {
            if (!condition)
            {
                Console.Write(type + ": " + toThrow + "\n");
                switch (type)
                {
                case AssertType.Error:
                    errors++;
                    break;

                case AssertType.Warning:
                    warnings++;
                    break;

                case AssertType.Info:
                    break;

                default:
                    break;
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>Common implementation method for Noting that Fault has occurred, with or without a related System.Exception ex.</summary>
        public static void NoteFaultOccurance(string faultDesc, System.Exception ex, AssertType assertType, System.Diagnostics.StackFrame sourceFrame)
		{
			if (ex == null)
				AssertCommon(Fcns.CheckedFormat("AssertFault:{0}", faultDesc), assertType, sourceFrame);
			else
				AssertCommon(Fcns.CheckedFormat("AssertFault:{0} with exception:{1}", faultDesc, ex.Message), assertType, sourceFrame);
		}
Пример #3
0
 public LatexResult(AssertType type, float memo, long trans, long state, double time, string res, bool clicked)
 {
     mType       = type;
     mMemo       = memo;
     mTransition = trans;
     mState      = state;
     mTime       = time;
     mRes        = res;
     mClicked    = clicked;
 }
Пример #4
0
        /// <summary>
        /// Shows a message and gets an exception that should be thrown.
        /// </summary>
        /// <param name="type">The type of assert condition that was evaluated.</param>
        /// <param name="message">The message that should be shown.</param>
        /// <returns>
        /// The exception that should be thrown, or null.
        /// </returns>
        protected override Exception Failed(AssertType type, string message)
        {
            switch (type)
            {
            case AssertType.NotDisposed:
                return(new ObjectDisposedException(message));

            default:
                return(new ValidationFailedException(message));
            }
        }
Пример #5
0
 public static AssertType IncludeExpectedResults(this AssertType assertType,
                                                 IExpectedResultRepository expectedResultRepository)
 {
     if (assertType.ExpectedResults != null)
     {
         return(assertType);
     }
     assertType.ExpectedResults =
         (ExpectedResultList)expectedResultRepository.GetDataByAssertTypeId(assertType.Id);
     return(assertType);
 }
Пример #6
0
 public ActionResult Create(AssertType assertType)
 {
     try
     {
         _dbAssertTypeRepository.Insert(assertType);
         return RedirectToAction("Index");
     }
     catch
     {
         return View(assertType);
     }
 }
Пример #7
0
 public ActionResult Edit(int id, AssertType assertType)
 {
     try
     {
         _dbAssertTypeRepository.Update(assertType);
         return RedirectToAction("Index");
     }
     catch
     {
         return View(assertType);
     }
 }
Пример #8
0
 public ActionResult Create(AssertType assertType)
 {
     try
     {
         _dbAssertTypeRepository.Insert(assertType);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(assertType));
     }
 }
Пример #9
0
 public ActionResult Edit(int id, AssertType assertType)
 {
     try
     {
         _dbAssertTypeRepository.Update(assertType);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(assertType));
     }
 }
 public void Update(string name, int id)
 {
     using (var client = new HttpClient(_messageHandler, false))
     {
         client.BaseAddress = new Uri(_baseAddress);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var assertType = new AssertType
         {
             Name = name,
             Id = id
         };
         var response = client.PutAsync(UrlBase, assertType, new JsonMediaTypeFormatter()).Result;
         response.EnsureSuccessStatusCode();
     }
 }
Пример #11
0
 public void Update(string name, int id)
 {
     using (var client = new HttpClient(_messageHandler, false))
     {
         client.BaseAddress = new Uri(_baseAddress);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var assertType = new AssertType
         {
             Name = name,
             Id   = id
         };
         var response = client.PutAsync(UrlBase, assertType, new JsonMediaTypeFormatter()).Result;
         response.EnsureSuccessStatusCode();
     }
 }
Пример #12
0
		/// <summary> This is the inner-most implementation method for the Assert helper class.  It implements all of the assertType specific behavior for all assertions that get triggered.</summary>
		private static void AssertCommon(string mesg, AssertType assertType, System.Diagnostics.StackFrame sourceFrame)
		{
			// always log all triggered asserts to the BasicFallbackLog

			string logStr = Fcns.CheckedFormat("{0} at file:'{1}', line:{2}", mesg, sourceFrame.GetFileName(), sourceFrame.GetFileLineNumber());

            if (assertType != AssertType.Log)
            {
                if (EnableBasicFallbackLogging)
                    Logging.BasicFallbackLogging.LogError(logStr);

                if (queuedAssertLogger == null)       // in an MT world we might create a few of these simultaneously.  This is not a problem as the distribution engine supports such a construct so locking is not required here in order to get valid behavior.
                    queuedAssertLogger = new Logging.QueuedLogger("MosaicLib.Utils.Assert");

                queuedAssertLogger.Emitter(DefaultAssertLoggingMesgType).Emit(logStr);
            }

			bool ignoreFault = false;		// intended to be used by debug user to ignore such asserts on a case by case basis

			if (assertType == AssertType.Log)
			{
                if (assertLogger == null)       // in an MT world we might create a few of these simultaneously.  This is not a problem as the distribution engine supports such a construct so locking is not required here in order to get valid behavior.
                    assertLogger = new Logging.Logger("MosaicLib.Utils.Assert");

                assertLogger.Emitter(DefaultAssertLoggingMesgType).Emit(logStr);

				return;
			}
			else if (assertType == AssertType.LogFallback)
			{
				return;	// already done
			}
			else if (assertType == AssertType.ThrowException)
			{
				if (!ignoreFault)
					throw new AssertException(mesg, sourceFrame);

				return;
			}

			if (!ignoreFault)
			{
                // the remaining types always trigger a breakpoint if a debugger is attached and the hosting environment has set the EnabledAssertDebugBreakpoints flag
                if (System.Diagnostics.Debugger.IsAttached && EnableAssertDebugBreakpoints)
					System.Diagnostics.Debugger.Break();
			}
		}
Пример #13
0
 public int Insert(string name)
 {
     using (var client = new HttpClient(_messageHandler, false))
     {
         client.BaseAddress = new Uri(_baseAddress);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var assertType = new AssertType
         {
             Name = name
         };
         var response = client.PostAsync(UrlBase, assertType, new JsonMediaTypeFormatter()).Result;
         response.EnsureSuccessStatusCode();
         var responseString = response.Content.ReadAsStringAsync().Result;
         var returnValue    = Convert.ToInt32(responseString);
         return(returnValue);
     }
 }
Пример #14
0
        /// <summary>
        /// Shows a message and gets an exception that should be thrown.
        /// </summary>
        /// <param name="type">The type of assert condition that was evaluated.</param>
        /// <param name="message">The message that should be shown.</param>
        /// <returns>
        /// The exception that should be thrown, or null.
        /// </returns>
        protected override Exception Failed(AssertType type, string message)
        {
            StackFrame frame    = new StackFrame(3, true);
            string     frameKey = frame.ToString();

            DialogResult result = DialogResult.Ignore;

            if (!this.ignoredAssertions.Contains(frameKey))
            {
                result = this.ShouldForceDialogResult
                    ? this.ForcedDialogResult
                    : MessageBox.Show(
                    message,
                    "Assertion Failed",
                    MessageBoxButtons.AbortRetryIgnore,
                    MessageBoxIcon.Exclamation);
            }

            switch (result)
            {
            case DialogResult.Abort:
                switch (type)
                {
                case AssertType.NotDisposed:
                    return(new ObjectDisposedException(message));

                default:
                    return(new AssertionFailedException(message));
                }

            case DialogResult.Retry:
                Debugger.Break();
                return(null);

            case DialogResult.Ignore:
                this.ignoredAssertions.Add(frameKey);
                return(null);

            default:
                return(null);
            }
        }
        private static ExpressionStatementSyntax Are(AssertType assertType, IArgument expected, IArgument actual, string message)
        {
            if (expected == null)
            {
                throw new ArgumentNullException(nameof(expected));
            }

            if (actual == null)
            {
                throw new ArgumentNullException(nameof(actual));
            }

            var arguments = new List <IArgument>
            {
                expected,
                actual,
                new ValueArgument(message ?? string.Empty)
            };

            return(Statement.Expression.Invoke("Assert", Enum.GetName(typeof(AssertType), assertType), arguments).AsStatement());
        }
Пример #16
0
 public void Update_Should_Update_A_AssertType() 
 {
     _repository
          .Setup(it => it.Update(It.IsAny<String>(), It.IsAny<Int32>()))
          .Callback<String, Int32>((name, id) => 
     { 
          var tAssertType = _repositoryList.Find(x => x.Id==id);
          tAssertType.Name = name; 
     });
     var tempAssertType = _repositoryList.Find(x => x.Id==id);
     var testAssertType = new AssertType {
          Id = tempAssertType.Id, 
          Name = tempAssertType.Name};
     
     //TODO change something on testAssertType
     //testAssertType.oldValue = newValue; 
     _target.Update(testAssertType);
     //Assert.AreEqual(newValue, _repositoryList.Find(x => x.Id==1).oldValue);
     //TODO fail until we update the test above
     Assert.Fail();
 }
Пример #17
0
        public void Update_Should_Update_A_AssertType()
        {
            _repository
            .Setup(it => it.Update(It.IsAny <String>(), It.IsAny <Int32>()))
            .Callback <String, Int32>((name, id) =>
            {
                var tAssertType  = _repositoryList.Find(x => x.Id == id);
                tAssertType.Name = name;
            });
            var tempAssertType = _repositoryList.Find(x => x.Id == id);
            var testAssertType = new AssertType {
                Id   = tempAssertType.Id,
                Name = tempAssertType.Name
            };

            //TODO change something on testAssertType
            //testAssertType.oldValue = newValue;
            _target.Update(testAssertType);
            //Assert.AreEqual(newValue, _repositoryList.Find(x => x.Id==1).oldValue);
            //TODO fail until we update the test above
            Assert.Fail();
        }
Пример #18
0
        /// <summary>
        /// Checks the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="condition">if set to <c>true</c> [condition].</param>
        /// <param name="message">The message.</param>
        /// <param name="messageArgs">The message arguments.</param>
        /// <param name="assertMessageFormat">The assert message format.</param>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        private bool Check(
            AssertType type,
            bool condition,
            string message,
            object[] messageArgs,
            string assertMessageFormat,
            params object[] args)
        {
            if (!condition)
            {
                StringBuilder builder = new StringBuilder()
                                        .AppendFormat(assertMessageFormat, args)
                                        .AppendLine();

                if (message != null)
                {
                    builder.Append("\t");
                    if (messageArgs == null)
                    {
                        builder.Append(message);
                    }
                    else
                    {
                        builder.AppendFormat(message, messageArgs);
                    }

                    builder.AppendLine();
                }

                Exception ex = this.Failed(type, builder.ToString());
                if (ex != null)
                {
                    throw ex;
                }
            }

            return(condition);
        }
Пример #19
0
        protected override Exception Failed(AssertType type, string message)
        {
            switch (type)
            {
            case AssertType.NotDisposed:
                return(new ObjectDisposedException(message));

            case AssertType.IsDisposed:
            case AssertType.IsTrue:
            case AssertType.IsFalse:
            case AssertType.AreEqual:
            case AssertType.AreNotEqual:
            case AssertType.IsNull:
            case AssertType.IsNullOrEmpty:
            case AssertType.IsNotNullOrEmpty:
            case AssertType.IsNullOrWhiteSpace:
            case AssertType.IsNotNullOrWhiteSpace:
            case AssertType.IsNotEmpty:
            case AssertType.IsEmpty:
            case AssertType.IsNotZero:
            case AssertType.Compare:
            case AssertType.IsType:
            case AssertType.IsTypeOrNull:
            case AssertType.Fail:
                return(new ArgumentException(message));

            case AssertType.IsNotNull:
                return(new ArgumentNullException(message));

            case AssertType.IsInRange:
                return(new ArgumentOutOfRangeException(message));

            default:
                return(new NotImplementedException(
                           $"Argument resolver for AssertType {type} has not been implemented."));
            }
        }
Пример #20
0
        public static string convertAssertType(AssertType type)
        {
            string ret = "";

            switch (type)
            {
            case AssertType.DEADLOCK_FREE:
                ret = "DeadlockFree";
                break;

            case AssertType.CONGESTION_CHANNEL:
                ret = "CongestionChannel";
                break;

            case AssertType.CONGESTION_SENSOR:
                ret = "CongestionSensor";
                break;

            default:
                break;
            }

            return(ret);
        }
Пример #21
0
 private LatexResult getLatexByType(AssertType assertType)
 {
     LatexResult ret = null;
     foreach (LatexResult lr in mLatexList)
     {
         if (lr != null && lr.mType == assertType)
         {
             ret = lr;
             break;
         }
     }
     return ret;
 }
Пример #22
0
 /// <summary>Asserts that the given cond condition is true.  Action taken when the condition is not true is determined by the given assertType value.</summary>
 public static void CheckIfConditionIsNotTrue(bool cond, string condDesc, AssertType assertType)
 {
     if (!cond) NoteConditionCheckFailed(condDesc, assertType, new System.Diagnostics.StackFrame(1, true));
 }
Пример #23
0
 public void Update(AssertType assertType)
 {
     _dbRepository.Update(assertType.Name, assertType.Id);
 }
Пример #24
0
 public static void CheckIfConditionIsNotTrue(bool cond, string condDesc, AssertType assertType) { if (!cond) NoteConditionCheckFailed(condDesc, assertType, new System.Diagnostics.StackFrame(1, true)); }
Пример #25
0
 public static void NoteConditionCheckFailed(string condDesc, AssertType assertType) { NoteConditionCheckFailed(condDesc, assertType, new System.Diagnostics.StackFrame(1, true)); }
 public void Delete(AssertType assertType)
 {
     Delete(assertType.Id);
 }
Пример #27
0
        /// <summary> This is the inner-most implementation method for the Assert helper class.  It implements all of the assertType specific behavior for all assertions that get triggered.</summary>
        private static void AssertCommon(string mesg, AssertType assertType, System.Diagnostics.StackFrame sourceFrame)
        {
            // always log all triggered asserts to the BasicFallbackLog

            string logStr = Fcns.CheckedFormat("{0} at file:'{1}', line:{2}", mesg, sourceFrame.GetFileName(), sourceFrame.GetFileLineNumber());

            if (assertType != AssertType.Log)
                Logging.BasicFallbackLogging.LogError(logStr);

            bool ignoreFault = false;		// intended to be used by debug user to ignore such asserts on a case by case basis

            if (assertType == AssertType.Log)
            {
                if (assertLogger == null)       // in an MT world we might create a few of these simultaneously.  This is not a problem as the distribution engine supports such a construct so locking is not required here in order to get valid behavior.
                    assertLogger = new Logging.Logger("MosaicLib.Utils.Assert");

                assertLogger.Warning.Emit(mesg);

                return;
            }
            else if (assertType == AssertType.LogFallback)
            {
                return;	// already done
            }
            else if (assertType == AssertType.ThrowException)
            {
                if (!ignoreFault)
                    throw new AssertException(mesg, sourceFrame);

                return;
            }

            if (!ignoreFault)
            {
                // the remaining types always trigger a breakpoint
                if (System.Diagnostics.Debugger.IsAttached)
                    System.Diagnostics.Debugger.Break();

                // finally if the type is a FatalExit then call the Kernel32.dll FatalExit entry point
                if (assertType == AssertType.FatalExit)
                    FatalExit(-1);
            }
        }
Пример #28
0
 public void Update(AssertType assertType)
 {
     Update(assertType.Name, assertType.Id);
 }
Пример #29
0
 public void Delete(AssertType assertType)
 {
     Delete(assertType.Id);
 }
Пример #30
0
 /// <summary>Common implementation method for Noting that Fault has occurred, with or without a related System.Exception ex.</summary>
 public static void NoteFaultOccurance(string faultDesc, System.Exception ex, AssertType assertType, System.Diagnostics.StackFrame sourceFrame)
 {
     if (ex == null)
         AssertCommon(Fcns.CheckedFormat("AssertFault:{0}", faultDesc), assertType, sourceFrame);
     else
         AssertCommon(Fcns.CheckedFormat("AssertFault:{0} with exception:{1}", faultDesc, ex.Message), assertType, sourceFrame);
 }
Пример #31
0
        private static void WarnTimeoutWasExtended()
        {
            var method = AssertType.GetMethod("Warn", new [] { typeof(string) });

            method?.Invoke(null, new object[] { "Timeout for Wait was extended." });
        }
Пример #32
0
 /// <summary>Reports that the given condDesc described condition test failed.  Action taken when the condition is not true is determined by the given assertType value.</summary>
 public static void NoteConditionCheckFailed(string condDesc, AssertType assertType)
 {
     NoteConditionCheckFailed(condDesc, assertType, new System.Diagnostics.StackFrame(1, true));
 }
Пример #33
0
 public static void Fault(string faultDesc, AssertType assertType)
 {
     NoteFaultOccurance(faultDesc, null, assertType, new System.Diagnostics.StackFrame(1, true));
 }
Пример #34
0
        /// <summary>
        /// Get latex result instance by assert type
        /// </summary>
        /// <returns>index in list, -1 if not found</returns>
        private int getLatexResultByType(AssertType type)
        {
            int index = -1;
            do
            {
                if (mLatexList.Count == 0)
                    break;

                for (int i = 0; i < mLatexList.Count; ++i)
                {
                    if (mLatexList.ElementAt(i).mType == type)
                    {
                        index = i;
                        break;
                    }
                }
            } while (false);

            return index;
        }
Пример #35
0
 public int Insert(AssertType assertType)
 {
     return(Insert(assertType.Name));
 }
 public int Insert(AssertType assertType)
 {
     return Insert(assertType.Name);
 }
Пример #37
0
 public void Update(AssertType assertType)
 {
     _dbRepository.Update(assertType.Name, assertType.Id);
 }
 public void Update(AssertType assertType)
 {
     Update(assertType.Name, assertType.Id);
 }
Пример #39
0
 public int Insert(AssertType assertType)
 {
     return _dbRepository.Insert(assertType.Name);
 }
 public int Insert(string name)
 {
     using (var client = new HttpClient(_messageHandler, false))
     {
         client.BaseAddress = new Uri(_baseAddress);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         var assertType = new AssertType
         {
             Name = name
         };
         var response = client.PostAsync(UrlBase, assertType, new JsonMediaTypeFormatter()).Result;
         response.EnsureSuccessStatusCode();
         var responseString = response.Content.ReadAsStringAsync().Result;
         var returnValue = Convert.ToInt32(responseString);
         return returnValue;
     }
 }
Пример #41
0
        /// <summary>Common implementation method for Noting that a condition test failed.</summary>
        public static void NoteConditionCheckFailed(string condDesc, AssertType assertType, System.Diagnostics.StackFrame sourceFrame)
		{
			AssertCommon(Fcns.CheckedFormat("AssertCondition:[{0}] Failed", condDesc), assertType, sourceFrame);
		}
Пример #42
0
 public int Insert(AssertType assertType)
 {
     return(_dbRepository.Insert(assertType.Name));
 }
Пример #43
0
 public static void NoteFaultOccurance(string faultDesc, System.Exception ex, AssertType assertType) { NoteFaultOccurance(faultDesc, ex, assertType, new System.Diagnostics.StackFrame(1, true)); }
Пример #44
0
        internal void Update(AssertionBase assertion)
        {
            // 2015-11-21-thu-update latex
            AssertType assertType = AssertType.NONE;
            string     non = "deadlockfree", channel = "_";
            string     assertion_text = assertion.ToString();

            if (assertion_text.Contains(non))
            {
                assertType = AssertType.DEADLOCK_FREE;
            }
            else if (assertion_text.Contains(channel))
            {
                assertType = AssertType.CONGESTION_CHANNEL;
            }
            else
            {
                assertType = AssertType.CONGESTION_SENSOR;
            }

            string result      = assertion.getResult();
            string resultlatex = "";

            // Get result of assersion
            do
            {
                if (assertType.Equals(AssertType.DEADLOCK_FREE))
                {
                    if (result.Equals("VALID"))
                    {
                        resultlatex = "\\vl";
                    }
                    else if (result.Equals("INVALID"))
                    {
                        resultlatex = "\\nv";
                    }
                    else
                    {
                        resultlatex = "\\unk";
                    }
                    break;
                }

                if (result.Equals("VALID"))
                {
                    resultlatex = "\\nv";
                }
                else if (result.Equals("INVALID"))
                {
                    resultlatex = "\\vl";
                }
                else
                {
                    resultlatex = "\\unk";
                }
            } while (false);

            // Mapping record to variable
            do
            {
                int posType = -1;
                if (assertType.Equals(AssertType.DEADLOCK_FREE))
                {
                    posType = 0;
                }
                else if (assertType.Equals(AssertType.CONGESTION_CHANNEL))
                {
                    posType = 1;
                }
                else if (assertType.Equals(AssertType.CONGESTION_SENSOR))
                {
                    posType = 2;
                }

                if (posType < 0)
                {
                    break;
                }

                mParseRes[posType].mTime       = assertion.getTimes();
                mParseRes[posType].mMemo       = (float)assertion.getMems();
                mParseRes[posType].mTransition = assertion.getTransitions();
                mParseRes[posType].mState      = assertion.getStates();
                mParseRes[posType].mClicked    = true;
                mParseRes[posType].mRes        = resultlatex;
            } while (false);
        }
Пример #45
0
        private string convertResultToLatex(AssertType type, string pureResult)
        {
            string ret = null;
            if (type == AssertType.DEADLOCK_FREE)
            {
                if ("VALID".Equals(pureResult)) ret = "\\vl";
                else if ("INVALID".Equals(pureResult)) ret = "\\nv";
                else ret = "\\unk";
            }
            else
            {
                if ("VALID".Equals(pureResult)) ret = "\\nv";
                else if ("INVALID".Equals(pureResult)) ret = "\\vl";
                else ret = "\\unk";
            }

            return ret;
        }
Пример #46
0
 /// <summary>Common implementation method for Noting that a condition test failed.</summary>
 public static void NoteConditionCheckFailed(string condDesc, AssertType assertType, System.Diagnostics.StackFrame sourceFrame)
 {
     AssertCommon(Fcns.CheckedFormat("AssertCondition:[{0}] Failed", condDesc), assertType, sourceFrame);
 }
Пример #47
0
 /// <summary>
 /// Shows a message and gets an exception that should be thrown.
 /// </summary>
 /// <param name="type">
 /// The type of assert condition that was evaluated.
 /// </param>
 /// <param name="message">The message that should be shown.</param>
 /// <returns>The exception that should be thrown, or null.</returns>
 protected abstract Exception Failed(AssertType type, string message);
Пример #48
0
 public AssertCommand(IXTable source, AssertType type, XDatabaseContext context) : base(source)
 {
     _type             = type;
     _singlePageSource = new SinglePageEnumerator(source);
     _assertPipeline   = context.Parser.NextQuery(_singlePageSource);
 }
Пример #49
0
 /// <summary>Reports that the faultDesc described fault and the ex Exception has occurred.  Action taken when the condition is not true is determined by the given assertType value.</summary>
 public static void NoteFaultOccurance(string faultDesc, System.Exception ex, AssertType assertType)
 {
     NoteFaultOccurance(faultDesc, ex, assertType, new System.Diagnostics.StackFrame(1, true));
 }