示例#1
0
        public void LoadUserConfigurationTest()
        {
            // Arrange
            string configFilename = "myConfig.xml";

            // Act
            UserConfiguration usrConf2 = _repositoryMockObject.LoadUserConfiguration(configFilename);


            // Assert
            Assert.AreEqual(_usrConfiguration, usrConf2);
        }
        // Constructors ...................................
        public UserConfigService(string configFilename, IUserConfigRepository repository)
        {
            // The service will receive the repository using constructor injection
            // The repo must follow the IUserConfigRepository contract
            // If the value is null, then send back exception
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            // Assign repositor for local use
            _userConfigRepository = repository;

            // If configuration file is available, load it.
            // Otherewise start a new one
            if (File.Exists(configFilename))
            {
                userConfiguration = _userConfigRepository.LoadUserConfiguration(configFilename);
            }
            else
            {
                userConfiguration = new UserConfiguration(configFilename);
            }
        }
        /// <summary>
        /// Reterives using configuration from a file
        /// </summary>
        /// <param name="configFilename"></param>
        /// <returns>UserConfiguration</returns>
        public bool LoadUserConfiguration()
        {
            userConfiguration = _userConfigRepository.LoadUserConfiguration(userConfiguration.ConfigFilename);

            return(userConfiguration != null);
        }