コード例 #1
0
        public void Setup()
        {
            this.appSettings = new ImeAppSettings();

            this.serviceLocator = new Mock <IServiceLocator>();

            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);

            this.appSettingService = new Mock <IAppSettingsService <ImeAppSettings> >();
            this.appSettingService.Setup(x => x.AppSettings).Returns(this.appSettings);

            this.assemblyLocationLoader = new Mock <IAssemblyLocationLoader>();

            var testDirectory = Path.Combine(Assembly.GetExecutingAssembly().Location, @"../../../../../");

#if DEBUG
            var frameworkVersion = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).Name;
            this.assemblyLocationLoader.Setup(x => x.GetLocation()).Returns(Path.GetFullPath(Path.Combine(testDirectory, $@"CDP4IME\bin\Debug\{frameworkVersion}")));
#else
            this.assemblyLocationLoader.Setup(x => x.GetLocation()).Returns(Path.GetFullPath(testDirectory));
#endif
            this.serviceLocator.Setup(s => s.GetInstance <IAssemblyLocationLoader>()).Returns(this.assemblyLocationLoader.Object);

            this.serviceLocator.Setup(s => s.GetInstance <IAppSettingsService <ImeAppSettings> >()).Returns(this.appSettingService.Object);

            this.viewModel = new PluginManagerViewModel <ImeAppSettings>(this.appSettingService.Object);
        }
コード例 #2
0
        public void Setup()
        {
#if DEBUG
            this.BuildFolder = $"CDP4IME{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug";
#else
            this.BuildFolder = $"CDP4ServicesDal{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Release";
#endif

            var frameworkVersion = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).Name;
            var testDirectory    = Path.Combine(Assembly.GetExecutingAssembly().Location, $"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}");
            testDirectory = Path.GetFullPath(Path.Combine(testDirectory, $"{this.BuildFolder}{Path.DirectorySeparatorChar}{frameworkVersion}"));

            this.assemblyLocationLoader = new Mock <IAssemblyInformationService>();
            this.assemblyLocationLoader.Setup(x => x.GetLocation()).Returns(testDirectory);

            this.serviceLocator = new Mock <IServiceLocator>();
            this.serviceLocator.Setup(s => s.GetInstance <IAssemblyInformationService>()).Returns(this.assemblyLocationLoader.Object);

            this.appSettingsService = new Mock <IAppSettingsService <ImeAppSettings> >();

            this.appSettings = JsonConvert.DeserializeObject <ImeAppSettings>(File.ReadAllText(Path.Combine(Assembly.GetExecutingAssembly().Location, $"..{Path.DirectorySeparatorChar}Modularity{Path.DirectorySeparatorChar}", AppSettingsJson)));
            this.appSettingsService.Setup(x => x.AppSettings).Returns(this.appSettings);

            this.serviceLocator.Setup(x => x.GetInstance <IAppSettingsService <ImeAppSettings> >())
            .Returns(this.appSettingsService.Object);

            Directory.SetCurrentDirectory(testDirectory);
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
        }