Esempio n. 1
0
		/// <summary>
		/// Constructs a <see cref="UnexpectedInvocationException"/> with the given parameters.
		/// </summary>
		/// <param name="factory">The MockFactory that threw this exception</param>
		/// <param name="invocation">The unexpected invocation</param>
		/// <param name="expectations">The expectations collection to describe</param>
		/// <param name="message">A message to help the user understand what was unexpected</param>
		internal UnexpectedInvocationException(MockFactory factory, Invocation invocation, IExpectationList expectations, string message)
		{
			if (factory == null)
				throw new ArgumentNullException("factory");
			if (invocation == null)
				throw new ArgumentNullException("invocation");
			if (expectations == null) 
				throw new ArgumentNullException("expectations");

			Factory = factory;

			var writer = new DescriptionWriter();
			writer.WriteLine();
			if (invocation.IsPropertySetAccessor)
				writer.WriteLine(UNEXPECTED_PROPERTY_SETTER_PREFIX);
			else if (invocation.IsPropertyGetAccessor)
				writer.WriteLine(UNEXPECTED_PROPERTY_GETTER_PREFIX);
			else
				writer.WriteLine(MESSAGE_PREFIX);
			writer.Write("  ");
			((ISelfDescribing)invocation).DescribeTo(writer);
			writer.Write(message);
			//expectations.DescribeActiveExpectationsTo(writer);
			//expectations.DescribeUnmetExpectationsTo(writer);
			expectations.DescribeTo(writer);

			_message = writer.ToString();
		}
Esempio n. 2
0
        /// <summary>
        /// Constructs a <see cref="UnexpectedInvocationException"/> with the given parameters.
        /// </summary>
        /// <param name="factory">The MockFactory that threw this exception</param>
        /// <param name="invocation">The unexpected invocation</param>
        /// <param name="expectations">The expectations collection to describe</param>
        /// <param name="message">A message to help the user understand what was unexpected</param>
        internal UnexpectedInvocationException(MockFactory factory, Invocation invocation, IExpectationList expectations, string message)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (invocation == null)
            {
                throw new ArgumentNullException("invocation");
            }
            if (expectations == null)
            {
                throw new ArgumentNullException("expectations");
            }

            Factory = factory;

            var writer = new DescriptionWriter();

            writer.WriteLine();
            if (invocation.IsPropertySetAccessor)
            {
                writer.WriteLine(UNEXPECTED_PROPERTY_SETTER_PREFIX);
            }
            else if (invocation.IsPropertyGetAccessor)
            {
                writer.WriteLine(UNEXPECTED_PROPERTY_GETTER_PREFIX);
            }
            else
            {
                writer.WriteLine(MESSAGE_PREFIX);
            }
            writer.Write("  ");
            ((ISelfDescribing)invocation).DescribeTo(writer);
            writer.Write(message);
            //expectations.DescribeActiveExpectationsTo(writer);
            //expectations.DescribeUnmetExpectationsTo(writer);
            expectations.DescribeTo(writer);

            _message = writer.ToString();
        }