Exemple #1
0
        private static CustomizationDefinition CreateCustomization(
            InfoDictionary <DownloadableContentDefinition> downloadableContents,
            KeyValuePair <string, Raw.CustomizationDefinition> kv)
        {
            var raw = kv.Value;

            DownloadableContentDefinition content = null;

            if (string.IsNullOrEmpty(raw.DLC) == false)
            {
                if (downloadableContents.TryGetValue(raw.DLC, out content) == false)
                {
                    throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLC);
                }
            }

            return(new CustomizationDefinition()
            {
                ResourcePath = kv.Key,
                Name = raw.Name,
                Type = raw.Type,
                Usage = raw.Usage,
                DataName = raw.DataName,
                PrimarySort = raw.PrimarySort,
                SecondarySort = raw.SecondarySort,
                DLC = content,
            });
        }
        public static void UseGlobalExceptionHandler(this IApplicationBuilder app)
        {
            app.UseExceptionHandler(error =>
            {
                error.Run(async context =>
                {
                    var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>();
                    var exception = exceptionHandlerFeature.Error;
                    var log       = app.ApplicationServices.GetService(typeof(ILogService)) as ILogService;

                    var statusCode = exception switch
                    {
                        ResourceNotFoundException _ => (int)HttpStatusCode.NotFound,
                        ModelFormatException _ => (int)HttpStatusCode.PreconditionFailed,
                        ArgumentOutOfRangeException _ => (int)HttpStatusCode.BadRequest,
                        _ => (int)HttpStatusCode.InternalServerError
                    };

                    context.Response.ContentType = "application/json";
                    context.Response.StatusCode  = statusCode;

                    log.LogToDatabase(new ExceptionModel
                    {
                        StatusCode       = statusCode,
                        ExceptionMessage = exception.Message,
                        StackTrace       = exception.StackTrace
                    });
                    await context.Response.WriteAsync(new ExceptionModel
                    {
                        StatusCode       = statusCode,
                        ExceptionMessage = exception.Message,
                    }.ToString());
                });
            });
        }
Exemple #3
0
        private static TravelStationDefinition CreateFastTravelStation(
            InfoDictionary <DownloadableContentDefinition> downloadableContents,
            string path,
            Raw.FastTravelStationDefinition raw)
        {
            DownloadableContentDefinition dlcExpansion = null;

            if (string.IsNullOrEmpty(raw.DLCExpansion) == false)
            {
                if (downloadableContents.TryGetValue(raw.DLCExpansion, out dlcExpansion) == false)
                {
                    throw ResourceNotFoundException.Create("downloadable content", raw.DLCExpansion);
                }
            }
            return(new FastTravelStationDefinition()
            {
                ResourcePath = path,
                ResourceName = raw.ResourceName,
                LevelName = raw.LevelName,
                DLCExpansion = dlcExpansion,
                StationDisplayName = raw.StationDisplayName,
                MissionDependencies = CreateMissionStatusData(raw.MissionDependencies),
                InitiallyActive = raw.InitiallyActive,
                SendOnly = raw.SendOnly,
                Description = raw.Description,
                Sign = raw.Sign,
                InaccessibleObjective = raw.InaccessibleObjective,
                AccessibleObjective = raw.AccessibleObjective,
            });
        }
Exemple #4
0
        public static InfoDictionary <WeaponBalanceDefinition> Load(InfoDictionary <WeaponTypeDefinition> weaponTypes)
        {
            try
            {
                var rawPartLists = LoaderHelper.DeserializeDump <Dictionary <string, Raw.WeaponBalancePartCollection> >(
                    "Weapon Balance Part Lists");
                var partLists = new InfoDictionary <WeaponBalancePartCollection>(
                    rawPartLists.ToDictionary(
                        kv => kv.Key,
                        kv => CreateWeaponBalancePartCollection(weaponTypes, kv)));

                var raws = LoaderHelper.DeserializeDump <Dictionary <string, Raw.WeaponBalanceDefinition> >(
                    "Weapon Balance");
                var balances = new InfoDictionary <WeaponBalanceDefinition>(
                    raws.ToDictionary(
                        kv => kv.Key,
                        kv => CreateWeaponBalance(weaponTypes, kv, partLists)));

                foreach (var kv in raws.Where(kv => string.IsNullOrEmpty(kv.Value.Base) == false))
                {
                    if (balances.TryGetValue(kv.Value.Base, out var baseBalance) == false)
                    {
                        throw ResourceNotFoundException.Create("weapon balance", kv.Value.Base);
                    }
                    balances[kv.Key].Base = baseBalance;
                }

                return(balances);
            }
            catch (Exception e)
            {
                throw new InfoLoadException("failed to load weapon balance", e);
            }
        }
        private static ItemBalancePartCollection CreateItemBalancePartCollection(
            InfoDictionary <ItemDefinition> items,
            KeyValuePair <string, Raw.ItemBalancePartCollection> kv)
        {
            var raw = kv.Value;

            ItemDefinition type = null;

            if (string.IsNullOrEmpty(raw.Item) == false)
            {
                if (items.TryGetValue(raw.Item, out type) == false)
                {
                    throw ResourceNotFoundException.Create("item type", raw.Item);
                }
            }

            return(new ItemBalancePartCollection()
            {
                Item = type,
                Mode = raw.Mode,
                AlphaParts = raw.AlphaParts,
                BetaParts = raw.BetaParts,
                GammaParts = raw.GammaParts,
                DeltaParts = raw.DeltaParts,
                EpsilonParts = raw.EpsilonParts,
                ZetaParts = raw.ZetaParts,
                EtaParts = raw.EtaParts,
                ThetaParts = raw.ThetaParts,
                MaterialParts = raw.MaterialParts,
            });
        }
        private static DownloadableContentDefinition CreateDownloadableContent(
            InfoDictionary <DownloadablePackageDefinition> packages,
            KeyValuePair <string, Raw.DownloadableContentDefinition> kv)
        {
            var raw = kv.Value;

            DownloadablePackageDefinition package = null;

            if (string.IsNullOrEmpty(raw.Package) == false)
            {
                if (packages.TryGetValue(raw.Package, out package) == false)
                {
                    throw ResourceNotFoundException.Create("downloadable package", kv.Value.Package);
                }
            }

            return(new DownloadableContentDefinition()
            {
                ResourcePath = kv.Key,
                Id = raw.Id,
                Name = raw.Name,
                Package = package,
                Type = raw.Type,
            });
        }
Exemple #7
0
        private static CustomizationDefinition GetCustomizationDefinition(
            InfoDictionary <DownloadableContentDefinition> downloadableContents,
            KeyValuePair <string, Raw.CustomizationDefinition> kv)
        {
            DownloadableContentDefinition content = null;

            if (string.IsNullOrEmpty(kv.Value.DLC) == false)
            {
                if (downloadableContents.ContainsKey(kv.Value.DLC) == false)
                {
                    throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLC);
                }
                content = downloadableContents[kv.Value.DLC];
            }

            return(new CustomizationDefinition()
            {
                ResourcePath = kv.Key,
                Name = kv.Value.Name,
                Type = kv.Value.Type,
                Usage = kv.Value.Usage,
                DataName = kv.Value.DataName,
                PrimarySort = kv.Value.PrimarySort,
                SecondarySort = kv.Value.SecondarySort,
                DLC = content,
            });
        }
Exemple #8
0
        public static void ConfigureExceptionHandler(this IApplicationBuilder app)
        {
            app.UseExceptionHandler(error =>
            {
                error.Run(async context =>
                {
                    var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>();
                    var exception = exceptionHandlerFeature.Error;

                    var statusCode = exception switch
                    {
                        ResourceNotFoundException _ => (int)HttpStatusCode.NotFound,
                        ModelFormatException _ => (int)HttpStatusCode.PreconditionFailed,
                        ResourceAlreadyExistsException _ => (int)HttpStatusCode.Conflict,
                        InvalidLoginException _ => (int)HttpStatusCode.Unauthorized,
                        UnauthorizedException _ => (int)HttpStatusCode.Unauthorized,
                        InvalidProductIdentifierException _ => (int)HttpStatusCode.PreconditionFailed,
                        _ => (int)HttpStatusCode.InternalServerError
                    };

                    context.Response.ContentType = "application/json";
                    context.Response.StatusCode  = statusCode;

                    await context.Response.WriteAsync(new ExceptionModel
                    {
                        StatusCode = statusCode,
                        Message    = exception.Message
                    }.ToString());
                });
            });
        }
Exemple #9
0
        private static WeaponBalancePartCollection CreateWeaponBalancePartCollection(
            InfoDictionary <WeaponTypeDefinition> weaponTypes,
            KeyValuePair <string, Raw.WeaponBalancePartCollection> kv)
        {
            var raw = kv.Value;

            WeaponTypeDefinition type = null;

            if (string.IsNullOrEmpty(raw.WeaponType) == false)
            {
                if (weaponTypes.TryGetValue(raw.WeaponType, out type) == false)
                {
                    throw ResourceNotFoundException.Create("weapon type", raw.WeaponType);
                }
            }

            return(new WeaponBalancePartCollection()
            {
                WeaponType = type,
                Mode = raw.Mode,
                BodyParts = raw.BodyParts,
                GripParts = raw.GripParts,
                BarrelParts = raw.BarrelParts,
                SightParts = raw.SightParts,
                StockParts = raw.StockParts,
                ElementalParts = raw.ElementalParts,
                Accessory1Parts = raw.Accessory1Parts,
                Accessory2Parts = raw.Accessory2Parts,
                MaterialParts = raw.MaterialParts,
            });
        }
        private static WeaponBalancePartCollection GetWeaponBalancePartCollection(
            InfoDictionary <WeaponTypeDefinition> weaponTypes, Raw.WeaponBalancePartCollection raw)
        {
            if (raw == null)
            {
                return(null);
            }

            WeaponTypeDefinition type = null;

            if (string.IsNullOrEmpty(raw.Type) == false)
            {
                if (weaponTypes.ContainsKey(raw.Type) == false)
                {
                    throw ResourceNotFoundException.Create("weapon type", raw.Type);
                }

                type = weaponTypes[raw.Type];
            }

            return(new WeaponBalancePartCollection()
            {
                Type = type,
                Mode = raw.Mode,
                BodyParts = raw.BodyParts,
                GripParts = raw.GripParts,
                BarrelParts = raw.BarrelParts,
                SightParts = raw.SightParts,
                StockParts = raw.StockParts,
                ElementalParts = raw.ElementalParts,
                Accessory1Parts = raw.Accessory1Parts,
                Accessory2Parts = raw.Accessory2Parts,
                MaterialParts = raw.MaterialParts,
            });
        }
Exemple #11
0
        private static TravelStationDefinition GetTravelStationDefinition(
            InfoDictionary <DownloadableContentDefinition> downloadableContents,
            KeyValuePair <string, Raw.TravelStationDefinition> kv)
        {
            DownloadableContentDefinition dlcExpansion = null;

            if (string.IsNullOrEmpty(kv.Value.DLCExpansion) == false)
            {
                if (downloadableContents.ContainsKey(kv.Value.DLCExpansion) == false)
                {
                    throw ResourceNotFoundException.Create("downloadable content", kv.Value.DLCExpansion);
                }
                dlcExpansion = downloadableContents[kv.Value.DLCExpansion];
            }

            if (kv.Value is Raw.FastTravelStationDefinition)
            {
                return(GetFastTravelStationDefinition(dlcExpansion, kv));
            }

            if (kv.Value is Raw.LevelTravelStationDefinition)
            {
                return(GetLevelTravelStationDefinition(dlcExpansion, kv));
            }

            throw new InvalidOperationException();
        }
        public async Task Search_NotFoundArtifact_ResourceNotFoundException()
        {
            // arrange
            ArtifactBasicDetails artifactBasicDetails = null;

            _sqlArtifactRepositoryMock.Setup(q => q.GetArtifactBasicDetails(ScopeId, UserId, null)).ReturnsAsync(artifactBasicDetails);
            _searchEngineRepositoryMock.Setup(q => q.GetCollectionContentSearchArtifactResults(ScopeId, _pagination, true, UserId, null)).ReturnsAsync(_searchArtifactsResult);
            var errorMessage   = I18NHelper.FormatInvariant(ErrorMessages.ArtifactNotFound, ScopeId);
            var excectedResult = new ResourceNotFoundException(errorMessage, ErrorCodes.ResourceNotFound);
            ResourceNotFoundException exception = null;

            // act
            try
            {
                await _searchEngineService.Search(ScopeId, _pagination, ScopeType.Contents, true, UserId);
            }
            catch (ResourceNotFoundException ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNotNull(exception);
            Assert.AreEqual(excectedResult.Message, exception.Message);
        }
Exemple #13
0
        private static PlayerClassDefinition CreatePlayerClass(
            InfoDictionary <DownloadableContentDefinition> downloadableContents,
            KeyValuePair <string, Raw.PlayerClassDefinition> kv)
        {
            var raw = kv.Value;

            DownloadableContentDefinition downloadableContent = null;

            if (string.IsNullOrEmpty(raw.DLC) == false)
            {
                if (downloadableContents.TryGetValue(kv.Value.DLC, out downloadableContent) == false)
                {
                    throw ResourceNotFoundException.Create("downloadable content", raw.DLC);
                }
            }

            return(new PlayerClassDefinition()
            {
                ResourcePath = kv.Key,
                Name = raw.Name,
                Class = raw.Class,
                SortOrder = raw.SortOrder,
                DLC = downloadableContent,
            });
        }
Exemple #14
0
        protected override async Task <TaskDTO> InternalExecute(GetTaskQuery query)
        {
            try
            {
                var uri = UriFactory.CreateDocumentUri(db, collection, query.ListId);

                var document = await documentClient.ReadDocumentAsync <ListDTO>(uri, new RequestOptions
                {
                    PartitionKey = new PartitionKey(query.ListId)
                });

                var task = document.Document.Tasks.FirstOrDefault(t => t.Id == query.TaskId);

                if (task == null)
                {
                    throw ResourceNotFoundException.FromResourceId(query.TaskId);
                }

                return(task);
            }
            catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                throw ResourceNotFoundException.FromResourceId(query.ListId);
            }
        }
Exemple #15
0
        private static ItemBalancePartCollection GetItemBalancePartCollection(
            InfoDictionary <ItemTypeDefinition> itemTypes, Raw.ItemBalancePartCollection raw)
        {
            if (raw == null)
            {
                return(null);
            }

            ItemTypeDefinition type = null;

            if (string.IsNullOrEmpty(raw.Type) == false)
            {
                if (itemTypes.ContainsKey(raw.Type) == false)
                {
                    throw ResourceNotFoundException.Create("item type", raw.Type);
                }

                type = itemTypes[raw.Type];
            }

            return(new ItemBalancePartCollection()
            {
                Type = type,
                Mode = raw.Mode,
                AlphaParts = raw.AlphaParts,
                BetaParts = raw.BetaParts,
                GammaParts = raw.GammaParts,
                DeltaParts = raw.DeltaParts,
                EpsilonParts = raw.EpsilonParts,
                ZetaParts = raw.ZetaParts,
                EtaParts = raw.EtaParts,
                ThetaParts = raw.ThetaParts,
                MaterialParts = raw.MaterialParts,
            });
        }
Exemple #16
0
        public void TestsConstructorWithAMessageAndException()
        {
            Exception innerException            = new Exception();
            ResourceNotFoundException exception = new ResourceNotFoundException("message", innerException);

            Assert.AreSame("message", exception.Message);
            Assert.AreSame(innerException, exception.InnerException);
        }
        public void Constructor_ForInvoked_SetsResourceName( )
        {
            var sut = new ResourceNotFoundException(ResourceName,
                                                    Message);

            sut.ResourceName
            .Should( )
            .Be(ResourceName);
        }
        public void ResourceNotFoundExceptionInitTest()
        {
            string message = string.Empty;

            ResourceNotFoundException exception = new ResourceNotFoundException(message);

            message   = "ResourceNotFoundException";
            exception = new ResourceNotFoundException(message);
        }
Exemple #19
0
        public void TestsConstructorWithAMessageAndUri()
        {
            Uri uri = new Uri("http://www.microsoft.com");

            ResourceNotFoundException exception = new ResourceNotFoundException("message", uri);

            Assert.AreSame("message", exception.Message);
            Assert.AreSame(uri, exception.Uri);
        }
        public void CreateFromEntity_ExpectedMessage_Ok()
        {
            const long entityId = 1;
            ResourceNotFoundException exception = ResourceNotFoundException.CreateFromEntity <AwesomeEntity>(entityId);

            Assert.Equal(
                $"Did not find any {typeof(AwesomeEntity).Name} by id={entityId}",
                exception.Message);
        }
        public void ResourceNotFoundExceptionInitTest()
        {
            string message = string.Empty;

            ResourceNotFoundException exception = new ResourceNotFoundException(message);

            message = "ResourceNotFoundException";
            exception = new ResourceNotFoundException(message);
        }
Exemple #22
0
        public async Task RemoveInactiveUserFromDatabaseAsync(long id)
        {
            User entity = await Context.Users
                          .FirstOrDefaultAsync(x => x.DeletedAt != null && x.Id == id)
                          ?? throw ResourceNotFoundException.CreateFromEntity <User>(id);

            Context.Remove(entity);

            await Context.SaveChangesAsync();
        }
Exemple #23
0
 public ExceptionResponse Map(Exception ex)
 {
     return(ex switch
     {
         EmailAlreadyInUseException emailAlreadyInUseException => new ExceptionResponse("email_in_use", ex.Message, HttpStatusCode.BadRequest),
         InvalidCredentialsException invalidCredentialsException => new ExceptionResponse("invalid_credentials", ex.Message, HttpStatusCode.BadRequest),
         InvalidEmailException invalidEmailException => new ExceptionResponse("invalid_email", ex.Message, HttpStatusCode.BadRequest),
         ResourceNotFoundException resourceNotFoundException => new ExceptionResponse("not_found", ex.Message, HttpStatusCode.NotFound),
         NameAlreadyExistException nameAlreadyExistException => new ExceptionResponse("name_in_use", ex.Message, HttpStatusCode.BadRequest),
         _ => null
     });
        public async Task <PipelineResponse> GetAsync(string id)
        {
            var pipeline = await _context.Pipelines.ByIdOrNullAsync(id)
                           ?? throw ResourceNotFoundException.FromEntity <Pipeline>(id);

            var tasks = await _context.Tasks
                        .Find(x => x.PipelineId == pipeline.Id)
                        .ToListAsync();

            return(new PipelineResponse(pipeline, tasks));
        }
        public async Task Returns404WhenCatching()
        {
            ResourceNotFoundException expectedException = new ResourceNotFoundException("test");

            _getWorkOrderUseCase.Setup(uc => uc.Execute(It.IsAny <int>())).ThrowsAsync(expectedException);

            var result = await _classUnderTest.Get(1);

            GetStatusCode(result).Should().Be(404);
            GetResultData <string>(result).Should().Be(expectedException.Message);
        }
        public void Return_the_original_exception_when_error_is_unknown()
        {
            // Arrange
            var exception = new ResourceNotFoundException("random_error");
            var builder = new ResourceNotFoundExceptionExtensions.Builder();

            // Act
            var result = builder.Build(exception);

            // Assert
            result.ShouldBe(exception);
        }
Exemple #27
0
 private static List <string> GetPartList(string path, Dictionary <string, List <string> > partLists)
 {
     if (path == null)
     {
         return(null);
     }
     if (partLists.TryGetValue(path, out var partList) == true)
     {
         return(partList);
     }
     throw ResourceNotFoundException.Create("item part list", path);
 }
 private static ItemDefinition GetItem(InfoDictionary <ItemDefinition> items, string itemPath)
 {
     if (string.IsNullOrEmpty(itemPath) == true)
     {
         return(null);
     }
     if (items.TryGetValue(itemPath, out var item) == true)
     {
         return(item);
     }
     throw ResourceNotFoundException.Create("item", itemPath);
 }
Exemple #29
0
 private static WeaponTypeDefinition GetWeaponType(InfoDictionary <WeaponTypeDefinition> types, string path)
 {
     if (string.IsNullOrEmpty(path) == true)
     {
         return(null);
     }
     if (types.TryGetValue(path, out var type) == true)
     {
         return(type);
     }
     throw ResourceNotFoundException.Create("weapon type", path);
 }
        public override AmazonServiceException UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
        {
            ErrorResponse errorResponse = JsonErrorResponseUnmarshaller.GetInstance().Unmarshall(context);

            if (errorResponse.Code != null && errorResponse.Code.Equals("ResourceNotFoundException"))
            {
                ResourceNotFoundException ex = new ResourceNotFoundException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);

                return(ex);
            }

            return(new AmazonOpsWorksException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode));
        }
Exemple #31
0
        public void LoadSet_NotExistedFile_ReturnsFalseResult(string filePath)
        {
            // Arrange
            var fileValidator = new FileValidator(new ValidationData());
            var setService    = new SetService(fileValidator);
            var fileSource    = new EmbeddedSource(filePath, Assembly.GetExecutingAssembly());

            // Act
            void action() => setService.Load(fileSource);

            // Assert
            ResourceNotFoundException ex = Assert.Throws <ResourceNotFoundException>(action);
        }
        public void Account_not_found()
        {
            // Arrange
            var exception = new ResourceNotFoundException(ErrorCode.AccountNotFound);
            var builder = new Builder {AccountName = "acme"};

            // Act
            var result = builder.Build(exception) as AccountNotFoundException;

            // Assert
            result.ShouldNotBe(null);
            result.AccountName.ShouldBe("acme");
        }
        public void App_not_found()
        {
            // Arrange
            var exception = new ResourceNotFoundException(ErrorCode.AppVersionNotFound);

            // Act
            var result = exception.WithApp("acme.vanilla", "1.2.3") as AppVersionNotFoundException;

            // Assert
            result.ShouldNotBe(null);
            result.Vendor.ShouldBe("acme");
            result.App.ShouldBe("vanilla");
            result.Version.ShouldBe("1.2.3");
        }
        public void Sandboxed_app_not_found()
        {
            // Arrange
            var exception = new ResourceNotFoundException(ErrorCode.SandboxedAppNotFound);

            // Act
            var result = exception.WithSandbox("acme", "cool", "vanilla") as SandboxedAppNotFoundException;

            // Assert
            result.ShouldNotBe(null);
            result.Sandbox.ShouldBe("cool");
            result.Vendor.ShouldBe("acme");
            result.App.ShouldBe("vanilla");
        }
Exemple #35
0
        private static ItemTypeDefinition GetItemType(InfoDictionary <ItemTypeDefinition> itemTypes, string type)
        {
            if (string.IsNullOrEmpty(type) == true)
            {
                return(null);
            }

            if (itemTypes.ContainsKey(type) == false)
            {
                throw ResourceNotFoundException.Create("item type", type);
            }

            return(itemTypes[type]);
        }
        public void Sandbox_file_not_found()
        {
            // Arrange
            var exception = new ResourceNotFoundException(ErrorCode.FileNotFound);

            // Act
            var result =
                exception.WithSandbox("acme", "cool", "vanilla", "front", "some.file") as SandboxFileNotFoundException;

            // Assert
            result.ShouldNotBe(null);
            result.Sandbox.ShouldBe("cool");
            result.Vendor.ShouldBe("acme");
            result.App.ShouldBe("vanilla");
            result.Path.ShouldBe("some.file");
        }
        public void Workspace_metadata_not_found()
        {
            // Arrange
            var exception = new ResourceNotFoundException(ErrorCode.WorkspaceMetadataNotFound);
            var builder = new Builder
            {
                AccountName = "acme",
                Workspace = "master"
            };

            // Act
            var result = builder.Build(exception) as WorkspaceMetadataNotFoundException;

            // Assert
            result.ShouldNotBe(null);
            result.AccountName.ShouldBe("acme");
            result.Workspace.ShouldBe("master");
        }
            public ResourceNotFoundException Build(ResourceNotFoundException parent)
            {
                switch (parent.Error.Code)
                {
                    case ErrorHandling.ErrorCode.AccountNotFound:
                        return new AccountNotFoundException(_accountName);

                    case ErrorHandling.ErrorCode.WorkspaceNotFound:
                        return new WorkspaceNotFoundException(_accountName, _workspace);

                    case ErrorHandling.ErrorCode.WorkspaceMetadataNotFound:
                        return new WorkspaceMetadataNotFoundException(_accountName, _workspace);

                    case ErrorHandling.ErrorCode.FileNotFound:
                        return new WorkspaceFileNotFoundException(_accountName, _workspace, _bucket, _path);

                    default:
                        return parent;
                }
            }
        public void File_not_found()
        {
            // Arrange
            var exception = new ResourceNotFoundException(ErrorCode.FileNotFound);
            var builder = new Builder
            {
                AccountName = "acme",
                Workspace = "master",
                Path = "some.file"
            };

            // Act
            var result = builder.Build(exception) as FileNotFoundException;

            // Assert
            result.ShouldNotBe(null);
            result.AccountName.ShouldBe("acme");
            result.Workspace.ShouldBe("master");
            result.Path.ShouldBe("some.file");
        }
            public ResourceNotFoundException Build(ResourceNotFoundException parent)
            {
                switch (parent.Error.Code)
                {
                    case ErrorCode.AccountNotFound:
                        return new AccountNotFoundException(Account);

                    case ErrorCode.FileNotFound:
                        return !string.IsNullOrWhiteSpace(Sandbox)
                            ? new SandboxFileNotFoundException(Vendor, Sandbox, App, Service, Path)
                            : new AppFileNotFoundException(Vendor, App, Version, Service, Path);

                    case ErrorCode.AppNotFound:
                        return new AppNotFoundException(Vendor, App);

                    case ErrorCode.AppVersionNotFound:
                        return new AppVersionNotFoundException(Vendor, App, Version);

                    case ErrorCode.SandboxNotFound:
                        return new SandboxNotFoundException(Vendor, Sandbox);

                    case ErrorCode.SandboxedAppNotFound:
                        return new SandboxedAppNotFoundException(Vendor, Sandbox, App);

                    case ErrorCode.WorkspaceNotFound:
                        return new WorkspaceNotFoundException(Account, Workspace);

                    default:
                        return parent;
                }
            }
        public void SearchFor_WithValidSearchTerm_ReturnsException()
        {
            const string SearchTerm = "qwesfddsfdsfdsf";
            const int ResultSetLimit = 5;
            const int Page = 1;
            var exception = new ResourceNotFoundException();
            _sdk.Setup(s => s.Search.CharitySearch(SearchTerm, Page, ResultSetLimit)).Throws(exception);

            var result = _client.SearchFor(SearchTerm, Page, ResultSetLimit);

            Assert.That(result.Count, Is.EqualTo(0));
        }