예제 #1
0
        public void Test_NamedInstance_MultipleInstanceResolved()
        {
            // Arrange
            var i1 = new TestInstance1("testInstance1");
            var i2 = new TestInstance2("testInstance2");
            var i3 = new TestInstance3("testInstance3");

            // Act
            var factory = new NamedInstanceFactory <ITestInterface>(new List <ITestInterface> {
                i1, i2, i3
            });
            var lookup1 = factory["testInstance1"];
            var lookup2 = factory["testInstance2"];
            var lookup3 = factory["testInstance3"];

            // Assert
            lookup1.Should().Equals(i1);
            lookup2.Should().Equals(i2);
            lookup3.Should().Equals(i3);
            factory.Clients.Count.Should().Be(3);
        }
예제 #2
0
        public void Test_NamedInstance_DuplicateInstanceName()
        {
            // Arrange
            var i1  = new TestInstance1("testInstanceA");
            var i2a = new TestInstance2("testInstanceB");
            var i2b = new TestInstance3("testInstanceB");
            var i2c = new TestInstance3("testInstanceB");

            // Act
            var factory = new NamedInstanceFactory <ITestInterface>(new List <ITestInterface> {
                i1, i2a, i2b, i2c
            });
            var lookup1  = factory["testInstanceA"];
            var lookup2a = factory["testInstanceB"];
            var lookup2b = factory["testInstanceB1"];
            var lookup2c = factory["testInstanceB2"];

            // Assert
            lookup1.Should().Equals(i1);
            lookup2a.Should().Equals(i2a);
            lookup2b.Should().Equals(i2b);
            lookup2c.Should().Equals(i2c);
            factory.Clients.Count.Should().Be(4);
        }