Пример #1
0
        public void SetUp()
        {
            var dependencies = ComTestHelper.ModifyAndBuildComDependencies();

            LoggingHelper.InitConsoleLogger("PDFCreatorTest", LoggingLevel.Off);

            var installationPathProvider = new InstallationPathProvider(@"Software\pdfforge\PDFCreator\Settings", @"Software\pdfforge\PDFCreator", "{00000000-0000-0000-0000-000000000000}");

            var settingsProvider = new DefaultSettingsProvider();

            var translationHelper = new TranslationHelper(settingsProvider, new AssemblyHelper(GetType().Assembly), new TranslationFactory(), null);

            translationHelper.InitTranslator("None");

            var settingsLoader = new SettingsLoader(translationHelper, Substitute.For <ISettingsMover>(), installationPathProvider, Substitute.For <IPrinterHelper>());

            var settingsManager = new SettingsManager(settingsProvider, settingsLoader, installationPathProvider, new VersionHelper(Assembly.GetExecutingAssembly()), new List <IFirstTimeCommand>());

            settingsManager.LoadAllSettings();

            var folderProvider = new FolderProvider(new PrinterPortReader(new RegistryWrap(), new PathWrapSafe()), new PathWrap());

            _queue = new Queue();
            _queue.Initialize();

            _testPageHelper = new TestPageHelper(new VersionHelper(GetType().Assembly), new OsHelper(), folderProvider,
                                                 dependencies.QueueAdapter.JobInfoQueue, new JobInfoManager(new LocalTitleReplacerProvider(new List <TitleReplacement>())), new ApplicationNameProvider("FREE"));
        }
Пример #2
0
        public void SetUp()
        {
            var builder      = new ComDependencyBuilder();
            var dependencies = builder.ComDependencies;

            LoggingHelper.InitConsoleLogger("PDFCreatorTest", LoggingLevel.Off);

            var installationPathProvider = new InstallationPathProvider(@"Software\pdfforge\PDFCreator\Settings", @"Software\pdfforge\PDFCreator", "{00000000-0000-0000-0000-000000000000}");

            var settingsProvider = new DefaultSettingsProvider();

            var translationHelper = new TranslationHelper(new TranslationProxy(), settingsProvider, new AssemblyHelper());

            translationHelper.InitTranslator("None");

            var settingsLoader = new SettingsLoader(translationHelper, Substitute.For <ISettingsMover>(), installationPathProvider, Substitute.For <ILanguageDetector>(), Substitute.For <IPrinterHelper>(), Substitute.For <ITranslator>());

            var settingsManager = new SettingsManager(settingsProvider, settingsLoader);

            settingsManager.LoadAllSettings();

            var folderProvider = new FolderProvider(new PrinterPortReader(new RegistryWrap(), new PathWrapSafe()), new PathWrap());

            _queue = new Queue();
            _queue.Initialize();

            _testPageHelper = new TestPageHelper(new AssemblyHelper(), new OsHelper(), folderProvider, dependencies.QueueAdapter.JobInfoQueue, new JobInfoManager(new LocalTitleReplacerProvider(new List <TitleReplacement>())));
        }
Пример #3
0
        public void TestSetup()
        {
            DefaultSettingsProvider.Reset();

            settingsFolder = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ClusterConfigClientDefaults.LocalFolder));

            EnsureDirectory();
        }
        public void GetValueWithExistingKeyAsString()
        {
            var sut = new DefaultSettingsProvider();

            var value = sut.GetValue<string>("test.string");

            Assert.AreEqual("hola", value);
        }
        public void GetValueWithExistingKeyAsInteger()
        {
            var sut = new DefaultSettingsProvider();

            var value = sut.GetValue<int>("test.int");

            Assert.AreEqual(1, value);
        }
        public void GetValueWithExistingKeyAsDouble()
        {
            var sut = new DefaultSettingsProvider();

            var value = sut.GetValue<double>("test.double");

            Assert.AreEqual(1.1, value);
        }
Пример #7
0
 /// <summary>
 /// Gets a default <see cref="SettingsDictionary"/> instance which is used if none are registered with the
 /// Dependency Engine.
 /// </summary>
 public static SettingsDictionary GetSettings()
 {
     if (_settings == null)
     {
         DefaultSettingsProvider settingsProvider = new DefaultSettingsProvider();
         SettingsDictionary      instance         = settingsProvider.GetSettings();
         Interlocked.CompareExchange(ref _settings, instance, null);
     }
     return(_settings);
 }
        public void GetValueWithExistingKeyAsDateYYYYMMDD()
        {
            var sut = new DefaultSettingsProvider();

            var value = sut.GetValue<DateTime>("test.date.YYYYMMDD");

            Assert.AreEqual(2013, value.Year);
            Assert.AreEqual(2, value.Month);
            Assert.AreEqual(28, value.Day);
        }
Пример #9
0
            public void Binary_Serialiser_Can_Be_Constructed_Using_its_Constructor()
            {
                //Arrange

                //Act
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings);

                //Assert
                Assert.That(serialiser, Is.Not.Null);
            }
Пример #10
0
 public void TestMethod1()
 {
     var setting = new DefaultSettingsProvider();
     var ser     = new NSJsonSerializer(setting);
     var o       = ser.Serialize(new Test {
         Id = 1, Name = "Test"
     });
     //var o = ser.Serialize(new { Id = 1, Name = "Test" });
     var sererialised = ser.Deserialize <object>(o);
     var t            = sererialised.GetType();
 }
Пример #11
0
        public void XmlSettingsInterpreterTests_ReadXdoc()
        {
            // arrange
            string test = string.Empty;

            /*
             * ResourceManager resourceManager = new ResourceManager(
             *  "RevitDKTools.Properties.Resources",
             *  Assembly.GetExecutingAssembly());
             *
             * Assert.Fail(Path.GetDirectoryName(
             *  Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\",string.Empty) +
             *        resourceManager.GetString("VISIBILITY_SWITCHER_XML_LOCATION"));
             */

            DefaultSettingsProvider defaultSettingsProvider = new DefaultSettingsProvider();
            XmlVisibilitySwitcherSettingsProvider switcherSettingsProvider =
                new XmlVisibilitySwitcherSettingsProvider();
            XmlSettingsInterpreter interpreter =
                new XmlSettingsInterpreter(defaultSettingsProvider, switcherSettingsProvider);

            // act

            /*
             * XDocument xdoc = switcherSettingsProvider.XDoc;
             * IEnumerable<VisibilitySwitcherCommandSetting> sth = xdoc.Root.Elements()
             *  .Where(e => e.Name.LocalName == "VisibilitySwitcher")
             *  .Where(e => e.Attribute(XName.Get("CommandName")) != null)
             *  .Where(e => e.Attribute(XName.Get("VisibilityNameRegex")) != null)
             *  .Select(e =>
             *  {
             *      var v = new VisibilitySwitcherCommandSetting();
             *      v.CommandName = e.Attribute(XName.Get("CommandName")).Value;
             *      v.VisibilityNameRegex = e.Attribute(XName.Get("VisibilityNameRegex")).Value;
             *      return v;
             *  });
             *
             * foreach (var e in sth)
             * {
             *  test = test + "commandName = " + e.CommandName + " | " + " regex = " +
             *      e.VisibilityNameRegex + "\r\n";
             * }
             */

            foreach (var e in interpreter.VisibilitySwitcherCommandSettings)
            {
                test = test + "commandName = " + e.CommandName + " | " + " regex = " +
                       e.VisibilityNameRegex + "\r\n";
            }

            // assert
            Assert.Fail(test);
        }
Пример #12
0
            public async Task Providing_Null_Will_Result_In_null()
            {
                //Arrange
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;

                //Act
                var result = await serialiser.Serialise(null);

                //Assert
                Assert.IsNotNull(result);
            }
Пример #13
0
            public async Task Objects_Containing_More_Complex_Types_Can_Be_Serialised()
            {
                //Arrange
                var obj        = new ComplexTypeSerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;

                //Act
                var result = await serialiser.Serialise(obj);

                //Assert
                Assert.That(result, Is.Not.Null);
            }
Пример #14
0
            public async Task Successful_Serialisation_Will_Return_A_Stream_Of_The_Serialised_Object()
            {
                //Arrange
                var obj        = new SerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;

                //Act
                var result = await serialiser.Serialise(obj);

                //Assert
                Assert.That(result, Is.Not.Null);
            }
Пример #15
0
        public void TestDefaultSettingsProvider()
        {
            var key      = SettingsKeys.DeploymentBranch;
            var value    = "master";
            var keyValue = new KeyValuePair <string, string>(key, value);

            var defaultSettingsProvider = new DefaultSettingsProvider();

            Assert.Equal(value, defaultSettingsProvider.GetValue(key));

            var results = defaultSettingsProvider.GetValues();

            Assert.Contains(keyValue, results);
        }
Пример #16
0
            public async Task DeserialisingToJsonObject()
            {
                //Arrange
                var obj        = new SerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings);
                var serialised = await serialiser.SerialiseToJson(obj);

                //Act
                var result = await serialiser.DeserialiseFromJson(serialised);

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result, Is.TypeOf <JObject>());
            }
Пример #17
0
            public async Task Successful_Deserialisation_Will_Return_An_Object_Of_Type_Specified()
            {
                //Arrange
                var obj        = new SerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings);
                var serialised = await serialiser.SerialiseToJson(obj);

                //Act
                var result = await serialiser.DeserialiseFromJson <SerialisableObject>(serialised);

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result, Is.TypeOf <SerialisableObject>());
            }
Пример #18
0
            public void Providing_Null_Will_Result_In_An_Argument_Null_Exception()
            {
                //Arrange
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;

                //Act
                async Task Delegate()
                {
                    await serialiser.Deserialise(null);
                }

                //Assert
                Assert.That(Delegate, Throws.ArgumentNullException);
            }
Пример #19
0
            public async Task Providing_A_Base_Class_Will_Cast_The_Return_The_Object_Cast_To_The_Base_Class()
            {
                //Arrange
                var obj        = new SerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;
                var stream     = await serialiser.Serialise(obj);

                stream.Position = 0;

                //Act
                var result = await serialiser.Deserialise <SerialisableObject>(stream);

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result, Is.TypeOf <SerialisableObject>());
            }
Пример #20
0
            public async Task An_Object_That_Exists_In_Two_Different_Namespaces_Can_Be_Deserialised_To_The_Correct_Type()
            {
                //Arrange
                var obj        = new NameSpaceSerialisationObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;
                var stream     = await serialiser.Serialise(obj);

                stream.Position = 0;

                //Act
                var result = await serialiser.Deserialise <NameSpaceSerialisationObject>(stream);

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result, Is.TypeOf <NameSpaceSerialisationObject>());
            }
Пример #21
0
        public void TestMethod2()
        {
            var setting = new DefaultSettingsProvider();
            var ser     = new NSJsonSerializer(setting);
            var o       = new Test {
                Id = 1, Name = "Test"
            };

            byte[] serialsed = null;
            using (var ms = new MemoryStream())
            {
                ((ISerializer)ser).Serialize(ms, new object[] { o });
                serialsed   = ms.ToArray();
                ms.Position = 0;
                var r = ((ISerializer)ser).Deserialize(ms, null).First();
            }
        }
Пример #22
0
            public async Task Successful_Deserialisation_Will_Return_An_Object()
            {
                //Arrange
                var obj        = new SerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;
                var stream     = await serialiser.Serialise(obj);

                stream.Position = 0;

                //Act
                var result = await serialiser.Deserialise <SerialisableObject>(stream);

                //Assert
                Assert.That(result.Number, Is.EqualTo(obj.Number));
                Assert.That(result.Words, Is.EqualTo(obj.Words));
                Assert.That(result, Is.TypeOf <SerialisableObject>());
            }
Пример #23
0
        public void SetUp()
        {
            var dependencies = ComTestHelper.ModifyAndBuildComDependencies();

            LoggingHelper.InitConsoleLogger("PDFCreatorTest", LoggingLevel.Off);

            var installationPathProvider = new InstallationPathProvider(@"Software\pdfforge\PDFCreator\Settings", @"Software\pdfforge\PDFCreator", "{00000000-0000-0000-0000-000000000000}", RegistryHive.CurrentUser);

            var settingsProvider = new DefaultSettingsProvider();

            var translationHelper = new TranslationHelper(settingsProvider, new AssemblyHelper(GetType().Assembly), new TranslationFactory(), null);

            translationHelper.InitTranslator("None");

            var defaultSettingsBuilder = Substitute.For <IDefaultSettingsBuilder>();

            defaultSettingsBuilder.
            CreateEmptySettings().
            Returns(new PdfCreatorSettings());

            defaultSettingsBuilder.
            CreateDefaultSettings(Arg.Any <string>(), Arg.Any <string>()).
            Returns(new PdfCreatorSettings());

            defaultSettingsBuilder.
            CreateDefaultProfile().
            Returns(new ConversionProfile());

            var migrationStorageFactory = Substitute.For <IMigrationStorageFactory>();
            var settingsLoader          = new SettingsLoader(translationHelper, Substitute.For <ISettingsMover>(), installationPathProvider, Substitute.For <IPrinterHelper>(), new EditionHelper(false, false), defaultSettingsBuilder, migrationStorageFactory);

            var settingsManager = new SettingsManager(settingsProvider, settingsLoader, installationPathProvider, new VersionHelper(Assembly.GetExecutingAssembly()), new List <IFirstTimeCommand>());

            settingsManager.LoadAllSettings();

            var folderProvider = new FolderProvider(new PrinterPortReader(new RegistryWrap()), new PathWrap());

            _queue = new Queue();
            _queue.Initialize();

            var testPageCreator = new TestPageCreator(new ApplicationNameProvider("FREE"), new VersionHelper(new Version(1, 0, 0, 0)), new OsHelper());

            _testPageHelper = new TestPageHelper(folderProvider, dependencies.QueueAdapter.JobInfoQueue, new JobInfoManager(new LocalTitleReplacerProvider(new List <TitleReplacement>()), null), testPageCreator);
        }
Пример #24
0
            public async Task Object_Containing_More_Complex_Types_Can_Be_Deserialised()
            {
                //Arrange
                var obj        = new ComplexTypeSerialisableObject();
                var settings   = new DefaultSettingsProvider();
                var serialiser = new NSJsonSerializer(settings) as ISerialiser;
                var stream     = await serialiser.Serialise(obj);

                stream.Position = 0;

                //Act
                var result = (ComplexTypeSerialisableObject)await serialiser.Deserialise <ComplexTypeSerialisableObject>(stream);

                //Assert
                Assert.That(result.Exception.Message, Is.EqualTo(obj.Exception.Message));
                Assert.That(result.Dictionary, Is.EqualTo(obj.Dictionary));
                Assert.That(result.Enumerable, Is.EqualTo(obj.Enumerable));
                Assert.That(result.List, Is.EqualTo(obj.List));
                Assert.That(result, Is.TypeOf <ComplexTypeSerialisableObject>());
            }
Пример #25
0
        public void SetUp()
        {
            _translationTestHelper = new TranslationTestHelper();

            var a      = Assembly.GetExecutingAssembly();
            var appDir = Path.GetDirectoryName(a.CodeBase.Replace(@"file:///", ""));

            if (appDir == null)
            {
                throw new InvalidDataException("The app dir may never be null");
            }

            _languagePath = _translationTestHelper.FindTranslationFolder();

            Assert.True(Directory.Exists(_languagePath), "Could not find language path: " + _languagePath);

            var languageLoader = new LanguageLoader(_languagePath);

            _translations = languageLoader.GetAvailableLanguages().ToList();

            _settings = new PdfCreatorSettings(new IniStorage());
            _settings.LoadData("settings.ini");

            var assemblyHelper = Substitute.For <IAssemblyHelper>();

            assemblyHelper.GetPdfforgeAssemblyDirectory().Returns(Path.Combine(_languagePath, ".."));

            LoggingHelper.InitConsoleLogger("PDFCreator-TranslationTest", LoggingLevel.Error);
            var settingsProvider = new DefaultSettingsProvider();

            settingsProvider.UpdateSettings(_settings);

            _translationProxy = new MappedTranslationProxy(new TranslationProxy(), _languagePath + "\\_sectionMappings.txt");

            _translationHelper = new TranslationHelper(_translationProxy, settingsProvider, assemblyHelper);
            _translationHelper.InitTranslator(_settings.ApplicationSettings.Language);

            // TODO extact stuff into separate classes, so this test only contains the actual test code
        }
        public void GetValueWithNotExistingKeyThrows()
        {
            var sut = new DefaultSettingsProvider();

            sut.GetValue<string>("MustThrow");
        }
Пример #27
0
        public void TearDown()
        {
            DefaultSettingsProvider.Reset();

            RemoveDirectory();
        }
        public void GetValueWithNullKeyThrows()
        {
            var sut = new DefaultSettingsProvider();

            sut.GetValue<string>(null);
        }