本文整理汇总了C#中Mock.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.GetHashCode方法的具体用法?C# Mock.GetHashCode怎么用?C# Mock.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.GetHashCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDataset
private static Mock<IProxyDataset> CreateDataset(int index, IEnumerable<Mock<IProxyDataset>> children)
{
var proxy = new Mock<IProxyDataset>();
{
proxy.Setup(p => p.Name)
.Returns(index.ToString(CultureInfo.InvariantCulture));
proxy.Setup(p => p.Children())
.Returns(children.Select(c => c.Object));
proxy.Setup(p => p.Id)
.Returns(new DatasetId(index));
proxy.Setup(d => d.Equals(It.IsAny<IProxyDataset>()))
.Returns<IProxyDataset>(other => ReferenceEquals(other, proxy.Object));
proxy.Setup(d => d.Equals(It.IsAny<object>()))
.Returns<object>(other => ReferenceEquals(other, proxy.Object));
proxy.Setup(d => d.GetHashCode())
.Returns(proxy.GetHashCode());
}
return proxy;
}
示例2: CreateDynamicType
private static Type CreateDynamicType(DynamicType dynamicType)
{
Mock<Type> type = new Mock<Type>();
type.Setup(t => t.Name).Returns(dynamicType.TypeName);
type.Setup(t => t.Namespace).Returns("SampleNamespace");
type.Setup(t => t.FullName).Returns("SampleNamespace." + dynamicType.TypeName);
type
.Setup(t => t.GetProperties(It.IsAny<BindingFlags>()))
.Returns(dynamicType.Properties.Select(property => CreateProperty(property, type.Object)).Cast<PropertyInfo>().ToArray());
type.Setup(t => t.IsAssignableFrom(type.Object)).Returns(true);
type.Setup(t => t.GetHashCode()).Returns(type.GetHashCode());
type.Setup(t => t.Equals(It.IsAny<object>())).Returns((Type t) => Object.ReferenceEquals(type.Object, t));
return type.Object;
}
示例3: CreateProperty
private static PropertyInfo CreateProperty(DynamicProperty property, Type reflectedType)
{
Mock<PropertyInfo> pi = new Mock<PropertyInfo>();
pi.Setup(p => p.Name).Returns(property.Name);
if (property.Type is DynamicType)
{
property.Type = CreateDynamicType(property.Type as DynamicType);
}
pi.Setup(p => p.PropertyType).Returns(property.Type as Type);
pi.Setup(p => p.ReflectedType).Returns(reflectedType);
pi.Setup(p => p.DeclaringType).Returns(reflectedType);
pi.Setup(p => p.CanRead).Returns(true);
pi.Setup(p => p.CanWrite).Returns(true);
pi.Setup(p => p.GetGetMethod(It.IsAny<bool>())).Returns(typeof(Product).GetProperty("ID").GetGetMethod());
pi.Setup(p => p.GetCustomAttributes(It.IsAny<bool>())).Returns(property.Attributes);
pi.Setup(p => p.GetHashCode()).Returns(pi.GetHashCode());
pi.Setup(p => p.Equals(It.IsAny<object>())).Returns((PropertyInfo p) => Object.ReferenceEquals(pi.Object, p));
return pi.Object;
}
示例4: CreateMockDataset
private static IProxyDataset CreateMockDataset()
{
var dataset = new Mock<IProxyDataset>();
{
dataset.Setup(d => d.Equals(It.IsAny<IProxyDataset>()))
.Returns<IProxyDataset>(other => ReferenceEquals(other, dataset.Object));
dataset.Setup(d => d.Equals(It.IsAny<object>()))
.Returns<object>(other => ReferenceEquals(other, dataset.Object));
dataset.Setup(d => d.GetHashCode())
.Returns(dataset.GetHashCode());
}
return dataset.Object;
}