示例#1
0
        public void DoCreateDirectory_ExecuteOperation_ImpersonatedUser_IsNotNull_RequiresOverwrite_True_ExecuteOperationWithAuthDirectoryExist_True_ExpectTrue()
        {
            //---------------------------Arrange--------------------------
            var mockActivityIOPath              = new Mock <IActivityIOPath>();
            var mockDev2CRUDOperationTO         = new Mock <IDev2CRUDOperationTO>();
            var mockDev2LogonProvider           = new Mock <IDev2LogonProvider>();
            var mockFileWrapper                 = new Mock <IFile>();
            var mockDirectory                   = new Mock <IDirectory>();
            var mockWindowsImpersonationContext = new Mock <IWindowsImpersonationContext>();

            mockDev2CRUDOperationTO.Setup(o => o.Overwrite).Returns(true);

            mockDirectory.Setup(o => o.Exists(It.IsAny <string>())).Returns(true);
            mockActivityIOPath.Setup(o => o.Path).Returns("testPath");

            var doCreateDirectory = new DoCreateDirectory(mockActivityIOPath.Object, mockDev2CRUDOperationTO.Object, mockDev2LogonProvider.Object, mockFileWrapper.Object, mockDirectory.Object, (arg1, arg2) => mockWindowsImpersonationContext.Object);
            //---------------------------Act------------------------------
            var isExecuteOperation = doCreateDirectory.ExecuteOperation();

            //---------------------------Assert---------------------------
            mockDirectory.VerifyAll();
            mockActivityIOPath.VerifyAll();
            mockDev2CRUDOperationTO.VerifyAll();
            Assert.IsTrue(isExecuteOperation);
        }
示例#2
0
        public static void HandleCreateDirectory(DoCreateDirectory command, Client client)
        {
            bool   isError = false;
            string message = null;

            Action <string> onError = (msg) =>
            {
                isError = true;
                message = msg;
            };

            try
            {
                Directory.CreateDirectory(Path.Combine(command.Path, command.Name));

                HandleGetDirectory(
                    new Packets.ServerPackets.GetDirectory(Path.GetDirectoryName(command.Path),
                                                           InformationDetail.Standard), client);
            }
            catch (UnauthorizedAccessException)
            {
                onError("CreateDirectory No permission");
            }
            catch (ArgumentNullException)
            {
                onError("CreateDirectory Path cannot be empty");
            }
            catch (PathTooLongException)
            {
                onError("CreateDirectory Path too long");
            }
            catch (DirectoryNotFoundException)
            {
                onError("CreateDirectory Path is invalid");
            }
            catch (NotSupportedException)
            {
                onError("CreateDirectory Path has invalid characters");
            }
            catch (ArgumentException)
            {
                onError("CreateDirectory Path is invalid");
            }
            catch (IOException)
            {
                onError("CreateDirectory I/O error");
            }
            finally
            {
                if (isError && !string.IsNullOrEmpty(message))
                {
                    new Packets.ClientPackets.SetStatusFileManager(message, false).Execute(client);
                }
            }
        }
示例#3
0
        public void DoCreateDirectory_ExecuteOperation_ImpersonatedUser_IsNull_ExpectArgumentNullException()
        {
            //---------------------------Arrange--------------------------
            var mockActivityIOPath      = new Mock <IActivityIOPath>();
            var mockDev2CRUDOperationTO = new Mock <IDev2CRUDOperationTO>();

            mockDev2CRUDOperationTO.Setup(o => o.Overwrite).Returns(true);

            var doCreateDirectory = new DoCreateDirectory(mockActivityIOPath.Object, mockDev2CRUDOperationTO.Object);

            //---------------------------Act------------------------------
            //---------------------------Assert---------------------------
            mockDev2CRUDOperationTO.VerifyAll();
            Assert.ThrowsException <ArgumentNullException>(() => doCreateDirectory.ExecuteOperation());
        }
示例#4
0
        public void DoCreateDirectory_ExecuteOperation_ImpersonatedUser_IsNull_ExpectTrue()
        {
            //---------------------------Arrange--------------------------
            var mockActivityIOPath      = new Mock <IActivityIOPath>();
            var mockDev2CRUDOperationTO = new Mock <IDev2CRUDOperationTO>();
            var mockDev2LogonProvider   = new Mock <IDev2LogonProvider>();
            var mockFileWrapper         = new Mock <IFile>();
            var mockDirectory           = new Mock <IDirectory>();

            var doCreateDirectory = new DoCreateDirectory(mockActivityIOPath.Object, mockDev2CRUDOperationTO.Object, mockDev2LogonProvider.Object, mockFileWrapper.Object, mockDirectory.Object, (arg1, arg2) => null);
            //---------------------------Act------------------------------
            var isExecuteOperation = doCreateDirectory.ExecuteOperation();

            //---------------------------Assert---------------------------
            Assert.IsTrue(isExecuteOperation);
        }