//选中的物体为有效可填入资源 static bool ValidateAsset(string filePath) { foreach (var pair in _dirDic) { string dir = pair.Key; DirConfig config = pair.Value; //判读文件是否有效 if (filePath.StartsWith(dir) && config.rules.Length > 0) { string fileName = Path.GetFileName(filePath); for (int i = 0; i < config.rules.Length; i++) { FileRule rule = config.rules[i]; bool result = true; if (!string.IsNullOrEmpty(rule.filter)) { result &= fileName.Contains(rule.filter); } if (!string.IsNullOrEmpty(rule.ext)) { result &= fileName.EndsWith(rule.ext); } if (result) { return(true); //满足文件规则 } } return(false); //所有的文件规则都不满足 } } return(true);//至此,说明文件是不受规则影响的文件 }
public void Matches_Drive() { var rule = new FileRule(); var drive = new DriveObject(@"C:", null); var result = rule.Matches(drive, null); Assert.AreEqual(false, result); }
public void Matches_Directory() { var rule = new FileRule(); var directory = new DirectoryObject(@"C:\dir", null); var result = rule.Matches(directory, null); Assert.AreEqual(false, result); }
public void Matches_File() { var rule = new FileRule(); var file = new FileObject(@"C:\file", null); var result = rule.Matches(file, null); Assert.AreEqual(true, result); }
public void TestValidateExist(int countIndex, bool existResult, string pattern, bool isRecursive, bool expectedIsValid) { // Arrange: fshMock.Setup(f => f.GetFolders(RootPath, It.IsAny <string>())).Returns(Counts[countIndex]); fshMock.Setup(f => f.Exists(It.IsAny <string>(), It.IsAny <string>())).Returns(existResult); // Act: var rule = new FileRule(pattern, CheckType.MustExist, fshMock.Object); var validationResult = rule.Validate(repositoryInfo); // Assert: fshMock.Verify(f => f.GetFolders(RootPath, It.IsAny <string>()), isRecursive ? Times.Once() : Times.Never()); fshMock.Verify(f => f.Exists(It.IsAny <string>(), It.IsAny <string>()), isRecursive ? (countIndex == 0 ? Times.Never() : Times.AtLeastOnce()) : Times.Once()); Assert.AreEqual(expectedIsValid, validationResult.IsValid); }