From 85c8769631520df26583e763147edfa2595d0295 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Sun, 29 Aug 2021 23:40:04 +0100 Subject: [PATCH] refactor(*): Refactor GetFileRepository to simplify the factory class and handle bad repository types Thanks to the enum it shouldn't be possible for there to be a bad repository type passed as an argument to this method, but this will handle it just in case. --- FileRepository/Factory.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/FileRepository/Factory.cs b/FileRepository/Factory.cs index 6a47560..2d5d4f5 100644 --- a/FileRepository/Factory.cs +++ b/FileRepository/Factory.cs @@ -47,11 +47,26 @@ namespace FileRepository /// Returns an initialised repository. public IFileRepository GetFileRepository(RepositoryType repositoryType) { - throw new NotImplementedException("This section won't work until another method is set up with at least one repository type."); + switch (repositoryType) + { + //case RepositoryType.Disk: + // return new DiskRepo() { }; - //IFileRepository fileRepository = // Here we need to get the specific class of repository based on the RepositoryType enum. + //case RepositoryType.MongoDb: + // break; - //return fileRepository; + //case RepositoryType.S3: + // break; + + //case RepositoryType.Sftp: + // break; + + //case RepositoryType.Sql: + // break; + + default: + throw new ArgumentException($"{Enum.GetName(typeof(RepositoryType), value: repositoryType)} is not a valid repository type."); + } } } }