示例#1
0
        public void CanAddGlobalSuffixWithTwoNames()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();
            var suffixName2   = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            TestStructure.TestAddGlobal <TestStructure>(new[] { suffixName, suffixName2 }, testSuffix);
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName));
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName2));
        }
示例#2
0
        public void CantFindStaticSuffixThatDoesntExist()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            Assert.Throws(typeof(KOSSuffixUseException),
                          (() => testStructure.GetSuffix(suffixName)),
                          "failed to throw exception getting nonexistent static suffix");

            TestStructure.TestAddGlobal <TestStructure>(suffixName, testSuffix);
            Assert.IsNotNull(testStructure.GetSuffix(suffixName));
        }
示例#3
0
        public void CanLetInstanceTakePrecedenceOverStatic()
        {
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            var testObject = new object();
            var testSuffix = Substitute.For <ISuffix>();

            testSuffix.Get().ReturnsForAnyArgs(info => testObject);
            testStructure.TestAddInstanceSuffix(suffixName, testSuffix);

            var testSuffixStatic = Substitute.For <ISuffix>();

            testSuffixStatic.Get().ReturnsForAnyArgs(info => int.MaxValue);
            TestStructure.TestAddGlobal <object>(suffixName, testSuffixStatic);

            Assert.IsNotNull(testStructure.GetSuffix(suffixName));
            Assert.AreSame(testObject, testStructure.GetSuffix(suffixName));
        }
示例#4
0
        public void CanAddInstanceSuffix()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            testStructure.TestAddInstanceSuffix(suffixName, testSuffix);
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName));
        }
示例#5
0
        public void CanSetSynonymInstanceSuffix()
        {
            var testObject  = new object();
            var testObject2 = new object();

            object internalStorage = null;
            var    testSuffix      = Substitute.For <ISetSuffix>();

            //Mock Set
            testSuffix.When(s => s.Set(Arg.Any <object>())).Do(info => internalStorage = info.Arg <object>());
            //Mock Get
            testSuffix.Get().ReturnsForAnyArgs(info => internalStorage);

            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();
            var suffixName2   = Guid.NewGuid().ToString();

            testStructure.TestAddInstanceSuffix(new[] { suffixName, suffixName2 }, testSuffix);

            Assert.IsNull(testStructure.GetSuffix(suffixName));
            Assert.IsNull(testStructure.GetSuffix(suffixName2));

            testStructure.SetSuffix(suffixName, testObject);
            Assert.AreSame(testObject, testStructure.GetSuffix(suffixName));
            Assert.AreSame(testObject, testStructure.GetSuffix(suffixName2));

            testStructure.SetSuffix(suffixName2, testObject2);
            Assert.AreSame(testObject2, testStructure.GetSuffix(suffixName));
            Assert.AreSame(testObject2, testStructure.GetSuffix(suffixName2));
        }
示例#6
0
        public void InstanceSuffixesAreCaseInsensitive()
        {
            var testStructure = new TestStructure();

            var testObject1 = new object();
            var testSuffix1 = Substitute.For <ISuffix>();

            testSuffix1.Get().Returns(testObject1);

            var testObject2 = new object();
            var testSuffix2 = Substitute.For <ISuffix>();

            testSuffix2.Get().Returns(testObject2);

            var suffixNameLower = Guid.NewGuid().ToString().ToLower();
            var suffixNameUpper = suffixNameLower.ToUpper();

            testStructure.TestAddInstanceSuffix(suffixNameUpper, testSuffix1);
            Assert.AreEqual(testObject1, testStructure.GetSuffix(suffixNameUpper));
            Assert.AreEqual(testObject1, testStructure.GetSuffix(suffixNameLower));
            testStructure.TestAddInstanceSuffix(suffixNameLower, testSuffix2);
            Assert.AreEqual(testObject2, testStructure.GetSuffix(suffixNameUpper));
            Assert.AreEqual(testObject2, testStructure.GetSuffix(suffixNameLower));
        }
示例#7
0
        public void InstanceSuffixesAreInFactInstanced()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);


            testStructure.TestAddInstanceSuffix(suffixName, testSuffix);
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName));
            Assert.Throws(typeof(KOSSuffixUseException),
                          (() => new TestStructure().GetSuffix(suffixName)),
                          "failed to throw exception getting instance suffix of unpopulated object");
        }