コード例 #1
0
        public void NewDirectory_InExistingConfigDirectory_IsValid()
        {
            var sut    = new FolderNameValidator(Environment.CurrentDirectory);
            var result = sut.Validate(Guid.NewGuid().ToString()); // Use new GUID as a name for a folder that won't already exist

            Assert.True(result.IsValid);
        }
コード例 #2
0
        public async Task <IActionResult> CreateNewFolder()
        {
            try
            {
                ObjectId userID = ObjectId.Parse(tokenService.GetTokenClaim(
                                                     requestService.GetToken(Request), "ID"));

                NewFolderDto newFolder = await requestService.GetRequestBody <NewFolderDto>(Request)
                                         .ConfigureAwait(false);

                var(result, errorMessage) = new FolderNameValidator(newFolder.FolderName).Validate();
                if (!result)
                {
                    return(new BadSentRequest <string>(errorMessage));
                }

                await folderService.CreateFolder(userID, newFolder.ParentFolderID, newFolder.FolderName)
                .ConfigureAwait(false);

                return(new Ok());
            }
            catch (DatabaseException ex)
            {
                return(new InternalServerError(ex.Message));
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                return(new InternalServerError());
            }
        }
コード例 #3
0
        public void Anything_InANonExistentConfigDirectory_IsValid()
        {
            var nonExistentDirectory = Path.Combine(Environment.CurrentDirectory, Guid.NewGuid().ToString()); // Use new GUID as a name for a folder that won't already exist

            var sut = new FolderNameValidator(nonExistentDirectory);

            var result = sut.Validate(Guid.NewGuid().ToString());

            Assert.True(result.IsValid);
        }
コード例 #4
0
        public void Validate_RecognizesExistingFolderAsInvalid()
        {
            var tempDir = Path.GetFullPath(@".\temp\");

            Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "temp\\testfolder"));

            var validator = new FolderNameValidator(tempDir);

            var result = validator.Validate("testfolder");

            Assert.False(result.IsValid);
            Assert.True(result.Errors.Count == 1);
            Assert.Equal(ValidationErrorType.AlreadyExists, result.Errors.FirstOrDefault()?.ErrorType);
            Assert.Equal(nameof(FolderNameValidator), result.Errors.FirstOrDefault()?.ValidatorName);
        }
コード例 #5
0
        public void ExistingDirectory_InAnExistingConfigDirectory_IsNotValid()
        {
            // Create directory so can be sure it exists
            var existingDir = Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, Guid.NewGuid().ToString()));

            try
            {
                var sut = new FolderNameValidator(Environment.CurrentDirectory);

                var result = sut.Validate(existingDir.Name);

                Assert.False(result.IsValid);
            }
            finally
            {
                existingDir.Delete();
            }
        }