public void TestThatGenerateFilterThrowsArgumentNullExceptionIfTableIsNull()
        {
            var fixture = new Fixture();

            var dataManipulator = new MyDataManipulator(fixture.CreateAnonymous <string>());

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

            Assert.Throws <ArgumentNullException>(() => dataManipulator.GenerateFilter(null, new Collection <Tuple <Type, string, object> >()));
        }
        public void TestThatGenerateFilterThrowsArgumentNullExceptionIfCriteriaConfigurationsIsNull()
        {
            var fixture = new Fixture();

            var tableMock = MockRepository.GenerateMock <ITable>();

            tableMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();
            fixture.Customize <ITable>(e => e.FromFactory(() => tableMock));

            var dataManipulator = new MyDataManipulator(tableMock.NameSource);

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

            Assert.Throws <ArgumentNullException>(() => dataManipulator.GenerateFilter(fixture.CreateAnonymous <ITable>(), null));
        }
        public void TestThatGenerateFilterCreatesFilterWithSomeIntervalCriterias()
        {
            var fixture = new Fixture();

            fixture.Customize <Type>(e => e.FromFactory(() => typeof(int?)));
            fixture.Customize <IMap>(e => e.FromFactory(() => MockRepository.GenerateMock <IMap>()));
            fixture.Customize <IField>(e => e.FromFactory(() =>
            {
                var fieldMock = MockRepository.GenerateMock <IField>();
                fieldMock.Expect(m => m.NameSource)
                .Return(fixture.CreateAnonymous <string>())
                .Repeat.Any();
                fieldMock.Expect(m => m.DatatypeOfSource)
                .Return(typeof(int?))
                .Repeat.Any();
                return(fieldMock);
            }));

            var tableMock = MockRepository.GenerateMock <ITable>();

            tableMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();
            tableMock.Expect(m => m.Fields)
            .Return(new ReadOnlyObservableCollection <IField>(new ObservableCollection <IField>(fixture.CreateMany <IField>(5).ToList())))
            .Repeat.Any();
            fixture.Customize <ITable>(e => e.FromFactory(() => tableMock));

            var dataManipulator = new MyDataManipulator(tableMock.NameSource);

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

            var criteriaConfigurations = new Collection <Tuple <Type, string, object> >
            {
                new Tuple <Type, string, object>(typeof(IntervalCriteria <>), tableMock.Fields.ElementAt(0).NameSource, new Tuple <string, string>(fixture.CreateAnonymous <int>().ToString(CultureInfo.InvariantCulture), fixture.CreateAnonymous <int>().ToString(CultureInfo.InvariantCulture))),
                new Tuple <Type, string, object>(typeof(IntervalCriteria <>), tableMock.Fields.ElementAt(1).NameSource, new Tuple <string, string>(fixture.CreateAnonymous <int>().ToString(CultureInfo.InvariantCulture), fixture.CreateAnonymous <int>().ToString(CultureInfo.InvariantCulture)))
            };

            var filter = dataManipulator.GenerateFilter(fixture.CreateAnonymous <ITable>(), criteriaConfigurations);

            Assert.That(filter, Is.Not.Null);
            Assert.That(filter.Criterias, Is.Not.Null);
            Assert.That(filter.Criterias, Is.Not.Empty);
            Assert.That(filter.Criterias.Count, Is.EqualTo(2));
        }
        public void TestThatGenerateFilterThrowsDeliveryEngineSystemExceptionIfDataTypeInCriteriaConfigurationsIsNotSupported()
        {
            var fixture = new Fixture();

            fixture.Customize <Type>(e => e.FromFactory(() => typeof(int?)));
            fixture.Customize <IMap>(e => e.FromFactory(() => MockRepository.GenerateMock <IMap>()));
            fixture.Customize <IField>(e => e.FromFactory(() =>
            {
                var fieldMock = MockRepository.GenerateMock <IField>();
                fieldMock.Expect(m => m.NameSource)
                .Return(fixture.CreateAnonymous <string>())
                .Repeat.Any();
                return(fieldMock);
            }));

            var tableMock = MockRepository.GenerateMock <ITable>();

            tableMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();
            tableMock.Expect(m => m.Fields)
            .Return(new ReadOnlyObservableCollection <IField>(new ObservableCollection <IField>(fixture.CreateMany <IField>(5).ToList())))
            .Repeat.Any();
            fixture.Customize <ITable>(e => e.FromFactory(() => tableMock));

            var dataManipulator = new MyDataManipulator(tableMock.NameSource);

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

            var criteriaConfigurations = new Collection <Tuple <Type, string, object> >
            {
                new Tuple <Type, string, object>(typeof(object), tableMock.Fields.ElementAt(0).NameSource, fixture.CreateAnonymous <int>())
            };

            var exception = Assert.Throws <DeliveryEngineSystemException>(() => dataManipulator.GenerateFilter(fixture.CreateAnonymous <ITable>(), criteriaConfigurations));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Empty);
            Assert.That(exception.Message, Is.EqualTo(Resource.GetExceptionMessage(ExceptionMessage.DataTypeNotSupported, criteriaConfigurations.ElementAt(0).Item1.Name)));
        }
        public void TestThatGenerateFilterCreatesFilterWithoutCriteriasIfCriteriaConfigurationsIsEmpty()
        {
            var fixture = new Fixture();

            var tableMock = MockRepository.GenerateMock <ITable>();

            tableMock.Expect(m => m.NameSource)
            .Return(fixture.CreateAnonymous <string>())
            .Repeat.Any();
            fixture.Customize <ITable>(e => e.FromFactory(() => tableMock));

            var dataManipulator = new MyDataManipulator(tableMock.NameSource);

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

            var filter = dataManipulator.GenerateFilter(fixture.CreateAnonymous <ITable>(), new Collection <Tuple <Type, string, object> >());

            Assert.That(filter, Is.Not.Null);
            Assert.That(filter.Criterias, Is.Not.Null);
            Assert.That(filter.Criterias, Is.Empty);
            Assert.That(filter.Criterias.Count, Is.EqualTo(0));
        }