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

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

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

            var dataManipulator = new MyDataManipulator(tableMock.NameTarget);

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

            var data            = new Collection <IEnumerable <IDataObjectBase> >();
            var manipulatedData = dataManipulator.FinalizeDataManipulation(fixture.CreateAnonymous <ITable>(), data);

            Assert.That(manipulatedData, Is.Not.Null);
            Assert.That(manipulatedData, Is.EqualTo(data));

            Assert.That(dataManipulator.DataIsFinalized, Is.True);

            tableMock.AssertWasCalled(m => m.NameTarget);
        }
        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 TestThatIsManipulatingFieldThrowsArgumentNullExceptionIfFieldNameIsEmpty()
        {
            var fixture = new Fixture();

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

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

            Assert.Throws <ArgumentNullException>(() => dataManipulator.IsManipulatingField(string.Empty));
        }
        public void TestThatIsManipulatingTableThrowsArgumentNullExceptionIfTableNameIsNull()
        {
            var fixture = new Fixture();

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

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

            Assert.Throws <ArgumentNullException>(() => dataManipulator.IsManipulatingTable(null));
        }
        public void TestThatFinalizeDataManipulationThrowsArgumentNullExceptionIfTableIsNull()
        {
            var fixture = new Fixture();

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

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

            Assert.Throws <ArgumentNullException>(() => dataManipulator.FinalizeDataManipulation(null, new Collection <IEnumerable <IDataObjectBase> >()));
        }
        public void TestThatIsManipulatingTableReturnsFalseIfTableNameDoesNotMatchTableNameForDataManipulator()
        {
            var fixture = new Fixture();

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

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

            Assert.That(dataManipulator.IsManipulatingTable(fixture.CreateAnonymous <string>()), Is.False);
        }
        public void TestThatConstructorInitializeDataManipulator()
        {
            var fixture         = new Fixture();
            var tableName       = fixture.CreateAnonymous <string>();
            var dataManipulator = new MyDataManipulator(tableName);

            Assert.That(dataManipulator, Is.Not.Null);
            Assert.That(dataManipulator.TableName, Is.Not.Null);
            Assert.That(dataManipulator.TableName, Is.Not.Empty);
            Assert.That(dataManipulator.TableName, Is.EqualTo(tableName));
        }
        public void TestThatIsManipulatingFieldCallsManipulatingField()
        {
            var fixture = new Fixture();

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

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

            Assert.That(dataManipulator.ManipulatingFieldCalled, Is.False);
            Assert.That(dataManipulator.IsManipulatingField(fixture.CreateAnonymous <string>()), Is.True);
            Assert.That(dataManipulator.ManipulatingFieldCalled, Is.True);
        }
        public void TestThatFinalizeDataManipulationThrowsArgumentNullExceptionIfDataIsNull()
        {
            var fixture = new Fixture();

            fixture.Customize <ITable>(e => e.FromFactory(() => MockRepository.GenerateMock <ITable>()));

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

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

            Assert.Throws <ArgumentNullException>(() => dataManipulator.FinalizeDataManipulation(fixture.CreateAnonymous <ITable>(), null));
        }
        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));
        }