private void SaveSettings_CallsUpdateModuleSetting_WithRightParameters(string stringValue, int integerValue, double doubleValue,
                                                                               bool booleanValue, DateTime datetimeValue, TimeSpan timeSpanValue, TestingEnum enumValue, ComplexType complexValue)
        {
            //Arrange
            var moduleInfo = GetModuleInfo;
            var settings   = new ModulesSettings
            {
                StringProperty   = stringValue,
                IntegerProperty  = integerValue,
                DoubleProperty   = doubleValue,
                BooleanProperty  = booleanValue,
                DateTimeProperty = datetimeValue,
                TimeSpanProperty = timeSpanValue,
                EnumProperty     = enumValue,
                ComplexProperty  = complexValue,
            };

            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "StringProperty", stringValue));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "IntegerProperty", integerValue.ToString()));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "DoubleProperty", doubleValue.ToString(CultureInfo.InvariantCulture)));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "BooleanProperty", booleanValue.ToString()));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "DateTimeProperty", datetimeValue.ToString("o", CultureInfo.InvariantCulture)));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "TimeSpanProperty", timeSpanValue.ToString("c", CultureInfo.InvariantCulture)));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "EnumProperty", enumValue.ToString()));
            MockModuleController.Setup(mc => mc.UpdateModuleSetting(ModuleId, SettingNamePrefix + "ComplexProperty", $"{complexValue.X} | {complexValue.Y}"));

            var settingsRepository = new ModulesSettingsRepository();

            //Act
            settingsRepository.SaveSettings(moduleInfo, settings);

            //Assert
            MockRepository.VerifyAll();
        }
Exemple #2
0
        private static async Task WriteModuleSettings(string content, string fileName)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            string fullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName);

            ModuleSettings typedModule = JsonConvert.DeserializeObject <ModuleSettings>(content);

            ModulesSettings modulesSettings = null;

            if (File.Exists(fullPath))
            {
                modulesSettings = JsonConvert.DeserializeObject <ModulesSettings>(File.ReadAllText(fullPath));

                if (modulesSettings != null)
                {
                    if (modulesSettings.Modules == null)
                    {
                        modulesSettings.Modules = new List <ModuleSettings> {
                            typedModule
                        }
                    }
                    ;
                    else
                    {
                        ModuleSettings existingModule = modulesSettings.Modules.SingleOrDefault(i => i.ModuleId == typedModule.ModuleId);

                        if (existingModule != null)
                        {
                            existingModule.ConnectionString = typedModule.ConnectionString;
                        }
                        else
                        {
                            modulesSettings.Modules.Add(typedModule);
                        }
                    }
                }
            }
            else
            {
                modulesSettings = new ModulesSettings {
                    Modules = new List <ModuleSettings> {
                        typedModule
                    }
                }
            };

            string dataToSerialize = JsonConvert.SerializeObject(modulesSettings, Formatting.Indented);

            await File.WriteAllTextAsync(fullPath, dataToSerialize);
        }
    }
Exemple #3
0
        public static async Task WriteModulesSettings(ModulesSettings content, string environment)
        {
            string fileName = $"{MODULES_SETTINGS_FILE_NAME}.json";

            if (!string.IsNullOrEmpty(environment))
            {
                fileName = $"{MODULES_SETTINGS_FILE_NAME}.{environment}.json";
            }

            await WriteSettings(JsonConvert.SerializeObject(content, Formatting.Indented), fileName);
        }
Exemple #4
0
        public void ReturnSortedCollection_WhenThereAreTwoDifferentCriterias()
        {
            // Arrange
            var listOfItems = new List <UserTestingClass>
            {
                new UserTestingClass {
                    Age = 10, FirstName = "Eadgar"
                },
                new UserTestingClass {
                    Age = 33, FirstName = "Barny"
                },
                new UserTestingClass {
                    Age = 5, FirstName = "Danny"
                },
                new UserTestingClass {
                    Age = 5, FirstName = "Connie"
                },
                new UserTestingClass {
                    Age = 10, FirstName = "Angel"
                }
            };

            var modulesSettings = new ModulesSettings
            {
                Sorting =
                    new List <SortingObject>
                {
                    new SortingObject {
                        Prop = "Age", Direction = SortingDirection.Asc
                    },
                    new SortingObject {
                        Prop = "FirstName", Direction = SortingDirection.Desc
                    }
                }
            };

            var sortingModule = new SortingModule();

            // Act
            var sortedCollection = sortingModule.ApplyExpression(listOfItems, modulesSettings).ToList();

            // Assert
            Assert.IsTrue(sortedCollection.Any());
            Assert.AreEqual(5, sortedCollection.First().Age);
            Assert.AreEqual("Danny", sortedCollection.First().FirstName);

            Assert.AreEqual(10, sortedCollection[3].Age);
            Assert.AreEqual("Angel", sortedCollection[3].FirstName);

            Assert.AreEqual(33, sortedCollection.Last().Age);
            Assert.AreEqual("Barny", sortedCollection.Last().FirstName);
        }
        public void ReturnsNull_WhenPassingNullSortingObjec()
        {
            // Arrange
            var sortingModule   = new SortingModule();
            var requestJson     = new ComboRequestJson();
            var modulesSettings = new ModulesSettings();

            // Act
            IModulesSettings result = sortingModule.Initialize(requestJson, modulesSettings);

            // Assert
            Assert.IsNull(result.Sorting);
        }
        public void SaveSettings_UpdatesCache()
        {
            //Arrange
            var moduleInfo = GetModuleInfo;
            var settings   = new ModulesSettings();

            MockCache.Setup(c => c.Insert(CacheKey(moduleInfo), settings));
            var settingsRepository = new ModulesSettingsRepository();

            //Act
            settingsRepository.SaveSettings(moduleInfo, settings);

            //Assert
            MockRepository.VerifyAll();
        }
        public void DontSetPaginationObject_WhenPaginationObjectInRequestIsNull()
        {
            // Arrange
            IModule paginationModule = new PaginationModule();
            var     requestJson      = new ComboRequestJson()
            {
                Filters    = new List <FilterObject>(),
                Pagination = null
            };
            var settings = new ModulesSettings();

            // Act
            var result = paginationModule.Initialize(requestJson, settings);

            // Assert
            Assert.IsNull(result.Pagination);
        }
        public void ReturnNotNull_WhenPassingCorrectParameters()
        {
            // Arrange
            IModule paginationModule = new PaginationModule();
            var     requestJson      = new ComboRequestJson()
            {
                Filters    = new List <FilterObject>(),
                Pagination = new PaginationObject()
            };
            var settings = new ModulesSettings();

            // Act
            var result = paginationModule.Initialize(requestJson, settings);

            // Assert
            Assert.IsNotNull(result);
        }
Exemple #9
0
        public IModulesSettings GetModulesSettings(IComboRequestJson comboRequestJson, IModulesSettings modulesSettingsObj)
        {
            if (comboRequestJson == null)
            {
                throw new ArgumentNullException("comboRequestJson");
            }

            if (modulesSettingsObj == null)
            {
                modulesSettingsObj = new ModulesSettings();
            }

            foreach (var module in this.Modules.Values)
            {
                modulesSettingsObj = module.Initialize(comboRequestJson, modulesSettingsObj);
            }

            return(modulesSettingsObj);
        }
Exemple #10
0
        public void ReturnSortedCollection()
        {
            // Arrange
            var listOfItems = new List <UserTestingClass>
            {
                new UserTestingClass {
                    Age = 10
                },
                new UserTestingClass {
                    Age = 33
                },
                new UserTestingClass {
                    Age = 5
                },
                new UserTestingClass {
                    Age = 55
                },
                new UserTestingClass {
                    Age = 15
                }
            };
            var modulesSettings = new ModulesSettings
            {
                Sorting =
                    new List <SortingObject> {
                    new SortingObject {
                        Prop = "Age", Direction = SortingDirection.Asc
                    }
                }
            };
            var sortingModule = new SortingModule();

            // Act
            var sortedCollection = (IOrderedEnumerable <UserTestingClass>)sortingModule.ApplyExpression(listOfItems, modulesSettings);

            // Assert
            Assert.IsTrue(sortedCollection.Any());
            Assert.AreEqual(5, sortedCollection.First().Age);
            Assert.AreEqual(55, sortedCollection.Last().Age);
        }
        public void ReturnCorrectCollection_WhenPassingPaginationObject()
        {
            // Arrange
            IModule paginationModule = new PaginationModule();
            var     settings         = new ModulesSettings
            {
                Pagination = new PaginationObject
                {
                    Page     = 2,
                    PageSize = 2
                }
            };
            var collection = new List <Filter> {
                new Filter(), new Filter(), new Filter(), new Filter(), new Filter()
            };

            // Act
            var result = paginationModule.ApplyExpression(collection, settings);

            // Assert
            Assert.AreEqual(2, result.Count());
        }
Exemple #12
0
        public void SetSortingObjectCorrectly()
        {
            // Arrange
            var sortingModule   = new SortingModule();
            var requestJson     = new ComboRequestJson();
            var modulesSettings = new ModulesSettings();

            requestJson.Sorting = new List <SortingObject>
            {
                new SortingObject {
                    Direction = SortingDirection.Asc, Prop = "Test"
                }
            };

            // Act
            IModulesSettings result = sortingModule.Initialize(requestJson, modulesSettings);

            // Assert
            Assert.IsNotNull(result.Sorting);
            Assert.IsNotNull(result.Sorting[0]);
            Assert.AreEqual(result.Sorting[0].Direction, result.Sorting[0].Direction);
            Assert.AreEqual(result.Sorting[0].Prop, result.Sorting[0].Prop);
        }
        private static async Task ClearDeviceIdInModulesSettings(string environmentName)
        {
            //Get the device settings related Options
            string modulesSettingsFilePath = "modulessettings.json";

            if (!string.IsNullOrEmpty(environmentName))
            {
                modulesSettingsFilePath = $"modulessettings.{environmentName}.json";
            }

            if (!File.Exists(modulesSettingsFilePath))
            {
                throw new Exception("Modules settings path not found to clear the device id related data.");
            }

            string settingsData = File.ReadAllText(modulesSettingsFilePath);

            if (!string.IsNullOrEmpty(settingsData))
            {
                ModulesSettings modulesSettings = JsonConvert.DeserializeObject <ModulesSettings>(settingsData);

                if (modulesSettings != null && modulesSettings.Modules != null && modulesSettings.Modules.Count > 0)
                {
                    foreach (var item in modulesSettings.Modules)
                    {
                        item.DeviceId         = string.Empty;
                        item.ConnectionString = string.Empty;
                    }

                    Console.WriteLine($"Clearing modules settings configuration file.");
                    await ConfigurationHelpers.WriteModulesSettings(modulesSettings, environmentName);

                    Console.WriteLine($"Modules settings cleared.");
                }
            }
        }