public void Singleton_Test_Success()
        {
            // Singleton entities are always the same object
            var singletonObject = _ep.GetSingleton <IInterfaceModel>();
            var singletonSame   = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests").GetSingleton <IInterfaceModel>();
            {
                var singletonObjectIndifferentScope = _ep.GetSingleton <IInterfaceModel>();

                // Assert

                // Singletons of same
                Assert.Equal(singletonObject, singletonSame);

                // Singletons gotten in different scopes are the same object
                Assert.Equal(singletonObject, singletonObjectIndifferentScope);
            }

            // EntityProviders must return different singletons from different namespaces
            var otherEp = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests.New");

            var singletonObjectNew = otherEp.GetSingleton <IInterfaceModel>();

            Assert.NotEqual(singletonObject, singletonObjectNew);

            // Entity providers cannot provide Singletons from Namespaces where there is no imlementation
            var noImplementationEp = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests.NotImplementedEntities");

            Assert.Throws <NotImplementedException>(() => noImplementationEp.GetSingleton <IInterfaceModel>());
        }
        public void BadSingletonConfigurationTests_Test_Fail()
        {
            var conf      = "<EP><Singletons xmlns:epns=\"EntityProvider.Tests\"><epns:Type>IInterfaceModelX</epns:Type></Singletons></EP>";
            var aProvider = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests", conf);

            Assert.Throws <TypeAccessException>(() => aProvider.GetSingleton <IInterfaceModel>());
        }
        public void SingletonConfiguration_Test_Success()
        {
            var conf = "<EP><Singletons xmlns:epns=\"EntityProvider.Tests\"><epns:Type>IInterfaceModel</epns:Type></Singletons></EP>";
            var localEpWithSingletonsConf = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests", conf);

            // Singleton entities are always the same object
            var singletonObject = _ep.GetSingleton <IInterfaceModel>();
            var singletonSame   = localEpWithSingletonsConf.New <IInterfaceModel>();
            {
                var singletonObjectIndifferentScope = localEpWithSingletonsConf.New <IInterfaceModel>();

                // Assert

                // Singletons of same
                Assert.Equal(singletonObject, singletonSame);

                // Singletons gotten in different scopes are the same object
                Assert.Equal(singletonObject, singletonObjectIndifferentScope);
            }

            // EntityProviders must return different singletons from different namespaces
            var otherEp = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests.New", conf);

            var singletonObjectNew = otherEp.New <IInterfaceModel>();

            Assert.NotEqual(singletonObject, singletonObjectNew);

            // Entity providers cannot provide Singletons from Namespaces where there is no imlementation
            var noImplementationEp = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests.NotImplementedEntities", conf);

            Assert.Throws <NotImplementedException>(() => noImplementationEp.New <IInterfaceModel>());
        }
        public void GetProviderusingLoadedAssembly_Tests()
        {
            var          ep       = EpFactory.GetProvider("EntityProvider.Tests", "EntityProvider.Tests");
            const string greeting = "Hello World";
            var          model    = ep.GetTransient <IInterfaceModel>(greeting, 42);

            Assert.Equal(greeting, model.SomeProp1);
        }
        public void StrongMapsTest_Test_Success()
        {
            var conf = "<EP><StrongMaps><Map implementation=\"OtherImplementedModel\">EntityProvider.Tests.IInterfaceModel</Map></StrongMaps></EP>";
            var Ep   = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests", conf);
            var impl = Ep.New <IInterfaceModel>();

            Assert.Equal("EntityProvider.Tests.OtherImplementedModel", impl.SomeProp1);
        }
        public void GetImplementationFromCurrentAssemblySuccess()
        {
            // Arrange
            var ep = EpFactory.GetProvider();

            // Act
            var implementedModel = ep.GetTransient <IInterfaceModel>();

            // Assert
            Assert.IsAssignableFrom <IInterfaceModel>(implementedModel);
        }
        public void FullyFeaturedConf_Test_Success()
        {
            var conf = $@"<EP xmlns:epns=""EntityProvider.Tests"" dll=""{Assembly.GetExecutingAssembly().Location}"">
                            <StrongMaps>
                                <Map implementation=""ImplementedModel"">
                                    EntityProvider.Tests.IInterfaceModel
                                </Map>
                            </StrongMaps>
                            <Singletons>
                                <epns:Type>IInterfaceModel</epns:Type>
                            </Singletons>
                         </EP>";
            var Ep   = EpFactory.GetProvider(conf);
            var impl = Ep.New <IInterfaceModel>();

            // Singleton entities are always the same object
            var singletonObject = _ep.GetSingleton <IInterfaceModel>();
            var singletonSame   = Ep.New <IInterfaceModel>();
            {
                var singletonObjectIndifferentScope = Ep.New <IInterfaceModel>();

                // Assert

                // Singletons of same
                Assert.Equal(singletonObject, singletonSame);

                // Singletons gotten in different scopes are the same object
                Assert.Equal(singletonObject, singletonObjectIndifferentScope);
            }

            // EntityProviders must return different singletons from different namespaces
            var otherEp = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests.New", conf);

            var singletonObjectNew = otherEp.New <IInterfaceModel>();

            Assert.NotEqual(singletonObject, singletonObjectNew);

            // Entity providers cannot provide Singletons from Namespaces where there is no imlementation
            var noImplementationEp = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests.NotImplementedEntities", conf);

            Assert.Throws <NotImplementedException>(() => noImplementationEp.New <IInterfaceModel>());
        }
 public EntityProviderTests()
 {
     _ep = EpFactory.GetProvider(Assembly.GetExecutingAssembly().Location, "EntityProvider.Tests");
 }