I have this plugin project with a service called ArticleServices. Bellow an example of the constructor.

I want't to create a unit-test project to test a method in the ArticleService service like so:


        [TestMethod]
        public void TestMethod1()
        {

            ArticleServices articleServices = new ArticleServices();

            articleServices.SyncProducts();


        }


This won't work of course, the constructor requires several services, witch are normaly injected through dependency injection.

What is the best way to do this. How can i create an instance of the ArticleServices in my test method? Do i have to mock all the injected services or is there another way. I want the injected services behave like they would in a real call. E.g. updating a product in the productService should actualy update the product in the database.

I searched for examples or tutorials, but none of the results are telling me how to use the autofac dependency injection.


I hope someone can provide me with some examples.



        public ArticleServices(IProductService productService,
            ICategoryService categoryService,
            IManufacturerService manufacturerService,
            IPictureService pictureService,
            IUrlRecordService urlRecordService,
            IStoreContext storeContext,
            INewsLetterSubscriptionService newsLetterSubscriptionService,
            ICountryService countryService,
            IStateProvinceService stateProvinceService,
            IEncryptionService encryptionService,
            IDataProvider dataProvider,
            MediaSettings mediaSettings,
            IVendorService vendorService,
            IProductTemplateService productTemplateService,
            IShippingService shippingService,
            ITaxCategoryService taxCategoryService,
            IMeasureService measureService,
            IProductAttributeService productAttributeService,
            ISpecificationAttributeService specificationAttributeService,
            CatalogSettings catalogSettings,
            ILanguageService languageService,
            ILocalizationService localizationService,
            ILocalizedEntityService localizedEntityService,
            ILogger logger,
            Data.DatabaseContext databaseContext)
        {
            this._productService = productService;
            this._categoryService = categoryService;
            this._manufacturerService = manufacturerService;
            this._pictureService = pictureService;
            this._urlRecordService = urlRecordService;
            this._storeContext = storeContext;
            this._newsLetterSubscriptionService = newsLetterSubscriptionService;
            this._countryService = countryService;
            this._stateProvinceService = stateProvinceService;
            this._encryptionService = encryptionService;
            this._dataProvider = dataProvider;
            this._mediaSettings = mediaSettings;
            this._vendorService = vendorService;
            this._productTemplateService = productTemplateService;
            this._shippingService = shippingService;
            this._taxCategoryService = taxCategoryService;
            this._measureService = measureService;
            this._productAttributeService = productAttributeService;
            this._specificationAttributeService = specificationAttributeService;
            this._catalogSettings = catalogSettings;
            this._languageService = languageService;
            this._localizationService = localizationService;
            this._localizedEntityService = localizedEntityService;
            this._logger = logger;        
            this._databaseContext = databaseContext;

            // Set the default language for the current store
            this.defaultCulture = this._languageService.GetLanguageById(this._storeContext.CurrentStore.DefaultLanguageId).LanguageCulture;
        }