Пример #1
0
        public void TestThatManipulateDataThrowsArgumentNullExceptionIfDataIsNull()
        {
            var containerMock = MockRepository.GenerateMock <IContainer>();

            containerMock.Expect(m => m.ResolveAll <IDataManipulator>())
            .Return(new Collection <IDataManipulator>().ToArray())
            .Repeat.Any();

            var dataManipulators = new DeliveryEngine.Repositories.DataManipulators.DataManipulators(containerMock);

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

            Assert.Throws <ArgumentNullException>(() => dataManipulators.ManipulateData(MockRepository.GenerateMock <ITable>(), null, true));
        }
Пример #2
0
        public void TestThatManipulateDataCallManipulateDataForEachDataManipulator()
        {
            var fixture = new Fixture();

            fixture.Customize <IDataManipulator>(e => e.FromFactory(() =>
            {
                var dataManipulatorMock = MockRepository.GenerateMock <IDataManipulator>();
                dataManipulatorMock.Expect(m => m.ManipulateData(Arg <ITable> .Is.NotNull, Arg <IEnumerable <IEnumerable <IDataObjectBase> > > .Is.NotNull))
                .Return(new Collection <IEnumerable <IDataObjectBase> >())
                .Repeat.Any();
                dataManipulatorMock.Expect(m => m.FinalizeDataManipulation(Arg <ITable> .Is.NotNull, Arg <IEnumerable <IEnumerable <IDataObjectBase> > > .Is.NotNull))
                .Return(new List <IEnumerable <IDataObjectBase> >())
                .Repeat.Any();
                return(dataManipulatorMock);
            }));

            var dataManipulatorCollectionMock = fixture.CreateMany <IDataManipulator>(3).ToList();
            var containerMock = MockRepository.GenerateMock <IContainer>();

            containerMock.Expect(m => m.ResolveAll <IDataManipulator>())
            .Return(dataManipulatorCollectionMock.ToArray())
            .Repeat.Any();

            var dataManipulators = new DeliveryEngine.Repositories.DataManipulators.DataManipulators(containerMock);

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

            var tableMock = MockRepository.GenerateMock <ITable>();
            var data      = new Collection <IEnumerable <IDataObjectBase> >();

            var result = dataManipulators.ManipulateData(tableMock, data, true);

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

            foreach (var dataManipulator in dataManipulators)
            {
                dataManipulator.AssertWasCalled(m => m.ManipulateData(tableMock, data));
                dataManipulator.AssertWasCalled(m => m.FinalizeDataManipulation(tableMock, data));
            }
        }