コード例 #1
0
        public void TestThatConstructorInitializeCriteria()
        {
            var fixture = new Fixture();

            fixture.Customize <Type>(e => e.FromFactory(() => typeof(object)));
            fixture.Customize <ITable>(e => e.FromFactory(() => MockRepository.GenerateMock <ITable>()));
            fixture.Customize <IField>(e => e.FromFactory(() => MockRepository.GenerateMock <IField>()));
            fixture.Customize <IMap>(e => e.FromFactory(() => MockRepository.GenerateMock <IMap>()));

            var fieldMock = fixture.CreateAnonymous <Field>();
            var criteria  = new IntervalCriteria <string>(fieldMock, fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>());

            Assert.That(criteria, Is.Not.Null);
            Assert.That(criteria.Field, Is.Not.Null);
            Assert.That(criteria.Field, Is.EqualTo(fieldMock));
        }
コード例 #2
0
        public void TestThatExcludeReturnsTrueIfIntegerValueIsNotBetweenValues()
        {
            var       fixture   = new Fixture();
            const int fromValue = 0;
            const int toValue   = 9;

            var fieldMock = MockRepository.GenerateMock <IField>();

            fieldMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();

            var criteria = new IntervalCriteria <int>(fieldMock, fromValue, toValue);

            Assert.That(criteria, Is.Not.Null);

            Assert.That(criteria.Exclude(10), Is.True);
        }
コード例 #3
0
        public void TestThatExcludeReturnsTrueIfStringValueIsNotBetweenValues()
        {
            var fixture   = new Fixture();
            var value     = fixture.CreateAnonymous <string>();
            var fromValue = string.Format("{0}0", value);
            var toValue   = string.Format("{0}9", value);

            var fieldMock = MockRepository.GenerateMock <IField>();

            fieldMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();

            var criteria = new IntervalCriteria <string>(fieldMock, fromValue, toValue);

            Assert.That(criteria, Is.Not.Null);

            Assert.That(criteria.Exclude(string.Format("{0}A", value)), Is.True);
        }
コード例 #4
0
        public void TestThatAsStringReturnsStringCriteriaForStringValues()
        {
            var fixture   = new Fixture();
            var fromValue = fixture.CreateAnonymous <string>();
            var toValue   = fixture.CreateAnonymous <string>();

            var fieldMock = MockRepository.GenerateMock <IField>();

            fieldMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();

            var criteria = new IntervalCriteria <string>(fieldMock, fromValue, toValue);

            Assert.That(criteria, Is.Not.Null);

            var stringCriteria = criteria.AsString();

            Assert.That(stringCriteria, Is.Not.Null);
            Assert.That(stringCriteria, Is.Not.Empty);

            Assert.That(stringCriteria, Is.EqualTo(string.Format("{0}.Value.CompareTo(\"{1}\") >= 0\r\n{0}.Value.CompareTo(\"{2}\") <= 0", fieldMock.NameSource, fromValue, toValue)));
        }
コード例 #5
0
        public void TestThatAsSqlReturnsSqlCriteriaForIntegerValues()
        {
            var fixture   = new Fixture();
            var fromValue = fixture.CreateAnonymous <int>();
            var toValue   = fixture.CreateAnonymous <int>();

            var fieldMock = MockRepository.GenerateMock <IField>();

            fieldMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();

            var criteria = new IntervalCriteria <int>(fieldMock, fromValue, toValue);

            Assert.That(criteria, Is.Not.Null);

            var stringCriteria = criteria.AsSql();

            Assert.That(stringCriteria, Is.Not.Null);
            Assert.That(stringCriteria, Is.Not.Empty);

            Assert.That(stringCriteria, Is.EqualTo(string.Format("{0} BETWEEN {1} AND {2}", fieldMock.NameSource, fromValue, toValue)));
        }