public void component_marked_as_transient_is_really_so()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var transient1 = windsorEngine.GetComponent <ITransientComponentMock>();
            var transient2 = windsorEngine.GetComponent <ITransientComponentMock>();

            // ASSERT
            Assert.That(transient1, Is.Not.EqualTo(transient2));
            windsorEngine.Stop();
        }
        public void components_are_singletons_by_default()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var component1 = windsorEngine.GetComponent <IComponentMock>();
            var component2 = windsorEngine.GetComponent <IComponentMock>();

            // ASSERT
            Assert.That(component1, Is.Not.Null);
            Assert.That(component1, Is.EqualTo(component2));
            windsorEngine.Stop();
        }
        public void component_marked_as_singleton_singletons__is_really_so()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var component1 = windsorEngine.GetComponent <ISingletonComponentMock>();
            var component2 = windsorEngine.GetComponent <ISingletonComponentMock>();

            // ASSERT
            Assert.That(component1, Is.Not.Null);
            Assert.That(component1, Is.EqualTo(component2));
            windsorEngine.Stop();
        }
        public void component_can_be_registered_using_factory_method()
        {
            // ARRANGE
            // see: https://github.com/castleproject/Windsor/blob/master/docs/registering-components-one-by-one.md
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var transient1 = windsorEngine.GetComponent <IComponentCreatedViaFactory>();
            var transient2 = windsorEngine.GetComponent <IComponentCreatedViaFactory>();
            var c1         = windsorEngine.GetComponent <IContainerForComponentCreatedViaFactory>();
            var c2         = windsorEngine.GetComponent <IContainerForComponentCreatedViaFactory>();

            // ASSERT
            Assert.That(transient1, Is.Not.EqualTo(transient2));
            Assert.That(c1, Is.EqualTo(c2));
            Assert.That(c1.GetComponentCreatedViaFactory(), Is.EqualTo(c2.GetComponentCreatedViaFactory()));

            windsorEngine.Stop();
        }
Exemple #5
0
        public void resolve_component_using_component_locator()
        {
            // ARRANGE
            IWindsorEngine windsorEngine    = ApplicationServer.Start();
            var            componentLocator = windsorEngine.GetComponent <IComponentLocator>();

            // ACT
            var component = componentLocator.GetComponent <ITransientComponentMock>();

            // ASSERT
            Assert.That(component, Is.Not.Null);
        }
        public void windsor_container_is_available_as_component()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var containerTakenFromWindsor = windsorEngine.GetComponent <IWindsorContainer>();

            // ASSERT
            Assert.NotNull(containerTakenFromWindsor);
            windsorEngine.Stop();
        }
        public void windsor_engine_is_available_as_component()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var engineTakenFromWindsor = windsorEngine.GetComponent <IWindsorEngine>();

            // ASSERT
            Assert.AreEqual(windsorEngine, engineTakenFromWindsor);
            windsorEngine.Stop();
        }
        public void component_can_be_overriden()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var userRpository = windsorEngine.GetComponent <IUserRepository>();

            // ASSERT
            Assert.NotNull(userRpository);
            Assert.IsAssignableFrom <UserRepositoryMock>(userRpository);
        }
Exemple #9
0
        public void can_have_multiple_transactions_to_the_same_database()
        {
            //ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();
            var            myService     = windsorEngine.GetComponent <IMyTransactionalService>();

            //ACT
            myService.InvokeAnotherSession();

            //ASSERT
            windsorEngine.Dispose();
        }
Exemple #10
0
        public void automatic_transaction_can_be_disabled()
        {
            //ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();
            var            myService     = windsorEngine.GetComponent <IMyTransactionalService>();

            //ACT
            bool transactionStarted = myService.MethodWithDisabledAutoTransaction();

            //ASSERT
            Assert.IsFalse(transactionStarted, "Transaction was started but it shouldn't be");
            windsorEngine.Dispose();
        }
Exemple #11
0
        public void GetRootLibrary()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();
            var            librarian     = windsorEngine.GetComponent <ILibrarian>();

            // ACT
            Library rootLibrary = librarian.GetRootLibrary();

            // ASSERT
            Assert.That(rootLibrary.Equals(new SynergyCoreTestLibrary()), Is.True);
            windsorEngine.Stop();
        }
Exemple #12
0
        public void automatic_transaction_should_be_started_because_of_attribute_inheritance()
        {
            //ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();
            var            myService     = windsorEngine.GetComponent <IMyTransactionalService>();

            //ACT
            int count = myService.StartTransactionBecauseThereIsAttributeOnInterface();

            //ASSERT
            Assert.AreEqual(0, count);
            windsorEngine.Dispose();
        }
Exemple #13
0
        public void automatic_transaction_should_be_started()
        {
            //ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();
            var            myService     = windsorEngine.GetComponent <IMyTransactionalService>();

            //ACT
            int count = myService.GetMyEntitiesCount();

            //ASSERT
            Assert.AreEqual(0, count);
            windsorEngine.Dispose();
        }
        public void ComponentShouldBeInteceptedIfRequired()
        {
            //ARRANGE
            IWindsorEngine c           = ApplicationServer.Start();
            var            intercepted = c.GetComponent <IInterceptedComponent>();

            ComponentInterceptor.WasInvoked = false;

            //ACT
            intercepted.Execute();

            //ASSERT
            Assert.That(ComponentInterceptor.WasInvoked, Is.True);
        }
        public void component_list_can_be_retrieved_from_windsor_engine()
        {
            // ARRANGE
            IWindsorEngine windsorEngine    = ApplicationServer.Start();
            var            componentLocator = windsorEngine.GetComponent <IComponentLocator>();

            // ACT
            IUserRepository[] components = componentLocator.GetComponents <IUserRepository>();

            // ASSERT
            Assert.NotNull(components);
            Assert.That(components, Is.Not.Empty);
            Assert.That(components.Length, Is.EqualTo(2));
            windsorEngine.Stop();
        }
        public void can_insert_dependent_collection_of_components()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();

            // ACT
            var component = windsorEngine.GetComponent <IComponentMock>();

            // ASSERT
            Assert.That(component, Is.Not.Null);
            IEnumerable <IDependentComponentMock> dependencies = component.GetDependencies();

            Assert.NotNull(dependencies);
            Assert.AreEqual(1, dependencies.Count());
            windsorEngine.Stop();
        }
Exemple #17
0
        public void resolve_stateful_component_using_component_locator()
        {
            // ARRANGE
            IWindsorEngine windsorEngine    = ApplicationServer.Start();
            var            componentLocator = windsorEngine.GetComponent <IComponentLocator>();
            var            id    = "1234";
            var            state = new State(id);

            // ACT
            var component = componentLocator.GetComponent <IStatefulComponent>(new { state });

            // ASSERT
            Assert.That(component, Is.Not.Null);
            Assert.That(component.Id, Is.EqualTo(id));
            Assert.That(component.Dependency, Is.Not.Null);
        }
Exemple #18
0
        public void GetLibraries()
        {
            // ARRANGE
            IWindsorEngine windsorEngine = ApplicationServer.Start();
            var            librarian     = windsorEngine.GetComponent <ILibrarian>();

            // ACT
            Library[] libraries = librarian.GetLibraries();

            // ASSERT
            Assert.That(libraries,
                        Is.EquivalentTo(
                            new Library[]
            {
                new SynergyCoreTestLibrary(),
                new SynergyCoreSampleLibrary(),
                new SynergyCoreLibrary(),
            }));
            windsorEngine.Stop();
        }