Skip to content

Improve error message on data row mismatch #4996

@nohwnd

Description

@nohwnd

Summary

datarow mismatch tells me that some indices have mismatches in data. This message is precise, but not very clear (to me).

Background and Motivation

Image

        [TestMethod]
        [DataRow("Luxury Car", "Alice Johnson", 1500, "https://example.com/luxurycar.jpg", "https://example.com/luxurycar")]
        [DataRow("Luxury Car", "Alice Johnson", 1500.00, "https://example.com/luxurycar.jpg", "https://example.com/luxurycar")]
        [DataRow("Diamond Ring", "Bob Brown", 2000.00, "https://example.com/diamondring.jpg", "https://example.com/diamondring")]
        public void AddGift_ShouldRejectExpensiveGifts(string name, string reservedBy, decimal price, string imageUrl, string link)
        {
            // Arrange
            var gift = new Gift(name, reservedBy, price, imageUrl, link);

            // Act & Assert
            Assert.ThrowsException<ArgumentException>(() => Program.AddGift(gift), "Gift price cannot exceed $1,000.");
        }

The warning is very precise, and probably wants to show me that there is error in the second parameter in the attribute, and also in the second parameter in the signature, but to me it reads as (x,y) coordinates and the error is not obvious to me, especially since double and decimal are both numbers.

Proposed Feature

Reword the warning to say: DataRow argument types do not match method parameter types. Parameter price expects decimal type, but the provided value has type double. (and the same for other mismatches... Parameter imageUrl expects string, but the provided value has type int.)

Alternative Designs

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions