public void TryGetTypeNameReplacementWhenReplacementDoesNotExists()
        {
            var microdotSerializationSecurityConfig = new MicrodotSerializationSecurityConfig {
                AssemblyNamesRegexReplacements =
                    new List <MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement>(new []
                {
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("mobar", "buz")
                })
            };

            var serializationConstraints =
                new MicrodotSerializationConstraints(
                    () =>
            {
                return(microdotSerializationSecurityConfig);
            });

            var result = serializationConstraints.TryGetAssemblyNameAndTypeReplacement("bar", "foobar");

            Assert.AreEqual("bar", result.AssemblyName);
            Assert.AreEqual("foobar", result.TypeName);

            result = serializationConstraints.TryGetAssemblyAndTypeNameReplacementFromType(
                typeof(string), "bar", "foobar");

            Assert.AreEqual("bar", result.AssemblyName);
            Assert.AreEqual("foobar", result.TypeName);
        }
        public void TryGetAssemblyNameAndTypeNameReplacementWhenReplacementExistsForFirstResult()
        {
            var microdotSerializationSecurityConfig = new MicrodotSerializationSecurityConfig {
                AssemblyNamesRegexReplacements =
                    new List <MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement>(new []
                {
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("foobar", "buz"),
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("foobar", "bull"),
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("carmel", "gilboa"),
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("carmel", "megido"),
                })
            };

            var serializationConstraints =
                new MicrodotSerializationConstraints(
                    () =>
            {
                return(microdotSerializationSecurityConfig);
            });

            var result = serializationConstraints.TryGetAssemblyNameAndTypeReplacement("carmel", "foobar");

            Assert.AreEqual("gilboa", result.AssemblyName);
            Assert.AreEqual("buz", result.TypeName);

            result = serializationConstraints.TryGetAssemblyAndTypeNameReplacementFromType(
                typeof(string), "carmel", "foobar");

            Assert.AreEqual("gilboa", result.AssemblyName);
            Assert.AreEqual("buz", result.TypeName);
        }
        public void ShouldClearTypeCacheOnConfigChange()
        {
            var microdotSerializationSecurityConfig = new MicrodotSerializationSecurityConfig {
                AssemblyNamesRegexReplacements =
                    new List <MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement>(new []
                {
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("foobar", "buz")
                })
            };

            var serializationConstraints =
                new MicrodotSerializationConstraints(
                    () =>
            {
                return(microdotSerializationSecurityConfig);
            });

            var result = serializationConstraints.TryGetAssemblyAndTypeNameReplacementFromType(
                typeof(string),
                "bar",
                "foobar");

            Assert.AreEqual("bar", result.AssemblyName);
            Assert.AreEqual("buz", result.TypeName);

            microdotSerializationSecurityConfig = new MicrodotSerializationSecurityConfig {
                AssemblyNamesRegexReplacements =
                    new List <MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement>(new []
                {
                    new MicrodotSerializationSecurityConfig.AssemblyNameToRegexReplacement("foobar", "ding")
                })
            };

            result = serializationConstraints.TryGetAssemblyAndTypeNameReplacementFromType(
                typeof(string),
                "bar",
                "foobar");

            Assert.AreEqual("bar", result.AssemblyName);
            Assert.AreEqual("ding", result.TypeName);
        }