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

            var dataSetter = new DataSetter(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <object>());

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

            Assert.Throws <ArgumentNullException>(() => dataSetter.ManipulateData(null, new Collection <IEnumerable <IDataObjectBase> >()));
        }
        public void TestThatManipulateDataChangesFieldValueWithoutUsingCriterias()
        {
            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 dataCollectionMock = new Collection <IEnumerable <IDataObjectBase> >();

            while (dataCollectionMock.Count < 250)
            {
                var dataObjects = new Collection <IDataObjectBase>();
                for (var i = 0; i < tableMock.Fields.Count; i++)
                {
                    var dataObject = MockRepository.GenerateMock <IFieldData <int, int> >();
                    dataObject.Expect(m => m.Field)
                    .Return(tableMock.Fields.ElementAt(i))
                    .Repeat.Any();
                    dataObjects.Add(dataObject);
                }
                dataCollectionMock.Add(dataObjects);
            }

            var newFieldValue = fixture.CreateAnonymous <int>();
            var dataSetter    = new DataSetter(tableMock.NameSource, tableMock.Fields.ElementAt(3).NameSource, newFieldValue);

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

            var manipulatedData = dataSetter.ManipulateData(fixture.CreateAnonymous <ITable>(), dataCollectionMock);

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

            foreach (var dataObjects in manipulatedData)
            {
                dataObjects.ElementAt(3).AssertWasCalled(m => m.UpdateSourceValue(Arg <int> .Is.Equal(newFieldValue)));
            }
        }
        public void TestThatManipulateDataThrowsArgumentNullExceptionIfDataIsNull()
        {
            var fixture = new Fixture();

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

            var dataSetter = new DataSetter(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <object>());

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

            Assert.Throws <ArgumentNullException>(() => dataSetter.ManipulateData(fixture.CreateAnonymous <ITable>(), null));
        }
        public void TestThatManipulateDataReturnsWithoutManipulatingDataIfTableSourceNameDoesNotMatchTableNameInTheConstructor()
        {
            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(() => MockRepository.GenerateMock <IField>()));

            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 dataCollectionMock = new Collection <IEnumerable <IDataObjectBase> >();

            while (dataCollectionMock.Count < 250)
            {
                var dataObjects = new Collection <IDataObjectBase>();
                for (var i = 0; i < tableMock.Fields.Count; i++)
                {
                    var dataObject = MockRepository.GenerateMock <IFieldData <int, int> >();
                    dataObject.Expect(m => m.GetSourceValue <int>())
                    .Return(i)
                    .Repeat.Any();
                    dataObjects.Add(dataObject);
                }
                dataCollectionMock.Add(dataObjects);
            }

            var dataSetter = new DataSetter(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <object>());

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

            var manipulatedData = dataSetter.ManipulateData(fixture.CreateAnonymous <ITable>(), dataCollectionMock);

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

            foreach (var dataObjects in manipulatedData)
            {
                Assert.That(dataObjects.ElementAt(3).GetSourceValue <int>(), Is.EqualTo(3));
            }
        }
        public void TestThatManipulateDataChangesFieldValueUsingIntervalCriterias()
        {
            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 criteriaCollectionMock = new Collection <Tuple <Type, string, object> >
            {
                new Tuple <Type, string, object>(typeof(IntervalCriteria <>), tableMock.Fields.ElementAt(0).NameSource, new Tuple <string, string>("1", "3"))
            };

            var dataCollectionMock = new Collection <IEnumerable <IDataObjectBase> >();

            while (dataCollectionMock.Count < 250)
            {
                var dataObjects = new Collection <IDataObjectBase>();
                for (var i = 0; i < tableMock.Fields.Count; i++)
                {
                    var dataObject = MockRepository.GenerateMock <IFieldData <int, int> >();
                    dataObject.Expect(m => m.Field)
                    .Return(tableMock.Fields.ElementAt(i))
                    .Repeat.Any();
                    dataObject.Expect(m => m.SourceValue)
                    .Return(i == 0 ? dataCollectionMock.Count % 4 : i)
                    .Repeat.Any();
                    dataObject.Expect(m => m.GetSourceValue <int>())
                    .Return(dataObject.SourceValue)
                    .Repeat.Any();
                    dataObjects.Add(dataObject);
                }
                dataCollectionMock.Add(dataObjects);
            }

            var newFieldValue = fixture.CreateAnonymous <int>();
            var dataSetter    = new DataSetter(tableMock.NameSource, tableMock.Fields.ElementAt(3).NameSource, newFieldValue, criteriaCollectionMock);

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

            var manipulatedData = dataSetter.ManipulateData(fixture.CreateAnonymous <ITable>(), dataCollectionMock);

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

            var dataRows = manipulatedData.ToList();

            for (var i = 0; i < dataRows.Count; i++)
            {
                if (dataRows.ElementAt(i).ElementAt(0).GetSourceValue <int>() > 0)
                {
                    dataRows.ElementAt(i).ElementAt(3).AssertWasCalled(m => m.UpdateSourceValue(Arg <int> .Is.Equal(newFieldValue)));
                    continue;
                }
                dataRows.ElementAt(i).ElementAt(3).AssertWasNotCalled(m => m.UpdateSourceValue(Arg <int> .Is.Anything));
            }
        }