Append() public method

Appends an object to the end of the stack, rather than pushing it onto the top of the stack. This method allows a serializer to communicate with other serializers by adding contextual data that does not have to be popped in order. There is no way to remove an object that was appended to the end of the stack without popping all other objects.
public Append ( object context ) : void
context object
return void
Beispiel #1
0
        public void IntegrityTest()
        {
            ContextStack stack = new ContextStack();

            string one = "one";
            string two = "two";
            stack.Push(two);
            stack.Push(one);
            Assert.Same(one, stack[typeof(string)]);
            Assert.Same(one, stack[0]);
            Assert.Same(one, stack.Current);

            Assert.Same(one, stack.Pop());

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            string three = "three";
            stack.Append(three);

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            Assert.Same(two, stack.Pop());

            Assert.Same(three, stack[typeof(string)]);
            Assert.Same(three, stack[0]);
            Assert.Same(three, stack.Current);
            Assert.Same(three, stack.Pop());

            Assert.Null(stack.Pop());
            Assert.Null(stack.Current);
        }
Beispiel #2
0
		public void IntegrityTest ()
		{
			ContextStack stack = new ContextStack ();

			string one = "one";
			string two = "two";
			stack.Push (two);
			stack.Push (one);
			Assert.AreSame (one, stack [typeof (string)], "#1");
			Assert.AreSame (one, stack [0], "#2");
			Assert.AreSame (one, stack.Current, "#3");

			Assert.AreSame (one, stack.Pop (), "#4");

			Assert.AreSame (two, stack [typeof (string)], "#5");
			Assert.AreSame (two, stack [0], "#6");
			Assert.AreSame (two, stack.Current, "#7");

			string three = "three";
			stack.Append (three);

			Assert.AreSame (two, stack[typeof (string)], "#8");
			Assert.AreSame (two, stack[0], "#9");
			Assert.AreSame (two, stack.Current, "#10");

			Assert.AreSame (two, stack.Pop (), "#11");

			Assert.AreSame (three, stack[typeof (string)], "#12");
			Assert.AreSame (three, stack[0], "#13");
			Assert.AreSame (three, stack.Current, "#14");
			Assert.AreSame (three, stack.Pop (), "#15");

			Assert.IsNull (stack.Pop (), "#16");
			Assert.IsNull (stack.Current, "#17");
		}
Beispiel #3
0
 public void Append_Context_Null()
 {
     ContextStack stack = new ContextStack();
     ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() => stack.Append(null));
     Assert.Equal(typeof(ArgumentNullException), ex.GetType());
     Assert.Null(ex.InnerException);
     Assert.NotNull(ex.Message);
     Assert.Equal("context", ex.ParamName);
 }
Beispiel #4
0
		public void Append_Context_Null ()
		{
			ContextStack stack = new ContextStack ();
			try {
				stack.Append (null);
				Assert.Fail ("#1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.AreEqual ("context", ex.ParamName, "#5");
			}
		}