Added service provider Test
This commit is contained in:
parent
5db2a3f669
commit
305f4b34de
0
src/tests/cases/service/__init__.py
Normal file
0
src/tests/cases/service/__init__.py
Normal file
78
src/tests/cases/service/provider_test.py
Normal file
78
src/tests/cases/service/provider_test.py
Normal file
@ -0,0 +1,78 @@
|
||||
import unittest
|
||||
|
||||
from sh_edraft.console import Console
|
||||
from sh_edraft.database.context import DatabaseContext
|
||||
from sh_edraft.hosting import ApplicationHost
|
||||
from sh_edraft.logging import Logger
|
||||
from sh_edraft.logging.base import LoggerBase
|
||||
|
||||
|
||||
class ProviderTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
Console.disable()
|
||||
self._app_host = ApplicationHost()
|
||||
self._configuration = self._app_host.configuration
|
||||
self._services = self._app_host.services
|
||||
|
||||
self._configuration.add_argument_variables()
|
||||
self._configuration.add_json_file(f'appsettings.json')
|
||||
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.environment_name}.json')
|
||||
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.host_name}.json', optional=True)
|
||||
|
||||
def test_get_db_context(self):
|
||||
self._services.add_db_context(DatabaseContext)
|
||||
db: DatabaseContext = self._services.get_db_context()
|
||||
|
||||
self.assertIsNotNone(db)
|
||||
|
||||
def test_get_service_singleton(self):
|
||||
self._services.add_singleton(LoggerBase, Logger)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNotNone(logger)
|
||||
|
||||
def test_get_service_scoped(self):
|
||||
self._services.add_scoped(LoggerBase, Logger)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNotNone(logger)
|
||||
|
||||
def test_get_service_transient(self):
|
||||
self._services.add_transient(LoggerBase, Logger)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNotNone(logger)
|
||||
|
||||
def test_remove_service_singleton(self):
|
||||
self._services.add_singleton(LoggerBase, Logger)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNotNone(logger)
|
||||
|
||||
self._services.remove_service(LoggerBase)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNone(logger)
|
||||
|
||||
def test_remove_service_scoped(self):
|
||||
self._services.add_scoped(LoggerBase, Logger)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNotNone(logger)
|
||||
|
||||
self._services.remove_service(LoggerBase)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNone(logger)
|
||||
|
||||
def test_remove_service_transient(self):
|
||||
self._services.add_transient(LoggerBase, Logger)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNotNone(logger)
|
||||
|
||||
self._services.remove_service(LoggerBase)
|
||||
logger = self._services.get_service(LoggerBase)
|
||||
|
||||
self.assertIsNone(logger)
|
@ -1,5 +1,7 @@
|
||||
import unittest
|
||||
from typing import Type
|
||||
|
||||
from tests.cases.service.provider_test import ProviderTest
|
||||
from tests.cases.time.time_format_settings import TimeFormatSettingsTest
|
||||
from tests.cases.utils.credential_manager import CredentialManagerTest
|
||||
|
||||
@ -8,7 +10,7 @@ class Tester:
|
||||
|
||||
def __init__(self):
|
||||
self._suite = unittest.TestSuite()
|
||||
self._cases = []
|
||||
self._cases: list[Type[unittest.TestCase]] = []
|
||||
|
||||
def _build_cases(self):
|
||||
for case in self._cases:
|
||||
@ -17,6 +19,7 @@ class Tester:
|
||||
self._suite.addTest(case(function))
|
||||
|
||||
def create(self):
|
||||
self._cases.append(ProviderTest)
|
||||
self._cases.append(CredentialManagerTest)
|
||||
self._cases.append(TimeFormatSettingsTest)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user