Sto tentando di affermare l'uguaglianza di due strutture System.Drawing.Size
e sto ricevendo un'eccezione di formato anziché l'errore di asserzione previsto.Perché questa affermazione genera un'eccezione di formato quando si confrontano le strutture?
[TestMethod]
public void AssertStructs()
{
var struct1 = new Size(0, 0);
var struct2 = new Size(1, 1);
//This throws a format exception, "System.FormatException: Input string was not in a correct format."
Assert.AreEqual(struct1, struct2, "Failed. Expected {0}, actually it is {1}", struct1, struct2);
//This assert fails properly, "Failed. Expected {Width=0, Height=0}, actually it is {Width=1, Height=1}".
Assert.AreEqual(struct1, struct2, "Failed. Expected " + struct1 + ", actually it is " + struct2);
}
È questo comportamento previsto? Sto facendo qualcosa di sbagliato qui?
hai provato ad avere 'Assert.AreEqual (struct1, struct2, string.Format (" Failed expected {0} in realtà è {1} ', struct1.ToString(), struct2.ToString()))'? – DiskJunky
Che funziona bene, tuttavia sono curioso di sapere perché Assert.AreEqual() non è in grado di formattare una stringa con tipi di struttura. – Kyle
@Kyle Per curiosità, questo non è con la versione compatibile Silverlight del framework Unit Testing, è ? Posso riprodurlo con quelle DLL (non ho ancora provato la versione completa di .NET framework) EDIT: non importa, testato anche con quelle complete e ancora fallito :) –