Skip to content

Instantly share code, notes, and snippets.

@rofr
Created November 8, 2012 22:59
Show Gist options
  • Save rofr/4042429 to your computer and use it in GitHub Desktop.
Save rofr/4042429 to your computer and use it in GitHub Desktop.
protobuf-net failing test case
/*
protobuf-net failing test case. This has got to be a bug!
*/
[TestMethod]
public void IsDefined_on_empty_model_should_return_false()
{
var typeModel = RuntimeTypeModel.Create();
//See definition of FailingType below!
Assert.IsFalse(typeModel.IsDefined(typeof(FailingType)));
}
// The documentation for IsDefined "Indicates whether the supplied type is explicitly modelled by the model"
// In addition to returning the wrong answer, the type is added to the model
// IsDefined is a query, yet mutates the state of the RuntimeTypeModel instance. This is a violation of the CQS principle.
/// <summary>
/// Any class with public readonly fields and a public constructor
/// with parameters with matching and names!
/// </summary>
class FailingType
{
public readonly int MyField;
public readonly string MyField2;
public FailingType(int myField, string myField2)
{
MyField = myField;
MyField2 = myField2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment