public void ExtractFile_GivenGivenValidArgs_ShouldNotThrowExc() { //---------------Set up test pack------------------- var tempFileName = Path.GetTempFileName(); var tempPath = Path.GetDirectoryName(tempFileName); Dev2UnZipOperationTO operationTO = new Dev2UnZipOperationTO("Password", false); ZipFile file = new ZipFile(); file.AddFile(tempFileName); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { Util.CommonDataUtils commonDataUtils = new Util.CommonDataUtils(); file.Save(tempFileName); commonDataUtils.ExtractFile(operationTO, file, tempPath); } catch (Exception ex) { Assert.AreEqual("", ex.Message); } finally { File.Delete(tempFileName); } //---------------Test Result ----------------------- }
public string UnZip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2UnZipOperationTO args) { Source = src; Destination = dst; Dev2UnZipOperationTO = args; return("Successful"); }
public void ActivityIOBrokerValidatorDriver_ValidateUnzipSourceDestinationFileOperation_DestinationNotADirectory() { //---------------Set up test pack------------------- var driver = new ActivityIOBrokerValidatorDriver(); var srcPath = Path.GetTempPath(); var src = new Mock <IActivityIOOperationsEndPoint>(); src.Setup(point => point.IOPath.Path).Returns(""); src.Setup(point => point.PathSeperator()).Returns(","); var dst = new Mock <IActivityIOOperationsEndPoint>(); dst.SetupProperty(point => point.IOPath.Path); dst.Setup(point => point.PathSeperator()).Returns(","); var args = new Dev2UnZipOperationTO("password", false); Func <string> performAfterValidation = () => "Success"; src.Setup(point => point.IOPath.Path).Returns(srcPath); dst.Setup(point => point.IOPath.Path).Returns(""); var hadException = false; try { driver.ValidateUnzipSourceDestinationFileOperation(src.Object, dst.Object, args, performAfterValidation); } catch (Exception ex1) { hadException = true; Assert.AreEqual(ErrorResource.DestinationMustBeADirectory, ex1.Message); } Assert.IsTrue(hadException); }
protected override string ExecuteBroker(IActivityOperationsBroker broker, IActivityIOOperationsEndPoint scrEndPoint, IActivityIOOperationsEndPoint dstEndPoint) { Dev2UnZipOperationTO zipTo = ActivityIOFactory.CreateUnzipTO(ColItr.FetchNextValue(_archPassItr), Overwrite); return(broker.UnZip(scrEndPoint, dstEndPoint, zipTo)); }
public void ActivityIOBrokerValidatorDriver_ValidateUnzipSourceDestinationFileOperation_DestinationDirectoryExists() { //---------------Set up test pack------------------- var driver = new ActivityIOBrokerValidatorDriver(); var srcPath = Path.GetTempPath(); var src = new Mock <IActivityIOOperationsEndPoint>(); src.Setup(point => point.IOPath.Path).Returns(""); src.Setup(point => point.PathSeperator()).Returns(","); var dst = new Mock <IActivityIOOperationsEndPoint>(); dst.SetupProperty(point => point.IOPath.Path); dst.Setup(point => point.PathSeperator()).Returns(","); var args = new Dev2UnZipOperationTO("password", false); Func <string> performAfterValidation = () => "Success"; src.Setup(point => point.IOPath.Path).Returns(srcPath); dst.Setup(point => point.IOPath.Path).Returns(""); dst.Setup(point => point.PathIs(It.IsAny <IActivityIOPath>())).Returns(enPathType.Directory); src.Setup(point => point.PathIs(It.IsAny <IActivityIOPath>())).Returns(enPathType.Directory); src.Setup(point => point.PathIs(It.IsAny <IActivityIOPath>())).Returns(enPathType.File); dst.Setup(point => point.PathExist(It.IsAny <IActivityIOPath>())).Returns(true); var hadException = false; try { driver.ValidateUnzipSourceDestinationFileOperation(src.Object, dst.Object, args, performAfterValidation); } catch (Exception ex3) { hadException = true; Assert.AreEqual(ErrorResource.DestinationDirectoryExist, ex3.Message); args = new Dev2UnZipOperationTO("pa", true); var invoke = driver.ValidateUnzipSourceDestinationFileOperation(src.Object, dst.Object, args, performAfterValidation); Assert.AreEqual(performAfterValidation.Invoke(), invoke.ToString()); } Assert.IsTrue(hadException); }
public void ValidateUnzipSourceDestinationFileOperation_GivenPathNotFile_ShouldThrowValidExc() { //---------------Set up test pack------------------- var activityOperationsBroker = CreateBroker(); var srcPath = Path.GetTempPath(); var dstPath = Path.GetTempPath(); var src = new Mock <IActivityIOOperationsEndPoint>(); src.Setup(point => point.IOPath.Path).Returns(""); src.Setup(point => point.PathSeperator()).Returns(","); var dst = new Mock <IActivityIOOperationsEndPoint>(); dst.SetupProperty(point => point.IOPath.Path); dst.Setup(point => point.PathSeperator()).Returns(","); var args = new Dev2UnZipOperationTO("password", false); Func <string> performAfterValidation = () => "Success"; PrivateObject privateObject = new PrivateObject(activityOperationsBroker); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { privateObject.Invoke("ValidateUnzipSourceDestinationFileOperation", src.Object, dst.Object, args, performAfterValidation); } catch (Exception ex) { Assert.AreEqual(ErrorResource.SourceCannotBeAnEmptyString, ex.Message); src.Setup(point => point.IOPath.Path).Returns(srcPath); dst.Setup(point => point.IOPath.Path).Returns(""); try { privateObject.Invoke("ValidateUnzipSourceDestinationFileOperation", src.Object, dst.Object, args, performAfterValidation); } catch (Exception ex1) { Assert.AreEqual(ErrorResource.DestinationMustBeADirectory, ex1.Message); dst.Setup(point => point.PathIs(It.IsAny <IActivityIOPath>())).Returns(enPathType.Directory); src.Setup(point => point.PathIs(It.IsAny <IActivityIOPath>())).Returns(enPathType.Directory); try { privateObject.Invoke("ValidateUnzipSourceDestinationFileOperation", src.Object, dst.Object, args, performAfterValidation); } catch (Exception ex2) { Assert.AreEqual(ErrorResource.SourceMustBeAFile, ex2.Message); src.Setup(point => point.PathIs(It.IsAny <IActivityIOPath>())).Returns(enPathType.File); dst.Setup(point => point.PathExist(It.IsAny <IActivityIOPath>())).Returns(true); try { privateObject.Invoke("ValidateUnzipSourceDestinationFileOperation", src.Object, dst.Object, args, performAfterValidation); } catch (Exception ex3) { Assert.AreEqual(ErrorResource.DestinationDirectoryExist, ex3.Message); args = new Dev2UnZipOperationTO("pa", true); var invoke = privateObject.Invoke("ValidateUnzipSourceDestinationFileOperation", src.Object, dst.Object, args, performAfterValidation); Assert.AreEqual(performAfterValidation.Invoke(), invoke.ToString()); } } } } //---------------Test Result ----------------------- }