public void CompareUsingEqualsOperatorsAndNullOperandsTest() { //Arrange SampleEntity entityLeft = null; SampleEntity entityRight = new SampleEntity(); entityRight.GenerateNewIdentity(); //Act if (!(entityLeft == (Entity)null))//this perform ==(left,right) Assert.Fail(); if (!(entityRight != (Entity)null))//this perform !=(left,right) Assert.Fail(); entityRight = null; //Act if (!(entityLeft == entityRight))//this perform ==(left,right) Assert.Fail(); if (entityLeft != entityRight)//this perform !=(left,right) Assert.Fail(); }
public void DiferentIdProduceEqualsFalseTest() { //Arrange var entityLeft = new SampleEntity(); var entityRight = new SampleEntity(); entityLeft.GenerateNewIdentity(); entityRight.GenerateNewIdentity(); //Act var resultOnEquals = entityLeft.Equals(entityRight); var resultOnOperator = entityLeft == entityRight; //Assert Assert.IsFalse(resultOnEquals); Assert.IsFalse(resultOnOperator); }
public void CreateOrSpecificationTest() { //Arrange DirectSpecification<SampleEntity> leftAdHocSpecification; DirectSpecification<SampleEntity> rightAdHocSpecification; var identifier = Guid.NewGuid(); Expression<Func<SampleEntity, bool>> leftSpec = s => s.Id == identifier; Expression<Func<SampleEntity, bool>> rightSpec = s => s.SampleProperty.Length > 2; leftAdHocSpecification = new DirectSpecification<SampleEntity>(leftSpec); rightAdHocSpecification = new DirectSpecification<SampleEntity>(rightSpec); //Act OrSpecification<SampleEntity> composite = new OrSpecification<SampleEntity>(leftAdHocSpecification, rightAdHocSpecification); //Assert Assert.IsNotNull(composite.SatisfiedBy()); Assert.ReferenceEquals(leftAdHocSpecification, composite.LeftSideSpecification); Assert.ReferenceEquals(rightAdHocSpecification, composite.RightSideSpecification); var list = new List<SampleEntity>(); var sampleA = new SampleEntity() { SampleProperty = "1" }; sampleA.ChangeCurrentIdentity(identifier); var sampleB = new SampleEntity() { SampleProperty = "the sample property" }; sampleB.GenerateNewIdentity(); list.AddRange(new SampleEntity[] { sampleA, sampleB }); var result = list.AsQueryable().Where(composite.SatisfiedBy()).ToList(); Assert.IsTrue(result.Count() == 2); }
public void UseSpecificationOrOperatorTest() { //Arrange DirectSpecification<SampleEntity> leftAdHocSpecification; DirectSpecification<SampleEntity> rightAdHocSpecification; var identifier = Guid.NewGuid(); Expression<Func<SampleEntity, bool>> leftSpec = s => s.Id == identifier; Expression<Func<SampleEntity, bool>> rightSpec = s => s.SampleProperty.Length > 2; //Act leftAdHocSpecification = new DirectSpecification<SampleEntity>(leftSpec); rightAdHocSpecification = new DirectSpecification<SampleEntity>(rightSpec); var orSpec = leftAdHocSpecification || rightAdHocSpecification; //Assert var list = new List<SampleEntity>(); var sampleA = new SampleEntity() { SampleProperty = "1" }; sampleA.ChangeCurrentIdentity(identifier); var sampleB = new SampleEntity() { SampleProperty = "the sample property" }; sampleB.GenerateNewIdentity(); list.AddRange(new SampleEntity[] { sampleA, sampleB }); var result = list.AsQueryable().Where(orSpec.SatisfiedBy()).ToList(); Assert.IsTrue(result.Count() == 2); }
public void ChangeIdentitySetNewIdentity() { //Arrange var entity = new SampleEntity(); entity.GenerateNewIdentity(); //act Guid expected = entity.Id; entity.ChangeCurrentIdentity(Guid.NewGuid()); //assert Assert.AreNotEqual(expected, entity.Id); }
public void SetIdentitySetANonTransientEntity() { //Arrange var entity = new SampleEntity(); //Act entity.GenerateNewIdentity(); //Assert Assert.IsFalse(entity.IsTransient()); }
public void CompareWhenLeftIsNullAndRightIsNullReturnFalseTest() { //Arrange SampleEntity entityLeft = null; var entityRight = new SampleEntity(); entityRight.GenerateNewIdentity(); //Act if (!(entityLeft == (Entity)null))//this perform ==(left,right) Assert.Fail(); if (!(entityRight != (Entity)null))//this perform !=(left,right) Assert.Fail(); }