Exemplo n.º 1
0
        public void DirectoryLoader_ShouldThrowException_IfDirectoryIsInvalid()
        {
            //Given
            var loader = new DirectoryLoader <TestAppEvents>(string.Empty);
            var events = new TestAppEvents();

            // When & Then
            Assert.Throws <ArgumentException>(() => loader.Load(events));
        }
Exemplo n.º 2
0
        public void DirectoryLoader_ShouldBindEvents_IfDirectoryIsValid()
        {
            //Given
            var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Test.Modules", "Path1");

            var loader = new DirectoryLoader <TestAppEvents>(path);
            var events = new TestAppEvents();

            //When
            var modules = loader.Load(events);

            //Then
            Assert.NotNull(events.MyEvent);
        }
Exemplo n.º 3
0
        public void DirectoryLoader_ShouldLoadModules_IfModuleFilterIsValid()
        {
            //Given
            var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Test.Modules", "Path3");

            var loader = new DirectoryLoader <TestAppEvents>(path, moduleFilter: "*.mod");
            var events = new TestAppEvents();

            //When
            var modules = loader.Load(events);

            //Then
            Assert.True(modules.Any());
        }
Exemplo n.º 4
0
        public void DirectoryLoader_ShouldLoadSubDirectories_IfRecurseiveIsSet()
        {
            //Given
            var path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;

            var loader = new DirectoryLoader <TestAppEvents>(path, true);
            var events = new TestAppEvents();

            //When
            var modules = loader.Load(events);

            //Then
            Assert.True(modules.Any());
        }
Exemplo n.º 5
0
        public void DirectoryLoader_ShouldLoadAllModules_IfMultipleDirectoriesAreProvided()
        {
            //Given
            var path1 = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Test.Modules", "Path1");
            var path2 = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Test.Modules", "Path2");

            var loader = new DirectoryLoader <TestAppEvents>(new string[] { path1, path2 });
            var events = new TestAppEvents();

            //When
            var modules = loader.Load(events);

            //Then
            Assert.Equal(2, modules.Count());
        }
        public void RegisterAssembly(IServiceCollection services, AssemblyName assemblyName)
        {
            var assembly = _loader.Load(assemblyName.Name);

            foreach (var type in assembly.DefinedTypes)
            {
                var taskInterface = type.GetInterface(_options.InjectFromInterfaceName, true);
                if (taskInterface == null)
                {
                    continue;
                }

                var dependencyAttributes = type.GetCustomAttributes <Attributes.DependencyAttribute>();

                // Each dependency can be registered as various types
                foreach (var serviceDescriptor in dependencyAttributes.Select(dependencyAttribute => dependencyAttribute.BuiildServiceDescriptor(type)))
                {
                    services.Add(serviceDescriptor);
                }
            }
        }