public void CompareUsingEqualsOperatorsAndNullOperandsTest()
        {
            //Arrange

            SampleEntity entityLeft = null;
            SampleEntity entityRight = new SampleEntity();

            entityRight.Id = IdentityGenerator.NewSequentialGuid(); ;

            //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();
        }
Beispiel #2
0
      public void CompareUsingEqualsOperatorsAndNullOperandsTest()
      {
         //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(); }

         entityRight = null;

         //Act
         if (!(entityLeft == entityRight)) //this perform ==(left,right)
         { Assert.Fail(); }

         if (entityLeft != entityRight) //this perform !=(left,right)
         { Assert.Fail(); }

      }
        public void CreateAndSpecificationTest()
        {
            //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
            AndSpecification<SampleEntity> composite = new AndSpecification<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.ChangeCurrentIdentity(identifier);

            list.AddRange(new SampleEntity[] { sampleA, sampleB });
            

            var result = list.AsQueryable().Where(composite.SatisfiedBy()).ToList();

            Assert.IsTrue(result.Count == 1);
        }
        public void CompareTheSameReferenceReturnTrueTest()
        {
            //Arrange
            SampleEntity entityLeft = new SampleEntity();
            SampleEntity entityRight = entityLeft;

            //Act
            if (! entityLeft.Equals(entityRight))
                Assert.Fail();

            if (!(entityLeft == entityRight))
                Assert.Fail();
        }
        public void CompareWhenLeftIsNullAndRightIsNullReturnFalseTest()
        {
            //Arrange

            SampleEntity entityLeft = null;
            SampleEntity entityRight = new SampleEntity();

            entityRight.Id = IdentityGenerator.NewSequentialGuid(); ;

            //Act
            if (!(entityLeft == (Entity)null))//this perform ==(left,right)
                Assert.Fail();

            if (!(entityRight != (Entity)null))//this perform !=(left,right)
                Assert.Fail();
        }
Beispiel #6
0
      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 SameIdentityProduceEqualsTrueTest()
        {
            //Arrange
            Guid id = Guid.NewGuid();

            var entityLeft = new SampleEntity();
            var entityRight = new SampleEntity();

            entityLeft.ChangeCurrentIdentity(id);
            entityRight.ChangeCurrentIdentity(id);
            
            //Act
            bool resultOnEquals = entityLeft.Equals(entityRight);
            bool resultOnOperator = entityLeft == entityRight;

            //Assert
            Assert.IsTrue(resultOnEquals);
            Assert.IsTrue(resultOnOperator);

        }
        public void DiferentIdProduceEqualsFalseTest()
        {
            //Arrange

            SampleEntity entityLeft = new SampleEntity();
            SampleEntity entityRight = new SampleEntity();

            entityLeft.Id = IdentityGenerator.NewSequentialGuid(); ;
            entityRight.Id = IdentityGenerator.NewSequentialGuid(); ;

            //Act
            bool resultOnEquals = entityLeft.Equals(entityRight);
            bool resultOnOperator = entityLeft == entityRight;

            //Assert
            Assert.IsFalse(resultOnEquals);
            Assert.IsFalse(resultOnOperator);
        }
        public void SameIdProduceEqualsTrueTest()
        {
            //Arrange
            Guid id = IdentityGenerator.NewSequentialGuid();

            SampleEntity entityLeft = new SampleEntity();
            SampleEntity entityRight = new SampleEntity();

            entityLeft.Id = id;
            entityRight.Id = id;

            //Act
            bool resultOnEquals = entityLeft.Equals(entityRight);
            bool resultOnOperator = entityLeft == entityRight;

            //Assert
            Assert.IsTrue(resultOnEquals);
            Assert.IsTrue(resultOnOperator);
        }
        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 bool GetA(SampleEntity s)
 {
     return false;
 }
        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());
        }
Beispiel #14
0
      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(); }
      }