Пример #1
0
 public void Setup()
 {
     _config = ConfigMock.BuildConfig();
     _robotCache = Substitute.For<IRobotCache>();
     _robotMove = new RobotMove(_robotCache, _config);
     _testRobot = new Robot();
 }
Пример #2
0
        public void TestStructuredObjectValidation(string token, string env, string personId, string userName, string email, int expectedTotalFailedRules)
        {
            Validator <PersonMock, PersonMock.PersonValidationRule> personValidator =
                new Validator <PersonMock, PersonMock.PersonValidationRule>()
                .AddValidation(
                    PersonMock.PersonValidationRule.ValidIdRequired,
                    (person) => { return(!string.IsNullOrWhiteSpace(person.Id)); }
                    )
                .AddValidation(
                    PersonMock.PersonValidationRule.IdMaxLengthLimit,
                    (person) => { return(!(person.Id?.Length > 5)); }
                    )
                .AddValidation(
                    PersonMock.PersonValidationRule.UserNameMaxLengthLimit,
                    (person) => { return(!(person.UserName?.Length > 10)); }
                    )
                .AddValidation(
                    PersonMock.PersonValidationRule.EmailMaxLengthLimit,
                    (person) => { return(!(person.Email?.Length > 10)); }
                    )
            ;

            Validator <ConfigMock, ConfigMock.ConfigValidationRule> configValidator =
                new Validator <ConfigMock, ConfigMock.ConfigValidationRule>()
                .AddValidation(
                    ConfigMock.ConfigValidationRule.ValidIdRequired,
                    (config) => { return(!string.IsNullOrWhiteSpace(config.Id)); }
                    )
                .AddValidation(
                    ConfigMock.ConfigValidationRule.IdMaxLengthLimit,
                    (config) => { return(!(config.Id?.Length > 6)); }
                    )
                .AddValidation(
                    ConfigMock.ConfigValidationRule.EnvironmentMaxLengthLimit,
                    (config) => { return(!(config.Environment?.Length > 5)); }
                    )
                .AddValidation(
                    ConfigMock.ConfigValidationRule.UserRequired,
                    (config) => { return(config.User != null); }
                    )
                .AddValidation(ConfigMock.ConfigValidationRule.ValidUser,
                               (config) => config.User,
                               personValidator
                               )
            ;

            PersonMock userMock = new PersonMock()
            {
                Id = personId, UserName = userName, Email = email,
            };
            ConfigMock configMock = new ConfigMock()
            {
                Id = token, Environment = env, User = userMock,
            };
            var failedValidationRules = configValidator.Validate(configMock);

            Assert.AreEqual(expectedTotalFailedRules, failedValidationRules.Count);
        }
Пример #3
0
        public void Config_WithFileNameAndDirectory_ShouldGetAndLoadConfiguration()
        {
            ConfigMock config = new ConfigMock();

            Assert.IsTrue(config.FullLoadedFileName.Contains("appsettings.Development.json")); // Tests file
            Assert.IsTrue(config.FullLoadedFileName.Contains("/bin/Debug"));                   // Tests directory
            Assert.AreEqual(1, config.LoadConfigurationCalled);
            Assert.AreEqual(1, config.GetConfigurationFileCalled);
        }
Пример #4
0
        public void GetConfigurationFile_WithProperties_ShouldSetDefaults(string fileName, string directory,
                                                                          string expectedFileName, string expectedDir)
        {
            Config config = new ConfigMock();

            config.SetConfigurationFile(fileName, directory);

            Assert.IsTrue(config.FullLoadedFileName.Contains(expectedFileName));
            Assert.IsTrue(config.FullLoadedFileName.Contains(expectedDir));
        }
Пример #5
0
        public void GetVariable_Simple_String()
        {
            // ARRANGE
            DslConfigurationSection configurationSection = new DslConfigurationSection();
            configurationSection.AutoReload = true;
            configurationSection.BaseDirectory = Path.Combine(TestContext.DeploymentDirectory, "Boo");
            configurationSection.ThrowExceptions = true;

            var config = new ConfigMock(configurationSection);
            // ACT
            var myVar = config.GetVariable<string>("MyVar");
            // ASSERT
            myVar.ShouldEqual("Hallo Welt");
        }
Пример #6
0
        public void Model_FinishSetup_ParameterPassthrough__RandomValues()
        {
            var     expectedBoxUrl   = XeRandom.CreateString();
            var     expectedUsername = XeRandom.CreateString();
            var     expectedPassword = XeRandom.CreateString();
            IConfig configMock       = new ConfigMock();
            var     dependencies     = new ModelDependencies {
                Config = configMock
            };
            var target = new Model(dependencies);

            target.FinishSetup(expectedBoxUrl, expectedUsername, expectedPassword);

            Assert.AreEqual(expectedBoxUrl, configMock.BoxUrlAsString);
            Assert.AreEqual(expectedPassword, configMock.Password);
            Assert.AreEqual(expectedUsername, configMock.Username);
        }
        public void TestSaveConfig()
        {
            var provider = new ConfigProviderMock();
            var serializer = new ConfigSerializerMock();
            var config = new ConfigMock();
            var manager = new ConfigManager(provider, serializer);

            manager.Save(config);
            provider.WrittenConfigs.Should().ContainSingle("the manager should have tried to write the config");
            provider.WrittenConfigs[0].Key.Should().Be(config.GetType(), "the written config should be the same as the provided one one");
            serializer.Serialized.Should().ContainSingle("the manager should have tried to serialize the config");
            serializer.Serialized[0].Key.Should().Be(config.GetType(), "the serialized config type should be the same as the original");
            serializer.Serialized[0].Value.Should().BeSameAs(config, "the serialized config should be the same as the provided one");

            manager.Save(config);
            provider.WrittenConfigs.Should().ContainSingle("the manager should not have tried to re-write an unmodified config");
        }