Push() публичный Метод

Pushes the given object onto the stack.
public Push ( object context ) : void
context object
Результат void
Пример #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);
        }
Пример #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");
		}
Пример #3
0
		public void Push_Context_Null ()
		{
			ContextStack stack = new ContextStack ();
			try {
				stack.Push (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");
			}
		}
Пример #4
0
		[Test] // Item (Type)
		public void Indexer2_Type_Null ()
		{
			ContextStack stack = new ContextStack ();
			stack.Push (new Foo ());
			try {
				object context = stack [(Type) null];
				Assert.Fail ("#1:" + context);
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.AreEqual ("type", ex.ParamName, "#5");
			}
		}
Пример #5
0
		[Test] // Item (Type)
		public void Indexer2 ()
		{
			ContextStack stack = new ContextStack ();

			Foo foo = new Foo ();
			FooBar foobar = new FooBar ();

			stack.Push (foobar);
			stack.Push (foo);
			Assert.AreSame (foo, stack [typeof (Foo)], "#1");
			Assert.AreSame (foo, stack [typeof (IFoo)], "#2");
			Assert.AreSame (foo, stack.Pop (), "#3");
			Assert.AreSame (foobar, stack [typeof (Foo)], "#4");
			Assert.AreSame (foobar, stack [typeof (FooBar)], "#5");
			Assert.AreSame (foobar, stack [typeof (IFoo)], "#6");
			Assert.IsNull (stack [typeof (string)], "#7");
		}
Пример #6
0
		[Test] // Item (Int32)
		public void Indexer1_Level_Negative ()
		{
			ContextStack stack = new ContextStack ();
			stack.Push (new Foo ());

			try {
				object context = stack [-1];
				Assert.Fail ("#A1:" + context);
			} catch (ArgumentOutOfRangeException ex) {
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#A4");
				Assert.AreEqual ("level", ex.ParamName, "#A5");
			}

			try {
				object context = stack [-5];
				Assert.Fail ("#B1:" + context);
			} catch (ArgumentOutOfRangeException ex) {
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#B4");
				Assert.AreEqual ("level", ex.ParamName, "#B5");
			}
		}
Пример #7
0
		[Test] // Item (Int32)
		public void Indexer1 ()
		{
			ContextStack stack = new ContextStack ();
			string one = "one";
			string two = "two";

			stack.Push (one);
			stack.Push (two);

			Assert.AreSame (two, stack [0], "#1");
			Assert.AreSame (one, stack [1], "#2");
			Assert.IsNull (stack [2], "#3");
			Assert.AreSame (two, stack.Pop (), "#4");
			Assert.AreSame (one, stack [0], "#5");
			Assert.IsNull (stack [1], "#6");
			Assert.AreSame (one, stack.Pop (), "#7");
			Assert.IsNull (stack [0], "#8");
			Assert.IsNull (stack [1], "#9");
		}
Пример #8
0
        [Fact] // Item (Int32)
        public void Indexer1()
        {
            ContextStack stack = new ContextStack();
            string one = "one";
            string two = "two";

            stack.Push(one);
            stack.Push(two);

            Assert.Same(two, stack[0]);
            Assert.Same(one, stack[1]);
            Assert.Null(stack[2]);
            Assert.Same(two, stack.Pop());
            Assert.Same(one, stack[0]);
            Assert.Null(stack[1]);
            Assert.Same(one, stack.Pop());
            Assert.Null(stack[0]);
            Assert.Null(stack[1]);
        }
Пример #9
0
 public void Push_Context_Null()
 {
     ContextStack stack = new ContextStack();
     ArgumentNullException ex= Assert.Throws<ArgumentNullException>(()=> stack.Push(null));
     Assert.Equal(typeof(ArgumentNullException), ex.GetType());
     Assert.Null(ex.InnerException);
     Assert.NotNull(ex.Message);
     Assert.Equal("context", ex.ParamName);
 }
Пример #10
0
 [Fact] // Item (Type)
 public void Indexer2_Type_Null()
 {
     ContextStack stack = new ContextStack();
     stack.Push(new Foo());
     ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() => stack[(Type)null]);
     Assert.Equal(typeof(ArgumentNullException), ex.GetType());
     Assert.Null(ex.InnerException);
     Assert.NotNull(ex.Message);
     Assert.Equal("type", ex.ParamName);
 }
Пример #11
0
        [Fact] // Item (Type)
        public void Indexer2()
        {
            ContextStack stack = new ContextStack();

            Foo foo = new Foo();
            FooBar foobar = new FooBar();

            stack.Push(foobar);
            stack.Push(foo);
            Assert.Same(foo, stack[typeof(Foo)]);
            Assert.Same(foo, stack[typeof(IFoo)]);
            Assert.Same(foo, stack.Pop());
            Assert.Same(foobar, stack[typeof(Foo)]);
            Assert.Same(foobar, stack[typeof(FooBar)]);
            Assert.Same(foobar, stack[typeof(IFoo)]);
            Assert.Null(stack[typeof(string)]);
        }
Пример #12
0
        [Fact] // Item (Int32)
        public void Indexer1_Level_Negative()
        {
            ContextStack stack = new ContextStack();
            stack.Push(new Foo());
            ArgumentOutOfRangeException ex;

            ex = Assert.Throws<ArgumentOutOfRangeException>(() => stack[-1]);
            Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
            Assert.Null(ex.InnerException);
            Assert.Equal(new ArgumentOutOfRangeException("level").Message, ex.Message);
            Assert.Equal("level", ex.ParamName);


            ex = Assert.Throws<ArgumentOutOfRangeException>(() => stack[-5]);
            Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
            Assert.Null(ex.InnerException);
            Assert.Equal(new ArgumentOutOfRangeException("level").Message, ex.Message);
            Assert.Equal("level", ex.ParamName);
        }