[Test] //order verification
        public void ShouldCopyDataFromSourceToDestinationMultipleTimes()
        {
            //GIVEN
            var copyOperation = new CopyOperation();
            var destination   = Substitute.For <IDataDestination>();
            var source        = Substitute.For <IDataSource>();
            var data1         = Any.Instance <Data>();
            var data2         = Any.Instance <Data>();


            source.RetrieveData().Returns(data1, data2);

            //WHEN
            copyOperation.ApplyTo(source, destination);
            copyOperation.ApplyTo(source, destination);

            //THEN
            Received.InOrder(() =>
            {
                destination.Save(data1);
                destination.Save(data2);
            });
        }
        public void ShouldCopyDataFromSourceToDestination()
        {
            //GIVEN
            var copyOperation = new CopyOperation();
            var destination   = Substitute.For <IDataDestination>();
            var source        = Substitute.For <IDataSource>();
            var data          = Any.Instance <Data>();

            source.RetrieveData().Returns(data);

            //WHEN
            copyOperation.ApplyTo(source, destination);

            //THEN
            destination.Received(1).Save(data);
            //destination.Received().Save(data);
        }
Exemplo n.º 3
0
        public void ShouldThrowExceptionWhenSavingToDestinationThrowsException()
        {
            //GIVEN
            var copyOperation = new CopyOperation();
            var destination   = Substitute.For <IDataDestination>();
            var source        = Substitute.For <IDataSource>();
            var data          = Any.Instance <Data>();
            var exception     = Any.Exception();

            source.RetrieveData().Returns(data);
            destination.When(d => d.Save(data)).Throw(exception);

            //WHEN - THEN
            var thrownException = Assert.Throws <Exception>(
                () => copyOperation.ApplyTo(source, destination));

            Assert.AreEqual(exception, thrownException);
        }
Exemplo n.º 4
0
        public void ShouldThrowExceptionWhenReadingFromSourceThrowsException()
        {
            //GIVEN
            var copyOperation = new CopyOperation();
            var destination   = Substitute.For <IDataDestination>();
            var source        = Substitute.For <IDataSource>();
            var exception     = Any.Exception();

            source.RetrieveData().Throws(exception);

            //WHEN - THEN
            var e = Assert.Throws <Exception>(
                () => copyOperation.ApplyTo(source, destination));

            Assert.AreEqual(exception, e);
            //never verification
            destination.DidNotReceive().Save(Arg.Any <Data>());
        }