コード例 #1
0
        private static void GenericServiceResolutionTest <TService>()
        {
            // arrange
            IConfiguration     mockedConfiguration = MockConfiguration.GetMock();
            Startup            pluggedStartup      = new Startup(mockedConfiguration);
            IServiceCollection serviceCollection   = new ServiceCollection();

            // act
            pluggedStartup.ConfigureServices(serviceCollection);
            //_ = serviceCollection.AddTransient<PersonController>();

            // assert
            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            TService service = serviceProvider.GetService <TService>();

            Assert.IsNotNull(service);
        }
コード例 #2
0
        public static void AssemblyInitialize(TestContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            IConfiguration  mockedConfiguration = MockConfiguration.GetMock();
            ServiceProvider serviceProvider     = new ServiceCollection()
                                                  .AddBusinessServices()
                                                  .AddRepositoryServices(mockedConfiguration)
                                                  .BuildServiceProvider();

            // création d'une base de données de test
            // TODO : nécessite d'être vidée après les tests : regarder du côté de EfCore/InMemory/Sqlite

            serviceProvider.ConfigureDataBase();

            context.Properties.Add("ServiceProvider", serviceProvider);
            context.Properties.Add("MockedConfiguration", mockedConfiguration);
        }