Ejemplo n.º 1
0
        public void Always_ShouldCacheSut()
        {
            //arrange

            //act
            var suit = TestSuit.Create <MyService>();
            var sut1 = suit.Sut;
            var sut2 = suit.Sut;

            //assert
            sut1.Should().Be(sut2);
        }
        public void DependencySetAsSuitInstance_CanConfigureIt()
        {
            //arrange
            _testSuit.SetDependencyToTestSuit <IDependency1>(TestSuit.Create <Dependency1>());

            //act
            _testSuit.SetupDependencySuit <IDependency1>(s => s.SetupMock <IDependency2>(d => d.Action2() == "42"));

            //assert
            // note: ParseNumberFromDependency() calls Dependency1.GetNumber() which in turn calls
            // IDependency2.Action2() which we mocked above
            _testSuit.Sut.ParseNumberFromDependency().Should().Be(42);
        }
        public void SutNotCreated_SetsDependencyToTestSuitInstance()
        {
            //arrange
            var dependencyTestSuit = TestSuit.Create <Dependency1>();

            //act
            _testSuit.SetDependencyToTestSuit <IDependency1>(dependencyTestSuit);

            //assert
            _testSuit.GetSuit <IDependency1>().Should().Be(dependencyTestSuit);
            _testSuit.GetDependency <IDependency1>().Should().Be(dependencyTestSuit.Sut);
            _testSuit.Sut.Dependency1.Should().Be(dependencyTestSuit.Sut);
        }
        public void Reset_ResetsTestSuit()
        {
            //arrange
            var dependencyTestSuit = (TestSuit <Dependency1>)TestSuit.Create <Dependency1>();

            _testSuit.SetDependencyToTestSuit <IDependency1>(dependencyTestSuit);
            _ = dependencyTestSuit.Sut; // create the dependency object

            //act
            _testSuit.Reset();

            //assert
            dependencyTestSuit.IsSutCreated.Should().BeFalse();
        }
        public void SetInstanceToSut_Throws()
        {
            //arrange

            //act
            var action = _testSuit.Invoking(s =>
                                            s.SetDependencyToInstance <ITestSuit <IDependency1>, ITestSuit <Dependency1> >(TestSuit.Create <Dependency1>()));

            //assert
            action.Should().Throw <ArgumentException>();
        }
        public void SutCreated_CannotSetDependencyToTestSuit()
        {
            //arrange
            _ = _testSuit.Sut;

            //act
            var action = _testSuit.Invoking(s => s.SetDependencyToTestSuit <IDependency1>(TestSuit.Create <Dependency1>()));

            //assert
            action.Should().Throw <InvalidOperationException>();
        }