Beispiel #1
0
        public void VerifyThatUriConfigFileHandlerWorks()
        {
            var configurator = new UriConfigFileHandler();

            // Open file that does not exist
            Assert.IsFalse(File.Exists(configurator.ConfigurationFilePath));
            Assert.IsEmpty(configurator.Read());

            // Try to write null
            Assert.Throws <ArgumentNullException>(() => configurator.Write(null));

            // Write row the same as the testing one
            var rows = new List <UriConfig>
            {
                new UriConfig
                {
                    Alias   = "Alias0",
                    Uri     = "Uri0",
                    DalType = "Web"
                }
            };

            configurator.Write(rows);

            // Normalize line endings, because JSON.Net serialization is a bit inconsistent on handling indentation and line endings on different platforms
            var testFileContent   = File.ReadAllText(this.testfile.FullName).Replace("\r\n", "\n");
            var configFileContent = File.ReadAllText(configurator.ConfigurationFilePath).Replace("\r\n", "\n");

            // Ensure the generated file is the same as the testing one
            Assert.AreEqual(testFileContent.Length, configFileContent.Length,
                            $"test file content:\n{testFileContent}\n, config file content:\n{configFileContent}\n");

            Assert.AreEqual(testFileContent, configFileContent,
                            $"test file content:\n{testFileContent}\n, config file content:\n{configFileContent}\n");
        }
Beispiel #2
0
        /// <summary>
        /// Method to write into a file the JSON configuration
        /// </summary>
        private void ExecuteApply()
        {
            var writer = new UriConfigFileHandler();

            writer.Write(this.UriRowList.Select(row => row.UriConfig).ToList());
            this.ExecuteClose();
        }
Beispiel #3
0
        /// <summary>
        /// Reloads all saved sources from the uri config file.
        /// </summary>
        private void RefreshSavedSources()
        {
            this.AllDefinedUris = new ReactiveList <UriRowViewModel>();

            var configHandler = new UriConfigFileHandler();
            var uriList       = configHandler.Read();

            foreach (var uri in uriList)
            {
                var row = new UriRowViewModel {
                    UriConfig = uri
                };
                this.AllDefinedUris.Add(row);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Clears and populates the <see cref="UriRowList"/>
        /// </summary>
        private void RePopulateUriRows()
        {
            this.UriRowList.Clear();

            var configHandler = new UriConfigFileHandler();
            var uriList       = configHandler.Read();

            foreach (var uri in uriList)
            {
                var row = new UriRowViewModel {
                    UriConfig = uri
                };
                this.UriRowList.Add(row);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Resets all the properties and populates the <see cref="AvailableDataSourceKinds"/> List
        /// and sets the <see cref="SelectedDataSourceKind"/> to the first in the <see cref="AvailableDataSourceKinds"/>
        /// </summary>
        private void ResetProperties()
        {
            this.AvailableDataSourceKinds = new ReactiveList <IDalMetaData>();

            this.AllDefinedUris = new ReactiveList <UriRowViewModel>();

            this.ShowBrowseButton = false;

            this.ErrorMessage = string.Empty;

            var dalAvailable = ServiceLocator.Current.GetInstance <AvailableDals>();

            this.dals = dalAvailable.DataAccessLayerKinds;

            foreach (var dal in this.dals)
            {
                this.AvailableDataSourceKinds.Add(dal.Metadata);
            }

            var configHandler = new UriConfigFileHandler();
            var uriList       = configHandler.Read();

            foreach (var uri in uriList)
            {
                var row = new UriRowViewModel {
                    UriConfig = uri
                };
                this.AllDefinedUris.Add(row);
            }

#if DEBUG
            this.UserName = "******";
            this.Password = "******";
            var debugUri = new UriRowViewModel {
                Uri = "http://localhost:1234", DalType = DalType.Web
            };
            this.AllDefinedUris.Add(debugUri);
#else
            this.UserName = string.Empty;
            this.Password = string.Empty;
            this.Uri      = string.Empty;
#endif
            this.IsProxyEnabled = false;
            this.ProxyUri       = string.Empty;
            this.ProxyPort      = string.Empty;

            this.SelectedDataSourceKind = this.AvailableDataSourceKinds.FirstOrDefault(v => v.DalType == DalType.Web);
        }
Beispiel #6
0
        public void VerifyThatUriConfigFileHandlerWorks()
        {
            var configurator = new UriConfigFileHandler();

            // Open file that does not exist
            Assert.IsFalse(File.Exists(configurator.ConfigurationFilePath));
            Assert.IsEmpty(configurator.Read());

            // Try to write null
            Assert.Throws <ArgumentNullException>(() => configurator.Write(null));

            // Write row the same as the testing one
            List <UriConfig> rows = new List <UriConfig>();

            rows.Add(new UriConfig()
            {
                Alias = "Alias0", Uri = "Uri0", DalType = "Web"
            });
            configurator.Write(rows);

            // Ensure the generated file is the same as the testing one
            Assert.IsTrue(File.ReadAllText(this.testfile.FullName).GetHashCode() ==
                          File.ReadAllText(configurator.ConfigurationFilePath).GetHashCode());
        }