Example #1
0
        public void HasValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.HasValue <TestValueB>(), Is.False);
        }
Example #2
0
        public void HasValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.HasValue <TestValueB>(), Is.False);
            Assert.Throws <InvalidOperationException>(() => context.HasValue <object>());
        }
Example #3
0
        public void SetValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            context.SetValue <TestValueB>();
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueB>(), Is.True);
            Assert.That(context.GetValue <TestValueB>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(2));
        }
Example #4
0
        public void SetValue()
        {
            var context = new TestContextBase();

            context.SetValue(new TestValueA());
            context.SetValue <TestValueB>();
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueB>(), Is.True);
            Assert.That(context.GetValue <TestValueB>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(2));
            Assert.Throws <ArgumentNullException>(() => context.SetValue <TestValueA>(null));
            Assert.Throws <InvalidOperationException>(() => context.SetValue(new object()));
        }
Example #5
0
        public void GetValueOrDefault()
        {
            var context = new TestContextBase();

            Assert.That(context.GetValueOrDefault <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.False);
        }
Example #6
0
        public void GetValueOrDefault()
        {
            var context = new TestContextBase();

            Assert.That(context.GetValueOrDefault <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.False);
            Assert.Throws <InvalidOperationException>(() => context.GetValueOrDefault <object>());
        }
Example #7
0
        public void GetOrCreateValue()
        {
            var context = new TestContextBase();

            Assert.That(context.GetOrCreateValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(1));
        }
Example #8
0
        public void GetOrCreateValue()
        {
            var context = new TestContextBase();

            Assert.That(context.GetOrCreateValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.HasValue <TestValueA>(), Is.True);
            Assert.That(context.GetValue <TestValueA>(), Is.Not.Null);
            Assert.That(context.Values.Length, Is.EqualTo(1));
            Assert.Throws <InvalidOperationException>(() => context.GetOrCreateValue <object>());
        }