/// <summary>
        /// If the given munger returns the same value for all the given
        /// songs, then return that value. Otherwise, return an empty string.
        /// </summary>
        /// <param name="songs">The list of songs to be considered</param>
        /// <param name="munger">The munger which will extract the value</param>
        /// <returns>The common value or an empty string</returns>
        private string GetCommonValue(IList <Song> songs, Munger munger)
        {
            if (songs.Count == 0 || songs.Count > 1000)
            {
                return("");
            }

            string value = (string)munger.GetValue(songs[0]);

            for (int i = 1; i < songs.Count; i++)
            {
                if (value != (string)munger.GetValue(songs[i]))
                {
                    return("");
                }
            }

            return(value);
        }
        public void Test_GetValue_DottedAspect_NullMidResult() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            Munger munger = new Munger("This.NullProperty.ToUpperInvariant");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.IsNull(value);
        }
Exemple #3
0
        public void Test_GetValue_DottedAspect_NullMidResult()
        {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            Munger        munger   = new Munger("This.NullProperty.ToUpperInvariant");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.IsNull(value);
        }
        public void Test_GetValue_VirtualProperty_CalledOnBaseClass() {
            // Arrange
            TestBaseClass instance = new TestSubClass();
            string testValue = "some test value";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("VirtualTestProperty");

            // Act
            string value = munger.GetValue(instance) as string;

            // Assert
            Assert.AreEqual(testValue, value);
        }
        public void Test_GetValue_DottedAspect_Success() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            string testValue = "1234567890";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.ToUpperInvariant.Length");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.AreEqual(testValue.Length, value);
        }
        public void Test_GetValue_DottedAspect_UnknownAspect() {
            // Arrange
            TestBaseClass instance = new TestBaseClass();
            string testValue = "1234567890";
            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.UnknownProperty.Length");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            string errorMsg = "'UnknownProperty' is not a parameter-less method, property or field of type 'System.String'";
            Assert.AreEqual(errorMsg, value);
        }
Exemple #7
0
        public void Test_GetValue_NonVirtualProperty_CalledOnSubClass()
        {
            // Arrange
            TestSubClass instance  = new TestSubClass();
            string       testValue = "some test value";

            instance.NonVirtualTestProperty = testValue;
            Munger munger = new Munger("NonVirtualTestProperty");

            // Act
            string value = munger.GetValue(instance) as string;

            // Assert
            Assert.AreEqual(testValue, value);
        }
Exemple #8
0
        public void Test_GetValue_VirtualPropertyOnBaseClass()
        {
            // Arrange
            TestBaseClass instance  = new TestBaseClass();
            string        testValue = "some test value";

            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("VirtualTestProperty");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.AreEqual(testValue, value);
        }
Exemple #9
0
        public void Test_GetValue_DottedAspect_Success()
        {
            // Arrange
            TestBaseClass instance  = new TestBaseClass();
            string        testValue = "1234567890";

            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.ToUpperInvariant.Length");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            Assert.AreEqual(testValue.Length, value);
        }
Exemple #10
0
        public void Test_GetValue_DottedAspect_UnknownAspect()
        {
            // Arrange
            TestBaseClass instance  = new TestBaseClass();
            string        testValue = "1234567890";

            instance.VirtualTestProperty = testValue;
            Munger munger = new Munger("This.VirtualTestProperty.UnknownProperty.Length");

            // Act
            object value = munger.GetValue(instance);

            // Assert
            string errorMsg = "'UnknownProperty' is not a parameter-less method, property or field of type 'System.String'";

            Assert.AreEqual(errorMsg, value);
        }