本文整理汇总了C#中TestEntity.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# TestEntity.Equals方法的具体用法?C# TestEntity.Equals怎么用?C# TestEntity.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestEntity
的用法示例。
在下文中一共展示了TestEntity.Equals方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EqualsWithNewObjectsUsesReferenceEquals
public void EqualsWithNewObjectsUsesReferenceEquals()
{
// Arrange
var ent1 = new TestEntity();
var ent2 = new TestEntity();
// Act
bool different = ent1.Equals( ent2 );
bool different2 = ent2.Equals( ent1 );
bool different3 = ent1 == ent2;
bool equal3 = ent1 != ent2;
var ent3 = ent1;
bool equal = ent1.Equals( ent3 );
bool equal2 = ent3.Equals( ent1 );
bool equal4 = ent1 == ent3;
bool different4 = ent1 != ent3;
// Assert
Assert.IsFalse( different );
Assert.IsFalse( different2 );
Assert.IsFalse( different3 );
Assert.IsFalse( different4 );
Assert.IsTrue( equal );
Assert.IsTrue( equal2 );
Assert.IsTrue( equal3 );
Assert.IsTrue( equal4 );
}
示例2: EntitiesWithDifferentIdShouldNotBeEqual
public void EntitiesWithDifferentIdShouldNotBeEqual()
{
var entity1 = new TestEntity(Guid.NewGuid());
var entity2 = new TestEntity(Guid.NewGuid());
Assert.IsFalse(entity1.Equals(entity2));
}
示例3: Equals_should_return_true_if_both_entities_have_same_Id
public void Equals_should_return_true_if_both_entities_have_same_Id()
{
var entity = new TestEntity();
var entity2 = new TestEntity();
SetEntityId(entity, 1);
SetEntityId(entity2, 1);
Assert.True(entity.Equals(entity2));
}
示例4: Equals_should_return_false_if_entities_have_different_Id
public void Equals_should_return_false_if_entities_have_different_Id()
{
var entity = new TestEntity();
var entity2 = new TestEntity();
SetEntityId(entity, 1);
SetEntityId(entity2, 2);
Assert.False(entity.Equals(entity2));
}
示例5: EntitiesWithSameIdShouldBeEqual
public void EntitiesWithSameIdShouldBeEqual()
{
var guid = Guid.NewGuid();
var entity1 = new TestEntity(guid);
var entity2 = new TestEntity(guid);
Assert.IsTrue(entity1.Equals(entity2));
}
示例6: EqualsNullIsFalse
public void EqualsNullIsFalse()
{
// Arrange
var entity = new TestEntity();
// Act
bool equals = entity.Equals( null );
// Assert
Assert.IsFalse( equals );
}
示例7: EqualsOtherTypeIsFalse
public void EqualsOtherTypeIsFalse()
{
// Arrange
var entity = new TestEntity();
// Act
// ReSharper disable once SuspiciousTypeConversion.Global
bool equals = entity.Equals( string.Empty );
// Assert
Assert.IsFalse( equals );
}
示例8: Equals_should_return_true_if_entity_is_new_and_compared_to_self
public void Equals_should_return_true_if_entity_is_new_and_compared_to_self()
{
var entity = new TestEntity();
Assert.True(entity.Equals(entity));
}
示例9: Equals_should_return_false_if_other_entity_is_null
public void Equals_should_return_false_if_other_entity_is_null()
{
var entity = new TestEntity();
Assert.False(entity.Equals(null));
}
示例10: Equals_should_return_false_if_both_entities_are_new
public void Equals_should_return_false_if_both_entities_are_new()
{
var entity = new TestEntity();
var entity2 = new TestEntity();
Assert.False(entity.Equals(entity2));
}
示例11: EntitiesWithDifferentTypeShouldNotBeEqual
public void EntitiesWithDifferentTypeShouldNotBeEqual()
{
var entity = new TestEntity(new Guid());
Assert.IsFalse(entity.Equals(new object()));
}
示例12: EntitiesWhereOneIsNullShouldNotBeEqual
public void EntitiesWhereOneIsNullShouldNotBeEqual()
{
var entity = new TestEntity(new Guid());
Assert.IsFalse(entity.Equals(null));
}
示例13: EqualsWorksWithSavedObjects
public void EqualsWorksWithSavedObjects()
{
// Arrange
var dbConfig = SQLiteConfiguration.Standard.InMemory().ShowSql();
var config = Fluently.Configure().Database( dbConfig )
.Mappings( map => map.FluentMappings.Add<TestEntityMap>() )
.BuildConfiguration();
var ent1 = new TestEntity { PropTwo = 1 };
var ent2 = new TestEntity { PropTwo = 2 };
var sessionFactory = config.BuildSessionFactory();
using( var session = sessionFactory.OpenSession() )
{
new SchemaExport( config ).Execute( true, true, false, session.Connection, null );
using( var tx = session.BeginTransaction() )
{
session.Save( ent1 );
session.Save( ent2 );
tx.Commit();
}
}
// Act
bool different = ent1.Equals( ent2 );
bool differnt2 = ent2.Equals( ent1 );
var ent3 = ent1;
bool equal = ent3.Equals( ent1 );
bool equal2 = ent1.Equals( ent3 );
// Assert
Assert.IsFalse( different );
Assert.IsFalse( differnt2 );
Assert.IsTrue( equal );
Assert.IsTrue( equal2 );
}
示例14: EqualsWorksWithUnsavedObjects
public void EqualsWorksWithUnsavedObjects()
{
// Arrange
TestEntity ent1 = new TestEntity { Id = 1 };
TestEntity ent2 = new TestEntity { Id = 2 };
// Act
bool different = ent1.Equals( ent2 );
bool different2 = ent2.Equals( ent1 );
ent1.Id = 2;
bool equal = ent1.Equals( ent2 );
bool equal2 = ent2.Equals( ent1 );
// Assert
Assert.IsFalse( different );
Assert.IsFalse( different2 );
Assert.IsTrue( equal );
Assert.IsTrue( equal2 );
}