testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Improve error message on data row mismatch

Open nohwnd opened this issue 11 months ago • 3 comments

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

nohwnd avatar Feb 12 '25 16:02 nohwnd

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

Youssef1313 avatar Feb 12 '25 18:02 Youssef1313

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

nohwnd avatar Feb 12 '25 19:02 nohwnd

Please copilot fix the analyzer message to have something easier to grasp.

Evangelink avatar Jun 18 '25 19:06 Evangelink