コード例 #1
0
        public void CanReplaceAMethodMapping()
        {
            // Arrange
            IInterfaceMap target = CreateIInterfaceMap();

            IMethodMapping mapping = CreateIMethodMapping();

            mapping.Name = "test";
            mapping.GenericArgumentTypes = new Type[] { typeof(string), typeof(object) };
            mapping.ArgumentTypes        = new Type[] { typeof(bool) };
            mapping.Subject = (arg, args) =>
            {
                Console.Out.WriteLine("Subject called");
                return(true);
            };
            IMethodMapping replacement = CreateIMethodMapping();

            replacement.Name = "test";
            replacement.GenericArgumentTypes = new Type[] { typeof(string), typeof(object) };
            replacement.ArgumentTypes        = new Type[] { typeof(bool) };
            replacement.Subject = (arg, args) =>
            {
                Console.Out.WriteLine("Subject replacement called");
                return(true);
            };

            // Act
            target.Add(mapping, false);
            target.Add(replacement, true);

            // Assert
            Verify.That(target.AsEnumerable()).DoesContain(replacement, "Should contain the replacement")
            .Now();
            Verify.That(target.AsEnumerable()).DoesNotContain(mapping, "Should not contain the original mapping")
            .Now();
        }
コード例 #2
0
        public void CanAddWithReplaceSetToFalse()
        {
            // Arrange
            IInterfaceMap  target  = CreateIInterfaceMap();
            IMethodMapping mapping = CreateIMethodMapping();

            mapping.Name = "test";
            mapping.GenericArgumentTypes = new Type[] { typeof(string), typeof(object) };
            mapping.ArgumentTypes        = new Type[] { typeof(bool) };
            mapping.Subject = (arg, args) =>
            {
                Console.Out.WriteLine("Subject called");
                return(true);
            };
            bool replace = false;

            // Act
            target.Add(mapping, replace);

            // Assert
            Verify.That(target.AsEnumerable()).DoesContain(mapping)
            .Now();
        }