コード例 #1
0
        public void PropertyInjectionBehavior_ChangedAfterFirstRegistration_Fails()
        {
            // Arrange
            var expectedBehavior = new AlternativePropertySelectionBehavior();

            var options = new ContainerOptions();

            var container = new Container(options);

            container.RegisterSingle <object>("The first registration.");

            try
            {
                // Act
                options.PropertySelectionBehavior = expectedBehavior;

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (InvalidOperationException ex)
            {
                AssertThat.ExceptionMessageContains(
                    "PropertySelectionBehavior property cannot be changed after the first registration",
                    ex);
            }
        }
コード例 #2
0
        public void PropertyInjectionBehavior_ChangedBeforeAnyRegistrations_ChangesThePropertyToTheSetInstance()
        {
            // Arrange
            var expectedBehavior = new AlternativePropertySelectionBehavior();

            var options = GetContainerOptions();

            // Act
            options.PropertySelectionBehavior = expectedBehavior;

            // Assert
            Assert.AreSame(expectedBehavior, options.PropertySelectionBehavior,
                           "The set_PropertySelectionBehavior did not work.");
        }
コード例 #3
0
        public void PropertyInjectionBehavior_ChangedBeforeAnyRegistrations_ChangesThePropertyToTheSetInstance()
        {
            // Arrange
            var expectedBehavior = new AlternativePropertySelectionBehavior();

            var options = new ContainerOptions();

            var container = new Container(options);

            // Act
            options.PropertySelectionBehavior = expectedBehavior;

            // Assert
            Assert.IsTrue(object.ReferenceEquals(expectedBehavior, options.PropertySelectionBehavior),
                          "The set_PropertySelectionBehavior did not work.");
        }