Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message on data row mismatch #4996

Open
nohwnd opened this issue Feb 12, 2025 · 2 comments
Open

Improve error message on data row mismatch #4996

nohwnd opened this issue Feb 12, 2025 · 2 comments

Comments

@nohwnd
Copy link
Member

nohwnd commented Feb 12, 2025

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

@Youssef1313
Copy link
Member

Yes, the wording isn't ideal. I thought we had this reported before but can't find an existing issue.

@nohwnd
Copy link
Member Author

nohwnd commented Feb 12, 2025

I could not find it either (I used "indices" as the keyword), so it was probably just (or also) me complaining in a chat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants