Пример #1
0
        public void WithDependency_T2_T3_Instance_ActionWithContext_InstanceTypeFound_ShouldInvokeActionWithInstanceAndContext()
        {
            // Arrange
            var invoked = false;

            var dependencies = new Dictionary <Type, object>
            {
                { typeof(IAccountRepository), new AccountRepository() }
            };

            var sut = new FluentArrangeContext <AccountService>(dependencies);

            var instance = new AccountRepository();

            // Act
            sut.WithDependency <IAccountRepository, AccountRepository>(instance, (context, repository) =>
            {
                invoked = true;

                // Assert
                context.Should().Be(sut);
                repository.Should().Be(instance);
            });

            // Assert
            invoked.Should().BeTrue();
        }
Пример #2
0
        public void WithDependency_T2_Action_T2_Always_ShouldReturnReferenceToSut()
        {
            // Arrange
            var sut = new FluentArrangeContext <AccountService>(new Dictionary <Type, object>());

            // Act
            var result = sut.WithDependency <IAccountRepository>(e => { });

            // Assert
            result.Should().Be(sut);
        }
Пример #3
0
        public void WithDependency_T2_Action_T2_TypeNotFound_ShouldNotInvokeAction()
        {
            // Arrange
            var invoked = false;
            var sut     = new FluentArrangeContext <object>(new Dictionary <Type, object>());

            // Act
            sut.WithDependency <IAccountRepository>(e => invoked = true);

            // Assert
            invoked.Should().BeFalse();
        }
Пример #4
0
        public void WithDependency_T2_Instance_InstanceTypeNotFound_ShouldThrowInvalidOperationException()
        {
            // Arrange
            var dependencies = new Dictionary <Type, object>
            {
                { typeof(IAccountRepository), new AccountRepository() }
            };

            var sut = new FluentArrangeContext <AccountService>(dependencies);

            // Act
            Action act = () => sut.WithDependency <IFoo>(new Foo());

            // Assert
            act.Should().Throw <InvalidOperationException>()
            .And.Message.Should().Be("No dependency found of type FluentArrange.Tests.TestClasses.IFoo");
        }
Пример #5
0
        public void WithDependency_T2_Instance_InstanceTypeFound_DependenciesShouldContainInstance()
        {
            // Arrange
            var dependencies = new Dictionary <Type, object>
            {
                { typeof(IAccountRepository), new AccountRepository() }
            };

            var sut = new FluentArrangeContext <AccountService>(dependencies);

            var newInstance = new AccountRepository();

            // Act
            sut.WithDependency <IAccountRepository>(newInstance);

            // Assert
            sut.Dependencies[typeof(IAccountRepository)].Should().Be(newInstance);
        }
Пример #6
0
        public void WithDependency_T2_Action_T2_TypeFound_ShouldInvokeAction()
        {
            // Arrange
            var invoked = false;

            var dependencies = new Dictionary <Type, object>
            {
                { typeof(IAccountRepository), new AccountRepository() }
            };

            var sut = new FluentArrangeContext <AccountService>(dependencies);

            // Act
            sut.WithDependency <IAccountRepository>(d =>
            {
                invoked = true;

                // Assert
                d.Should().Be(dependencies.Single().Value);
            });

            // Assert
            invoked.Should().BeTrue();
        }