Exemplo n.º 1
0
 public void CreateNotSpeNullSpecThrowArgumentNullExceptionTest()
 {
     //Arrange
     NotSpecification<User> notSpec;
     //Act
     notSpec = new NotSpecification<User>((ISpecification<User>)null);
 }
 public void SpecificationIsSatisfiedWhenSpecIsNotSatisfied()
 {
     sut = new NotSpecification<string>(spec);
     spec.IsSatisfiedBy(TestString).Returns(false);
     Assert.IsTrue(sut.IsSatisfiedBy(TestString));
     Assert.AreEqual(0, sut.ReasonsForDissatisfaction.Count());
 }
Exemplo n.º 3
0
        public void Test_Not_Degenerate()
        {
            // TODO: this is the current behaviour - perhaps it should throw an exception instead
            NotSpecification s = new NotSpecification();

            Assert.IsFalse(s.Test(null).Success);
        }
                public When_First_Option_Is_False()
                {
                    option = new NotSpecification(
                        new FalseSpecification()
                    );

                    result = option.IsSatisfiedBy(new object());
                }
Exemplo n.º 5
0
        public void Test_Not_Mixed()
        {
            NotSpecification s = new NotSpecification();

            s.Add(AlwaysFalse);
            s.Add(AlwaysTrue);
            Assert.IsTrue(s.Test(null).Success);
        }
        public void IsSatisfiedByReturnsTrueWhenSpecifactionIsFalse(TestObject testObject, bool result)
        {
            var specification1 = new ExpressionSpecification <TestObject>(p => p.BooleanProperty);

            var notSpecification = new NotSpecification <TestObject>(specification1);

            notSpecification.IsSatisfiedBy(testObject).ShouldBe(result);
        }
Exemplo n.º 7
0
        public bool IsSatisfied_Reverses_Original_One(bool origResult)
        {
            var originalSpec = new DirectSpecification <object>(obj => origResult);

            var spec = new NotSpecification <object>(originalSpec);

            return(spec.IsSatisfiedBy(new object()));
        }
Exemplo n.º 8
0
        public void NotSpecification_Not_Test()
        {
            var notSpec = new NotSpecification <TestObjects.Member>(spec);

            member.City = "Moscow";

            Assert.That(!notSpec.IsSatisfiedBy(member));
        }
 public void NotSpecification_IsSatisfiedBy_SpecificationTrue_False()
 {
     var mockRepository = new MockRepository(MockBehavior.Strict);
     var singleSpecification = mockRepository.CreateSpecificationMock<string>(true);
     var specification = new NotSpecification<string>(singleSpecification);
     Assert.AreEqual(false, specification.IsSatisfiedBy("test"));
     mockRepository.VerifyAll();
 }
        public void ExpressionReturnsTrueWhenSpecifactionIsFalse(TestObject testObject, bool result)
        {
            var specification1 = new ExpressionSpecification <TestObject>(p => p.BooleanProperty);

            var notSpecification = new NotSpecification <TestObject>(specification1);

            ExpressionSpecificationTester.TestSpecification(notSpecification, testObject, result);
        }
Exemplo n.º 11
0
        public void Can_Be_Constructed_With_Specification()
        {
            var originalSpec = new TrueSpecification <object>();

            var spec = new NotSpecification <object>(originalSpec);

            Assert.That(spec.OriginalSpecification, Is.EqualTo(originalSpec));
        }
Exemplo n.º 12
0
        public void CreateNotSpecificationNullCriteriaThrowArgumentNullExceptionTest()
        {
            //Arrange
            NotSpecification <SampleEntity> notSpec;

            //Act
            notSpec = new NotSpecification <SampleEntity>((Expression <Func <SampleEntity, bool> >)null);
        }
Exemplo n.º 13
0
        public void CreateNotSpecificationNullSpecificationThrowArgumentNullExceptionTest()
        {
            //Arrange
            NotSpecification <SampleEntity> notSpec;

            //Act
            notSpec = new NotSpecification <SampleEntity>((ISpecification <SampleEntity>)null);
        }
 public void ReasonsForDissatisfactionIsClearedBeforeSatisfactionIsEvaluated()
 {
     sut = new NotSpecification<string>(spec);
     spec.IsSatisfiedBy(TestString).Returns(true, false);
     Assert.IsFalse(sut.IsSatisfiedBy(TestString));
     Assert.IsTrue(sut.IsSatisfiedBy(TestString));
     Assert.AreEqual(0, sut.ReasonsForDissatisfaction.Count());
 }
Exemplo n.º 15
0
        public void NotFalse()
        {
            NotSpecification    not    = new NotSpecification(ConstantSpecification.True);
            SpecificationResult result = not.Evaluate(new Dictionary <string, object>());

            Assert.False(result.IsSatisfied);
            Assert.Equal("not/true", result.Details);
        }
Exemplo n.º 16
0
        public void CreateNotSpeNullSpecThrowArgumentNullExceptionTest()
        {
            //Arrange
            NotSpecification <User> notSpec;

            //Act
            notSpec = new NotSpecification <User>((ISpecification <User>)null);
        }
        public void IsSatisfiedByReturnsNegateOfPassedSpecification()
        {
            var otherSpecification = new Mock<ISpecification<object>>();
            otherSpecification.Setup<bool>(x => x.IsSatisfiedBy(It.IsAny<object>())).Returns(false);

            var specification = new NotSpecification<object>(otherSpecification.Object);
            Assert.True(specification.IsSatisfiedBy(string.Empty));
        }
Exemplo n.º 18
0
        public void Visit(NotSpecification <TItem, TVisitor> spec)
        {
            var specExpr = ExpressionForSpecification(spec.Spec);

            var exprBody = Expression.Not(specExpr.Body);

            Expr = Expression.Lambda <Func <TEntity, bool> > (exprBody, specExpr.Parameters.Single());
        }
        public void NotSpecification_Creation_NullSpecificationThrowArgumentNullException_Test()
        {
            //Arrange
            NotSpecification <TEntity> notSpec;

            //Act
            notSpec = new NotSpecification <TEntity>((ISpecification <TEntity>)null);
        }
        public void InvokeNotMinLength_ReturnNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new MinLengthSpecification <string>(0, true));

            var sut = Specification.NotMinLength <string>(0);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Exemplo n.º 21
0
        public void InvokeCompositeNotMaxLength_ReturnNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new MaxLengthSpecification <string>(0, true));

            var sut = new MockCompositeSpecification <string>().NotMaxLength(0);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
        public void InvokeCompositeNotNull_ReturnNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new NullSpecification <string>());

            var sut = new MockCompositeSpecification <string>().NotNull();

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Exemplo n.º 23
0
            public void InvokeNull_NotRaiseException()
            {
                var specification = MockComplexSpecification.True();
                var sut           = new NotSpecification <object>(specification);

                var exception = Record.Exception(() => sut.GetExpression().Compile().Invoke(null));

                Assert.Null(exception);
            }
Exemplo n.º 24
0
        public void InvokeNotEmail_ReturnNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new EmailSpecification());

            var sut = Specification.NotEmail();

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
        public void InvokeStringNotContains_ReturnStringNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new ContainsSpecification(" "));

            var sut = Specification.NotContains(" ");

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Exemplo n.º 26
0
        public void NotMethodWithCalledShouldReturnNotSpecification()
        {
            Specification<object> spec = SpecificationUtils.CreateSatisfiedSpecification();
            Specification<object> expectedResult = new NotSpecification<object>(spec);

            Specification<object> result = spec.Not();

            Assert.AreEqual(expectedResult, result);
        }
        public void InvokeNotCreditCard_ReturnNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new CreditCardSpecification());

            var sut = Specification.NotCreditCard();

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Exemplo n.º 28
0
        public void InvokeNotLengthBetween_ReturnNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new LengthBetweenSpecification <string>(0, 0, true));

            var sut = Specification.NotLengthBetween <string>(0, 0);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
            public void NullCandidate_NoException()
            {
                var specification = MockComplexSpecification.True();
                var sut           = new NotSpecification <object>(specification);

                var exception = Record.Exception(() => sut.IsSatisfiedBy(null));

                Assert.Null(exception);
            }
Exemplo n.º 30
0
            public void WithAFailingSpecItShouldPass()
            {
                var specification = new FunctionSpecification<int>(i => i > 0);
                var sut = new NotSpecification<int>(specification);

                var result = sut.IsSatisfiedBy(1);

                result.Should().BeFalse();
            }
Exemplo n.º 31
0
        public void InvokeIsNotType_ReturnNotSpecification()
        {
            var expected = new NotSpecification <int>(
                new IsTypeSpecification <int>(typeof(FakeType)));

            var sut = Specification.IsNotType <int>(typeof(FakeType));

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Exemplo n.º 32
0
            public void WithAPassingSpecItShouldReturnAFail()
            {
                var specification = new FunctionSpecification<int>(i => i > 0);
                var sut = new NotSpecification<int>(specification);

                var result = sut.IsSatisfiedBy(0);

                result.Should().BeTrue();
            }
Exemplo n.º 33
0
        public void InvokeNotMatch_ReturnStringNotSpecification()
        {
            var expected = new NotSpecification <string>(
                new MatchSpecification("pattern", RegexOptions.IgnoreCase));

            var sut = Specification.NotMatch("pattern", RegexOptions.IgnoreCase);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
        public void InvokeCompositeNotEqual_ReturnNotSpecification()
        {
            var comparer = new FakeIntComparer();
            var expected = new NotSpecification <int>(
                new EqualSpecification <int>(0, comparer));

            var sut = new MockCompositeSpecification <int>().NotEqual(0, comparer);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Exemplo n.º 35
0
            public void NonGenericILinqSpecification_ReturnBaseExpressionAsAbstractExpression()
            {
                var specification = MockSpecification.True();
                var sut           = new NotSpecification <object>(specification);

                var expected = sut.GetExpression();
                var result   = ((ILinqSpecification)sut).GetExpression();

                Assert.Equal(expected, result);
            }
        public void InvokeNotGreaterThanOrEqual_ReturnNotSpecification()
        {
            var comparer = new FakeIntComparer();
            var expected = new NotSpecification <int>(
                new GreaterThanOrEqualSpecification <int>(0, comparer));

            var sut = Specification.NotGreaterThanOrEqual(0, comparer);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
        public void InvokeNotExclusiveBetween_ReturnNotSpecification()
        {
            var comparer = new FakeIntComparer();
            var expected = new NotSpecification <int>(
                new ExclusiveBetweenSpecification <int>(0, 0, comparer));

            var sut = Specification.NotExclusiveBetween(0, 0, comparer);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
        public override Specification VisitNot(NotSpecification not)
        {
            this.XmlWriter.WriteStartElement(Consts.Not, this.NameSpace);

            var result = base.VisitNot(not);

            this.XmlWriter.WriteEndElement();

            return(result);
        }
Exemplo n.º 39
0
            public void CorrectSpecification_ReturnNegatedExpression()
            {
                var specification = MockSpecification.True();
                var sut           = new NotSpecification <object>(specification);

                var expression = sut.GetExpression();
                var result     = expression.ToString();

                Assert.Matches(@"candidate => Not\(.*\.IsSatisfiedBy\(candidate\)\)", result);
            }
Exemplo n.º 40
0
        public void testAndIsSatisifedBy()
        {
            AlwaysTrueSpec trueSpec = new AlwaysTrueSpec();
            AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();

            NotSpecification<object> notSpecification = new NotSpecification<object>(trueSpec);
            Assert.False(notSpecification.isSatisfiedBy(new object()));

            notSpecification = new NotSpecification<object>(falseSpec);
            Assert.True(notSpecification.isSatisfiedBy(new object()));
        }
                public When_Invoked()
                {
                    subject = new object();

                    option = new NotSpecification(
                        new Specification(
                            s => {
                                option1Subject = s;
                                option1Called = true;
                                return false;
                            }
                        )
                    );

                    option.IsSatisfiedBy(subject);
                }
Exemplo n.º 42
0
        public void CriaNotSpecificationTest()
        {
            Expression<Func<ClienteStub, bool>> leftLambda = s => s.Nome == "MARCUS";

            var leftSpecification = new DirectSpecification<ClienteStub>(leftLambda);

            Specification<ClienteStub> andSpec = new NotSpecification<ClienteStub>(leftSpecification);

            List<ClienteStub> listaCliente = new List<ClienteStub>();

            listaCliente.Add(new ClienteStub() { Nome = "MARCUS" });

            var result = listaCliente.AsQueryable().Where(andSpec.SatisfiedBy()).ToList();

            Assert.IsTrue(result.Count == 0);
        }
Exemplo n.º 43
0
        public void Not_Should_Reverse_SatisfiedBy_Value()
        {
            var mocks = new MockRepository();
            var s = mocks.StrictMock<ISpecification<int>>();

            Expect.Call(s.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s.IsSatisfiedBy(6)).Return(false);

            mocks.ReplayAll();

            var not = new NotSpecification<int>(s);

            Assert.IsFalse(not.IsSatisfiedBy(5));
            Assert.IsTrue(not.IsSatisfiedBy(6));

            mocks.VerifyAll();
        }
Exemplo n.º 44
0
		public void Test_Not_Degenerate()
		{
			// TODO: this is the current behaviour - perhaps it should throw an exception instead
			NotSpecification s = new NotSpecification();
			Assert.IsFalse(s.Test(null).Success);
		}
        public void CreateNotSpecificationNullSpecificationThrowArgumentNullExceptionTest()
        {
            //Arrange
            NotSpecification<SampleEntity> notSpec;

            //Act
            notSpec = new NotSpecification<SampleEntity>((ISpecification<SampleEntity>)null);
        }
Exemplo n.º 46
0
		public void Test_Not_Mixed()
		{
			NotSpecification s = new NotSpecification();
			s.Add(AlwaysFalse);
			s.Add(AlwaysTrue);
			Assert.IsTrue(s.Test(null).Success);
		}
Exemplo n.º 47
0
        public void NotSpecification_Creation_WithCriteria_Test()
        {
            //Arrange
            Expression<Func<Entity, bool>> specificationCriteria = t => t.Id == 0;
            

            //Act
            NotSpecification<Entity> notSpec = new NotSpecification<Entity>(specificationCriteria);

            //Assert
            Assert.IsNotNull(notSpec);
            Assert.IsNotNull(notSpec.GetType().GetField("_OriginalCriteria", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(notSpec));
        }
Exemplo n.º 48
0
        public void CreateNotSpecificationWithCriteriaTest()
        {
            //Arrange
            Expression<Func<SampleEntity, bool>> specificationCriteria = t => t.Id == IdentityGenerator.NewSequentialGuid();

            //Act
            NotSpecification<SampleEntity> notSpec = new NotSpecification<SampleEntity>(specificationCriteria);

            //Assert
            Assert.IsNotNull(notSpec);
            Assert.IsNotNull(new PrivateObject(notSpec).GetField("_OriginalCriteria"));
        }
Exemplo n.º 49
0
		public void ItShouldBeASpecification(NotSpecification<TestType> sut)
		{
			sut.Should().BeAssignableTo<ISpecification<TestType>>();
		}
        public void NotSpecificationCreationWithCriteriaTest()
        {
            //Arrange
            Expression<Func<TEntity, bool>> specificationCriteria = t => t.Id == 0;

            //Act
            NotSpecification<TEntity> notSpec = new NotSpecification<TEntity>(specificationCriteria);

            //Assert
            Assert.IsNotNull(notSpec);
            Assert.IsNotNull(new PrivateObject(notSpec).GetField("_originalCriteria"));
        }
Exemplo n.º 51
0
        public void CreateNotSpecificationithSpecificationTest()
        {
            //Arrange
            Expression<Func<SampleEntity, bool>> specificationCriteria = t => t.Id == IdentityGenerator.NewSequentialGuid();
            DirectSpecification<SampleEntity> specification = new DirectSpecification<SampleEntity>(specificationCriteria);

            //Act
            NotSpecification<SampleEntity> notSpec = new NotSpecification<SampleEntity>(specification);
            Expression<Func<SampleEntity, bool>> resultCriteria = new PrivateObject(notSpec).GetField("_OriginalCriteria") as Expression<Func<SampleEntity, bool>>;

            //Assert
            Assert.IsNotNull(notSpec);
            Assert.IsNotNull(resultCriteria);
            Assert.IsNotNull(notSpec.SatisfiedBy());
        }
 public void SpecIsMandatoryParameterInConstruction()
 {
     sut = new NotSpecification<string>(null);
 }
        public void NotSpecificationCreationWithSpecificationTest()
        {
            //Arrange
            Expression<Func<TEntity, bool>> specificationCriteria = t => t.Id == 0;
            DirectSpecification<TEntity> specification = new DirectSpecification<TEntity>(specificationCriteria);

            //Act
            NotSpecification<TEntity> notSpec = new NotSpecification<TEntity>(specification);
            Expression<Func<TEntity,bool>> resultCriteria = new PrivateObject(notSpec).GetField("_originalCriteria") as Expression<Func<TEntity,bool>>;

            //Assert
            Assert.IsNotNull(notSpec);
            Assert.IsNotNull(resultCriteria);
            Assert.IsNotNull(notSpec.SatisfiedBy());
        }
Exemplo n.º 54
0
        public void NotSpecification_Creation_WithSpecification_Test()
        {
            // Arrange
            Expression<Func<Entity, bool>> specificationCriteria = t => t.Id == 0;
            var specification = new DirectSpecification<Entity>(specificationCriteria);

            // Act
            var notSpec = new NotSpecification<Entity>(specification);

            var resultCriteria = notSpec.GetType()
                                 .GetField(
                                     "originalCriteria",
                                     BindingFlags.Instance |
                                     BindingFlags.NonPublic).
                                 GetValue(notSpec) as Expression<Func<Entity, bool>>;

            // Assert
            Assert.IsNotNull(notSpec);
            Assert.IsNotNull(resultCriteria);
            Assert.IsNotNull(notSpec.SatisfiedBy());
        }
        public void NotSpecification_Creation_NullSpecificationThrowArgumentNullException_Test()
        {
            //Arrange
            NotSpecification<TEntity> notSpec;

            //Act
            notSpec = new NotSpecification<TEntity>((ISpecification<TEntity>)null);
        }
        public void NotSpecification_Creation_NullCriteriaThrowArgumentNullException_Test()
        {
            //Arrange
            NotSpecification<TEntity> notSpec;

            //Act
            notSpec = new NotSpecification<TEntity>((Expression<Func<TEntity,bool>>)null);
        }