Ejemplo n.º 1
0
        public void ClassWhoseLongerConstructorThrowsCreation(
            ClassWhoseLongerConstructorThrows dummy1, ClassWhoseLongerConstructorThrows dummy2)
        {
            "Given a type with multiple constructors"
            .See <ClassWhoseLongerConstructorThrows>();

            "And its longer constructor throws"
            .See(() => new ClassWhoseLongerConstructorThrows(0, 0));

            "And a dummy of that type is requested"
            .x(() => dummy1 = this.CreateDummy <ClassWhoseLongerConstructorThrows>());

            "And another dummy of that type is requested"
            .x(() => dummy2 = this.CreateDummy <ClassWhoseLongerConstructorThrows>());

            "Then it returns a dummy from the first request"
            .x(() => dummy1.Should().NotBeNull());

            "And the dummy is created via the shorter constructor"
            .x(() => dummy1.CalledConstructor.Should().Be("(int)"));

            "And it returns a dummy from the second request"
            .x(() => dummy2.Should().NotBeNull());

            "And that dummy is created via the shorter constructor"
            .x(() => dummy2.CalledConstructor.Should().Be("(int)"));

            "And the dummies are distinct"
            .x(() => dummy1.Should().NotBeSameAs(dummy2));

            "And the longer constructor was only attempted once"
            .x(() => ClassWhoseLongerConstructorThrows.NumberOfTimesLongerConstructorWasCalled.Should().Be(1));
        }
Ejemplo n.º 2
0
        public void ClassWhoseLongerConstructorThrowsCreation(
            ClassWhoseLongerConstructorThrows dummy)
        {
            "Given a type with multiple constructors"
            .See <ClassWhoseLongerConstructorThrows>();

            "And its longer constructor throws"
            .See(() => new ClassWhoseLongerConstructorThrows(0, 0));

            "When a dummy of that type is requested"
            .x(() => dummy = this.CreateDummy <ClassWhoseLongerConstructorThrows>());

            "Then it returns a dummy"
            .x(() => dummy.Should().NotBeNull());

            "And the dummy is created via the shorter constructor"
            .x(() => dummy.CalledConstructor.Should().Be("(int)"));
        }
Ejemplo n.º 3
0
        public void ClassWhoseLongerConstructorThrowsCreation(
            ClassWhoseLongerConstructorThrows dummy1, ClassWhoseLongerConstructorThrows dummy2)
        {
            "Given a type with multiple constructors"
            .See <ClassWhoseLongerConstructorThrows>();

            "And its longer constructor throws"
            .See(() => new ClassWhoseLongerConstructorThrows(0, 0));

            // If multiple theads attempt to create the dummy at the same time, the
            // unsuccessful constructors may be called more than once, so serialize dummy
            // creation for this test.
            "And nobody else is trying to create a dummy of the class right now"
            .x(() => Monitor.TryEnter(typeof(ClassWhoseLongerConstructorThrows), TimeSpan.FromSeconds(30)).Should().BeTrue("we must enter the monitor"))
            .Teardown(() => Monitor.Exit(typeof(ClassWhoseLongerConstructorThrows)));

            "When a dummy of that type is requested"
            .x(() => dummy1 = this.CreateDummy <ClassWhoseLongerConstructorThrows>());

            "And another dummy of that type is requested"
            .x(() => dummy2 = this.CreateDummy <ClassWhoseLongerConstructorThrows>());

            "Then it returns a dummy from the first request"
            .x(() => dummy1.Should().NotBeNull());

            "And the dummy is created via the shorter constructor"
            .x(() => dummy1.CalledConstructor.Should().Be("(int)"));

            "And it returns a dummy from the second request"
            .x(() => dummy2.Should().NotBeNull());

            "And that dummy is created via the shorter constructor"
            .x(() => dummy2.CalledConstructor.Should().Be("(int)"));

            "And the dummies are distinct"
            .x(() => dummy1.Should().NotBeSameAs(dummy2));

            "And the longer constructor was only attempted once"
            .x(() => ClassWhoseLongerConstructorThrows.NumberOfTimesLongerConstructorWasCalled.Should().Be(1));
        }