所以我有一组对象.确切的类型并不重要.从中我想提取一对特定属性的所有唯一对,因此:
myObjectCollection.Select(item=>new
{
Alpha = item.propOne,
Bravo = item.propTwo
}
).Distinct();
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:在这种情况下会不会使用默认对象equals(这对我来说没用,因为每个对象都是新的)或者可以告诉它做一个不同的equals(在这种情况下,Alpha和Bravo的值相等) =>相等的实例)?有没有办法实现这个结果,如果不这样做的话?
我有以下测试,有支持类,但我无法弄清楚如何验证对依赖项的调用.
[TestFixture]
public class AnonymousGenericTypeParameterTests
{
[Test]
public void Test()
{
// Arrange
var dependency = new Mock<IDependency>();
var towns = new List<Town>
{
new Town { Name = "Lifford", County = "Donegal", Country="Ireland", Population = 1658 },
new Town { Name = "Ballyshannon", County = "Donegal", Country="Ireland", Population = 2504 },
new Town { Name = "Buxton", County = "Derbyshire", Country="United Kingdom", Population = 13599 },
};
var sut = new MyClass(dependency.Object);
// Act
sut.DoSomething(towns);
// Assert
// The …Run Code Online (Sandbox Code Playgroud)