public void IsValidTest()
        {
            var sut = new FileValidator("docx");

            Assert.IsTrue(sut.IsValid(fullDocxTestFilePath));
            Assert.IsFalse(sut.IsValid(fullJsonTestFilePath));
        }
        public void Validate_When_File_Size_Zero()
        {
            // arrange
            var file = new FormFile(null, 0, 0, "test", "test.pdf");

            // act
            var result = _fileValidator.IsValid(file);

            // assert
            Assert.IsFalse(result);
        }
Exemplo n.º 3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            _executor        = new Executor();
            _env             = new ProcEnvironInfo();
            _defaultCmdPaths = new List <string>();
            _defaultCmdPaths.Add(_env.SysDir.System32);
            _defaultCmdPaths.Add(_env.SysDir.WinDir);

            _configFile = Path.Combine(_env.WorkingDir, CmdConfigFile);
            if (FileValidator.IsValid(_configFile))
            {
                _cmdTable = ObjSerializer.Load <DataTable>(Path.Combine(_env.WorkingDir, CmdConfigFile));
            }
            else
            {
                _cmdTable = new DataTable("CommandTable");
                _cmdTable.Columns.Add("Command");
                _cmdTable.Columns.Add("Parameters");

                object[] itemArray = new object[_cmdTable.Columns.Count];
                itemArray[0] = ExplorerCmd;
                itemArray[1] = ExplorerParam;
                DataRow dtRowTmp = _cmdTable.NewRow();
                dtRowTmp.ItemArray = itemArray;
                _cmdTable.Rows.Add(dtRowTmp);
            }

            FillSettingTable();
        }
Exemplo n.º 4
0
        private bool DoLoad <SettingT>(string filePath, out SettingT obj) where SettingT : new()
        {
            if (FileValidator.IsValid(filePath, 1))
            {
                try
                {
                    obj = ObjSerializer.Load <SettingT>(filePath);
                    return(true);
                }
                catch
                {
                }
            }

            obj = new SettingT();
            return(false);
        }
        public static TicketsTask GetTicketsTask(string[] args)
        {
            var filePath = args[0];

            if (!FileValidator.IsValid(filePath))
            {
                throw new FileNotFoundException($"File '{filePath}' not found");
            }

            var fileManager = new FileManager(filePath);
            var algorithm   = fileManager.ReadText();

            return(new TicketsTask
            {
                Algorithm = algorithm
            });
        }
Exemplo n.º 6
0
        public void IsValid_ReturnsExpected(int?len, string name, bool expected, string expectedMessage)
        {
            byte[] buffer = null;
            if (len.HasValue)
            {
                buffer = new byte[len.Value];
            }

            var result = _validator.IsValid(name, buffer, out var message);

            Assert.Equal(expected, result);
            if (expectedMessage is null)
            {
                Assert.Null(message);
            }
            else
            {
                Assert.Contains(expectedMessage, message);
            }
        }