示例#1
0
        public void ExecuteTest()
        {
            var fakeApplicationController = new FakeApplicationController();

            FileUtility.DeleteFiles(fakeApplicationController.SettingsPath);

            var testApplication = TestApplication.CreateTestApplication();

            testApplication.Controller.RegisterType <IDialogController, AutoDialogController>();
            testApplication.AddModule <TSettingsModule>();
            var module = testApplication.GetModule <TSettingsModule>();

            module.DialogCommand();
            var dialog = testApplication.GetNavigatedDialog <TDialog>();

            var settingsFiles = FileUtility.GetFiles(fakeApplicationController.SettingsPath);

            Assert.AreEqual(1, settingsFiles.Count());
            var settingsManager = new DesktopSettingsManager(fakeApplicationController);
            var settings        = settingsManager.Resolve <TClass>();

            Assert.IsNotNull(settings);

            module.DialogCommand();
            dialog = testApplication.GetNavigatedDialog <TDialog>();

            settingsFiles = FileUtility.GetFiles(fakeApplicationController.SettingsPath);
            Assert.AreEqual(1, settingsFiles.Count());
            settingsManager = new DesktopSettingsManager(fakeApplicationController);
            settings        = settingsManager.Resolve <TClass>();
            Assert.IsNotNull(settings);
        }
        public TSettingsObject Resolve <TSettingsObject>(Type settingsType = null) where TSettingsObject : new()
        {
            var type             = settingsType ?? typeof(TSettingsObject);
            var savedFileSetting = GetSavedSolutionFileSetting(type);

            if (savedFileSetting != null)
            {
                string readFileContents = null;

                var fileName = savedFileSetting.FileName;
                if (savedFileSetting.UsePersonalisedFile)
                {
                    readFileContents = VisualStudioService.GetVsixSettingText(savedFileSetting.PersonalisedFileName);
                }
                if (readFileContents == null)
                {
                    readFileContents = VisualStudioService.GetVsixSettingText(fileName);
                }

                if (string.IsNullOrEmpty(readFileContents))
                {
                    return(new TSettingsObject());
                }
                else
                {
                    if (type == typeof(XrmRecordConfiguration))
                    {
                        //this saved as a dictionary rather than object
                        //because the solution template test project
                        //needs to deserialise it to a new defined type
                        //with different namespaces
                        var dictionary = string.IsNullOrEmpty(readFileContents)
                            ? new Dictionary <string, string>()
                            : (Dictionary <string, string>)
                                         JsonHelper.JsonStringToObject(readFileContents, typeof(Dictionary <string, string>));

                        var xrmConfig = new TSettingsObject();
                        foreach (var prop in xrmConfig.GetType().GetReadWriteProperties())
                        {
                            if (dictionary.ContainsKey(prop.Name))
                            {
                                xrmConfig.SetPropertyByString(prop.Name, dictionary[prop.Name]);
                            }
                        }
                        return(xrmConfig);
                    }
                    else
                    {
                        return((TSettingsObject)JsonHelper.JsonStringToObject(readFileContents, type));
                    }
                }
            }
            else
            {
                return(DesktopSettingsManager.Resolve <TSettingsObject>(settingsType: settingsType));
            }
        }
示例#3
0
        public void DesktopSettingsManagerTest()
        {
            var fakeApplicationController = new FakeApplicationController();

            FileUtility.DeleteFiles(fakeApplicationController.SettingsPath);
            FileUtility.DeleteSubFolders(fakeApplicationController.SettingsPath);

            var settingsManager = new DesktopSettingsManager(fakeApplicationController);

            var resolveNotYetCreated = settingsManager.Resolve <TestResolveType>();

            Assert.IsNotNull(resolveNotYetCreated);
            Assert.AreEqual(0, resolveNotYetCreated.Int);

            resolveNotYetCreated.Int = 50;
            settingsManager.SaveSettingsObject(resolveNotYetCreated);

            var resolveAfterCreation = settingsManager.Resolve <TestResolveType>();

            Assert.AreEqual(resolveNotYetCreated.Int, resolveAfterCreation.Int);
        }
示例#4
0
        public TSettingsObject Resolve <TSettingsObject>(Type settingsType = null) where TSettingsObject : new()
        {
            var type = settingsType ?? typeof(TSettingsObject);

            if (SolutionSettingTypes.ContainsKey(type))
            {
                var fileName = MapTypeToFileName(settingsType ?? typeof(TSettingsObject));

                string read = fileName != null?VisualStudioService.GetSolutionItemText(fileName) : null;

                if (string.IsNullOrEmpty(read))
                {
                    return(new TSettingsObject());
                }
                else
                {
                    if (type == typeof(XrmRecordConfiguration))
                    {
                        //csan't recall why but this type is saved as a dictionary rather than just an object
                        //maybe due to interfaces
                        var dictionary = string.IsNullOrEmpty(read)
                            ? new Dictionary <string, string>()
                            : (Dictionary <string, string>)
                                         JsonHelper.JsonStringToObject(read, typeof(Dictionary <string, string>));

                        var xrmConfig = new TSettingsObject();
                        foreach (var prop in xrmConfig.GetType().GetReadWriteProperties())
                        {
                            if (dictionary.ContainsKey(prop.Name))
                            {
                                xrmConfig.SetPropertyByString(prop.Name, dictionary[prop.Name]);
                            }
                        }
                        return(xrmConfig);
                    }
                    else
                    {
                        return((TSettingsObject)JsonHelper.JsonStringToObject(read, type));
                    }
                }
            }
            else
            {
                return(DesktopSettingsManager.Resolve <TSettingsObject>(settingsType: settingsType));
            }
        }