Exemple #1
0
        public void ConstructorResolutionBehavior_ChangedAfterFirstCallToGetInstance_Fails()
        {
            // Arrange
            var expectedBehavior = new AlternativeConstructorResolutionBehavior();

            var options = new ContainerOptions();

            var container = new Container(options);

            // Request a concrete instance that can be created by the container, even without any registrations.
            container.GetInstance <ClassWithContainerAsDependency>();

            try
            {
                // Act
                options.ConstructorResolutionBehavior = expectedBehavior;

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (InvalidOperationException ex)
            {
                AssertThat.StringContains(
                    "ConstructorResolutionBehavior property cannot be changed after the first registration",
                    ex.Message);
            }
        }
Exemple #2
0
        public void ConstructorResolutionBehavior_ChangedAfterFirstRegistration_Fails()
        {
            // Arrange
            var expectedBehavior = new AlternativeConstructorResolutionBehavior();

            var options = new ContainerOptions();

            var container = new Container(options);

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

            try
            {
                // Act
                options.ConstructorResolutionBehavior = expectedBehavior;

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (InvalidOperationException ex)
            {
                AssertThat.ExceptionMessageContains(
                    "ConstructorResolutionBehavior property cannot be changed after the first registration",
                    ex);
            }
        }
Exemple #3
0
        public void ConstructorResolutionBehavior_ChangedBeforeAnyRegistrations_ChangesThePropertyToTheSetInstance()
        {
            // Arrange
            var expectedBehavior = new AlternativeConstructorResolutionBehavior();

            var container = new Container();

            // Act
            container.Options.ConstructorResolutionBehavior = expectedBehavior;

            // Assert
            Assert.IsTrue(object.ReferenceEquals(expectedBehavior, container.Options.ConstructorResolutionBehavior),
                          "The set_ConstructorResolutionBehavior did not work.");
        }
Exemple #4
0
        public void ConstructorResolutionBehavior_ChangedAfterFirstCallToGetInstance_Fails()
        {
            // Arrange
            var expectedBehavior = new AlternativeConstructorResolutionBehavior();

            var container = new Container();

            // Request a concrete instance that can be created by the container, even without any registrations.
            container.GetInstance <ClassWithContainerAsDependency>();

            // Act
            Action action = () => container.Options.ConstructorResolutionBehavior = expectedBehavior;

            // Assert
            AssertThat.ThrowsWithExceptionMessageContains <InvalidOperationException>(
                "ConstructorResolutionBehavior property cannot be changed after the first registration",
                action);
        }