예제 #1
0
        public void TestThatManipulateDataReturnsWithoutManipulatingDataIfTableSourceNameDoesNotMatchTableNameInTheConstructor()
        {
            var fixture = new Fixture();

            fixture.Customize <Type>(e => e.FromFactory(() => typeof(int)));
            fixture.Customize <IContainer>(e => e.FromFactory(() => MockRepository.GenerateMock <IContainer>()));
            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 workerMock = MockRepository.GenerateMock <IMissingForeignKeyWorker>();

            fixture.Customize <IMissingForeignKeyWorker>(e => e.FromFactory(() => workerMock));

            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++)
                {
                    dataObjects.Add(MockRepository.GenerateMock <IFieldData <int, int> >());
                }
                dataCollectionMock.Add(dataObjects);
            }

            var missingForeignKeyHandler = new MissingForeignKeyHandler(fixture.CreateAnonymous <string>(), fixture.CreateAnonymous <IMissingForeignKeyWorker>(), fixture.CreateAnonymous <IContainer>());

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

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

            Assert.That(manipulatedData, Is.Not.Null);
            Assert.That(manipulatedData, Is.Not.Empty);
            Assert.That(manipulatedData.Count(), Is.EqualTo(dataCollectionMock.Count));

            workerMock.AssertWasNotCalled(m => m.ManipulateData(Arg <ITable> .Is.Anything, Arg <IDataRepository> .Is.Anything, Arg <IEnumerable <IEnumerable <IDataObjectBase> > > .Is.Anything));
        }
예제 #2
0
        public void TestThatManipulateDataReturnsDataFromWorkerWhichManipulatesMissingForeignKeyValues()
        {
            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 dataRepositoryMock = MockRepository.GenerateMock <IDataRepository>();

            fixture.Customize <IDataRepository>(e => e.FromFactory(() => dataRepositoryMock));

            var containerMock = MockRepository.GenerateMock <IContainer>();

            containerMock.Expect(m => m.Resolve <IDataRepository>())
            .Return(fixture.CreateAnonymous <IDataRepository>())
            .Repeat.Any();
            fixture.Customize <IContainer>(e => e.FromFactory(() => containerMock));

            var workerMock = MockRepository.GenerateMock <IMissingForeignKeyWorker>();

            workerMock.Expect(m => m.ManipulateData(Arg <ITable> .Is.NotNull, Arg <IDataRepository> .Is.NotNull, Arg <IEnumerable <IEnumerable <IDataObjectBase> > > .Is.NotNull))
            .Return(new Collection <IEnumerable <IDataObjectBase> >())
            .Repeat.Any();
            fixture.Customize <IMissingForeignKeyWorker>(e => e.FromFactory(() => workerMock));

            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();
            // ReSharper disable ImplicitlyCapturedClosure
            fixture.Customize <ITable>(e => e.FromFactory(() => tableMock));
            // ReSharper restore ImplicitlyCapturedClosure

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

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

            var missingForeignKeyHandler = new MissingForeignKeyHandler(tableMock.NameSource, fixture.CreateAnonymous <IMissingForeignKeyWorker>(), fixture.CreateAnonymous <IContainer>());

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

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

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

            workerMock.AssertWasCalled(m => m.ManipulateData(Arg <ITable> .Is.Equal(tableMock), Arg <IDataRepository> .Is.Equal(dataRepositoryMock), Arg <IEnumerable <IEnumerable <IDataObjectBase> > > .Is.Equal(dataCollectionMock)));
        }