From 84d0bd8180d4dafae33c581ee7e14a790638c801 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 21:09:10 +0530 Subject: [PATCH 1/7] =?UTF-8?q?Add=20jetbrains.resharper.globaltools=20?= =?UTF-8?q?=E2=9E=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/dotnet-tools.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..92211a4f --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "jetbrains.resharper.globaltools": { + "version": "2022.2.3", + "commands": [ + "jb" + ] + } + } +} \ No newline at end of file From 9e1664ecef0d0fae9abe4397522ff605b98d33ce Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:06:45 +0530 Subject: [PATCH 2/7] Updated editorconfig file --- .editorconfig | 291 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 273 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index f8d20ed2..7e8f258c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,261 @@ +root = true # EditorConfig is awesome: https://EditorConfig.org # top-most EditorConfig file -root = true # Don't use tabs for indentation. [*] indent_style = space + +[*.cs] +# Microsoft .NET properties +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.constants_rule.severity = suggestion +dotnet_naming_rule.constants_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_rule.symbols = constants_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_description = constants_should_be_pascal_case +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_guid = a0135172-b297-46cb-bb0f-b1f267109d7b +dotnet_naming_rule.constants_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule.symbols = constants_should_be_pascal_case_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.import_to_resharper = False +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.symbols = constants_should_be_pascal_case_symbols_1 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_description = instance_fields_should_be_camel_case +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_guid = ed8be1d2-8aa4-45a9-a0fe-964e144ccec7 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.style = lower_camel_case_style +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.symbols = instance_fields_should_be_camel_case_symbols +dotnet_naming_rule.interfaces_rule.import_to_resharper = as_predefined +dotnet_naming_rule.interfaces_rule.severity = suggestion +dotnet_naming_rule.interfaces_rule.style = upper_camel_case_style +dotnet_naming_rule.interfaces_rule.symbols = interfaces_symbols +dotnet_naming_rule.locals_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_description = locals_should_be_camel_case +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_guid = dd900f14-6d42-4a58-8277-056e5dab89e7 +dotnet_naming_rule.locals_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.locals_should_be_camel_case_rule.style = lower_camel_case_style_1 +dotnet_naming_rule.locals_should_be_camel_case_rule.symbols = locals_should_be_camel_case_symbols +dotnet_naming_rule.local_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.local_constants_rule.resharper_style = AaBb, aaBb +dotnet_naming_rule.local_constants_rule.severity = suggestion +dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_description = local_functions_should_be_pascal_case +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_guid = 67e7ac04-3277-4549-b0bb-98cbfad21765 +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.symbols = local_functions_should_be_pascal_case_symbols +dotnet_naming_rule.members_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_description = members_should_be_pascal_case +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_guid = 605fba47-8912-494e-9e4c-98aeb57fd884 +dotnet_naming_rule.members_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.members_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.members_should_be_pascal_case_rule.symbols = members_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_description = non_private_readonly_fields_should_be_pascal_case +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_guid = e8e1b724-94dd-4cbe-9385-85343fea2b41 +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.symbols = non_private_readonly_fields_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_description = non_private_static_fields_should_be_pascal_case +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_guid = 51051115-1f5e-4eea-aa9d-2eac02e9b082 +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.symbols = non_private_static_fields_should_be_pascal_case_symbols +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.private_constants_rule.severity = suggestion +dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_static_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_fields_rule.severity = suggestion +dotnet_naming_rule.private_static_fields_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols +dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_readonly_rule.severity = suggestion +dotnet_naming_rule.private_static_readonly_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.public_fields_rule.severity = suggestion +dotnet_naming_rule.public_fields_rule.style = lower_camel_case_style +dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols +dotnet_naming_rule.static_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_description = static_fields_should_be_camel_case +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_guid = f286ec29-34ab-4806-9c8a-586f11eedd52 +dotnet_naming_rule.static_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.static_fields_should_be_camel_case_rule.style = s_lower_camel_case_style +dotnet_naming_rule.static_fields_should_be_camel_case_rule.symbols = static_fields_should_be_camel_case_symbols +dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.static_readonly_rule.resharper_style = AaBb, s_ + aaBb +dotnet_naming_rule.static_readonly_rule.severity = suggestion +dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style +dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols +dotnet_naming_rule.type_parameters_rule.import_to_resharper = as_predefined +dotnet_naming_rule.type_parameters_rule.severity = suggestion +dotnet_naming_rule.type_parameters_rule.style = upper_camel_case_style +dotnet_naming_rule.type_parameters_rule.symbols = type_parameters_symbols +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style.required_prefix = _ +dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.required_prefix = s_ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_kinds = local +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.required_modifiers = const +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_applicable_kinds = constant_field,local_constant +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_kinds = field +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.required_modifiers = const +dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_symbols.applicable_kinds = field +dotnet_naming_symbols.constants_symbols.required_modifiers = const +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.interfaces_symbols.applicable_accessibilities = * +dotnet_naming_symbols.interfaces_symbols.applicable_kinds = interface +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local +dotnet_naming_symbols.local_constants_symbols.required_modifiers = const +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_kinds = namespace,class,struct,interface,enum,property,method,field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_applicable_kinds = namespace,class,struct,interface,enum,property,method,any_field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.required_modifiers = readonly +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = readonly_field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.required_modifiers = static +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.required_modifiers = static +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.type_parameters_symbols.applicable_accessibilities = * +dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +# ReSharper properties +# resharper_arguments_anonymous_function = named +# resharper_arguments_literal = named +# resharper_arguments_named = named +# resharper_arguments_other = named +# resharper_arguments_string_literal = named +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_before_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +resharper_case_block_braces = next_line_shifted_2 +resharper_csharp_blank_lines_around_single_line_invocable = 1 +resharper_csharp_keep_blank_lines_in_code = 1 +resharper_csharp_keep_blank_lines_in_declarations = 1 +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_extends_list_style = chop_if_long +resharper_csharp_wrap_parameters_style = chop_if_long +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_keep_existing_declaration_block_arrangement = true +resharper_keep_existing_declaration_parens_arrangement = false +resharper_keep_existing_embedded_block_arrangement = true +resharper_keep_existing_enum_arrangement = true +resharper_keep_existing_expr_member_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_local_function_body = expression_body +resharper_max_enum_members_on_line = 1 +resharper_max_formal_parameters_on_line = 4 +resharper_place_field_attribute_on_same_line = if_owner_is_single_line +resharper_space_within_single_line_array_initializer_braces = false +resharper_trailing_comma_in_multiline_lists = true +resharper_use_heuristics_for_body_style = false +resharper_use_indent_from_vs = false +resharper_wrap_before_eq = true +resharper_wrap_before_first_type_parameter_constraint = true + +# ReSharper inspection severities +resharper_arrange_accessor_owner_body_highlighting = none +resharper_arrange_local_function_body_highlighting = suggestion +resharper_arrange_namespace_body_highlighting = suggestion +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = none +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_built_in_type_reference_style_for_member_access_highlighting = suggestion +resharper_built_in_type_reference_style_highlighting = suggestion +resharper_inconsistent_naming_highlighting = suggestion +resharper_redundant_base_qualifier_highlighting = none +resharper_suggest_var_or_type_built_in_types_highlighting = suggestion +resharper_suggest_var_or_type_elsewhere_highlighting = suggestion +resharper_suggest_var_or_type_simple_types_highlighting = suggestion + +resharper_csharp_force_attribute_style=separate +resharper_csharp_method_or_operator_body=expression_body +resharper_csharp_max_enum_members_on_line=1 +resharper_csharp_place_attribute_on_same_line=false +resharper_csharp_wrap_object_and_collection_initializer_style=chop_always +resharper_csharp_use_heuristics_for_body_style=true + +# Standard properties +insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) # Code files @@ -39,7 +289,7 @@ indent_size = 2 [*.{cs,vb}] # IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = warning +dotnet_diagnostic.ide0055.severity = warning # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true @@ -143,23 +393,23 @@ dotnet_naming_symbols.all_members.applicable_kinds = * dotnet_naming_style.pascal_case_style.capitalization = pascal_case # error RS2008: Enable analyzer release tracking for the analyzer project containing rule '{0}' -dotnet_diagnostic.RS2008.severity = none +dotnet_diagnostic.rs2008.severity = none # IDE0073: File header # dotnet_diagnostic.IDE0073.severity = warning # file_header_template = # IDE0035: Remove unreachable code -dotnet_diagnostic.IDE0035.severity = warning +dotnet_diagnostic.ide0035.severity = warning # IDE0036: Order modifiers -dotnet_diagnostic.IDE0036.severity = warning +dotnet_diagnostic.ide0036.severity = warning # IDE0043: Format string contains invalid placeholder -dotnet_diagnostic.IDE0043.severity = warning +dotnet_diagnostic.ide0043.severity = warning # IDE0044: Make field readonly -dotnet_diagnostic.IDE0044.severity = warning +dotnet_diagnostic.ide0044.severity = warning # RS0016: Only enable if API files are present dotnet_public_api_analyzer.require_api_files = true @@ -236,39 +486,39 @@ csharp_preserve_single_line_statements = true [src/CodeStyle/**.{cs,vb}] # warning RS0005: Do not use generic CodeAction.Create to create CodeAction -dotnet_diagnostic.RS0005.severity = none +dotnet_diagnostic.rs0005.severity = none [src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures,VisualStudio}/**/*.{cs,vb}] # IDE0011: Add braces csharp_prefer_braces = when_multiline:warning # NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201 -dotnet_diagnostic.IDE0011.severity = warning +dotnet_diagnostic.ide0011.severity = warning # IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = warning +dotnet_diagnostic.ide0040.severity = warning # CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings? # IDE0051: Remove unused private member -dotnet_diagnostic.IDE0051.severity = warning +dotnet_diagnostic.ide0051.severity = warning # IDE0052: Remove unread private member -dotnet_diagnostic.IDE0052.severity = warning +dotnet_diagnostic.ide0052.severity = warning # IDE0059: Unnecessary assignment to a value -dotnet_diagnostic.IDE0059.severity = warning +dotnet_diagnostic.ide0059.severity = warning # IDE0060: Remove unused parameter -dotnet_diagnostic.IDE0060.severity = warning +dotnet_diagnostic.ide0060.severity = warning # CA1012: Abstract types should not have public constructors -dotnet_diagnostic.CA1012.severity = warning +dotnet_diagnostic.ca1012.severity = warning # CA1822: Make member static -dotnet_diagnostic.CA1822.severity = warning +dotnet_diagnostic.ca1822.severity = warning # Prefer "var" everywhere -dotnet_diagnostic.IDE0007.severity = warning +dotnet_diagnostic.ide0007.severity = warning csharp_style_var_for_built_in_types = true:warning csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_elsewhere = true:warning @@ -277,4 +527,9 @@ csharp_style_var_elsewhere = true:warning # CA1822: Make member static # Not enforced as a build 'warning' for 'VisualStudio' layer due to large number of false positives from https://github.com/dotnet/roslyn-analyzers/issues/3857 and https://github.com/dotnet/roslyn-analyzers/issues/3858 # Additionally, there is a risk of accidentally breaking an internal API that partners rely on though IVT. -dotnet_diagnostic.CA1822.severity = suggestion \ No newline at end of file +dotnet_diagnostic.ca1822.severity = suggestion + +[*.{appxmanifest,asax,ascx,aspx,axaml,axml,build,config,cs,cshtml,csproj,css,dbml,discomap,dtd,htm,html,js,json,jsproj,jsx,lsproj,master,njsproj,nuspec,paml,proj,props,proto,razor,resjson,resw,resx,skin,StyleCop,targets,tasks,ts,tsx,vb,vbproj,xaml,xamlx,xml,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 From af6b1af7b6f5d90b4c0f5d80bb7f038a9892ffd5 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:08:51 +0530 Subject: [PATCH 3/7] =?UTF-8?q?Run=20solution=20wide=20linter=20?= =?UTF-8?q?=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Api/ApiEndpoints.cs | 124 ++- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 14 +- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 16 +- .../BlocksRetrieveChildrenParameters.cs | 1 + .../UpdateBlocks/AudioUpdateBlock.cs | 3 +- .../UpdateBlocks/BookmarkUpdateBlock.cs | 4 +- .../UpdateBlocks/BreadcrumbUpdateBlock.cs | 12 +- .../UpdateBlocks/DividerUpdateBlock.cs | 12 +- .../TableOfContentsUpdateBlock.cs | 12 +- .../Create/Request/CreateCommentParameters.cs | 22 +- .../Api/Comments/ICommentsClient.cs | 6 +- .../Api/Comments/Retrieve/CommentsClient.cs | 6 +- .../Request/RetrieveCommentsParameters.cs | 2 + .../Api/Comments/Retrieve/Response/Comment.cs | 8 +- .../Retrieve/Response/ICommentParent.cs | 4 +- .../Api/Databases/DatabasesClient.cs | 4 +- .../Api/Databases/IDatabasesClient.cs | 28 +- .../DatabasesCreateParameters.cs | 12 +- .../RequestParams/DatabasesListParameters.cs | 1 + .../RequestParams/DatabasesQueryParameters.cs | 3 + .../DatabasesUpdateParameters.cs | 1 - .../Api/Databases/RequestParams/Direction.cs | 2 +- .../Api/Databases/RequestParams/Timestamp.cs | 2 +- Src/Notion.Client/Api/Pages/IPagesClient.cs | 49 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 23 +- .../PagesCreateParameters.cs | 4 + .../PagesCreateParametersBuilder.cs | 17 +- .../RequestParams/PagesUpdateParameters.cs | 12 +- Src/Notion.Client/Api/Search/ISearchClient.cs | 9 +- .../Api/Search/Parameters/SearchDirection.cs | 2 +- .../Api/Search/Parameters/SearchFilter.cs | 1 + .../Api/Search/Parameters/SearchObjectType.cs | 2 +- .../Api/Search/Parameters/SearchParameters.cs | 4 + Src/Notion.Client/Api/Users/IUsersClient.cs | 22 +- Src/Notion.Client/Api/Users/UsersClient.cs | 7 +- Src/Notion.Client/Constants.cs | 1 + .../DI/ServiceCollectionExtensions.cs | 4 +- .../Extensions/EnumExtensions.cs | 9 +- .../HttpResponseMessageExtensions.cs | 8 +- Src/Notion.Client/Models/Blocks/AudioBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/Block.cs | 2 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 2 +- .../Models/Blocks/BookmarkBlock.cs | 4 +- .../Models/Blocks/BreadcrumbBlock.cs | 4 +- .../Models/Blocks/BulletedListItemBlock.cs | 4 +- .../Models/Blocks/CalloutBlock.cs | 4 +- .../Models/Blocks/ChildDatabaseBlock.cs | 4 +- .../Models/Blocks/ChildPageBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/CodeBlock.cs | 4 +- .../Models/Blocks/ColumnListBlock.cs | 4 +- .../Models/Blocks/DividerBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/EmbedBlock.cs | 5 +- .../Models/Blocks/EquationBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/FileBlock.cs | 4 +- .../Models/Blocks/HeadingOneBlock.cs | 4 +- .../Models/Blocks/HeadingThreeeBlock.cs | 4 +- .../Models/Blocks/HeadingTwoBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/IBlock.cs | 64 +- .../Models/Blocks/IBlockParent.cs | 8 +- Src/Notion.Client/Models/Blocks/ImageBlock.cs | 4 +- .../Models/Blocks/LinkPreviewBlock.cs | 8 +- .../Models/Blocks/LinkToPageBlock.cs | 4 +- .../Models/Blocks/NumberedListItemBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/PDFBlock.cs | 4 +- .../Models/Blocks/ParagraphBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 4 +- .../Models/Blocks/SyncedBlockBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/TableBlock.cs | 4 +- .../Models/Blocks/TableOfContentsBlock.cs | 4 +- .../Models/Blocks/TableRowBlock.cs | 4 +- .../Models/Blocks/TemplateBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 4 +- .../Models/Blocks/ToggleBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/VideoBlock.cs | 4 +- .../Models/Common/IObjectModificationData.cs | 8 +- Src/Notion.Client/Models/Database/Database.cs | 32 +- .../Models/Database/IDatabaseParent.cs | 6 +- .../Models/Database/Properties/Property.cs | 40 +- .../RelationProperty/RelationData.cs | 4 +- .../RelationProperty/RelationProperty.cs | 4 +- .../RelationProperty/RelationType.cs | 2 +- .../Database/Properties/SelectProperty.cs | 8 +- .../Models/Database/RichText/RichTextBase.cs | 6 +- .../Models/Database/RichText/RichTextType.cs | 2 +- Src/Notion.Client/Models/EmojiObject.cs | 6 +- Src/Notion.Client/Models/File/FileObject.cs | 10 +- .../Models/File/FileObjectWithName.cs | 4 +- .../Models/Filters/CheckboxFilter.cs | 23 +- .../Models/Filters/DateFilter.cs | 93 +-- .../Models/Filters/EmailFilter.cs | 23 +- .../Models/Filters/FilesFilter.cs | 20 +- Src/Notion.Client/Models/Filters/Filter.cs | 13 +- .../Models/Filters/FormulaFilter.cs | 39 +- .../Models/Filters/MultiSelectFilter.cs | 39 +- .../Models/Filters/NumberFilter.cs | 64 +- .../Models/Filters/PeopleFilter.cs | 39 +- .../Models/Filters/PhoneNumberFilter.cs | 23 +- .../Models/Filters/RelationFilter.cs | 39 +- .../Models/Filters/RichTextFilter.cs | 63 +- .../Models/Filters/Rollup/RollupFilter.cs | 29 +- .../Models/Filters/SelectFilter.cs | 39 +- .../Models/Filters/StatusFilter.cs | 39 +- .../Filters/TimestampCreatedTimeFilter.cs | 32 +- .../Filters/TimestampLastEditedTimeFilter.cs | 32 +- .../Models/Filters/TitleFilter.cs | 23 +- Src/Notion.Client/Models/Filters/URLFilter.cs | 23 +- Src/Notion.Client/Models/IObject.cs | 8 +- Src/Notion.Client/Models/Page/IPageIcon.cs | 6 +- Src/Notion.Client/Models/Page/IPageParent.cs | 8 +- Src/Notion.Client/Models/Page/Page.cs | 56 +- .../Models/Parents/BlockParent.cs | 10 +- .../Models/Parents/DatabaseParent.cs | 10 +- .../Models/Parents/PageParent.cs | 10 +- .../Models/Parents/WorkspaceParent.cs | 2 +- .../PropertyItems/IPropertyItemObject.cs | 7 +- .../Models/PropertyItems/ListPropertyItem.cs | 17 +- .../PropertyItems/RollupPropertyItem.cs | 24 +- .../PropertyItems/SimplePropertyItem.cs | 40 +- .../PropertyItems/StatusPropertyItem.cs | 3 +- .../PropertyValue/CheckboxPropertyValue.cs | 2 +- .../PropertyValue/CreatedByPropertyValue.cs | 4 +- .../PropertyValue/CreatedTimePropertyValue.cs | 4 +- .../Models/PropertyValue/DatePropertyValue.cs | 13 +- .../PropertyValue/EmailPropertyValue.cs | 4 +- .../PropertyValue/FilesPropertyValue.cs | 4 +- .../PropertyValue/FormulaPropertyValue.cs | 16 +- .../LastEditedByPropertyValue.cs | 4 +- .../LastEditedTimePropertyValue.cs | 4 +- .../PropertyValue/MultiSelectPropertyValue.cs | 4 +- .../PropertyValue/NumberPropertyValue.cs | 4 +- .../PropertyValue/PeoplePropertyValue.cs | 4 +- .../PropertyValue/PhoneNumberPropertyValue.cs | 4 +- .../Models/PropertyValue/PropertyValue.cs | 44 +- .../Models/PropertyValue/PropertyValueType.cs | 2 +- .../PropertyValue/RelationPropertyValue.cs | 4 +- .../PropertyValue/RichTextPropertyValue.cs | 4 +- .../PropertyValue/RollupPropertyValue.cs | 14 +- .../PropertyValue/SelectPropertyValue.cs | 2 +- .../PropertyValue/StatusPropertyValue.cs | 56 +- .../PropertyValue/TitlePropertyValue.cs | 4 +- .../Models/PropertyValue/UrlPropertyValue.cs | 4 +- .../Models/User/BotOwner/IBotOwner.cs | 4 +- .../Models/User/BotOwner/UserOwner.cs | 4 +- .../BotOwner/WorkspaceIntegrationOwner.cs | 4 +- Src/Notion.Client/Models/User/User.cs | 7 +- Src/Notion.Client/NotionApiErrorResponse.cs | 2 +- Src/Notion.Client/NotionApiException.cs | 1 + Src/Notion.Client/NotionClient.cs | 12 + Src/Notion.Client/NotionClientFactory.cs | 10 +- Src/Notion.Client/RestClient/ClientOptions.cs | 2 + .../RestClient/LoggingHandler.cs | 5 +- Src/Notion.Client/RestClient/RestClient.cs | 116 +-- Src/Notion.Client/http/QueryHelpers.cs | 8 +- .../CommentsClientTests.cs | 207 ++--- .../IBlocksClientTests.cs | 775 ++++++++---------- .../IPageClientTests.cs | 401 ++++----- Test/Notion.UnitTests/ApiTestBase.cs | 93 +-- Test/Notion.UnitTests/BlocksClientTests.cs | 265 +++--- Test/Notion.UnitTests/DatabasesClientTests.cs | 658 +++++++-------- Test/Notion.UnitTests/FilterTests.cs | 247 +++--- Test/Notion.UnitTests/HelperAsserts.cs | 61 +- Test/Notion.UnitTests/PagesClientTests.cs | 354 ++++---- Test/Notion.UnitTests/PropertyTests.cs | 104 ++- Test/Notion.UnitTests/SearchClientTest.cs | 92 +-- Test/Notion.UnitTests/UserClientTest.cs | 253 +++--- 165 files changed, 2744 insertions(+), 2852 deletions(-) diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index ec6f5b1a..51dbe7fd 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -1,72 +1,140 @@ -using System; - -namespace Notion.Client +namespace Notion.Client { public static class ApiEndpoints { public static class DatabasesApiUrls { - public static string Retrieve(string databaseId) => $"/v1/databases/{databaseId}"; - public static string List() => "/v1/databases"; - public static string Query(string databaseId) => $"/v1/databases/{databaseId}/query"; public static string Create => "/v1/databases"; - public static string Update(string databaseId) => $"/v1/databases/{databaseId}"; + + public static string Retrieve(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } + + public static string List() + { + return "/v1/databases"; + } + + public static string Query(string databaseId) + { + return $"/v1/databases/{databaseId}/query"; + } + + public static string Update(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } } public static class UsersApiUrls { - public static string Retrieve(string userId) => $"/v1/users/{userId}"; - public static string List() => "/v1/users"; + public static string Retrieve(string userId) + { + return $"/v1/users/{userId}"; + } + + public static string List() + { + return "/v1/users"; + } /// - /// Get the for retrieve your token's bot user. + /// Get the for retrieve your token's bot user. /// - /// Returns a retrieve your token's bot user. - public static string Me() => "/v1/users/me"; + /// Returns a retrieve your token's bot user. + public static string Me() + { + return "/v1/users/me"; + } } public static class BlocksApiUrls { - public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}"; - public static string Update(string blockId) => $"/v1/blocks/{blockId}"; + public static string Retrieve(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string Update(string blockId) + { + return $"/v1/blocks/{blockId}"; + } /// - /// Get the for deleting a block. + /// Get the for deleting a block. /// /// Identifier for a Notion block - /// Returns a for deleting a block. - public static string Delete(string blockId) => $"/v1/blocks/{blockId}"; + /// Returns a for deleting a block. + public static string Delete(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string RetrieveChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } - public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children"; - public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children"; + public static string AppendChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } } public static class PagesApiUrls { - public static string Create() => $"/v1/pages"; - public static string Retrieve(string pageId) => $"/v1/pages/{pageId}"; - public static string Update(string pageId) => $"/v1/pages/{pageId}"; - public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}"; + public static string Create() + { + return "/v1/pages"; + } + + public static string Retrieve(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string Update(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string UpdateProperties(string pageId) + { + return $"/v1/pages/{pageId}"; + } /// - /// Get the for retrieve page property item + /// Get the for retrieve page property item /// /// Identifier for a Notion Page /// Identifier for a Notion Property /// - public static string RetrievePropertyItem(string pageId, string propertyId) => $"/v1/pages/{pageId}/properties/{propertyId}"; + public static string RetrievePropertyItem(string pageId, string propertyId) + { + return $"/v1/pages/{pageId}/properties/{propertyId}"; + } } public static class SearchApiUrls { - public static string Search() => "/v1/search"; + public static string Search() + { + return "/v1/search"; + } } public static class CommentsApiUrls { - public static string Retrieve() => "/v1/comments"; + public static string Retrieve() + { + return "/v1/comments"; + } - public static string Create() => "/v1/comments"; + public static string Create() + { + return "/v1/comments"; + } } } } diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index cc06642e..8fbdcd26 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -14,7 +14,9 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null) + public async Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -25,16 +27,18 @@ public async Task> RetrieveChildrenAsync(string blockId, B var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor?.ToString() }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync>(url, queryParams); } - public async Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null) + public async Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 90ebf073..f45611b7 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -5,32 +5,36 @@ namespace Notion.Client public interface IBlocksClient { /// - /// Retrieves a Block object using the ID specified. + /// Retrieves a Block object using the ID specified. /// /// /// Block Task RetrieveAsync(string blockId); /// - /// Updates the content for the specified block_id based on the block type. + /// Updates the content for the specified block_id based on the block type. /// /// /// /// Block Task UpdateAsync(string blockId, IUpdateBlock updateBlock); - Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null); + Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null); /// - /// Creates and appends new children blocks to the parent block_id specified. + /// Creates and appends new children blocks to the parent block_id specified. /// /// Identifier for a block /// /// A paginated list of newly created first level children block objects. - Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null); + Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null); /// - /// Sets a Block object, including page blocks, to archived: true using the ID specified. + /// Sets a Block object, including page blocks, to archived: true using the ID specified. /// /// Identifier for a Notion block Task DeleteAsync(string blockId); diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs index ddc73a91..30f9c17d 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs @@ -3,6 +3,7 @@ public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs index 8747ad63..f341e441 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs index c3333737..612b6dda 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public bool Archived { get; set; } + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs index 2bb8be38..a90f6966 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class BreadcrumbUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public BreadcrumbUpdateBlock() + { + Breadcrumb = new Info(); + } [JsonProperty("breadcrumb")] public Info Breadcrumb { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public BreadcrumbUpdateBlock() + public class Info { - Breadcrumb = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs index 6c5b447c..79f332f0 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class DividerUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public DividerUpdateBlock() + { + Divider = new Info(); + } [JsonProperty("divider")] public Info Divider { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public DividerUpdateBlock() + public class Info { - Divider = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs index 36eee182..bef1f278 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class TableOfContentsUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public TableOfContentsUpdateBlock() + { + TableOfContents = new Info(); + } [JsonProperty("table_of_contents")] public Info TableOfContents { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public TableOfContentsUpdateBlock() + public class Info { - TableOfContents = new Info(); } } } diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs index aadaf1f1..3b676133 100644 --- a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -24,25 +24,23 @@ public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameter public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters { public string DiscussionId { get; set; } + public IEnumerable RichText { get; set; } + public ParentPageInput Parent { get; set; } - public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable richText) + public static CreateCommentParameters CreatePageComment( + ParentPageInput parent, + IEnumerable richText) { - return new CreateCommentParameters - { - Parent = parent, - RichText = richText - }; + return new CreateCommentParameters {Parent = parent, RichText = richText}; } - public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable richText) + public static CreateCommentParameters CreateDiscussionComment( + string discussionId, + IEnumerable richText) { - return new CreateCommentParameters - { - DiscussionId = discussionId, - RichText = richText - }; + return new CreateCommentParameters {DiscussionId = discussionId, RichText = richText}; } } } diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index d936203c..871319da 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -5,10 +5,12 @@ namespace Notion.Client public interface ICommentsClient { /// - /// Retrieves a list of un-resolved Comment objects from a page or block. + /// Retrieves a list of un-resolved Comment objects from a page or block. /// /// Retrieve comments parameters - /// + /// + /// + /// Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); Task Create(CreateCommentParameters createCommentParameters); diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index d228200c..b979086f 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -9,11 +9,9 @@ public async Task Retrieve(RetrieveCommentsParameters { var qp = (IRetrieveCommentsQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "block_id", qp.BlockId }, - { "start_cursor", qp.StartCursor }, - { "page_size", qp.PageSize.ToString() }, + {"block_id", qp.BlockId}, {"start_cursor", qp.StartCursor}, {"page_size", qp.PageSize.ToString()}, }; return await _client.GetAsync( diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs index e78c4cad..d42ec9e7 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs @@ -3,7 +3,9 @@ public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters { public string BlockId { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs index 531fb43c..9b9ef2ae 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs @@ -6,10 +6,6 @@ namespace Notion.Client { public class Comment : IObject { - public string Id { get; set; } - - public ObjectType Object => ObjectType.Comment; - [JsonProperty("parent")] public ICommentParent Parent { get; set; } @@ -27,5 +23,9 @@ public class Comment : IObject [JsonProperty("last_edited_time")] public DateTime LastEditedTime { get; set; } + + public string Id { get; set; } + + public ObjectType Object => ObjectType.Comment; } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs index e323c7e1..9e05d019 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface ICommentParent { } diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 2ab17a8b..5157dee9 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -17,7 +17,9 @@ public async Task RetrieveAsync(string databaseId) return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId)); } - public async Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters) + public async Task> QueryAsync( + string databaseId, + DatabasesQueryParameters databasesQueryParameters) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index 115ccfed..9c245ce3 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -5,35 +5,43 @@ namespace Notion.Client public interface IDatabasesClient { /// - /// Retrieves a Database object using the ID specified. + /// Retrieves a Database object using the ID specified. /// /// Identifier for a Notion database - /// + /// + /// + /// Task RetrieveAsync(string databaseId); /// - /// Gets a list of Pages contained in the database, filtered and ordered according to the - /// filter conditions and sort criteria provided in the request. The response may contain - /// fewer than page_size of results. + /// Gets a list of Pages contained in the database, filtered and ordered according to the + /// filter conditions and sort criteria provided in the request. The response may contain + /// fewer than page_size of results. /// /// /// - /// + /// + /// + /// Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); /// - /// Creates a database as a subpage in the specified parent page, with the specified properties schema. + /// Creates a database as a subpage in the specified parent page, with the specified properties schema. /// /// - /// + /// + /// + /// Task CreateAsync(DatabasesCreateParameters databasesCreateParameters); /// - /// Updates an existing database as specified by the parameters. + /// Updates an existing database as specified by the parameters. /// /// /// - /// + /// + /// + /// Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters); } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index bafad0ec..9cb7086b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -5,6 +5,12 @@ namespace Notion.Client { public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters { + [JsonProperty("icon")] + public IPageIcon Icon { get; set; } + + [JsonProperty("cover")] + public FileObject Cover { get; set; } + [JsonProperty("parent")] public ParentPageInput Parent { get; set; } @@ -14,12 +20,6 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba [JsonProperty("title")] public List Title { get; set; } - [JsonProperty("icon")] - public IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - public FileObject Cover { get; set; } - public bool? IsInline { get; set; } public List Description { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs index 51136e47..922e54fc 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs @@ -3,6 +3,7 @@ public class DatabasesListParameters : IDatabasesListQueryParmaters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs index 454961a2..51bd8a06 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs @@ -5,8 +5,11 @@ namespace Notion.Client public class DatabasesQueryParameters : IDatabaseQueryBodyParameters { public Filter Filter { get; set; } + public List Sorts { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index b9cb182e..41da2d17 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index c79d501d..76b87da3 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -11,6 +11,6 @@ public enum Direction Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 334b8c22..4eb359d4 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -11,6 +11,6 @@ public enum Timestamp CreatedTime, [EnumMember(Value = "last_edited_time")] - LastEditedTime + LastEditedTime, } } diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index 90eac980..f6b8f94f 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -6,49 +6,58 @@ namespace Notion.Client public interface IPagesClient { /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters - /// Created object. + /// Created object. Task CreateAsync(PagesCreateParameters pagesCreateParameters); /// - /// Retrieves a Page object using the ID specified. + /// Retrieves a Page object using the ID specified. /// /// Identifier for a Notion page - /// + /// + /// + /// Task RetrieveAsync(string pageId); /// - /// Updates page property values for the specified page. - /// Note: Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Note: Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page - /// Property values to update for this page. The keys are the names or IDs of the property and the values are property values. - /// Updated object + /// + /// Property values to update for this page. The keys are the names or IDs of the property + /// and the values are property values. + /// + /// Updated object Task UpdatePropertiesAsync( string pageId, - IDictionary updatedProperties - ); + IDictionary updatedProperties); /// - /// Updates page property values for the specified page. - /// Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page /// Update property parameters - /// Updated object + /// Updated object Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters); /// - /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object returned will either be a value or a paginated list of property item values. + /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object + /// returned will either be a value or a paginated list of property item values. /// /// Property body and query parameters - /// - Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters); + /// + /// + /// + Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters); } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index 5bce1904..b71f924f 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -15,11 +15,12 @@ public PagesClient(IRestClient client) } /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters /// Created page. @@ -48,20 +49,22 @@ public async Task CreateAsync(PagesCreateParameters pagesCreateParameters) public async Task RetrieveAsync(string pageId) { var url = PagesApiUrls.Retrieve(pageId); + return await _client.GetAsync(url); } - public async Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters) + public async Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters) { var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters; var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters; var url = PagesApiUrls.RetrievePropertyItem(pathParameters.PageId, pathParameters.PropertyId); - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync(url, queryParams); @@ -81,7 +84,7 @@ public async Task UpdatePropertiesAsync( IDictionary updatedProperties) { var url = PagesApiUrls.UpdateProperties(pageId); - var body = new UpdatePropertiesParameters { Properties = updatedProperties }; + var body = new UpdatePropertiesParameters {Properties = updatedProperties}; return await _client.PatchAsync(url, body); } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs index 52cb0a89..08572811 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs @@ -5,9 +5,13 @@ namespace Notion.Client public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQueryParameters { public IPageParentInput Parent { get; set; } + public IDictionary Properties { get; set; } + public IList Children { get; set; } + public IPageIcon Icon { get; set; } + public FileObject Cover { get; set; } } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index b86a207a..7df2fe4c 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class PagesCreateParametersBuilder { - private IPageParentInput parent; - private readonly Dictionary properties = new Dictionary(); private readonly IList children = new List(); - private IPageIcon icon; + private readonly Dictionary properties = new(); private FileObject cover; + private IPageIcon icon; + private IPageParentInput parent; private PagesCreateParametersBuilder() { @@ -16,33 +16,34 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder - { - parent = parent - }; + return new PagesCreateParametersBuilder {parent = parent}; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) { properties[nameOrId] = value; + return this; } public PagesCreateParametersBuilder AddPageContent(IBlock block) { children.Add(block); + return this; } public PagesCreateParametersBuilder SetIcon(IPageIcon pageIcon) { icon = pageIcon; + return this; } public PagesCreateParametersBuilder SetCover(FileObject pageCover) { cover = pageCover; + return this; } @@ -54,7 +55,7 @@ public PagesCreateParameters Build() Properties = properties, Children = children, Icon = icon, - Cover = cover + Cover = cover, }; } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs index 40f06b12..742ef8dd 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs @@ -5,16 +5,16 @@ namespace Notion.Client { public class PagesUpdateParameters : IPagesUpdateBodyParameters { - [JsonProperty("archived")] - public bool Archived { get; set; } - - [JsonProperty("properties")] - public IDictionary Properties { get; set; } - [JsonProperty("icon")] public IPageIcon Icon { get; set; } [JsonProperty("cover")] public FileObject Cover { get; set; } + + [JsonProperty("archived")] + public bool Archived { get; set; } + + [JsonProperty("properties")] + public IDictionary Properties { get; set; } } } diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 9eb487d5..8071db6d 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -5,12 +5,13 @@ namespace Notion.Client public interface ISearchClient { /// - /// Searches all original pages, databases, and child pages/databases that are shared with the integration. - /// - /// It will not return linked databases, since these duplicate their source databases. + /// Searches all original pages, databases, and child pages/databases that are shared with the integration. + /// It will not return linked databases, since these duplicate their source databases. /// /// Search filters and body parameters - /// + /// + /// + /// Task> SearchAsync(SearchParameters parameters); } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index fdac0b59..0bde8d23 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -8,6 +8,6 @@ public enum SearchDirection Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs index cc84a9a3..dbd5cf5f 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs @@ -7,6 +7,7 @@ public class SearchFilter { [JsonConverter(typeof(StringEnumConverter))] public SearchObjectType Value { get; set; } + public string Property => "object"; } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 78a012df..773ef95a 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -8,6 +8,6 @@ public enum SearchObjectType Page, [EnumMember(Value = "database")] - Database + Database, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs index ae02c0f4..e1c8ced8 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs @@ -3,9 +3,13 @@ public class SearchParameters : ISearchBodyParameters { public string Query { get; set; } + public SearchSort Sort { get; set; } + public SearchFilter Filter { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 41443678..69981022 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -5,24 +5,30 @@ namespace Notion.Client public interface IUsersClient { /// - /// Retrieves a User using the ID specified. + /// Retrieves a User using the ID specified. /// /// Identifier for a Notion user - /// + /// + /// + /// Task RetrieveAsync(string userId); /// - /// Returns a paginated list of Users for the workspace. - /// - /// The response may contain fewer than page_size of results. + /// Returns a paginated list of Users for the workspace. + /// The response may contain fewer than page_size of results. /// - /// + /// + /// + /// Task> ListAsync(); /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// object of type bot having an owner field with information about the person who authorized the integration. + /// + /// object of type bot having an owner field with information about the person who authorized + /// the integration. + /// Task MeAsync(); } } diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 5c745f72..957ac45e 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -23,9 +23,12 @@ public async Task> ListAsync() } /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// User object of type bot having an owner field with information about the person who authorized the integration. + /// + /// User object of type bot having an owner field with information about the person who authorized the + /// integration. + /// public async Task MeAsync() { return await _client.GetAsync(UsersApiUrls.Me()); diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 5034edae..072291e1 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Notion.UnitTests")] + namespace Notion.Client { internal class Constants diff --git a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs index a4aed7fd..866dc92d 100644 --- a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs +++ b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs @@ -5,7 +5,9 @@ namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { - public static IServiceCollection AddNotionClient(this IServiceCollection services, Action options) + public static IServiceCollection AddNotionClient( + this IServiceCollection services, + Action options) { services.AddSingleton(sp => { diff --git a/Src/Notion.Client/Extensions/EnumExtensions.cs b/Src/Notion.Client/Extensions/EnumExtensions.cs index 987104b8..cd60aebd 100644 --- a/Src/Notion.Client/Extensions/EnumExtensions.cs +++ b/Src/Notion.Client/Extensions/EnumExtensions.cs @@ -1,15 +1,18 @@ -using System.Linq; +using System; +using System.Linq; using System.Runtime.Serialization; namespace Notion.Client.Extensions { public static class EnumExtensions { - public static string GetEnumMemberValue(this T enumValue) where T : System.Enum + public static string GetEnumMemberValue(this T enumValue) where T : Enum { var enumType = typeof(T); var memInfo = enumType.GetMember(enumValue.ToString()); - var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType().FirstOrDefault(); + + var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType() + .FirstOrDefault(); if (attr != null) { diff --git a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs index 9b01580d..b6a9396d 100644 --- a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs +++ b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs @@ -7,11 +7,13 @@ namespace Notion.Client.Extensions { internal static class HttpResponseMessageExtensions { - internal static async Task ParseStreamAsync(this HttpResponseMessage response, JsonSerializerSettings serializerSettings = null) + internal static async Task ParseStreamAsync( + this HttpResponseMessage response, + JsonSerializerSettings serializerSettings = null) { - using (Stream stream = await response.Content.ReadAsStreamAsync()) + using (var stream = await response.Content.ReadAsStreamAsync()) { - using (StreamReader streamReader = new StreamReader(stream)) + using (var streamReader = new StreamReader(stream)) { using (JsonReader jsonReader = new JsonTextReader(streamReader)) { diff --git a/Src/Notion.Client/Models/Blocks/AudioBlock.cs b/Src/Notion.Client/Models/Blocks/AudioBlock.cs index 040f346b..1ba1a4a3 100644 --- a/Src/Notion.Client/Models/Blocks/AudioBlock.cs +++ b/Src/Notion.Client/Models/Blocks/AudioBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Audio; - [JsonProperty("audio")] public FileObject Audio { get; set; } + + public override BlockType Type => BlockType.Audio; } } diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 81bcd6bb..883399df 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -21,7 +21,7 @@ public abstract class Block : IBlock public PartialUser LastEditedBy { get; set; } /// - /// Information about the block's parent. + /// Information about the block's parent. /// public IBlockParent Parent { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 8a2c626a..f15c3b37 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -101,6 +101,6 @@ public enum BlockType LinkPreview, [EnumMember(Value = "unsupported")] - Unsupported + Unsupported, } } diff --git a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs index 735b1725..73099c82 100644 --- a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Bookmark; - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public override BlockType Type => BlockType.Bookmark; + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs index 73ae614d..d5585a40 100644 --- a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Breadcrumb; - [JsonProperty("breadcrumb")] public Data Breadcrumb { get; set; } + public override BlockType Type => BlockType.Breadcrumb; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 7eca3397..c823b4bd 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.BulletedListItem; - [JsonProperty("bulleted_list_item")] public Info BulletedListItem { get; set; } + public override BlockType Type => BlockType.BulletedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index 8cc4bb7a..d4ef61c4 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Callout; - [JsonProperty("callout")] public Info Callout { get; set; } + public override BlockType Type => BlockType.Callout; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs index 273836a9..e56fcadb 100644 --- a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildDatabase; - [JsonProperty("child_database")] public Info ChildDatabase { get; set; } + public override BlockType Type => BlockType.ChildDatabase; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs index 91c8f343..216b0d82 100644 --- a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildPage; - [JsonProperty("child_page")] public Info ChildPage { get; set; } + public override BlockType Type => BlockType.ChildPage; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 5eb1456b..9cb2c350 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Code; - [JsonProperty("code")] public Info Code { get; set; } + public override BlockType Type => BlockType.Code; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs index f86ecba0..59bd6245 100644 --- a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class ColumnListBlock : Block, INonColumnBlock { - public override BlockType Type => BlockType.ColumnList; - [JsonProperty("column_list")] public Info ColumnList { get; set; } + public override BlockType Type => BlockType.ColumnList; + public class Info { [JsonProperty("children")] diff --git a/Src/Notion.Client/Models/Blocks/DividerBlock.cs b/Src/Notion.Client/Models/Blocks/DividerBlock.cs index 61e0301b..26c55783 100644 --- a/Src/Notion.Client/Models/Blocks/DividerBlock.cs +++ b/Src/Notion.Client/Models/Blocks/DividerBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Divider; - [JsonProperty("divider")] public Data Divider { get; set; } + public override BlockType Type => BlockType.Divider; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs index bbd93e10..92c1dfdd 100644 --- a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Embed; - [JsonProperty("embed")] public Info Embed { get; set; } + public override BlockType Type => BlockType.Embed; + public class Info { [JsonProperty("url")] @@ -17,7 +17,6 @@ public class Info [JsonProperty("caption")] public IEnumerable Caption { get; set; } - } } } diff --git a/Src/Notion.Client/Models/Blocks/EquationBlock.cs b/Src/Notion.Client/Models/Blocks/EquationBlock.cs index 310a76df..411c4e3b 100644 --- a/Src/Notion.Client/Models/Blocks/EquationBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EquationBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Equation; - [JsonProperty("equation")] public Info Equation { get; set; } + public override BlockType Type => BlockType.Equation; + public class Info { [JsonProperty("expression")] diff --git a/Src/Notion.Client/Models/Blocks/FileBlock.cs b/Src/Notion.Client/Models/Blocks/FileBlock.cs index 5495e4bc..7749a693 100644 --- a/Src/Notion.Client/Models/Blocks/FileBlock.cs +++ b/Src/Notion.Client/Models/Blocks/FileBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.File; - [JsonProperty("file")] public FileObject File { get; set; } + + public override BlockType Type => BlockType.File; } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 853f9ae5..aced5461 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_1; - [JsonProperty("heading_1")] public Info Heading_1 { get; set; } + public override BlockType Type => BlockType.Heading_1; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 99d9b861..10999e0e 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_3; - [JsonProperty("heading_3")] public Info Heading_3 { get; set; } + public override BlockType Type => BlockType.Heading_3; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index ea074e8a..553d56f2 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_2; - [JsonProperty("heading_2")] public Info Heading_2 { get; set; } + public override BlockType Type => BlockType.Heading_2; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index a09f923a..fcf5364d 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -5,38 +5,38 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] - [JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] - [JsonSubtypes.KnownSubType(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] - [JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] - [JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)] - [JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] - [JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] - [JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)] - [JsonSubtypes.KnownSubType(typeof(ColumnBlock), BlockType.Column)] - [JsonSubtypes.KnownSubType(typeof(ColumnListBlock), BlockType.ColumnList)] - [JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)] - [JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)] - [JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)] - [JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)] - [JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)] - [JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] - [JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] - [JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] - [JsonSubtypes.KnownSubType(typeof(LinkPreviewBlock), BlockType.LinkPreview)] - [JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)] - [JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] - [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] - [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] - [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] - [JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)] - [JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)] - [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] - [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] - [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] - [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] - [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] - [JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(AudioBlock), BlockType.Audio)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BookmarkBlock), BlockType.Bookmark)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CalloutBlock), BlockType.Callout)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildPageBlock), BlockType.ChildPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CodeBlock), BlockType.Code)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnBlock), BlockType.Column)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnListBlock), BlockType.ColumnList)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DividerBlock), BlockType.Divider)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmbedBlock), BlockType.Embed)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EquationBlock), BlockType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileBlock), BlockType.File)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingOneBlock), BlockType.Heading_1)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingTwoBlock), BlockType.Heading_2)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingThreeeBlock), BlockType.Heading_3)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ImageBlock), BlockType.Image)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkPreviewBlock), BlockType.LinkPreview)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkToPageBlock), BlockType.LinkToPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TemplateBlock), BlockType.Template)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToDoBlock), BlockType.ToDo)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToggleBlock), BlockType.Toggle)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(VideoBlock), BlockType.Video)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.Unsupported)] public interface IBlock : IObject, IObjectModificationData { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Blocks/IBlockParent.cs b/Src/Notion.Client/Models/Blocks/IBlockParent.cs index 73634400..b2f8783f 100644 --- a/Src/Notion.Client/Models/Blocks/IBlockParent.cs +++ b/Src/Notion.Client/Models/Blocks/IBlockParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IBlockParent : IParent { } diff --git a/Src/Notion.Client/Models/Blocks/ImageBlock.cs b/Src/Notion.Client/Models/Blocks/ImageBlock.cs index 17aa6bae..cd6b055f 100644 --- a/Src/Notion.Client/Models/Blocks/ImageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ImageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class ImageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Image; - [JsonProperty("image")] public FileObject Image { get; set; } + + public override BlockType Type => BlockType.Image; } } diff --git a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs index 83f138c6..72107e48 100644 --- a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs @@ -4,13 +4,15 @@ namespace Notion.Client { public class LinkPreviewBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkPreview; + [JsonProperty("link_preview")] + public Data LinkPreview { get; set; } - [JsonProperty("link_preview")] public Data LinkPreview { get; set; } + public override BlockType Type => BlockType.LinkPreview; public class Data { - [JsonProperty("url")] public string Url { get; set; } + [JsonProperty("url")] + public string Url { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs index 30d3d7dd..ad688ca2 100644 --- a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class LinkToPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkToPage; - [JsonProperty("link_to_page")] public IPageParent LinkToPage { get; set; } + + public override BlockType Type => BlockType.LinkToPage; } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 3fe0d76a..f4a645e9 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class NumberedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.NumberedListItem; - [JsonProperty("numbered_list_item")] public Info NumberedListItem { get; set; } + public override BlockType Type => BlockType.NumberedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/PDFBlock.cs b/Src/Notion.Client/Models/Blocks/PDFBlock.cs index 85458796..55e3ce42 100644 --- a/Src/Notion.Client/Models/Blocks/PDFBlock.cs +++ b/Src/Notion.Client/Models/Blocks/PDFBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class PDFBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.PDF; - [JsonProperty("pdf")] public FileObject PDF { get; set; } + + public override BlockType Type => BlockType.PDF; } } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 67458b3c..f3b73f36 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ParagraphBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Paragraph; - [JsonProperty("paragraph")] public Info Paragraph { get; set; } + public override BlockType Type => BlockType.Paragraph; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 5fdad7da..e1466be6 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Quote; - [JsonProperty("quote")] public Info Quote { get; set; } + public override BlockType Type => BlockType.Quote; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs index 33c4dd25..98aa1d0f 100644 --- a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs +++ b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class SyncedBlockBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.SyncedBlock; - [JsonProperty("synced_block")] public Data SyncedBlock { get; set; } + public override BlockType Type => BlockType.SyncedBlock; + public class Data { [JsonProperty("synced_from")] diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index dd20d94b..cf41440c 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Table; - [JsonProperty("table")] public TableInfo Table { get; set; } + public override BlockType Type => BlockType.Table; + public class TableInfo { [JsonProperty("table_width")] diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 991ff903..0a6c9f26 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableOfContents; - [JsonProperty("table_of_contents")] public Data TableOfContents { get; set; } + public override BlockType Type => BlockType.TableOfContents; + public class Data { [JsonProperty("color")] diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs index e7214e6c..be105447 100644 --- a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableRow; - [JsonProperty("table_row")] public Info TableRow { get; set; } + public override BlockType Type => BlockType.TableRow; + public class Info { [JsonProperty("cells")] diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs index 69a78b62..705eaac3 100644 --- a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TemplateBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Template; - [JsonProperty("template")] public Data Template { get; set; } + public override BlockType Type => BlockType.Template; + public class Data { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 8b153f3b..0c52201a 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToDoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ToDo; - [JsonProperty("to_do")] public Info ToDo { get; set; } + public override BlockType Type => BlockType.ToDo; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 6646e9be..f61a1368 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToggleBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Toggle; - [JsonProperty("toggle")] public Info Toggle { get; set; } + public override BlockType Type => BlockType.Toggle; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/VideoBlock.cs b/Src/Notion.Client/Models/Blocks/VideoBlock.cs index 015bed96..7713ff7b 100644 --- a/Src/Notion.Client/Models/Blocks/VideoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/VideoBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class VideoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Video; - [JsonProperty("video")] public FileObject Video { get; set; } + + public override BlockType Type => BlockType.Video; } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs index 06177ccd..0e70ffcf 100644 --- a/Src/Notion.Client/Models/Common/IObjectModificationData.cs +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -6,25 +6,25 @@ namespace Notion.Client public interface IObjectModificationData { /// - /// Date and time when this object was created. + /// Date and time when this object was created. /// [JsonProperty("created_time")] DateTime CreatedTime { get; set; } /// - /// Date and time when this object was updated. + /// Date and time when this object was updated. /// [JsonProperty("last_edited_time")] DateTime LastEditedTime { get; set; } /// - /// User who created the object. + /// User who created the object. /// [JsonProperty("created_by")] PartialUser CreatedBy { get; set; } /// - /// User who last modified the object. + /// User who last modified the object. /// [JsonProperty("last_edited_by")] PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 502d8a5a..33da29b7 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -6,16 +6,6 @@ namespace Notion.Client { public class Database : IObject, IObjectModificationData { - public ObjectType Object => ObjectType.Database; - - public string Id { get; set; } - - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - [JsonProperty("title")] public List Title { get; set; } @@ -32,25 +22,35 @@ public class Database : IObject, IObjectModificationData public FileObject Cover { get; set; } /// - /// The URL of the Notion database. + /// The URL of the Notion database. /// [JsonProperty("url")] public string Url { get; set; } /// - /// The archived status of the database. + /// The archived status of the database. /// [JsonProperty("archived")] public bool Archived { get; set; } - public PartialUser CreatedBy { get; set; } - - public PartialUser LastEditedBy { get; set; } - [JsonProperty("is_inline")] public bool IsInline { get; set; } [JsonProperty("description")] public IEnumerable Description { get; set; } + + public ObjectType Object => ObjectType.Database; + + public string Id { get; set; } + + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/IDatabaseParent.cs b/Src/Notion.Client/Models/Database/IDatabaseParent.cs index 59233c38..768f815b 100644 --- a/Src/Notion.Client/Models/Database/IDatabaseParent.cs +++ b/Src/Notion.Client/Models/Database/IDatabaseParent.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IDatabaseParent : IParent { } diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 1f61b0dc..163b7ef0 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -5,26 +5,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxProperty), PropertyType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DateProperty), PropertyType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailProperty), PropertyType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesProperty), PropertyType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaProperty), PropertyType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectProperty), PropertyType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberProperty), PropertyType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeopleProperty), PropertyType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationProperty), PropertyType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextProperty), PropertyType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupProperty), PropertyType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectProperty), PropertyType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusProperty), PropertyType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitleProperty), PropertyType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlProperty), PropertyType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxProperty), PropertyType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DateProperty), PropertyType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailProperty), PropertyType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesProperty), PropertyType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaProperty), PropertyType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectProperty), PropertyType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberProperty), PropertyType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeopleProperty), PropertyType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationProperty), PropertyType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextProperty), PropertyType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupProperty), PropertyType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectProperty), PropertyType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs index 87e4b10a..d129acc6 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs @@ -5,8 +5,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(SinglePropertyRelation), RelationType.Single)] - [JsonSubtypes.KnownSubType(typeof(DualPropertyRelation), RelationType.Dual)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SinglePropertyRelation), RelationType.Single)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DualPropertyRelation), RelationType.Dual)] public abstract class RelationData { [JsonProperty("database_id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs index 103cdc0c..382e7088 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs index 89ce1c56..a0a58a47 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -8,6 +8,6 @@ public enum RelationType Single, [EnumMember(Value = "dual_property")] - Dual + Dual, } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 3ed99234..9af6397b 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -7,6 +7,7 @@ namespace Notion.Client public class SelectProperty : Property { public override PropertyType Type => PropertyType.Select; + public OptionWrapper Select { get; set; } } @@ -19,19 +20,20 @@ public class OptionWrapper public class SelectOption { /// - /// Name of the option as it appears in Notion. + /// Name of the option as it appears in Notion. /// [JsonProperty("name")] public string Name { get; set; } /// - /// ID of the option. + /// ID of the option. /// [JsonProperty("id")] public string Id { get; set; } /// - /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". + /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", + /// "purple", "pink". Defaults to "default". /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 88af1acd..3f10d578 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -5,9 +5,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(RichTextText), RichTextType.Text)] - [JsonSubtypes.KnownSubType(typeof(RichTextEquation), RichTextType.Equation)] - [JsonSubtypes.KnownSubType(typeof(RichTextMention), RichTextType.Mention)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextText), RichTextType.Text)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextEquation), RichTextType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextMention), RichTextType.Mention)] public class RichTextBase { [JsonProperty("plain_text")] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 59bc414f..58406612 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -14,6 +14,6 @@ public enum RichTextType Mention, [EnumMember(Value = "equation")] - Equation + Equation, } } diff --git a/Src/Notion.Client/Models/EmojiObject.cs b/Src/Notion.Client/Models/EmojiObject.cs index 95c67b61..9b5c64df 100644 --- a/Src/Notion.Client/Models/EmojiObject.cs +++ b/Src/Notion.Client/Models/EmojiObject.cs @@ -4,10 +4,10 @@ namespace Notion.Client { public class EmojiObject : IPageIcon { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("emoji")] public string Emoji { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index ce4d02f0..9ed206de 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -5,14 +5,14 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFile), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFile), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFile), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFile), "external")] public abstract class FileObject : IPageIcon { - [JsonProperty("type")] - public virtual string Type { get; set; } - [JsonProperty("caption")] public IEnumerable Caption { get; set; } + + [JsonProperty("type")] + public virtual string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObjectWithName.cs b/Src/Notion.Client/Models/File/FileObjectWithName.cs index a7381929..855a5e0f 100644 --- a/Src/Notion.Client/Models/File/FileObjectWithName.cs +++ b/Src/Notion.Client/Models/File/FileObjectWithName.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFileWithName), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFileWithName), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFileWithName), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFileWithName), "external")] public abstract class FileObjectWithName { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs index da144aec..53343e35 100644 --- a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs +++ b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs @@ -1,35 +1,34 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class CheckboxFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("checkbox")] - public Condition Checkbox { get; set; } - public CheckboxFilter( string propertyName, bool? equal = null, bool? doesNotEqual = null) { Property = propertyName; - Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual); + Checkbox = new Condition(equal, doesNotEqual); } + [JsonProperty("checkbox")] + public Condition Checkbox { get; set; } + public class Condition { + public Condition(bool? equal = null, bool? doesNotEqual = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + } + [JsonProperty("equals")] public bool? Equal { get; set; } [JsonProperty("does_not_equal")] public bool? DoesNotEqual { get; set; } - - public Condition(Nullable equal = null, Nullable doesNotEqual = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - } } } } diff --git a/Src/Notion.Client/Models/Filters/DateFilter.cs b/Src/Notion.Client/Models/Filters/DateFilter.cs index 51b38dc2..dde7ad47 100644 --- a/Src/Notion.Client/Models/Filters/DateFilter.cs +++ b/Src/Notion.Client/Models/Filters/DateFilter.cs @@ -7,9 +7,6 @@ namespace Notion.Client { public class DateFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("date")] - public Condition Date { get; set; } - public DateFilter( string propertyName, DateTime? equal = null, @@ -27,25 +24,59 @@ public DateFilter( bool? isNotEmpty = null) { Property = propertyName; + Date = new Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + [JsonProperty("date")] + public Condition Date { get; set; } + public class Condition { + public Condition( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + Before = before; + After = after; + OnOrBefore = onOrBefore; + OnOrAfter = onOrAfter; + PastWeek = pastWeek; + PastMonth = pastMonth; + PastYear = pastYear; + NextWeek = nextWeek; + NextMonth = nextMonth; + NextYear = nextYear; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime? Equal { get; set; } @@ -89,36 +120,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - DateTime? equal = null, - DateTime? before = null, - DateTime? after = null, - DateTime? onOrBefore = null, - DateTime? onOrAfter = null, - Dictionary pastWeek = null, - Dictionary pastMonth = null, - Dictionary pastYear = null, - Dictionary nextWeek = null, - Dictionary nextMonth = null, - Dictionary nextYear = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - Before = before; - After = after; - OnOrBefore = onOrBefore; - OnOrAfter = onOrAfter; - PastWeek = pastWeek; - PastMonth = pastMonth; - PastYear = pastYear; - NextWeek = nextWeek; - NextMonth = nextMonth; - NextYear = nextYear; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/EmailFilter.cs b/Src/Notion.Client/Models/Filters/EmailFilter.cs index ff5feda9..36bc3dde 100644 --- a/Src/Notion.Client/Models/Filters/EmailFilter.cs +++ b/Src/Notion.Client/Models/Filters/EmailFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class EmailFilter : SinglePropertyFilter { - [JsonProperty("email")] - public TextFilter.Condition Email { get; set; } - public EmailFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public EmailFilter( bool? isNotEmpty = null) { Property = propertyName; + Email = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("email")] + public TextFilter.Condition Email { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FilesFilter.cs b/Src/Notion.Client/Models/Filters/FilesFilter.cs index a32d4d7b..6c4b23c6 100644 --- a/Src/Notion.Client/Models/Filters/FilesFilter.cs +++ b/Src/Notion.Client/Models/Filters/FilesFilter.cs @@ -4,26 +4,20 @@ namespace Notion.Client { public class FilesFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("files")] - public Condition Files { get; set; } - public FilesFilter( string propertyName, bool? isEmpty = null, bool? isNotEmpty = null) { Property = propertyName; - Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty); + Files = new Condition(isEmpty, isNotEmpty); } + [JsonProperty("files")] + public Condition Files { get; set; } + public class Condition { - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( bool? isEmpty = null, bool? isNotEmpty = null) @@ -31,6 +25,12 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/Filter.cs b/Src/Notion.Client/Models/Filters/Filter.cs index 61f81f7e..47eced53 100644 --- a/Src/Notion.Client/Models/Filters/Filter.cs +++ b/Src/Notion.Client/Models/Filters/Filter.cs @@ -5,7 +5,6 @@ namespace Notion.Client { public class Filter { - } public class SinglePropertyFilter : Filter @@ -16,16 +15,16 @@ public class SinglePropertyFilter : Filter public class CompoundFilter : Filter { - [JsonProperty("or")] - public List Or { get; set; } - - [JsonProperty("and")] - public List And { get; set; } - public CompoundFilter(List or = null, List and = null) { Or = or; And = and; } + + [JsonProperty("or")] + public List Or { get; set; } + + [JsonProperty("and")] + public List And { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FormulaFilter.cs b/Src/Notion.Client/Models/Filters/FormulaFilter.cs index eee9fc52..5aec5e00 100644 --- a/Src/Notion.Client/Models/Filters/FormulaFilter.cs +++ b/Src/Notion.Client/Models/Filters/FormulaFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class FormulaFilter : SinglePropertyFilter { - [JsonProperty("formula")] - public Condition Formula { get; set; } - public FormulaFilter( string propertyName, TextFilter.Condition @string = null, @@ -15,28 +12,20 @@ public FormulaFilter( DateFilter.Condition date = null) { Property = propertyName; + Formula = new Condition( - @string: @string, - checkbox: checkbox, - number: number, - date: date + @string, + checkbox, + number, + date ); } + [JsonProperty("formula")] + public Condition Formula { get; set; } + public class Condition { - [JsonProperty("string")] - public TextFilter.Condition String { get; set; } - - [JsonProperty("checkbox")] - public CheckboxFilter.Condition Checkbox { get; set; } - - [JsonProperty("number")] - public NumberFilter.Condition Number { get; set; } - - [JsonProperty("date")] - public DateFilter.Condition Date { get; set; } - public Condition( TextFilter.Condition @string = null, CheckboxFilter.Condition checkbox = null, @@ -48,6 +37,18 @@ public Condition( Number = number; Date = date; } + + [JsonProperty("string")] + public TextFilter.Condition String { get; set; } + + [JsonProperty("checkbox")] + public CheckboxFilter.Condition Checkbox { get; set; } + + [JsonProperty("number")] + public NumberFilter.Condition Number { get; set; } + + [JsonProperty("date")] + public DateFilter.Condition Date { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs index 14aec6d5..011a127e 100644 --- a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class MultiSelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("multi_select")] - public Condition MultiSelect { get; set; } - public MultiSelectFilter( string propertyName, string contains = null, @@ -15,29 +12,20 @@ public MultiSelectFilter( bool? isNotEmpty = null) { Property = propertyName; + MultiSelect = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("multi_select")] + public Condition MultiSelect { get; set; } public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -49,7 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } - } + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Filters/NumberFilter.cs b/Src/Notion.Client/Models/Filters/NumberFilter.cs index 4895d3e8..1a2f6879 100644 --- a/Src/Notion.Client/Models/Filters/NumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/NumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class NumberFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("number")] - public Condition Number { get; set; } - public NumberFilter( string propertyName, double? equal = null, @@ -19,20 +16,44 @@ public NumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Number = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - greaterThan: greaterThan, - lessThan: lessThan, - greaterThanOrEqualTo: greaterThanOrEqualTo, - lessThanOrEqualTo: lessThanOrEqualTo, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + greaterThan, + lessThan, + greaterThanOrEqualTo, + lessThanOrEqualTo, + isEmpty, + isNotEmpty ); } + [JsonProperty("number")] + public Condition Number { get; set; } + public class Condition { + public Condition( + double? equal = null, + double? doesNotEqual = null, + double? greaterThan = null, + double? lessThan = null, + double? greaterThanOrEqualTo = null, + double? lessThanOrEqualTo = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + GreaterThan = greaterThan; + LessThan = lessThan; + GreaterThanOrEqualTo = greaterThanOrEqualTo; + LessThanOrEqualTo = lessThanOrEqualTo; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public double? Equal { get; set; } @@ -56,27 +77,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - double? equal = null, - double? doesNotEqual = null, - double? greaterThan = null, - double? lessThan = null, - double? greaterThanOrEqualTo = null, - double? lessThanOrEqualTo = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - GreaterThan = greaterThan; - LessThan = lessThan; - GreaterThanOrEqualTo = greaterThanOrEqualTo; - LessThanOrEqualTo = lessThanOrEqualTo; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } - } } diff --git a/Src/Notion.Client/Models/Filters/PeopleFilter.cs b/Src/Notion.Client/Models/Filters/PeopleFilter.cs index af1067c4..6b83dda4 100644 --- a/Src/Notion.Client/Models/Filters/PeopleFilter.cs +++ b/Src/Notion.Client/Models/Filters/PeopleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PeopleFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("people")] - public Condition People { get; set; } - public PeopleFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public PeopleFilter( bool? isNotEmpty = null) { Property = propertyName; + People = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("people")] + public Condition People { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs index 758a65db..9ea9cf68 100644 --- a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PhoneNumberFilter : SinglePropertyFilter { - [JsonProperty("phone_number")] - public TextFilter.Condition Text { get; set; } - public PhoneNumberFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public PhoneNumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Text = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("phone_number")] + public TextFilter.Condition Text { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/RelationFilter.cs b/Src/Notion.Client/Models/Filters/RelationFilter.cs index b7e2924d..bff5f498 100644 --- a/Src/Notion.Client/Models/Filters/RelationFilter.cs +++ b/Src/Notion.Client/Models/Filters/RelationFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RelationFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("relation")] - public Condition Relation { get; set; } - public RelationFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public RelationFilter( bool? isNotEmpty = null) { Property = propertyName; + Relation = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("relation")] + public Condition Relation { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/RichTextFilter.cs b/Src/Notion.Client/Models/Filters/RichTextFilter.cs index 90bae02e..733b93ba 100644 --- a/Src/Notion.Client/Models/Filters/RichTextFilter.cs +++ b/Src/Notion.Client/Models/Filters/RichTextFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RichTextFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("rich_text")] - public TextFilter.Condition RichText { get; set; } - public RichTextFilter( string propertyName, string equal = null, @@ -19,23 +16,47 @@ public RichTextFilter( bool? isNotEmpty = null) { Property = propertyName; + RichText = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("rich_text")] + public TextFilter.Condition RichText { get; set; } } public static class TextFilter { public class Condition { + public Condition( + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + Contains = contains; + DoesNotContain = doesNotContain; + StartsWith = startsWith; + EndsWith = endsWith; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public string Equal { get; set; } @@ -59,26 +80,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - string equal = null, - string doesNotEqual = null, - string contains = null, - string doesNotContain = null, - string startsWith = null, - string endsWith = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - Contains = contains; - DoesNotContain = doesNotContain; - StartsWith = startsWith; - EndsWith = endsWith; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs index 41cb759e..df641729 100644 --- a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs +++ b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs @@ -4,18 +4,16 @@ namespace Notion.Client { public class RollupFilter : SinglePropertyFilter { - [JsonProperty("rollup")] - public Condition Rollup { get; set; } - public RollupFilter( - string propertyName - , IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + string propertyName, + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Property = propertyName; + Rollup = new Condition( any, none, @@ -25,14 +23,17 @@ string propertyName ); } + [JsonProperty("rollup")] + public Condition Rollup { get; set; } + public class Condition { public Condition( - IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Any = any; None = none; diff --git a/Src/Notion.Client/Models/Filters/SelectFilter.cs b/Src/Notion.Client/Models/Filters/SelectFilter.cs index 6f0887a4..064334f1 100644 --- a/Src/Notion.Client/Models/Filters/SelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/SelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class SelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("select")] - public Condition Select { get; set; } - public SelectFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public SelectFilter( bool? isNotEmpty = null) { Property = propertyName; + Select = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("select")] + public Condition Select { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/StatusFilter.cs b/Src/Notion.Client/Models/Filters/StatusFilter.cs index 7ed9b23f..0af0a22c 100644 --- a/Src/Notion.Client/Models/Filters/StatusFilter.cs +++ b/Src/Notion.Client/Models/Filters/StatusFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class StatusFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("status")] - public Condition Status { get; set; } - public StatusFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public StatusFilter( bool? isNotEmpty = null) { Property = propertyName; + Status = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("status")] + public Condition Status { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs index ac8f2244..d550817e 100644 --- a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampCreatedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "created_time"; - [JsonProperty("created_time")] - public DateFilter.Condition CreatedTime { get; set; } - public TimestampCreatedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampCreatedTimeFilter( bool? isNotEmpty = null) { CreatedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("created_time")] + public DateFilter.Condition CreatedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs index 1d6acb7f..51a6e39f 100644 --- a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampLastEditedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "last_modified_time"; - [JsonProperty("last_edited_time")] - public DateFilter.Condition LastEditedTime { get; set; } - public TimestampLastEditedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampLastEditedTimeFilter( bool? isNotEmpty = null) { LastEditedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("last_edited_time")] + public DateFilter.Condition LastEditedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TitleFilter.cs b/Src/Notion.Client/Models/Filters/TitleFilter.cs index 7c21bb33..1e0d4303 100644 --- a/Src/Notion.Client/Models/Filters/TitleFilter.cs +++ b/Src/Notion.Client/Models/Filters/TitleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class TitleFilter : SinglePropertyFilter { - [JsonProperty("title")] - public TextFilter.Condition Title { get; set; } - public TitleFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public TitleFilter( bool? isNotEmpty = null) { Property = propertyName; + Title = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("title")] + public TextFilter.Condition Title { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/URLFilter.cs b/Src/Notion.Client/Models/Filters/URLFilter.cs index b6a1fe6b..b2d4c611 100644 --- a/Src/Notion.Client/Models/Filters/URLFilter.cs +++ b/Src/Notion.Client/Models/Filters/URLFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class URLFilter : SinglePropertyFilter { - [JsonProperty("url")] - public TextFilter.Condition URL { get; set; } - public URLFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public URLFilter( bool? isNotEmpty = null) { Property = propertyName; + URL = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("url")] + public TextFilter.Condition URL { get; set; } } } diff --git a/Src/Notion.Client/Models/IObject.cs b/Src/Notion.Client/Models/IObject.cs index 2f72f929..b8ab1108 100644 --- a/Src/Notion.Client/Models/IObject.cs +++ b/Src/Notion.Client/Models/IObject.cs @@ -5,10 +5,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(Page), ObjectType.Page)] - [JsonSubtypes.KnownSubType(typeof(Database), ObjectType.Database)] - [JsonSubtypes.KnownSubType(typeof(IBlock), ObjectType.Block)] - [JsonSubtypes.KnownSubType(typeof(User), ObjectType.User)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Page), ObjectType.Page)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Database), ObjectType.Database)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(IBlock), ObjectType.Block)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(User), ObjectType.User)] public interface IObject { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Page/IPageIcon.cs b/Src/Notion.Client/Models/Page/IPageIcon.cs index a89184fe..b9ebea56 100644 --- a/Src/Notion.Client/Models/Page/IPageIcon.cs +++ b/Src/Notion.Client/Models/Page/IPageIcon.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(EmojiObject), "emoji")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "file")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmojiObject), "emoji")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "external")] public interface IPageIcon { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Page/IPageParent.cs b/Src/Notion.Client/Models/Page/IPageParent.cs index 439b1a3f..b9111d91 100644 --- a/Src/Notion.Client/Models/Page/IPageParent.cs +++ b/Src/Notion.Client/Models/Page/IPageParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IPageParent : IParent { } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index d96fef8a..996bdd46 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -7,63 +7,63 @@ namespace Notion.Client public class Page : IObject, IObjectModificationData { /// - /// Object type - /// - public ObjectType Object => ObjectType.Page; - - /// - /// Unique identifier of the page. - /// - public string Id { get; set; } - - /// - /// The parent of this page. Can be a database, page, or workspace. + /// The parent of this page. Can be a database, page, or workspace. /// [JsonProperty("parent")] public IPageParent Parent { get; set; } /// - /// Date and time when this page was created. - /// - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - /// - /// Date and time when this page was updated. - /// - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - - /// - /// The archived status of the page. + /// The archived status of the page. /// [JsonProperty("archived")] public bool IsArchived { get; set; } /// - /// Property values of this page. + /// Property values of this page. /// [JsonProperty("properties")] public IDictionary Properties { get; set; } /// - /// The URL of the Notion page. + /// The URL of the Notion page. /// [JsonProperty("url")] public string Url { get; set; } /// - /// Page icon. + /// Page icon. /// [JsonProperty("icon")] public IPageIcon Icon { get; set; } /// - /// Page cover image. + /// Page cover image. /// [JsonProperty("cover")] public FileObject Cover { get; set; } + /// + /// Object type + /// + public ObjectType Object => ObjectType.Page; + + /// + /// Unique identifier of the page. + /// + public string Id { get; set; } + + /// + /// Date and time when this page was created. + /// + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + /// + /// Date and time when this page was updated. + /// + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs index 1ac1fd51..e3fd7749 100644 --- a/Src/Notion.Client/Models/Parents/BlockParent.cs +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class BlockParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always has a value "block_id" + /// The ID of the block that the element belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("block_id")] + public string BlockId { get; set; } /// - /// The ID of the block that the element belongs to. + /// Always has a value "block_id" /// - [JsonProperty("block_id")] - public string BlockId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/DatabaseParent.cs b/Src/Notion.Client/Models/Parents/DatabaseParent.cs index 2e680655..878dbe89 100644 --- a/Src/Notion.Client/Models/Parents/DatabaseParent.cs +++ b/Src/Notion.Client/Models/Parents/DatabaseParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class DatabaseParent : IPageParent, IBlockParent { /// - /// Always "database_id" + /// The ID of the database that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("database_id")] + public string DatabaseId { get; set; } /// - /// The ID of the database that this page belongs to. + /// Always "database_id" /// - [JsonProperty("database_id")] - public string DatabaseId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/PageParent.cs b/Src/Notion.Client/Models/Parents/PageParent.cs index 13b1c95a..565f7ccc 100644 --- a/Src/Notion.Client/Models/Parents/PageParent.cs +++ b/Src/Notion.Client/Models/Parents/PageParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class PageParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always "page_id". + /// The ID of the page that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("page_id")] + public string PageId { get; set; } /// - /// The ID of the page that this page belongs to. + /// Always "page_id". /// - [JsonProperty("page_id")] - public string PageId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs index 86c60a54..a0b5e1c4 100644 --- a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs +++ b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs @@ -3,7 +3,7 @@ public class WorkspaceParent : IPageParent, IDatabaseParent, IBlockParent { /// - /// Always "workspace". + /// Always "workspace". /// public ParentType Type { get; set; } } diff --git a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs index 5ebc7730..58db1a7d 100644 --- a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs +++ b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(SimplePropertyItem), "property_item")] - [JsonSubtypes.KnownSubType(typeof(ListPropertyItem), "list")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SimplePropertyItem), "property_item")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ListPropertyItem), "list")] public interface IPropertyItemObject { [JsonProperty("object")] @@ -18,7 +18,8 @@ public interface IPropertyItemObject string Id { get; } /// - /// Only present in paginated property values with another page of results. If present, the url the user can request to get the next page of results. + /// Only present in paginated property values with another page of results. If present, the url the user can request to + /// get the next page of results. /// [JsonProperty("next_url")] string NextURL { get; } diff --git a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs index f539fcd6..5e35159c 100644 --- a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs @@ -1,19 +1,10 @@ using System.Collections.Generic; -using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client { public class ListPropertyItem : IPropertyItemObject { - public string Object => "list"; - - public virtual string Type { get; set; } - - public string Id { get; set; } - - public string NextURL { get; set; } - [JsonProperty("results")] public IEnumerable Results { get; set; } @@ -25,5 +16,13 @@ public class ListPropertyItem : IPropertyItemObject [JsonProperty("property_item")] public SimplePropertyItem PropertyItem { get; set; } + + public string Object => "list"; + + public virtual string Type { get; set; } + + public string Id { get; set; } + + public string NextURL { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs index 3df75fd7..04d7da7b 100644 --- a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs @@ -7,23 +7,31 @@ public class RollupPropertyItem : SimplePropertyItem { public override string Type => "rollup"; - [JsonProperty("rollup")] public Data Rollup { get; set; } + [JsonProperty("rollup")] + public Data Rollup { get; set; } public class Data { - [JsonProperty("type")] public string Type { get; set; } + [JsonProperty("type")] + public string Type { get; set; } - [JsonProperty("function")] public string Function { get; set; } + [JsonProperty("function")] + public string Function { get; set; } - [JsonProperty("number")] public double? Number { get; set; } + [JsonProperty("number")] + public double? Number { get; set; } - [JsonProperty("date")] public Date Date { get; set; } + [JsonProperty("date")] + public Date Date { get; set; } - [JsonProperty("array")] public IEnumerable> Array { get; set; } + [JsonProperty("array")] + public IEnumerable> Array { get; set; } - [JsonProperty("unsupported")] public Dictionary Unsupported { get; set; } + [JsonProperty("unsupported")] + public Dictionary Unsupported { get; set; } - [JsonProperty("incomplete")] public Dictionary Incomplete { get; set; } + [JsonProperty("incomplete")] + public Dictionary Incomplete { get; set; } } } } diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index 50d95184..ed3bef38 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -4,26 +4,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyItem), "number")] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyItem), "url")] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyItem), "select")] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyItem), "multi_select")] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyItem), "status")] - [JsonSubtypes.KnownSubType(typeof(DatePropertyItem), "date")] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyItem), "email")] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyItem), "phone_number")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyItem), "checkbox")] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyItem), "files")] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyItem), "created_by")] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyItem), "created_time")] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyItem), "last_edited_by")] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyItem), "last_edited_time")] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyItem), "formula")] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyItem), "title")] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyItem), "rich_text")] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyItem), "people")] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyItem), "relation")] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyItem), "number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyItem), "url")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyItem), "select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyItem), "multi_select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyItem), "status")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyItem), "date")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyItem), "email")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyItem), "phone_number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyItem), "checkbox")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyItem), "files")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyItem), "created_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyItem), "created_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyItem), "last_edited_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyItem), "last_edited_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyItem), "formula")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyItem), "title")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyItem), "rich_text")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyItem), "people")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyItem), "relation")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyItem), "rollup")] public abstract class SimplePropertyItem : IPropertyItemObject { public string Object => "property_item"; diff --git a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs index 46e70108..6b6b863c 100644 --- a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs @@ -6,6 +6,7 @@ public class StatusPropertyItem : SimplePropertyItem { public override string Type => "status"; - [JsonProperty("status")] public SelectOption Status { get; set; } + [JsonProperty("status")] + public SelectOption Status { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs index 1f3fec50..422eb9b7 100644 --- a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Checkbox property value objects contain a boolean within the checkbox property. + /// Checkbox property value objects contain a boolean within the checkbox property. /// public class CheckboxPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs index 17fa4ef4..31cf5f5b 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created by property value object + /// Created by property value object /// public class CreatedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedBy; /// - /// Describes the user who created this page. + /// Describes the user who created this page. /// [JsonProperty("created_by")] public User CreatedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs index 0b20b2dc..e0550d13 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created time property value object. + /// Created time property value object. /// public class CreatedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedTime; /// - /// The date and time when this page was created. + /// The date and time when this page was created. /// [JsonProperty("created_time")] public string CreatedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index aeb3cd8e..22715b2e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -4,38 +4,39 @@ namespace Notion.Client { /// - /// Date property value object. + /// Date property value object. /// public class DatePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Date; /// - /// Date + /// Date /// [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } /// - /// Date value object. + /// Date value object. /// public class Date { /// - /// Start date with optional time. + /// Start date with optional time. /// [JsonProperty("start")] public DateTime? Start { get; set; } /// - /// End date with optional time. + /// End date with optional time. /// [JsonProperty("end")] public DateTime? End { get; set; } /// - /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js. + /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are + /// based on the time zones from Moment.js. /// [JsonProperty("time_zone")] public string TimeZone { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs index 1869fc85..5a8e2c7a 100644 --- a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Email property value object. + /// Email property value object. /// public class EmailPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Email; /// - /// Describes an email address. + /// Describes an email address. /// [JsonProperty("email")] public string Email { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs index 41580fdb..67bc864a 100644 --- a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// File property value object. + /// File property value object. /// public class FilesPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Files; /// - /// Array of File Object with name. + /// Array of File Object with name. /// [JsonProperty("files")] public List Files { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs index e85fd5bd..a1242f47 100644 --- a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs @@ -3,50 +3,50 @@ namespace Notion.Client { /// - /// Formula property value object. + /// Formula property value object. /// public class FormulaPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Formula; /// - /// A formula described in the database's properties. + /// A formula described in the database's properties. /// [JsonProperty("formula")] public FormulaValue Formula { get; set; } } /// - /// Formula value object. + /// Formula value object. /// public class FormulaValue { /// - /// Formula value type + /// Formula value type /// [JsonProperty("type")] public string Type { get; set; } /// - /// String formula value. + /// String formula value. /// [JsonProperty("string")] public string String { get; set; } /// - /// Number formula value. + /// Number formula value. /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Boolean formula value. + /// Boolean formula value. /// [JsonProperty("boolean")] public bool? Boolean { get; set; } /// - /// Date formula value + /// Date formula value /// [JsonProperty("date")] public Date Date { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs index b5e26efc..a536ad60 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited by property value object. + /// Last edited by property value object. /// public class LastEditedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedBy; /// - /// Describes the user who last updated this page. + /// Describes the user who last updated this page. /// [JsonProperty("last_edited_by")] public User LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs index 785ac3bc..25d3100d 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited time property value object. + /// Last edited time property value object. /// public class LastEditedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedTime; /// - /// The date and time when this page was last updated. + /// The date and time when this page was last updated. /// [JsonProperty("last_edited_time")] public string LastEditedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs index a5ee4f0a..ff820527 100644 --- a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Multi-select property value object. + /// Multi-select property value object. /// public class MultiSelectPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.MultiSelect; /// - /// An array of multi-select option values. + /// An array of multi-select option values. /// [JsonProperty("multi_select")] public List MultiSelect { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs index a98a34d4..15f9c768 100644 --- a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Number formula property value object. + /// Number formula property value object. /// public class NumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Number; /// - /// Value of number + /// Value of number /// [JsonProperty("number")] public double? Number { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs index 047d33ee..62557560 100644 --- a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// People property value object. + /// People property value object. /// public class PeoplePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.People; /// - /// List of users. + /// List of users. /// [JsonProperty("people")] public List People { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs index be5e482e..79a24dac 100644 --- a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Phone number property value object. + /// Phone number property value object. /// public class PhoneNumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.PhoneNumber; /// - /// Phone number value + /// Phone number value /// [JsonProperty("phone_number")] public string PhoneNumber { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index 8437b4f8..f893e47a 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -5,33 +5,33 @@ namespace Notion.Client { /// - /// An object describing the identifier, type, and value of a page property. + /// An object describing the identifier, type, and value of a page property. /// [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DatePropertyValue), PropertyValueType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyValue), PropertyValueType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyValue), PropertyValueType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyValue), PropertyValueType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyValue), PropertyValueType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyValue), PropertyValueType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyValue), PropertyValueType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyValue), PropertyValueType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyValue), PropertyValueType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyValue), PropertyValueType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyValue), PropertyValueType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyValue), PropertyValueType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyValue), PropertyValueType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyValue), PropertyValueType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyValue), PropertyValueType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyValue), PropertyValueType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyValue), PropertyValueType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyValue), PropertyValueType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyValue), PropertyValueType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyValue), PropertyValueType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyValue), PropertyValueType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyValue), PropertyValueType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyValue), PropertyValueType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] public class PropertyValue { /// - /// Underlying identifier of the property. + /// Underlying identifier of the property. /// [JsonProperty("id")] public string Id { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index fcbeae61..93a8d63e 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Types of Property Value + /// Types of Property Value /// public enum PropertyValueType { diff --git a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs index 3d11a096..6f9e0ec8 100644 --- a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Relation property value object. + /// Relation property value object. /// public class RelationPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Relation; /// - /// Array of page references + /// Array of page references /// [JsonProperty("relation")] public List Relation { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs index 028ed046..90e8d0be 100644 --- a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Rich Text property value object. + /// Rich Text property value object. /// public class RichTextPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.RichText; /// - /// List of rich text objects + /// List of rich text objects /// [JsonProperty("rich_text")] public List RichText { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs index 7c573081..2eb104fb 100644 --- a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs @@ -4,7 +4,7 @@ namespace Notion.Client { /// - /// Rollup property value object. + /// Rollup property value object. /// public class RollupPropertyValue : PropertyValue { @@ -15,31 +15,31 @@ public class RollupPropertyValue : PropertyValue } /// - /// Object containing rollup type-specific data. + /// Object containing rollup type-specific data. /// public class RollupValue { /// - /// The type of rollup. Possible values are "number", "date", and "array". + /// The type of rollup. Possible values are "number", "date", and "array". /// [JsonProperty("type")] public string Type { get; set; } /// - /// Number rollup property values contain a number + /// Number rollup property values contain a number /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Date rollup property values contain a date property value. + /// Date rollup property values contain a date property value. /// [JsonProperty("date")] public DatePropertyValue Date { get; set; } /// - /// Array rollup property values contain an array of element objects. - /// Array containing the property value object will not contain value for Id field + /// Array rollup property values contain an array of element objects. + /// Array containing the property value object will not contain value for Id field /// [JsonProperty("array")] public List Array { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs index 07b2a346..74c94c82 100644 --- a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Select property value object. + /// Select property value object. /// public class SelectPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index 497e4c18..f4a82e48 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -5,37 +5,10 @@ namespace Notion.Client { /// - /// Status property value objects contain page status + /// Status property value objects contain page status /// public class StatusPropertyValue : PropertyValue { - public override PropertyValueType Type => PropertyValueType.Status; - - [JsonProperty("status")] - public Data Status { get; set; } - - public class Data - { - /// - /// ID of the option. - /// - [JsonProperty("id")] - public string Id { get; set; } - - /// - /// Name of the option as it appears in Notion. - /// - [JsonProperty("name")] - public string Name { get; set; } - - /// - /// Color of the option. - /// - [JsonProperty("color")] - [JsonConverter(typeof(StringEnumConverter))] - public Color? Color { get; set; } - } - public enum Color { [EnumMember(Value = "default")] @@ -68,5 +41,32 @@ public enum Color [EnumMember(Value = "red")] Red, } + + public override PropertyValueType Type => PropertyValueType.Status; + + [JsonProperty("status")] + public Data Status { get; set; } + + public class Data + { + /// + /// ID of the option. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Name of the option as it appears in Notion. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Color of the option. + /// + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs index 58b7842d..e72a2a08 100644 --- a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Title property value object. + /// Title property value object. /// public class TitlePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Title; /// - /// An array of rich text objects + /// An array of rich text objects /// [JsonProperty("title")] public List Title { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs index 08b800e6..5fc8f8bb 100644 --- a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// URL property value object. + /// URL property value object. /// public class UrlPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Url; /// - /// Describes a web address + /// Describes a web address /// [JsonProperty("url")] public string Url { get; set; } diff --git a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs index 61a7a887..062d75c0 100644 --- a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UserOwner), "user")] - [JsonSubtypes.KnownSubType(typeof(WorkspaceIntegrationOwner), "workspace")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UserOwner), "user")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceIntegrationOwner), "workspace")] public interface IBotOwner { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs index 40d69867..e60a4fab 100644 --- a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class UserOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("user")] public User User { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs index 78a84f6f..b5304157 100644 --- a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class WorkspaceIntegrationOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("workspace")] public bool Workspace { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/User.cs b/Src/Notion.Client/Models/User/User.cs index 7f336929..6ae9efef 100644 --- a/Src/Notion.Client/Models/User/User.cs +++ b/Src/Notion.Client/Models/User/User.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class User : IObject { - public ObjectType Object => ObjectType.User; - public string Id { get; set; } - [JsonProperty("type")] public string Type { get; set; } @@ -21,5 +18,9 @@ public class User : IObject [JsonProperty("bot")] public Bot Bot { get; set; } + + public ObjectType Object => ObjectType.User; + + public string Id { get; set; } } } diff --git a/Src/Notion.Client/NotionApiErrorResponse.cs b/Src/Notion.Client/NotionApiErrorResponse.cs index f27288fb..44a225b2 100644 --- a/Src/Notion.Client/NotionApiErrorResponse.cs +++ b/Src/Notion.Client/NotionApiErrorResponse.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - class NotionApiErrorResponse + internal class NotionApiErrorResponse { [JsonProperty("code")] public NotionAPIErrorCode ErrorCode { get; set; } diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index 358db384..c7c9d7d4 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -29,6 +29,7 @@ public NotionApiException( } public NotionAPIErrorCode? NotionAPIErrorCode { get; } + public HttpStatusCode StatusCode { get; } } } diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index f1650b29..f752413a 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -3,11 +3,17 @@ public interface INotionClient { IUsersClient Users { get; } + IDatabasesClient Databases { get; } + IPagesClient Pages { get; } + ISearchClient Search { get; } + IBlocksClient Blocks { get; } + ICommentsClient Comments { get; } + IRestClient RestClient { get; } } @@ -32,11 +38,17 @@ public NotionClient( } public IUsersClient Users { get; } + public IDatabasesClient Databases { get; } + public IPagesClient Pages { get; } + public ISearchClient Search { get; } + public IBlocksClient Blocks { get; } + public ICommentsClient Comments { get; } + public IRestClient RestClient { get; } } } diff --git a/Src/Notion.Client/NotionClientFactory.cs b/Src/Notion.Client/NotionClientFactory.cs index 0a02eb3c..e82ba2de 100644 --- a/Src/Notion.Client/NotionClientFactory.cs +++ b/Src/Notion.Client/NotionClientFactory.cs @@ -7,11 +7,11 @@ public static NotionClient Create(ClientOptions options) var restClient = new RestClient(options); return new NotionClient( - restClient: restClient - , users: new UsersClient(restClient) - , databases: new DatabasesClient(restClient) - , pages: new PagesClient(restClient) - , search: new SearchClient(restClient) + restClient + , new UsersClient(restClient) + , new DatabasesClient(restClient) + , new PagesClient(restClient) + , new SearchClient(restClient) , blocks: new BlocksClient(restClient) , comments: new CommentsClient(restClient) ); diff --git a/Src/Notion.Client/RestClient/ClientOptions.cs b/Src/Notion.Client/RestClient/ClientOptions.cs index 3c6be1bc..d0015767 100644 --- a/Src/Notion.Client/RestClient/ClientOptions.cs +++ b/Src/Notion.Client/RestClient/ClientOptions.cs @@ -3,7 +3,9 @@ public class ClientOptions { public string BaseUrl { get; set; } + public string NotionVersion { get; set; } + public string AuthToken { get; set; } } } diff --git a/Src/Notion.Client/RestClient/LoggingHandler.cs b/Src/Notion.Client/RestClient/LoggingHandler.cs index 8655bb97..a6001d10 100644 --- a/Src/Notion.Client/RestClient/LoggingHandler.cs +++ b/Src/Notion.Client/RestClient/LoggingHandler.cs @@ -7,7 +7,9 @@ namespace Notion.Client { public class LoggingHandler : DelegatingHandler { - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) { Log.Trace("Request: {request}", request); @@ -22,6 +24,7 @@ protected override async Task SendAsync(HttpRequestMessage catch (Exception ex) { Log.Error(ex, "Failed to get response: {exception}", ex); + throw; } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index bba3a866..5da38f61 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -14,50 +14,98 @@ namespace Notion.Client { public class RestClient : IRestClient { - private HttpClient _httpClient; private readonly ClientOptions _options; - protected readonly JsonSerializerSettings defaultSerializerSettings = new JsonSerializerSettings + protected readonly JsonSerializerSettings defaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, }; + private HttpClient _httpClient; + public RestClient(ClientOptions options) { _options = MergeOptions(options); } - private static ClientOptions MergeOptions(ClientOptions options) + public async Task GetAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) { - return new ClientOptions - { - AuthToken = options.AuthToken, - BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION - }; + var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, + cancellationToken: cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); } - public async Task GetAsync( + public async Task PostAsync( string uri, + object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { - var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, cancellationToken: cancellationToken); + void AttachContent(HttpRequestMessage httpRequest) => + httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), + Encoding.UTF8, "application/json"); + + var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, + cancellationToken); return await response.ParseStreamAsync(serializerSettings); } + public async Task PatchAsync( + string uri, + object body, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + void AttachContent(HttpRequestMessage httpRequest) + { + var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); + httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); + } + + var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, + cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); + } + + public async Task DeleteAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); + } + + private static ClientOptions MergeOptions(ClientOptions options) + { + return new ClientOptions + { + AuthToken = options.AuthToken, + BaseUrl = options.BaseUrl ?? Constants.BASE_URL, + NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION, + }; + } + private static async Task BuildException(HttpResponseMessage response) { var errorBody = await response.Content.ReadAsStringAsync(); NotionApiErrorResponse errorResponse = null; + if (!string.IsNullOrWhiteSpace(errorBody)) { try @@ -114,47 +162,11 @@ private static void AddHeaders(HttpRequestMessage request, IDictionary PostAsync( - string uri, - object body, - IDictionary queryParams = null, - IDictionary headers = null, - JsonSerializerSettings serializerSettings = null, - CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task PatchAsync(string uri, object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); - httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task DeleteAsync(string uri, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); - } - private HttpClient EnsureHttpClient() { if (_httpClient == null) { - var pipeline = new LoggingHandler() { InnerHandler = new HttpClientHandler() }; + var pipeline = new LoggingHandler {InnerHandler = new HttpClientHandler()}; _httpClient = new HttpClient(pipeline); _httpClient.BaseAddress = new Uri(_options.BaseUrl); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 783ae20e..86a2f0fb 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -25,7 +25,7 @@ public static string AddQueryString(string uri, string name, string value) throw new ArgumentNullException(nameof(value)); } - return AddQueryString(uri, new[] { new KeyValuePair(name, value) }); + return AddQueryString(uri, new[] {new KeyValuePair(name, value)}); } public static string AddQueryString(string uri, IDictionary queryParams) @@ -74,6 +74,7 @@ private static string AddQueryString( var sb = new StringBuilder(); sb.Append(uriToBeAppended); + foreach (var parameter in queryParams) { sb.Append(hasQuery ? '&' : '?'); @@ -84,13 +85,14 @@ private static string AddQueryString( } sb.Append(anchorText); + return sb.ToString(); } - private static IEnumerable> RemoveEmptyValueQueryParams(IEnumerable> queryParams) + private static IEnumerable> RemoveEmptyValueQueryParams( + IEnumerable> queryParams) { return queryParams.Where(x => !string.IsNullOrWhiteSpace(x.Value)); } - } } diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 2ac7219d..32d887eb 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -5,130 +5,95 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class CommentsClientTests : IDisposable { - public class CommentsClientTests : IDisposable + private readonly INotionClient _client; + private readonly Page _page; + private readonly string _pageParentId; + + public CommentsClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + + _client = NotionClientFactory.Create(options); + + _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? + throw new ArgumentNullException("Page parent id is required."); + + _page = _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = _pageParentId} + ).Build() + ).Result; + } + + public void Dispose() + { + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters {Archived = true}).Wait(); + } + + [Fact] + public async Task ShouldCreatePageComment() { - private readonly INotionClient _client; - private readonly string _pageParentId; - private readonly Page _page; - - public CommentsClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; - - _client = NotionClientFactory.Create(options); - _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? throw new ArgumentNullException("Page parent id is required."); - - _page = _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = _pageParentId - } - ).Build() - ).Result; - } - - [Fact] - public async Task ShouldCreatePageComment() - { - // Arrange - var parameters = CreateCommentParameters.CreatePageComment( - new ParentPageInput + // Arrange + var parameters = CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ); + + // Act + var response = await _client.Comments.Create(parameters); + + // Arrange + + Assert.NotNull(response.Parent); + Assert.NotNull(response.Id); + Assert.NotNull(response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); + } + + [Fact] + public async Task ShouldCreateADiscussionComment() + { + // Arrange + var comment = await _client.Comments.Create( + CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ) + ); + + // Act + var response = await _client.Comments.Create( + CreateCommentParameters.CreateDiscussionComment( + comment.DiscussionId, + new List { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } + new RichTextTextInput {Text = new Text {Content = "This is a sub comment"}}, } - ); - - // Act - var response = await _client.Comments.Create(parameters); - - // Arrange - - Assert.NotNull(response.Parent); - Assert.NotNull(response.Id); - Assert.NotNull(response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - [Fact] - public async Task ShouldCreateADiscussionComment() - { - // Arrange - var comment = await _client.Comments.Create( - CreateCommentParameters.CreatePageComment( - new ParentPageInput - { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } - } - ) - ); - - // Act - var response = await _client.Comments.Create( - CreateCommentParameters.CreateDiscussionComment( - comment.DiscussionId, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a sub comment" - } - } - } - ) - ); - - // Arrange - Assert.Null(response.Parent); - Assert.NotNull(response.Id); - Assert.Equal(comment.DiscussionId, response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a sub comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - public void Dispose() - { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters - { - Archived = true, - }).Wait(); - } + ) + ); + + // Arrange + Assert.Null(response.Parent); + Assert.NotNull(response.Id); + Assert.Equal(comment.DiscussionId, response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a sub comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index eabef5b4..1aaa2726 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -6,537 +6,430 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IBlocksClientTests { - public class IBlocksClientTests + private readonly INotionClient _client; + + public IBlocksClientTests() { - private readonly INotionClient _client; + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - public IBlocksClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + _client = NotionClientFactory.Create(options); + } - _client = NotionClientFactory.Create(options); - } + [Fact] + public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Fact] - public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() + new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}, + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new CalloutBlock { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - }, - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - new CalloutBlock + Callout = new CalloutBlock.Info { - Callout = new CalloutBlock.Info + RichText = new List { - RichText = new List { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } - } - } - } - ); - - blocks.Results.Should().HaveCount(4); - - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, + }, + }, + }, + } + ); - [Fact] - public async Task UpdateBlockAsync_UpdatesGivenBlock() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + blocks.Results.Should().HaveCount(4); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - } - } - } - ); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); + [Fact] + public async Task UpdateBlockAsync_UpdatesGivenBlock() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters { - Archived = true - }); - } + Children = new List {new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}}, + } + ); - [Fact] - public async Task DeleteAsync_DeleteBlockWithGivenId() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - } - } - ); + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); - blocks.Results.Should().HaveCount(2); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + [Fact] + public async Task DeleteAsync_DeleteBlockWithGivenId() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Theory] - [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() - { - block - } - } - ); + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + }, + } + ); + + blocks.Results.Should().HaveCount(2); - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, updateBlock); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + [Theory] + [MemberData(nameof(BlockData))] + public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - var updatedBlock = blocks.Results.First(); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - assert.Invoke(updatedBlock); + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters {Children = new List {block}} + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, updateBlock); + + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); + + var updatedBlock = blocks.Results.First(); + + assert.Invoke(updatedBlock); + + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - private static IEnumerable BlockData() + private static IEnumerable BlockData() + { + return new List { - return new List + new object[] { - new object[] { - new BookmarkBlock + new BookmarkBlock + { + Bookmark = new BookmarkBlock.Info { - Bookmark = new BookmarkBlock.Info - { - Url = "https://developers.notion.com/reference/rich-text", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Notion API" - } - } - } - } - }, - new BookmarkUpdateBlock { - Bookmark = new BookmarkUpdateBlock.Info + Url = "https://developers.notion.com/reference/rich-text", + Caption = new List { - Url = "https://github.com/notion-dotnet/notion-sdk-net", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Github" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Notion API"}}, + }, }, - new Action((block) => { - var updatedBlock = (BookmarkBlock)block; - Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); - Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); - }) }, - new object[] { - new EquationBlock + new BookmarkUpdateBlock + { + Bookmark = new BookmarkUpdateBlock.Info { - Equation = new EquationBlock.Info + Url = "https://github.com/notion-dotnet/notion-sdk-net", + Caption = new List { - Expression = "e=mc^3" - } - }, - new EquationUpdateBlock { - Equation = new EquationUpdateBlock.Info - { - Expression = "e=mc^2" - } - }, - new Action((block) => { - var updatedBlock = (EquationBlock)block; - Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); - }) - }, - new object[] { - new DividerBlock { - Divider = new DividerBlock.Data() - }, - new DividerUpdateBlock(), - new Action((block) => { - Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] { - new AudioBlock { - Audio = new ExternalFile { - External = new ExternalFile.Info { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" - } - } - }, - new AudioUpdateBlock { - Audio = new ExternalFileInput { - External = new ExternalFileInput.Data { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" - } - } + new RichTextTextInput {Text = new Text {Content = "Github"}}, + }, }, - new Action((block) => { - block.Should().NotBeNull(); - - block.Should().BeOfType().Subject - .Audio.Should().BeOfType().Subject - .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); - }) }, - new object[] + new Action(block => { - new TableOfContentsBlock { - TableOfContents = new TableOfContentsBlock.Data() - }, - new TableOfContentsUpdateBlock(), - new Action((block) => + var updatedBlock = (BookmarkBlock)block; + Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); + Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); + }), + }, + new object[] + { + new EquationBlock {Equation = new EquationBlock.Info {Expression = "e=mc^3"}}, + new EquationUpdateBlock {Equation = new EquationUpdateBlock.Info {Expression = "e=mc^2"}}, + new Action(block => + { + var updatedBlock = (EquationBlock)block; + Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); + }), + }, + new object[] + { + new DividerBlock {Divider = new DividerBlock.Data()}, new DividerUpdateBlock(), new Action( + block => { Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] + Assert.IsType(block); + }), + }, + new object[] + { + new AudioBlock { - new CalloutBlock + Audio = new ExternalFile { - Callout = new CalloutBlock.Info + External = new ExternalFile.Info { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", + }, }, - new CalloutUpdateBlock() + }, + new AudioUpdateBlock + { + Audio = new ExternalFileInput { - Callout = new CalloutUpdateBlock.Info + External = new ExternalFileInput.Data { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", + }, }, - new Action((block) => - { - Assert.NotNull(block); - var calloutBlock = Assert.IsType(block); - - Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new QuoteBlock + block.Should().NotBeNull(); + + block.Should().BeOfType().Subject + .Audio.Should().BeOfType().Subject + .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); + }), + }, + new object[] + { + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new TableOfContentsUpdateBlock(), new Action(block => + { + Assert.NotNull(block); + Assert.IsType(block); + }), + }, + new object[] + { + new CalloutBlock + { + Callout = new CalloutBlock.Info { - Quote = new QuoteBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new QuoteUpdateBlock() + }, + new CalloutUpdateBlock + { + Callout = new CalloutUpdateBlock.Info { - Quote = new QuoteUpdateBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action((block) => - { - Assert.NotNull(block); - var quoteBlock = Assert.IsType(block); - - Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new ImageBlock() { - Image = new ExternalFile + Assert.NotNull(block); + var calloutBlock = Assert.IsType(block); + + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new QuoteBlock + { + Quote = new QuoteBlock.Info + { + RichText = new List { - External = new ExternalFile.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new ImageUpdateBlock() + }, + new QuoteUpdateBlock + { + Quote = new QuoteUpdateBlock.Info { - Image = new ExternalFileInput + RichText = new List { - External = new ExternalFileInput.Data - { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action (block => - { - Assert.NotNull(block); - var imageBlock = Assert.IsType(block); - var imageFile = Assert.IsType(imageBlock.Image); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); - }) }, - new object[] + new Action(block => + { + Assert.NotNull(block); + var quoteBlock = Assert.IsType(block); + + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new ImageBlock { - new EmbedBlock() + Image = new ExternalFile { - Embed = new EmbedBlock.Info + External = new ExternalFile.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new EmbedUpdateBlock() + }, + new ImageUpdateBlock + { + Image = new ExternalFileInput { - Embed = new EmbedUpdateBlock.Info + External = new ExternalFileInput.Data { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } + Url + = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + }, }, - new Action (block => + }, + new Action(block => + { + Assert.NotNull(block); + var imageBlock = Assert.IsType(block); + var imageFile = Assert.IsType(imageBlock.Image); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + imageFile.External.Url); + }), + }, + new object[] + { + new EmbedBlock + { + Embed = new EmbedBlock.Info { - Assert.NotNull(block); - var embedBlock = Assert.IsType(block); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); - }) + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new object[] + new EmbedUpdateBlock { - new TemplateBlock() + Embed = new EmbedUpdateBlock.Info { - Template = new TemplateBlock.Data - { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Template" - } - } - }, - Children = new List - { - new EmbedBlock() - { - Embed = new EmbedBlock.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } - } - } + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", }, - new TemplateUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var embedBlock = Assert.IsType(block); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + embedBlock.Embed.Url); + }), + }, + new object[] + { + new TemplateBlock + { + Template = new TemplateBlock.Data { - Template = new TemplateUpdateBlock.Info + RichText = new List { - RichText = new List + new RichTextText {Text = new Text {Content = "Test Template"}}, + }, + Children = new List + { + new EmbedBlock { - new RichTextTextInput + Embed = new EmbedBlock.Info { - Text = new Text - { - Content = "Test Template 2" - } - } - } - } + Url + = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, + }, + }, }, - new Action (block => - { - Assert.NotNull(block); - var templateBlock = Assert.IsType(block); - - Assert.Single(templateBlock.Template.RichText); - Assert.Null(templateBlock.Template.Children); - Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); - }) }, - new object[] + new TemplateUpdateBlock { - new LinkToPageBlock() + Template = new TemplateUpdateBlock.Info { - LinkToPage = new PageParent + RichText = new List { - Type = ParentType.PageId, - PageId = "533578e3edf14c0a91a9da6b09bac3ee" - } + new RichTextTextInput {Text = new Text {Content = "Test Template 2"}}, + }, }, - new LinkToPageUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var templateBlock = Assert.IsType(block); + + Assert.Single(templateBlock.Template.RichText); + Assert.Null(templateBlock.Template.Children); + + Assert.Equal("Test Template 2", + templateBlock.Template.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new LinkToPageBlock + { + LinkToPage = new PageParent { - LinkToPage = new ParentPageInput - { - PageId = "3c357473a28149a488c010d2b245a589" - } + Type = ParentType.PageId, PageId = "533578e3edf14c0a91a9da6b09bac3ee", }, - new Action(block => - { - Assert.NotNull(block); - var linkToPageBlock = Assert.IsType(block); + }, + new LinkToPageUpdateBlock + { + LinkToPage = new ParentPageInput {PageId = "3c357473a28149a488c010d2b245a589"}, + }, + new Action(block => + { + Assert.NotNull(block); + var linkToPageBlock = Assert.IsType(block); - var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - // TODO: Currently the api doesn't allow to update the link_to_page block type - // This will change to updated ID once api start to support - Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); - }) - } - }; - } + // TODO: Currently the api doesn't allow to update the link_to_page block type + // This will change to updated ID once api start to support + Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); + }), + }, + }; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index dbf74a90..24f11940 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -6,297 +6,228 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IPageClientTests { - public class IPageClientTests - { - private readonly INotionClient _client; - private readonly string _databaseId; + private readonly INotionClient _client; + private readonly string _databaseId; - public IPageClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + public IPageClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - _client = NotionClientFactory.Create(options); - _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - } + _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + } - [Fact] - public async Task CreateAsync_CreatesANewPage() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task CreateAsync_CreatesANewPage() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Bug_unable_to_create_page_with_select_property() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty("TestSelect", new SelectPropertyValue - { - Select = new SelectOption + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Bug_unable_to_create_page_with_select_property() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - Id = "dfbfbe65-6f67-4876-9f75-699124334d06" - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty("TestSelect", + new SelectPropertyValue {Select = new SelectOption {Id = "dfbfbe65-6f67-4876-9f75-699124334d06"}}) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Test_RetrievePagePropertyItemAsync() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Test_RetrievePagePropertyItemAsync() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText + Title = new List { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = "title" - }); + var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = "title", + }); - property.Should().NotBeNull(); - property.Should().BeOfType(); + property.Should().NotBeNull(); + property.Should().BeOfType(); - var listProperty = (ListPropertyItem)property; + var listProperty = (ListPropertyItem)property; - listProperty.Type.Should().NotBeNull(); - listProperty.Results.Should().SatisfyRespectively(p => - { - p.Should().BeOfType(); - var titleProperty = (TitlePropertyItem)p; + listProperty.Type.Should().NotBeNull(); - titleProperty.Title.PlainText.Should().Be("Test Page Title"); - }); + listProperty.Results.Should().SatisfyRespectively(p => + { + p.Should().BeOfType(); + var titleProperty = (TitlePropertyItem)p; - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Title.PlainText.Should().Be("Test Page Title"); + }); - [Fact] - public async Task Test_UpdatePageProperty_with_date_as_null() - { - // setup - add property to db and create a page with the property having a date + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - string datePropertyName = "Test Date Property"; - var updateDatabaseParameters = new DatabasesUpdateParameters(); - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty(datePropertyName, new DatePropertyValue - { - Date = new Date() + var datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Test Date Property", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue + { + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty(datePropertyName, + new DatePropertyValue { - Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z") - } - }) + Date = new Date + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z"), + }, + }) .Build(); - var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties[datePropertyName].Id - }); + var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = page.Properties[datePropertyName].Id, + }); - setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); - // verify - IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue {Date = null}); - var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Properties = testProps - }); + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Properties = testProps}); - var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters { - PageId = page.Id, - PropertyId = updatedPage.Properties[datePropertyName].Id + PageId = page.Id, PropertyId = updatedPage.Properties[datePropertyName].Id, }); - verifyDate?.Date.Should().BeNull(); + verifyDate?.Date.Should().BeNull(); - //cleanup - await _client.Blocks.DeleteAsync(page.Id); - } + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } - [Fact] - public async Task Bug_Unable_To_Parse_NumberPropertyItem() - { - // Arrange - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }).AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task Bug_Unable_To_Parse_NumberPropertyItem() + { + // Arrange + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}).AddProperty("Name", + new TitlePropertyValue + { + Title = new List { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }).AddProperty("Number", new NumberPropertyValue - { - Number = 200.00 - }).Build(); + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }).AddProperty("Number", new NumberPropertyValue {Number = 200.00}).Build(); - // Act - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + // Act + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - // Assert - Assert.NotNull(page); - var pageParent = Assert.IsType(page.Parent); - Assert.Equal(_databaseId, pageParent.DatabaseId); + // Assert + Assert.NotNull(page); + var pageParent = Assert.IsType(page.Parent); + Assert.Equal(_databaseId, pageParent.DatabaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Name"].Id - }); + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Name"].Id}); - Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); + Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); - var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Number"].Id - }); + var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Number"].Id}); - Assert.Equal(200.00, numberProperty.Number); + Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); } } diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index e593a47c..ceb415d2 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -7,64 +7,55 @@ using WireMock.RequestBuilders; using WireMock.Server; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class ApiTestBase : IDisposable { - public class ApiTestBase : IDisposable + protected static readonly JsonSerializerSettings JsonSerializerSettings = new() { - protected readonly WireMockServer Server; - - protected static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings() - { - Formatting = Newtonsoft.Json.Formatting.Indented, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } - }; + Formatting = Formatting.Indented, + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + }; - protected readonly ClientOptions ClientOptions; + protected readonly ClientOptions ClientOptions; + protected readonly WireMockServer Server; - protected ApiTestBase() - { - Server = WireMockServer.Start(); - ClientOptions = new ClientOptions() - { - BaseUrl = Server.Urls.First(), - AuthToken = "" - }; - } + protected ApiTestBase() + { + Server = WireMockServer.Start(); + ClientOptions = new ClientOptions {BaseUrl = Server.Urls.First(), AuthToken = ""}; + } - public void Dispose() - { - Server.Stop(); - Server.Dispose(); - } + public void Dispose() + { + Server.Stop(); + Server.Dispose(); + } - protected IRequestBuilder CreateGetRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingGet() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreateGetRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingGet() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePostRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPost() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePostRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPost() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePatchRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPatch() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePatchRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPatch() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); } } diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 753e5464..8a568a13 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -7,191 +7,184 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class BlocksClientTests : ApiTestBase { - public class BlocksClientTests : ApiTestBase - { - private readonly IBlocksClient _client; + private readonly IBlocksClient _client; - public BlocksClientTests() - { - _client = new BlocksClient(new RestClient(ClientOptions)); - } + public BlocksClientTests() + { + _client = new BlocksClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveBlockChildren() - { - // Arrange - string blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; - var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); + [Fact] + public async Task RetrieveBlockChildren() + { + // Arrange + var blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; + var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); + // Act + var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); - // Assert - var children = childrenResult.Results; - children.Should().HaveCount(8); - } + // Assert + var children = childrenResult.Results; + children.Should().HaveCount(8); + } - [Fact] - public async Task AppendBlockChildren() - { - // Arrange - string blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; - var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); + [Fact] + public async Task AppendBlockChildren() + { + // Arrange + var blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; + var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var parameters = new BlocksAppendChildrenParameters() + var parameters = new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List + new HeadingTwoBlock { - new HeadingTwoBlock() + Heading_2 = new HeadingTwoBlock.Info { - Heading_2 = new HeadingTwoBlock.Info + RichText = new List { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Lacinato kale" - } - } - } - } + new RichTextText {Text = new Text {Content = "Lacinato kale"}}, + }, }, - new ParagraphBlock() + }, + new ParagraphBlock + { + Paragraph = new ParagraphBlock.Info { - Paragraph = new ParagraphBlock.Info + RichText = new List { - RichText = new List + new RichTextText { - new RichTextText + Text = new Text { - Text = new Text + Content + = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", + Link = new Link { - Content = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", - Link = new Link - { - Url = "https://en.wikipedia.org/wiki/Lacinato_kale" - } - } - } - } - } - } - } - }; - - // Act - var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); - - // Assert - var blocks = blocksResult.Results; - blocks.Should().SatisfyRespectively( - block => - { - block.Type.Should().Be(BlockType.Heading_2); - var headingBlock = (HeadingTwoBlock)block; - var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); - text.Text.Content.Should().Be("Lacinato kale"); + Url + = "https://en.wikipedia.org/wiki/Lacinato_kale", + }, + }, + }, + }, + }, }, - block => - { - block.Type.Should().Be(BlockType.Paragraph); - var paragraphBlock = (ParagraphBlock)block; - var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); - text.Text.Content.Should().Be("Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); - text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); - } - ); - } + }, + }; - [Fact] - public async Task RetrieveAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); + // Act + var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); + + // Assert + var blocks = blocksResult.Results; + + blocks.Should().SatisfyRespectively( + block => + { + block.Type.Should().Be(BlockType.Heading_2); + var headingBlock = (HeadingTwoBlock)block; + var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); + text.Text.Content.Should().Be("Lacinato kale"); + }, + block => + { + block.Type.Should().Be(BlockType.Paragraph); + var paragraphBlock = (ParagraphBlock)block; + var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); + + text.Text.Content.Should().Be( + "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); + + text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); + } + ); + } + + [Fact] + public async Task RetrieveAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var block = await _client.RetrieveAsync(blockId); + var block = await _client.RetrieveAsync(blockId); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); + } - [Fact] - public async Task UpdateAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Update(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); + [Fact] + public async Task UpdateAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Update(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateBlock = new ToDoUpdateBlock + var updateBlock = new ToDoUpdateBlock + { + ToDo = new ToDoUpdateBlock.Info { - ToDo = new ToDoUpdateBlock.Info + RichText = new List { - RichText = new List() - { - new RichTextTextInput - { - Text = new Text - { - Content = "Lacinato kale" - }, - } - }, - IsChecked = true - } - }; + new RichTextTextInput {Text = new Text {Content = "Lacinato kale"}}, + }, + IsChecked = true, + }, + }; - var block = await _client.UpdateAsync(blockId, updateBlock); + var block = await _client.UpdateAsync(blockId, updateBlock); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index cc4c2396..e78d0e68 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -7,483 +7,437 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class DatabasesClientTests : ApiTestBase { - public class DatabasesClientTests : ApiTestBase + private readonly IDatabasesClient _client; + private readonly IPagesClient _pagesClient; + + public DatabasesClientTests() { - private readonly IDatabasesClient _client; - private readonly IPagesClient _pagesClient; - public DatabasesClientTests() - { - _client = new DatabasesClient(new RestClient(ClientOptions)); - _pagesClient = new PagesClient(new RestClient(ClientOptions)); - } + _client = new DatabasesClient(new RestClient(ClientOptions)); + _pagesClient = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task QueryAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); + [Fact] + public async Task QueryAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); - } + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); } + } - [Fact] - public async Task RetrieveDatabaseAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); + [Fact] + public async Task RetrieveDatabaseAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - HelperAsserts.IPageIconAsserts(database.Icon); - HelperAsserts.FileObjectAsserts(database.Cover); + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } - [Fact] - public async Task DatabasePropertyObjectContainNameProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + HelperAsserts.IPageIconAsserts(database.Icon); + HelperAsserts.FileObjectAsserts(database.Cover); + } - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task DatabasePropertyObjectContainNameProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } + } - [Fact] - public async Task DatabasePropertyObjectContainRelationProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); + [Fact] + public async Task DatabasePropertyObjectContainRelationProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( - new RelationProperty() + database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( + new RelationProperty + { + Id = "zDGa", + Name = "Property", + Relation = new DualPropertyRelation + { + DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", + DualProperty = new DualPropertyRelation.Data { - Id = "zDGa", - Name = "Property", - Relation = new DualPropertyRelation() - { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - DualProperty = new DualPropertyRelation.Data - { - SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{" - } - } - }); - } + SyncedPropertyName = "Related to sample table (Property)", + SyncedPropertyId = "VQ}{", + }, + }, + }); + } - [Fact] - public async Task DatabasePropertyObjectContainParentProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); + [Fact] + public async Task DatabasePropertyObjectContainParentProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); + } - [Fact] - public async Task CreateDatabaseAsync() - { - var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); + [Fact] + public async Task CreateDatabaseAsync() + { + var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; - createDatabaseParameters.Title = new List + createDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitlePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, { - new RichTextTextInput + "Food group", + new SelectPropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetable"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DatePropertySchema {Date = new Dictionary()}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitlePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, - { "Food group", new SelectPropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOptionSchema - { - Color = Color.Green, - Name = "🥦Vegetable" - }, - new SelectOptionSchema - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOptionSchema - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetable"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); + } - [Fact] - public async Task UpdateDatabaseAsync() - { - var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; - var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); + [Fact] + public async Task UpdateDatabaseAsync() + { + var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; + var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateDatabaseParameters = new DatabasesUpdateParameters(); + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List New", Link = null}}, + }; - updateDatabaseParameters.Title = new List + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberUpdatePropertySchema {Number = new Number {Format = "yen"}}}, { - new RichTextTextInput + "Food group", + new SelectUpdatePropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List New", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetables"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, - { "Food group", new SelectUpdatePropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOption - { - Color = Color.Green, - Name = "🥦Vegetables" - }, - new SelectOption - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOption - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); - var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + database.Title.Should().ContainSingle(); - database.Title.Should().ContainSingle(); - database.Title.Should().SatisfyRespectively( - title => - { - title.Should().BeAssignableTo(); - ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); - } - ); + database.Title.Should().SatisfyRespectively( + title => + { + title.Should().BeAssignableTo(); + ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); + } + ); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var price = (NumberProperty)database.Properties["Price"]; - price.Number.Format.Should().Be("yen"); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetables"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); - [Fact] - public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() - { - var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + var price = (NumberProperty)database.Properties["Price"]; + price.Number.Format.Should().Be("yen"); + } - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() + { + var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + + var jsonData + = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; - createDatabaseParameters.Title = new List + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; + + createDatabaseParameters.Properties = new Dictionary + { { - new RichTextTextInput + "Cost of next trip", + new FormulaPropertySchema { - Text = new Text - { - Content = "Grocery List", - Link = null - } + Formula = new Formula {Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))"}, } - }; + }, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(2); - database.Properties.Should().HaveCount(2); + var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; + formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); + } - var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; - formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); - } + [Fact] + public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() + { + var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - [Fact] - public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() - { - var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); + var jsonData + = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) + Server.Given(CreateGetRequestBuilder( + ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) .RespondWith( Response.Create() - .WithStatusCode(200) - .WithBody("{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") + .WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") ); - var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["FormulaProp"].Id - }); + var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id}); - //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; - formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); - formulaPropertyValue.Formula.Date.End.Should().BeNull(); - } + //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; + formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); + formulaPropertyValue.Formula.Date.End.Should().BeNull(); } } } diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 5b4650a5..b31a6530 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -4,131 +4,138 @@ using Notion.Client; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SerializerSettingsSource : RestClient +{ + public SerializerSettingsSource(ClientOptions options) : base(options) + { + } + + public JsonSerializerSettings GetSerializerSettings() + { + return defaultSerializerSettings; + } +} + +public class FilterTests { - public class SerializerSettingsSource : RestClient + private readonly SerializerSettingsSource _settingsSource = new(new ClientOptions()); + + private string SerializeFilter(Filter filter) + { + return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); + } + + [Fact] + public void CompoundFilterTest() + { + var selectFilter = new SelectFilter("A select", "Option"); + var relationFilter = new RelationFilter("Link", "subtask#1"); + var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); + + var filterGroup = new List {relationFilter, selectFilter}; + + var complexFiler = new CompoundFilter( + and: new List {dateFilter, new CompoundFilter(filterGroup)} + ); + + Assert.Equal( + "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," + + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + + "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", + SerializeFilter(complexFiler) + ); + } + + [Fact] + public void CheckboxFilterTest() + { + var filter = new CheckboxFilter("Property name", false); + + Assert.Equal( + "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void DateFilterTest() { - public SerializerSettingsSource(ClientOptions options) : base(options) - { + var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - } + Assert.Equal( + "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void FilesFilterTest() + { + var filter = new FilesFilter("Attachments", isNotEmpty: false); + + Assert.Equal( + "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", + SerializeFilter(filter) + ); + } - public JsonSerializerSettings GetSerializerSettings() - { - return defaultSerializerSettings; - } + [Fact] + public void FormulaFilterTest() + { + var filter = new FormulaFilter( + "Some", + number: new NumberFilter.Condition(isEmpty: true) + ); + + Assert.Equal( + "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", + SerializeFilter(filter) + ); + } + [Fact] + public void MultiSelectFilterTest() + { + var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); + + Assert.Equal( + "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", + SerializeFilter(filter) + ); } - public class FilterTests + + [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] + public void NumberFilterTest() { - private readonly SerializerSettingsSource _settingsSource = new SerializerSettingsSource(new ClientOptions()); - - private string SerializeFilter(Filter filter) - { - return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); - } - - [Fact] - public void CompoundFilterTest() - { - var selectFilter = new SelectFilter("A select", equal: "Option"); - var relationFilter = new RelationFilter("Link", contains: "subtask#1"); - var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); - - var filterGroup = new List { relationFilter, selectFilter }; - var complexFiler = new CompoundFilter( - and: new List { dateFilter, new CompoundFilter(or: filterGroup) } - ); - - Assert.Equal( - "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," - + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + - "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", - SerializeFilter(complexFiler) - ); - } - - [Fact] - public void CheckboxFilterTest() - { - var filter = new CheckboxFilter("Property name", equal: false); - Assert.Equal( - "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void DateFilterTest() - { - var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - Assert.Equal( - "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FilesFilterTest() - { - var filter = new FilesFilter("Attachments", isNotEmpty: false); - Assert.Equal( - "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FormulaFilterTest() - { - var filter = new FormulaFilter( - "Some", - number: new NumberFilter.Condition(isEmpty: true) - ); - Assert.Equal( - "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void MultiSelectFilterTest() - { - var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); - Assert.Equal( - "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", - SerializeFilter(filter) - ); - } - - [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] - public void NumberFilterTest() - { - var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); - Assert.Equal( - "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void PeopleFilter() - { - var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); - Assert.Equal( - "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void RichTextFilterTest() - { - var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); - Assert.Equal( - "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", - SerializeFilter(filter) - ); - } + var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); + + Assert.Equal( + "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void PeopleFilter() + { + var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); + + Assert.Equal( + "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void RichTextFilterTest() + { + var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); + + Assert.Equal( + "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", + SerializeFilter(filter) + ); } -} +} diff --git a/Test/Notion.UnitTests/HelperAsserts.cs b/Test/Notion.UnitTests/HelperAsserts.cs index 1b07fbf5..3b1a29ec 100644 --- a/Test/Notion.UnitTests/HelperAsserts.cs +++ b/Test/Notion.UnitTests/HelperAsserts.cs @@ -1,41 +1,44 @@ using FluentAssertions; using Notion.Client; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public static class HelperAsserts { - public static class HelperAsserts + public static void IPageIconAsserts(IPageIcon icon) { - public static void IPageIconAsserts(IPageIcon icon) + icon.Should().NotBeNull(); + + switch (icon) { - icon.Should().NotBeNull(); - - switch (icon) - { - case EmojiObject emoji: - emoji.Emoji.Should().NotBeNull(); - break; - case FileObject fileObject: - FileObjectAsserts(fileObject); - break; - } + case EmojiObject emoji: + emoji.Emoji.Should().NotBeNull(); + + break; + case FileObject fileObject: + FileObjectAsserts(fileObject); + + break; } + } - public static void FileObjectAsserts(FileObject fileObject) + public static void FileObjectAsserts(FileObject fileObject) + { + fileObject.Should().NotBeNull(); + + switch (fileObject) { - fileObject.Should().NotBeNull(); - - switch (fileObject) - { - case UploadedFile uploadedFile: - uploadedFile.File.Should().NotBeNull(); - uploadedFile.File.Url.Should().NotBeNull(); - uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); - break; - case ExternalFile externalFile: - externalFile.External.Should().NotBeNull(); - externalFile.External.Url.Should().NotBeNull(); - break; - } + case UploadedFile uploadedFile: + uploadedFile.File.Should().NotBeNull(); + uploadedFile.File.Url.Should().NotBeNull(); + uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); + + break; + case ExternalFile externalFile: + externalFile.External.Should().NotBeNull(); + externalFile.External.Url.Should().NotBeNull(); + + break; } } } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 13598b0f..3f6710a5 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -8,264 +8,246 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PagesClientTests : ApiTestBase { - public class PagesClientTests : ApiTestBase - { - private readonly IPagesClient _client; + private readonly IPagesClient _client; - public PagesClientTests() - { - _client = new PagesClient(new RestClient(ClientOptions)); - } + public PagesClientTests() + { + _client = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task RetrieveAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - page.Id.Should().Be(pageId); - page.Parent.Type.Should().Be(ParentType.DatabaseId); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); - page.IsArchived.Should().BeFalse(); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + page.Id.Should().Be(pageId); + page.Parent.Type.Should().Be(ParentType.DatabaseId); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); + page.IsArchived.Should().BeFalse(); + } - [Fact] - public async Task CreateAsync() - { - var path = ApiEndpoints.PagesApiUrls.Create(); + [Fact] + public async Task CreateAsync() + { + var path = ApiEndpoints.PagesApiUrls.Create(); - var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589" - }).AddProperty("Name", new TitlePropertyValue() - { - Title = new List() + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"}).AddProperty("Name", + new TitlePropertyValue { - new RichTextText() - { - Text = new Text - { - Content = "Test" - } - } - } - }).Build(); - - var page = await _client.CreateAsync(pagesCreateParameters); - - page.Id.Should().NotBeNullOrEmpty(); - page.Url.Should().NotBeNullOrEmpty(); - page.Properties.Should().HaveCount(1); - page.Properties.First().Key.Should().Be("Name"); - page.IsArchived.Should().BeFalse(); - page.Parent.Should().NotBeNull(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); - } - - [Fact] - public async Task UpdatePropertiesAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + Title = new List {new RichTextText {Text = new Text {Content = "Test"}}}, + }).Build(); + + var page = await _client.CreateAsync(pagesCreateParameters); + + page.Id.Should().NotBeNullOrEmpty(); + page.Url.Should().NotBeNullOrEmpty(); + page.Properties.Should().HaveCount(1); + page.Properties.First().Key.Should().Be("Name"); + page.IsArchived.Should().BeFalse(); + page.Parent.Should().NotBeNull(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); + } - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + [Fact] + public async Task UpdatePropertiesAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var updatedProperties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - }; + var updatedProperties = new Dictionary + { + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }; - var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); + var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); - page.Id.Should().Be(pageId); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task PageObjectShouldHaveUrlProperty() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task PageObjectShouldHaveUrlProperty() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + } - [Fact] - public async Task UpdatePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + [Fact] + public async Task UpdatePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Properties = new Dictionary { - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task ArchivePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; + [Fact] + public async Task ArchivePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Archived = true, + Properties = new Dictionary { - Archived = true, - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeTrue(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeTrue(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() - { - Func act = async () => await _client.CreateAsync(null); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() + { + Func act = async () => await _client.CreateAsync(null); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() - { - var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() + { + var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + { + var pagesCreateParameters = new PagesCreateParameters { - var pagesCreateParameters = new PagesCreateParameters - { - Parent = new ParentPageInput() - { - PageId = "3c357473-a281-49a4-88c0-10d2b245a589", - }, - Properties = null - }; + Parent = new ParentPageInput {PageId = "3c357473-a281-49a4-88c0-10d2b245a589"}, Properties = null, + }; - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); } } diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index d09e4a87..c8196f15 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -1,67 +1,65 @@ using System; -using FluentAssertions; using Notion.Client; using Notion.Client.Extensions; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PropertyTests { - public class PropertyTests + [Theory] + [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] + [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [InlineData(typeof(DateProperty), PropertyType.Date)] + [InlineData(typeof(EmailProperty), PropertyType.Email)] + [InlineData(typeof(FilesProperty), PropertyType.Files)] + [InlineData(typeof(FormulaProperty), PropertyType.Formula)] + [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [InlineData(typeof(NumberProperty), PropertyType.Number)] + [InlineData(typeof(PeopleProperty), PropertyType.People)] + [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [InlineData(typeof(RelationProperty), PropertyType.Relation)] + [InlineData(typeof(RichTextProperty), PropertyType.RichText)] + [InlineData(typeof(RollupProperty), PropertyType.Rollup)] + [InlineData(typeof(SelectProperty), PropertyType.Select)] + [InlineData(typeof(TitleProperty), PropertyType.Title)] + [InlineData(typeof(UrlProperty), PropertyType.Url)] + public void TestPropertyType(Type type, PropertyType expectedPropertyType) { - [Theory] - [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] - [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [InlineData(typeof(DateProperty), PropertyType.Date)] - [InlineData(typeof(EmailProperty), PropertyType.Email)] - [InlineData(typeof(FilesProperty), PropertyType.Files)] - [InlineData(typeof(FormulaProperty), PropertyType.Formula)] - [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [InlineData(typeof(NumberProperty), PropertyType.Number)] - [InlineData(typeof(PeopleProperty), PropertyType.People)] - [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [InlineData(typeof(RelationProperty), PropertyType.Relation)] - [InlineData(typeof(RichTextProperty), PropertyType.RichText)] - [InlineData(typeof(RollupProperty), PropertyType.Rollup)] - [InlineData(typeof(SelectProperty), PropertyType.Select)] - [InlineData(typeof(TitleProperty), PropertyType.Title)] - [InlineData(typeof(UrlProperty), PropertyType.Url)] - public void TestPropertyType(Type type, PropertyType expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type; + var actualPropertyType = typeInstance.Type; - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); + } - [Theory] - [InlineData(typeof(CheckboxProperty), "checkbox")] - [InlineData(typeof(CreatedByProperty), "created_by")] - [InlineData(typeof(CreatedTimeProperty), "created_time")] - [InlineData(typeof(DateProperty), "date")] - [InlineData(typeof(EmailProperty), "email")] - [InlineData(typeof(FilesProperty), "files")] - [InlineData(typeof(FormulaProperty), "formula")] - [InlineData(typeof(LastEditedByProperty), "last_edited_by")] - [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] - [InlineData(typeof(NumberProperty), "number")] - [InlineData(typeof(PeopleProperty), "people")] - [InlineData(typeof(PhoneNumberProperty), "phone_number")] - [InlineData(typeof(RelationProperty), "relation")] - [InlineData(typeof(RichTextProperty), "rich_text")] - [InlineData(typeof(RollupProperty), "rollup")] - [InlineData(typeof(SelectProperty), "select")] - [InlineData(typeof(TitleProperty), "title")] - [InlineData(typeof(UrlProperty), "url")] - public void TestPropertyTypeText(Type type, string expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + [Theory] + [InlineData(typeof(CheckboxProperty), "checkbox")] + [InlineData(typeof(CreatedByProperty), "created_by")] + [InlineData(typeof(CreatedTimeProperty), "created_time")] + [InlineData(typeof(DateProperty), "date")] + [InlineData(typeof(EmailProperty), "email")] + [InlineData(typeof(FilesProperty), "files")] + [InlineData(typeof(FormulaProperty), "formula")] + [InlineData(typeof(LastEditedByProperty), "last_edited_by")] + [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] + [InlineData(typeof(NumberProperty), "number")] + [InlineData(typeof(PeopleProperty), "people")] + [InlineData(typeof(PhoneNumberProperty), "phone_number")] + [InlineData(typeof(RelationProperty), "relation")] + [InlineData(typeof(RichTextProperty), "rich_text")] + [InlineData(typeof(RollupProperty), "rollup")] + [InlineData(typeof(SelectProperty), "select")] + [InlineData(typeof(TitleProperty), "title")] + [InlineData(typeof(UrlProperty), "url")] + public void TestPropertyTypeText(Type type, string expectedPropertyType) + { + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); + var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); } } diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index aa506572..3ca7dd27 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -1,71 +1,65 @@ -using System; -using System.IO; +using System.IO; using System.Threading.Tasks; using FluentAssertions; using Notion.Client; using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SearchClientTest : ApiTestBase { - public class SearchClientTest : ApiTestBase - { - private readonly SearchClient _client; + private readonly SearchClient _client; - public SearchClientTest() - { - _client = new SearchClient(new RestClient(ClientOptions)); - } + public SearchClientTest() + { + _client = new SearchClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task Search() - { - // Arrange - var path = ApiEndpoints.SearchApiUrls.Search(); - var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); + [Fact] + public async Task Search() + { + // Arrange + var path = ApiEndpoints.SearchApiUrls.Search(); + var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - SearchParameters searchParameters = new SearchParameters() - { - Query = "External tasks", - Sort = new SearchSort - { - Direction = SearchDirection.Ascending, - Timestamp = "last_edited_time" - } - }; + var searchParameters = new SearchParameters + { + Query = "External tasks", + Sort = new SearchSort {Direction = SearchDirection.Ascending, Timestamp = "last_edited_time"}, + }; - // Act - var searchResult = await _client.SearchAsync(searchParameters); + // Act + var searchResult = await _client.SearchAsync(searchParameters); - // Assert - var results = searchResult.Results; + // Assert + var results = searchResult.Results; - results.Should().SatisfyRespectively( - obj => - { - obj.Object.Should().Be(ObjectType.Database); + results.Should().SatisfyRespectively( + obj => + { + obj.Object.Should().Be(ObjectType.Database); - var database = (Database)obj; - database.Properties.Should().HaveCount(2); - }, - obj => - { - obj.Object.Should().Be(ObjectType.Page); + var database = (Database)obj; + database.Properties.Should().HaveCount(2); + }, + obj => + { + obj.Object.Should().Be(ObjectType.Page); - var page = (Page)obj; - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(1); - page.Parent.Should().BeAssignableTo(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); - } - ); - } + var page = (Page)obj; + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(1); + page.Parent.Should().BeAssignableTo(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); + } + ); } } diff --git a/Test/Notion.UnitTests/UserClientTest.cs b/Test/Notion.UnitTests/UserClientTest.cs index d9b27984..6e93decc 100644 --- a/Test/Notion.UnitTests/UserClientTest.cs +++ b/Test/Notion.UnitTests/UserClientTest.cs @@ -5,145 +5,144 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class UserClientTest : ApiTestBase { - public class UserClientTest : ApiTestBase + private readonly IUsersClient _client; + + public UserClientTest() + { + _client = new UsersClient(new RestClient(ClientOptions)); + } + + [Fact] + public async Task ListUsers() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); + var path = ApiEndpoints.UsersApiUrls.List(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) + ); + + // Act + var users = await _client.ListAsync(); + + // Assert + users.Results.Should().SatisfyRespectively( + user => + { + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + }, + user => + { + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + } + ); + } + + [Fact] + public async Task RetrieveUser() { - private readonly IUsersClient _client; - - public UserClientTest() - { - _client = new UsersClient(new RestClient(ClientOptions)); - } - - [Fact] - public async Task ListUsers() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); - var path = ApiEndpoints.UsersApiUrls.List(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); + var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; + var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var users = await _client.ListAsync(); - - // Assert - users.Results.Should().SatisfyRespectively( - user => - { - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - }, - user => - { - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - } + // Act + var user = await _client.RetrieveAsync(userId); + + // Assert + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + } + + [Fact] + public async Task RetrieveTokenUser_WorkspaceInternalToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) ); - } - - [Fact] - public async Task RetrieveUser() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); - var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; - var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; + owner.Workspace.Should().BeTrue(); + } + + [Fact] + public async Task RetrieveTokenUser_UserLevelToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var user = await _client.RetrieveAsync(userId); - - // Assert - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - } - - [Fact] - public async Task RetrieveTokenUser_WorkspaceInternalToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; - owner.Workspace.Should().BeTrue(); - } - - [Fact] - public async Task RetrieveTokenUser_UserLevelToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); - user.Name.Should().Be("pied piper"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (UserOwner)user.Bot.Owner; - owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); - owner.User.Name.Should().Be("christine makenotion"); - owner.User.AvatarUrl.Should().BeNull(); - owner.User.Type.Should().Be("person"); - owner.User.Person.Email.Should().Be("christine@makenotion.com"); - owner.User.Bot.Should().BeNull(); - } + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); + user.Name.Should().Be("pied piper"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (UserOwner)user.Bot.Owner; + owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); + owner.User.Name.Should().Be("christine makenotion"); + owner.User.AvatarUrl.Should().BeNull(); + owner.User.Type.Should().Be("person"); + owner.User.Person.Email.Should().Be("christine@makenotion.com"); + owner.User.Bot.Should().BeNull(); } } From 3e482b11ff79f4c12e635b4471a00aac75445e25 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 21:09:10 +0530 Subject: [PATCH 4/7] =?UTF-8?q?Add=20jetbrains.resharper.globaltools=20?= =?UTF-8?q?=E2=9E=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/dotnet-tools.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..92211a4f --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "jetbrains.resharper.globaltools": { + "version": "2022.2.3", + "commands": [ + "jb" + ] + } + } +} \ No newline at end of file From f012d884f8bdf63f61b3baf7ec786473eadbf098 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:06:45 +0530 Subject: [PATCH 5/7] Updated editorconfig file --- .editorconfig | 291 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 273 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index f8d20ed2..7e8f258c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,261 @@ +root = true # EditorConfig is awesome: https://EditorConfig.org # top-most EditorConfig file -root = true # Don't use tabs for indentation. [*] indent_style = space + +[*.cs] +# Microsoft .NET properties +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.constants_rule.severity = suggestion +dotnet_naming_rule.constants_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_rule.symbols = constants_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_description = constants_should_be_pascal_case +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_guid = a0135172-b297-46cb-bb0f-b1f267109d7b +dotnet_naming_rule.constants_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule.symbols = constants_should_be_pascal_case_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.import_to_resharper = False +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.symbols = constants_should_be_pascal_case_symbols_1 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_description = instance_fields_should_be_camel_case +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_guid = ed8be1d2-8aa4-45a9-a0fe-964e144ccec7 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.style = lower_camel_case_style +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.symbols = instance_fields_should_be_camel_case_symbols +dotnet_naming_rule.interfaces_rule.import_to_resharper = as_predefined +dotnet_naming_rule.interfaces_rule.severity = suggestion +dotnet_naming_rule.interfaces_rule.style = upper_camel_case_style +dotnet_naming_rule.interfaces_rule.symbols = interfaces_symbols +dotnet_naming_rule.locals_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_description = locals_should_be_camel_case +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_guid = dd900f14-6d42-4a58-8277-056e5dab89e7 +dotnet_naming_rule.locals_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.locals_should_be_camel_case_rule.style = lower_camel_case_style_1 +dotnet_naming_rule.locals_should_be_camel_case_rule.symbols = locals_should_be_camel_case_symbols +dotnet_naming_rule.local_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.local_constants_rule.resharper_style = AaBb, aaBb +dotnet_naming_rule.local_constants_rule.severity = suggestion +dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_description = local_functions_should_be_pascal_case +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_guid = 67e7ac04-3277-4549-b0bb-98cbfad21765 +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.symbols = local_functions_should_be_pascal_case_symbols +dotnet_naming_rule.members_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_description = members_should_be_pascal_case +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_guid = 605fba47-8912-494e-9e4c-98aeb57fd884 +dotnet_naming_rule.members_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.members_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.members_should_be_pascal_case_rule.symbols = members_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_description = non_private_readonly_fields_should_be_pascal_case +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_guid = e8e1b724-94dd-4cbe-9385-85343fea2b41 +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.symbols = non_private_readonly_fields_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_description = non_private_static_fields_should_be_pascal_case +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_guid = 51051115-1f5e-4eea-aa9d-2eac02e9b082 +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.symbols = non_private_static_fields_should_be_pascal_case_symbols +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.private_constants_rule.severity = suggestion +dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_static_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_fields_rule.severity = suggestion +dotnet_naming_rule.private_static_fields_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols +dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_readonly_rule.severity = suggestion +dotnet_naming_rule.private_static_readonly_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.public_fields_rule.severity = suggestion +dotnet_naming_rule.public_fields_rule.style = lower_camel_case_style +dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols +dotnet_naming_rule.static_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_description = static_fields_should_be_camel_case +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_guid = f286ec29-34ab-4806-9c8a-586f11eedd52 +dotnet_naming_rule.static_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.static_fields_should_be_camel_case_rule.style = s_lower_camel_case_style +dotnet_naming_rule.static_fields_should_be_camel_case_rule.symbols = static_fields_should_be_camel_case_symbols +dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.static_readonly_rule.resharper_style = AaBb, s_ + aaBb +dotnet_naming_rule.static_readonly_rule.severity = suggestion +dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style +dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols +dotnet_naming_rule.type_parameters_rule.import_to_resharper = as_predefined +dotnet_naming_rule.type_parameters_rule.severity = suggestion +dotnet_naming_rule.type_parameters_rule.style = upper_camel_case_style +dotnet_naming_rule.type_parameters_rule.symbols = type_parameters_symbols +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style.required_prefix = _ +dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.required_prefix = s_ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_kinds = local +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.required_modifiers = const +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_applicable_kinds = constant_field,local_constant +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_kinds = field +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.required_modifiers = const +dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_symbols.applicable_kinds = field +dotnet_naming_symbols.constants_symbols.required_modifiers = const +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.interfaces_symbols.applicable_accessibilities = * +dotnet_naming_symbols.interfaces_symbols.applicable_kinds = interface +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local +dotnet_naming_symbols.local_constants_symbols.required_modifiers = const +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_kinds = namespace,class,struct,interface,enum,property,method,field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_applicable_kinds = namespace,class,struct,interface,enum,property,method,any_field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.required_modifiers = readonly +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = readonly_field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.required_modifiers = static +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.required_modifiers = static +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.type_parameters_symbols.applicable_accessibilities = * +dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +# ReSharper properties +# resharper_arguments_anonymous_function = named +# resharper_arguments_literal = named +# resharper_arguments_named = named +# resharper_arguments_other = named +# resharper_arguments_string_literal = named +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_before_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +resharper_case_block_braces = next_line_shifted_2 +resharper_csharp_blank_lines_around_single_line_invocable = 1 +resharper_csharp_keep_blank_lines_in_code = 1 +resharper_csharp_keep_blank_lines_in_declarations = 1 +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_extends_list_style = chop_if_long +resharper_csharp_wrap_parameters_style = chop_if_long +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_keep_existing_declaration_block_arrangement = true +resharper_keep_existing_declaration_parens_arrangement = false +resharper_keep_existing_embedded_block_arrangement = true +resharper_keep_existing_enum_arrangement = true +resharper_keep_existing_expr_member_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_local_function_body = expression_body +resharper_max_enum_members_on_line = 1 +resharper_max_formal_parameters_on_line = 4 +resharper_place_field_attribute_on_same_line = if_owner_is_single_line +resharper_space_within_single_line_array_initializer_braces = false +resharper_trailing_comma_in_multiline_lists = true +resharper_use_heuristics_for_body_style = false +resharper_use_indent_from_vs = false +resharper_wrap_before_eq = true +resharper_wrap_before_first_type_parameter_constraint = true + +# ReSharper inspection severities +resharper_arrange_accessor_owner_body_highlighting = none +resharper_arrange_local_function_body_highlighting = suggestion +resharper_arrange_namespace_body_highlighting = suggestion +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = none +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_built_in_type_reference_style_for_member_access_highlighting = suggestion +resharper_built_in_type_reference_style_highlighting = suggestion +resharper_inconsistent_naming_highlighting = suggestion +resharper_redundant_base_qualifier_highlighting = none +resharper_suggest_var_or_type_built_in_types_highlighting = suggestion +resharper_suggest_var_or_type_elsewhere_highlighting = suggestion +resharper_suggest_var_or_type_simple_types_highlighting = suggestion + +resharper_csharp_force_attribute_style=separate +resharper_csharp_method_or_operator_body=expression_body +resharper_csharp_max_enum_members_on_line=1 +resharper_csharp_place_attribute_on_same_line=false +resharper_csharp_wrap_object_and_collection_initializer_style=chop_always +resharper_csharp_use_heuristics_for_body_style=true + +# Standard properties +insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) # Code files @@ -39,7 +289,7 @@ indent_size = 2 [*.{cs,vb}] # IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = warning +dotnet_diagnostic.ide0055.severity = warning # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true @@ -143,23 +393,23 @@ dotnet_naming_symbols.all_members.applicable_kinds = * dotnet_naming_style.pascal_case_style.capitalization = pascal_case # error RS2008: Enable analyzer release tracking for the analyzer project containing rule '{0}' -dotnet_diagnostic.RS2008.severity = none +dotnet_diagnostic.rs2008.severity = none # IDE0073: File header # dotnet_diagnostic.IDE0073.severity = warning # file_header_template = # IDE0035: Remove unreachable code -dotnet_diagnostic.IDE0035.severity = warning +dotnet_diagnostic.ide0035.severity = warning # IDE0036: Order modifiers -dotnet_diagnostic.IDE0036.severity = warning +dotnet_diagnostic.ide0036.severity = warning # IDE0043: Format string contains invalid placeholder -dotnet_diagnostic.IDE0043.severity = warning +dotnet_diagnostic.ide0043.severity = warning # IDE0044: Make field readonly -dotnet_diagnostic.IDE0044.severity = warning +dotnet_diagnostic.ide0044.severity = warning # RS0016: Only enable if API files are present dotnet_public_api_analyzer.require_api_files = true @@ -236,39 +486,39 @@ csharp_preserve_single_line_statements = true [src/CodeStyle/**.{cs,vb}] # warning RS0005: Do not use generic CodeAction.Create to create CodeAction -dotnet_diagnostic.RS0005.severity = none +dotnet_diagnostic.rs0005.severity = none [src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures,VisualStudio}/**/*.{cs,vb}] # IDE0011: Add braces csharp_prefer_braces = when_multiline:warning # NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201 -dotnet_diagnostic.IDE0011.severity = warning +dotnet_diagnostic.ide0011.severity = warning # IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = warning +dotnet_diagnostic.ide0040.severity = warning # CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings? # IDE0051: Remove unused private member -dotnet_diagnostic.IDE0051.severity = warning +dotnet_diagnostic.ide0051.severity = warning # IDE0052: Remove unread private member -dotnet_diagnostic.IDE0052.severity = warning +dotnet_diagnostic.ide0052.severity = warning # IDE0059: Unnecessary assignment to a value -dotnet_diagnostic.IDE0059.severity = warning +dotnet_diagnostic.ide0059.severity = warning # IDE0060: Remove unused parameter -dotnet_diagnostic.IDE0060.severity = warning +dotnet_diagnostic.ide0060.severity = warning # CA1012: Abstract types should not have public constructors -dotnet_diagnostic.CA1012.severity = warning +dotnet_diagnostic.ca1012.severity = warning # CA1822: Make member static -dotnet_diagnostic.CA1822.severity = warning +dotnet_diagnostic.ca1822.severity = warning # Prefer "var" everywhere -dotnet_diagnostic.IDE0007.severity = warning +dotnet_diagnostic.ide0007.severity = warning csharp_style_var_for_built_in_types = true:warning csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_elsewhere = true:warning @@ -277,4 +527,9 @@ csharp_style_var_elsewhere = true:warning # CA1822: Make member static # Not enforced as a build 'warning' for 'VisualStudio' layer due to large number of false positives from https://github.com/dotnet/roslyn-analyzers/issues/3857 and https://github.com/dotnet/roslyn-analyzers/issues/3858 # Additionally, there is a risk of accidentally breaking an internal API that partners rely on though IVT. -dotnet_diagnostic.CA1822.severity = suggestion \ No newline at end of file +dotnet_diagnostic.ca1822.severity = suggestion + +[*.{appxmanifest,asax,ascx,aspx,axaml,axml,build,config,cs,cshtml,csproj,css,dbml,discomap,dtd,htm,html,js,json,jsproj,jsx,lsproj,master,njsproj,nuspec,paml,proj,props,proto,razor,resjson,resw,resx,skin,StyleCop,targets,tasks,ts,tsx,vb,vbproj,xaml,xamlx,xml,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 From 311dcde9e9d52a028959df2b3fe2d01c1116da40 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:08:51 +0530 Subject: [PATCH 6/7] =?UTF-8?q?Run=20solution=20wide=20linter=20?= =?UTF-8?q?=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Api/ApiEndpoints.cs | 124 ++- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 14 +- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 16 +- .../BlocksRetrieveChildrenParameters.cs | 1 + .../UpdateBlocks/AudioUpdateBlock.cs | 3 +- .../UpdateBlocks/BookmarkUpdateBlock.cs | 4 +- .../UpdateBlocks/BreadcrumbUpdateBlock.cs | 12 +- .../UpdateBlocks/DividerUpdateBlock.cs | 12 +- .../TableOfContentsUpdateBlock.cs | 12 +- .../Create/Request/CreateCommentParameters.cs | 22 +- .../Api/Comments/ICommentsClient.cs | 6 +- .../Api/Comments/Retrieve/CommentsClient.cs | 6 +- .../Request/RetrieveCommentsParameters.cs | 2 + .../Api/Comments/Retrieve/Response/Comment.cs | 8 +- .../Retrieve/Response/ICommentParent.cs | 4 +- .../Api/Databases/DatabasesClient.cs | 4 +- .../Api/Databases/IDatabasesClient.cs | 28 +- .../DatabasesCreateParameters.cs | 12 +- .../RequestParams/DatabasesListParameters.cs | 1 + .../RequestParams/DatabasesQueryParameters.cs | 3 + .../DatabasesUpdateParameters.cs | 1 - .../Api/Databases/RequestParams/Direction.cs | 2 +- .../Api/Databases/RequestParams/Timestamp.cs | 2 +- Src/Notion.Client/Api/Pages/IPagesClient.cs | 49 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 23 +- .../PagesCreateParameters.cs | 4 + .../PagesCreateParametersBuilder.cs | 17 +- .../RequestParams/PagesUpdateParameters.cs | 12 +- Src/Notion.Client/Api/Search/ISearchClient.cs | 9 +- .../Api/Search/Parameters/SearchDirection.cs | 2 +- .../Api/Search/Parameters/SearchFilter.cs | 1 + .../Api/Search/Parameters/SearchObjectType.cs | 2 +- .../Api/Search/Parameters/SearchParameters.cs | 4 + Src/Notion.Client/Api/Users/IUsersClient.cs | 22 +- Src/Notion.Client/Api/Users/UsersClient.cs | 7 +- Src/Notion.Client/Constants.cs | 1 + .../DI/ServiceCollectionExtensions.cs | 4 +- .../Extensions/EnumExtensions.cs | 9 +- .../HttpResponseMessageExtensions.cs | 8 +- Src/Notion.Client/Models/Blocks/AudioBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/Block.cs | 2 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 2 +- .../Models/Blocks/BookmarkBlock.cs | 4 +- .../Models/Blocks/BreadcrumbBlock.cs | 4 +- .../Models/Blocks/BulletedListItemBlock.cs | 4 +- .../Models/Blocks/CalloutBlock.cs | 4 +- .../Models/Blocks/ChildDatabaseBlock.cs | 4 +- .../Models/Blocks/ChildPageBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/CodeBlock.cs | 4 +- .../Models/Blocks/ColumnListBlock.cs | 4 +- .../Models/Blocks/DividerBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/EmbedBlock.cs | 5 +- .../Models/Blocks/EquationBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/FileBlock.cs | 4 +- .../Models/Blocks/HeadingOneBlock.cs | 4 +- .../Models/Blocks/HeadingThreeeBlock.cs | 4 +- .../Models/Blocks/HeadingTwoBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/IBlock.cs | 64 +- .../Models/Blocks/IBlockParent.cs | 8 +- Src/Notion.Client/Models/Blocks/ImageBlock.cs | 4 +- .../Models/Blocks/LinkPreviewBlock.cs | 8 +- .../Models/Blocks/LinkToPageBlock.cs | 4 +- .../Models/Blocks/NumberedListItemBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/PDFBlock.cs | 4 +- .../Models/Blocks/ParagraphBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 4 +- .../Models/Blocks/SyncedBlockBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/TableBlock.cs | 4 +- .../Models/Blocks/TableOfContentsBlock.cs | 4 +- .../Models/Blocks/TableRowBlock.cs | 4 +- .../Models/Blocks/TemplateBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 4 +- .../Models/Blocks/ToggleBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/VideoBlock.cs | 4 +- .../Models/Common/IObjectModificationData.cs | 8 +- Src/Notion.Client/Models/Database/Database.cs | 32 +- .../Models/Database/IDatabaseParent.cs | 6 +- .../Models/Database/Properties/Property.cs | 40 +- .../RelationProperty/RelationData.cs | 4 +- .../RelationProperty/RelationProperty.cs | 4 +- .../RelationProperty/RelationType.cs | 2 +- .../Database/Properties/SelectProperty.cs | 8 +- .../Models/Database/RichText/RichTextBase.cs | 6 +- .../Models/Database/RichText/RichTextType.cs | 2 +- Src/Notion.Client/Models/EmojiObject.cs | 6 +- Src/Notion.Client/Models/File/FileObject.cs | 10 +- .../Models/File/FileObjectWithName.cs | 4 +- .../Models/Filters/CheckboxFilter.cs | 23 +- .../Models/Filters/DateFilter.cs | 93 +-- .../Models/Filters/EmailFilter.cs | 23 +- .../Models/Filters/FilesFilter.cs | 20 +- Src/Notion.Client/Models/Filters/Filter.cs | 13 +- .../Models/Filters/FormulaFilter.cs | 39 +- .../Models/Filters/MultiSelectFilter.cs | 39 +- .../Models/Filters/NumberFilter.cs | 64 +- .../Models/Filters/PeopleFilter.cs | 39 +- .../Models/Filters/PhoneNumberFilter.cs | 23 +- .../Models/Filters/RelationFilter.cs | 39 +- .../Models/Filters/RichTextFilter.cs | 63 +- .../Models/Filters/Rollup/RollupFilter.cs | 29 +- .../Models/Filters/SelectFilter.cs | 39 +- .../Models/Filters/StatusFilter.cs | 39 +- .../Filters/TimestampCreatedTimeFilter.cs | 32 +- .../Filters/TimestampLastEditedTimeFilter.cs | 32 +- .../Models/Filters/TitleFilter.cs | 23 +- Src/Notion.Client/Models/Filters/URLFilter.cs | 23 +- Src/Notion.Client/Models/IObject.cs | 8 +- Src/Notion.Client/Models/Page/IPageIcon.cs | 6 +- Src/Notion.Client/Models/Page/IPageParent.cs | 8 +- Src/Notion.Client/Models/Page/Page.cs | 56 +- .../Models/Parents/BlockParent.cs | 10 +- .../Models/Parents/DatabaseParent.cs | 10 +- .../Models/Parents/PageParent.cs | 10 +- .../Models/Parents/WorkspaceParent.cs | 2 +- .../PropertyItems/IPropertyItemObject.cs | 7 +- .../Models/PropertyItems/ListPropertyItem.cs | 17 +- .../PropertyItems/RollupPropertyItem.cs | 24 +- .../PropertyItems/SimplePropertyItem.cs | 40 +- .../PropertyItems/StatusPropertyItem.cs | 3 +- .../PropertyValue/CheckboxPropertyValue.cs | 2 +- .../PropertyValue/CreatedByPropertyValue.cs | 4 +- .../PropertyValue/CreatedTimePropertyValue.cs | 4 +- .../Models/PropertyValue/DatePropertyValue.cs | 13 +- .../PropertyValue/EmailPropertyValue.cs | 4 +- .../PropertyValue/FilesPropertyValue.cs | 4 +- .../PropertyValue/FormulaPropertyValue.cs | 16 +- .../LastEditedByPropertyValue.cs | 4 +- .../LastEditedTimePropertyValue.cs | 4 +- .../PropertyValue/MultiSelectPropertyValue.cs | 4 +- .../PropertyValue/NumberPropertyValue.cs | 4 +- .../PropertyValue/PeoplePropertyValue.cs | 4 +- .../PropertyValue/PhoneNumberPropertyValue.cs | 4 +- .../Models/PropertyValue/PropertyValue.cs | 44 +- .../Models/PropertyValue/PropertyValueType.cs | 2 +- .../PropertyValue/RelationPropertyValue.cs | 4 +- .../PropertyValue/RichTextPropertyValue.cs | 4 +- .../PropertyValue/RollupPropertyValue.cs | 14 +- .../PropertyValue/SelectPropertyValue.cs | 2 +- .../PropertyValue/StatusPropertyValue.cs | 56 +- .../PropertyValue/TitlePropertyValue.cs | 4 +- .../Models/PropertyValue/UrlPropertyValue.cs | 4 +- .../Models/User/BotOwner/IBotOwner.cs | 4 +- .../Models/User/BotOwner/UserOwner.cs | 4 +- .../BotOwner/WorkspaceIntegrationOwner.cs | 4 +- Src/Notion.Client/Models/User/User.cs | 7 +- Src/Notion.Client/NotionApiErrorResponse.cs | 2 +- Src/Notion.Client/NotionApiException.cs | 1 + Src/Notion.Client/NotionClient.cs | 12 + Src/Notion.Client/NotionClientFactory.cs | 10 +- Src/Notion.Client/RestClient/ClientOptions.cs | 2 + .../RestClient/LoggingHandler.cs | 5 +- Src/Notion.Client/RestClient/RestClient.cs | 116 +-- Src/Notion.Client/http/QueryHelpers.cs | 8 +- .../CommentsClientTests.cs | 207 ++--- .../IBlocksClientTests.cs | 775 ++++++++---------- .../IPageClientTests.cs | 401 ++++----- Test/Notion.UnitTests/ApiTestBase.cs | 93 +-- Test/Notion.UnitTests/BlocksClientTests.cs | 265 +++--- Test/Notion.UnitTests/DatabasesClientTests.cs | 658 +++++++-------- Test/Notion.UnitTests/FilterTests.cs | 247 +++--- Test/Notion.UnitTests/HelperAsserts.cs | 61 +- Test/Notion.UnitTests/PagesClientTests.cs | 354 ++++---- Test/Notion.UnitTests/PropertyTests.cs | 104 ++- Test/Notion.UnitTests/SearchClientTest.cs | 92 +-- Test/Notion.UnitTests/UserClientTest.cs | 253 +++--- 165 files changed, 2744 insertions(+), 2852 deletions(-) diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index ec6f5b1a..51dbe7fd 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -1,72 +1,140 @@ -using System; - -namespace Notion.Client +namespace Notion.Client { public static class ApiEndpoints { public static class DatabasesApiUrls { - public static string Retrieve(string databaseId) => $"/v1/databases/{databaseId}"; - public static string List() => "/v1/databases"; - public static string Query(string databaseId) => $"/v1/databases/{databaseId}/query"; public static string Create => "/v1/databases"; - public static string Update(string databaseId) => $"/v1/databases/{databaseId}"; + + public static string Retrieve(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } + + public static string List() + { + return "/v1/databases"; + } + + public static string Query(string databaseId) + { + return $"/v1/databases/{databaseId}/query"; + } + + public static string Update(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } } public static class UsersApiUrls { - public static string Retrieve(string userId) => $"/v1/users/{userId}"; - public static string List() => "/v1/users"; + public static string Retrieve(string userId) + { + return $"/v1/users/{userId}"; + } + + public static string List() + { + return "/v1/users"; + } /// - /// Get the for retrieve your token's bot user. + /// Get the for retrieve your token's bot user. /// - /// Returns a retrieve your token's bot user. - public static string Me() => "/v1/users/me"; + /// Returns a retrieve your token's bot user. + public static string Me() + { + return "/v1/users/me"; + } } public static class BlocksApiUrls { - public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}"; - public static string Update(string blockId) => $"/v1/blocks/{blockId}"; + public static string Retrieve(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string Update(string blockId) + { + return $"/v1/blocks/{blockId}"; + } /// - /// Get the for deleting a block. + /// Get the for deleting a block. /// /// Identifier for a Notion block - /// Returns a for deleting a block. - public static string Delete(string blockId) => $"/v1/blocks/{blockId}"; + /// Returns a for deleting a block. + public static string Delete(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string RetrieveChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } - public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children"; - public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children"; + public static string AppendChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } } public static class PagesApiUrls { - public static string Create() => $"/v1/pages"; - public static string Retrieve(string pageId) => $"/v1/pages/{pageId}"; - public static string Update(string pageId) => $"/v1/pages/{pageId}"; - public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}"; + public static string Create() + { + return "/v1/pages"; + } + + public static string Retrieve(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string Update(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string UpdateProperties(string pageId) + { + return $"/v1/pages/{pageId}"; + } /// - /// Get the for retrieve page property item + /// Get the for retrieve page property item /// /// Identifier for a Notion Page /// Identifier for a Notion Property /// - public static string RetrievePropertyItem(string pageId, string propertyId) => $"/v1/pages/{pageId}/properties/{propertyId}"; + public static string RetrievePropertyItem(string pageId, string propertyId) + { + return $"/v1/pages/{pageId}/properties/{propertyId}"; + } } public static class SearchApiUrls { - public static string Search() => "/v1/search"; + public static string Search() + { + return "/v1/search"; + } } public static class CommentsApiUrls { - public static string Retrieve() => "/v1/comments"; + public static string Retrieve() + { + return "/v1/comments"; + } - public static string Create() => "/v1/comments"; + public static string Create() + { + return "/v1/comments"; + } } } } diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index cc06642e..8fbdcd26 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -14,7 +14,9 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null) + public async Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -25,16 +27,18 @@ public async Task> RetrieveChildrenAsync(string blockId, B var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor?.ToString() }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync>(url, queryParams); } - public async Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null) + public async Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 90ebf073..f45611b7 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -5,32 +5,36 @@ namespace Notion.Client public interface IBlocksClient { /// - /// Retrieves a Block object using the ID specified. + /// Retrieves a Block object using the ID specified. /// /// /// Block Task RetrieveAsync(string blockId); /// - /// Updates the content for the specified block_id based on the block type. + /// Updates the content for the specified block_id based on the block type. /// /// /// /// Block Task UpdateAsync(string blockId, IUpdateBlock updateBlock); - Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null); + Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null); /// - /// Creates and appends new children blocks to the parent block_id specified. + /// Creates and appends new children blocks to the parent block_id specified. /// /// Identifier for a block /// /// A paginated list of newly created first level children block objects. - Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null); + Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null); /// - /// Sets a Block object, including page blocks, to archived: true using the ID specified. + /// Sets a Block object, including page blocks, to archived: true using the ID specified. /// /// Identifier for a Notion block Task DeleteAsync(string blockId); diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs index ddc73a91..30f9c17d 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs @@ -3,6 +3,7 @@ public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs index 8747ad63..f341e441 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs index c3333737..612b6dda 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public bool Archived { get; set; } + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs index 2bb8be38..a90f6966 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class BreadcrumbUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public BreadcrumbUpdateBlock() + { + Breadcrumb = new Info(); + } [JsonProperty("breadcrumb")] public Info Breadcrumb { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public BreadcrumbUpdateBlock() + public class Info { - Breadcrumb = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs index 6c5b447c..79f332f0 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class DividerUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public DividerUpdateBlock() + { + Divider = new Info(); + } [JsonProperty("divider")] public Info Divider { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public DividerUpdateBlock() + public class Info { - Divider = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs index 36eee182..bef1f278 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class TableOfContentsUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public TableOfContentsUpdateBlock() + { + TableOfContents = new Info(); + } [JsonProperty("table_of_contents")] public Info TableOfContents { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public TableOfContentsUpdateBlock() + public class Info { - TableOfContents = new Info(); } } } diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs index aadaf1f1..3b676133 100644 --- a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -24,25 +24,23 @@ public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameter public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters { public string DiscussionId { get; set; } + public IEnumerable RichText { get; set; } + public ParentPageInput Parent { get; set; } - public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable richText) + public static CreateCommentParameters CreatePageComment( + ParentPageInput parent, + IEnumerable richText) { - return new CreateCommentParameters - { - Parent = parent, - RichText = richText - }; + return new CreateCommentParameters {Parent = parent, RichText = richText}; } - public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable richText) + public static CreateCommentParameters CreateDiscussionComment( + string discussionId, + IEnumerable richText) { - return new CreateCommentParameters - { - DiscussionId = discussionId, - RichText = richText - }; + return new CreateCommentParameters {DiscussionId = discussionId, RichText = richText}; } } } diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index d936203c..871319da 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -5,10 +5,12 @@ namespace Notion.Client public interface ICommentsClient { /// - /// Retrieves a list of un-resolved Comment objects from a page or block. + /// Retrieves a list of un-resolved Comment objects from a page or block. /// /// Retrieve comments parameters - /// + /// + /// + /// Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); Task Create(CreateCommentParameters createCommentParameters); diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index d228200c..b979086f 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -9,11 +9,9 @@ public async Task Retrieve(RetrieveCommentsParameters { var qp = (IRetrieveCommentsQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "block_id", qp.BlockId }, - { "start_cursor", qp.StartCursor }, - { "page_size", qp.PageSize.ToString() }, + {"block_id", qp.BlockId}, {"start_cursor", qp.StartCursor}, {"page_size", qp.PageSize.ToString()}, }; return await _client.GetAsync( diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs index e78c4cad..d42ec9e7 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs @@ -3,7 +3,9 @@ public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters { public string BlockId { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs index 531fb43c..9b9ef2ae 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs @@ -6,10 +6,6 @@ namespace Notion.Client { public class Comment : IObject { - public string Id { get; set; } - - public ObjectType Object => ObjectType.Comment; - [JsonProperty("parent")] public ICommentParent Parent { get; set; } @@ -27,5 +23,9 @@ public class Comment : IObject [JsonProperty("last_edited_time")] public DateTime LastEditedTime { get; set; } + + public string Id { get; set; } + + public ObjectType Object => ObjectType.Comment; } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs index e323c7e1..9e05d019 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface ICommentParent { } diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 2ab17a8b..5157dee9 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -17,7 +17,9 @@ public async Task RetrieveAsync(string databaseId) return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId)); } - public async Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters) + public async Task> QueryAsync( + string databaseId, + DatabasesQueryParameters databasesQueryParameters) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index 115ccfed..9c245ce3 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -5,35 +5,43 @@ namespace Notion.Client public interface IDatabasesClient { /// - /// Retrieves a Database object using the ID specified. + /// Retrieves a Database object using the ID specified. /// /// Identifier for a Notion database - /// + /// + /// + /// Task RetrieveAsync(string databaseId); /// - /// Gets a list of Pages contained in the database, filtered and ordered according to the - /// filter conditions and sort criteria provided in the request. The response may contain - /// fewer than page_size of results. + /// Gets a list of Pages contained in the database, filtered and ordered according to the + /// filter conditions and sort criteria provided in the request. The response may contain + /// fewer than page_size of results. /// /// /// - /// + /// + /// + /// Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); /// - /// Creates a database as a subpage in the specified parent page, with the specified properties schema. + /// Creates a database as a subpage in the specified parent page, with the specified properties schema. /// /// - /// + /// + /// + /// Task CreateAsync(DatabasesCreateParameters databasesCreateParameters); /// - /// Updates an existing database as specified by the parameters. + /// Updates an existing database as specified by the parameters. /// /// /// - /// + /// + /// + /// Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters); } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index bafad0ec..9cb7086b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -5,6 +5,12 @@ namespace Notion.Client { public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters { + [JsonProperty("icon")] + public IPageIcon Icon { get; set; } + + [JsonProperty("cover")] + public FileObject Cover { get; set; } + [JsonProperty("parent")] public ParentPageInput Parent { get; set; } @@ -14,12 +20,6 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba [JsonProperty("title")] public List Title { get; set; } - [JsonProperty("icon")] - public IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - public FileObject Cover { get; set; } - public bool? IsInline { get; set; } public List Description { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs index 51136e47..922e54fc 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs @@ -3,6 +3,7 @@ public class DatabasesListParameters : IDatabasesListQueryParmaters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs index 454961a2..51bd8a06 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs @@ -5,8 +5,11 @@ namespace Notion.Client public class DatabasesQueryParameters : IDatabaseQueryBodyParameters { public Filter Filter { get; set; } + public List Sorts { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index b9cb182e..41da2d17 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index c79d501d..76b87da3 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -11,6 +11,6 @@ public enum Direction Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 334b8c22..4eb359d4 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -11,6 +11,6 @@ public enum Timestamp CreatedTime, [EnumMember(Value = "last_edited_time")] - LastEditedTime + LastEditedTime, } } diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index 90eac980..f6b8f94f 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -6,49 +6,58 @@ namespace Notion.Client public interface IPagesClient { /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters - /// Created object. + /// Created object. Task CreateAsync(PagesCreateParameters pagesCreateParameters); /// - /// Retrieves a Page object using the ID specified. + /// Retrieves a Page object using the ID specified. /// /// Identifier for a Notion page - /// + /// + /// + /// Task RetrieveAsync(string pageId); /// - /// Updates page property values for the specified page. - /// Note: Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Note: Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page - /// Property values to update for this page. The keys are the names or IDs of the property and the values are property values. - /// Updated object + /// + /// Property values to update for this page. The keys are the names or IDs of the property + /// and the values are property values. + /// + /// Updated object Task UpdatePropertiesAsync( string pageId, - IDictionary updatedProperties - ); + IDictionary updatedProperties); /// - /// Updates page property values for the specified page. - /// Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page /// Update property parameters - /// Updated object + /// Updated object Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters); /// - /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object returned will either be a value or a paginated list of property item values. + /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object + /// returned will either be a value or a paginated list of property item values. /// /// Property body and query parameters - /// - Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters); + /// + /// + /// + Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters); } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index 5bce1904..b71f924f 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -15,11 +15,12 @@ public PagesClient(IRestClient client) } /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters /// Created page. @@ -48,20 +49,22 @@ public async Task CreateAsync(PagesCreateParameters pagesCreateParameters) public async Task RetrieveAsync(string pageId) { var url = PagesApiUrls.Retrieve(pageId); + return await _client.GetAsync(url); } - public async Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters) + public async Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters) { var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters; var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters; var url = PagesApiUrls.RetrievePropertyItem(pathParameters.PageId, pathParameters.PropertyId); - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync(url, queryParams); @@ -81,7 +84,7 @@ public async Task UpdatePropertiesAsync( IDictionary updatedProperties) { var url = PagesApiUrls.UpdateProperties(pageId); - var body = new UpdatePropertiesParameters { Properties = updatedProperties }; + var body = new UpdatePropertiesParameters {Properties = updatedProperties}; return await _client.PatchAsync(url, body); } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs index 52cb0a89..08572811 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs @@ -5,9 +5,13 @@ namespace Notion.Client public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQueryParameters { public IPageParentInput Parent { get; set; } + public IDictionary Properties { get; set; } + public IList Children { get; set; } + public IPageIcon Icon { get; set; } + public FileObject Cover { get; set; } } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index b86a207a..7df2fe4c 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class PagesCreateParametersBuilder { - private IPageParentInput parent; - private readonly Dictionary properties = new Dictionary(); private readonly IList children = new List(); - private IPageIcon icon; + private readonly Dictionary properties = new(); private FileObject cover; + private IPageIcon icon; + private IPageParentInput parent; private PagesCreateParametersBuilder() { @@ -16,33 +16,34 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder - { - parent = parent - }; + return new PagesCreateParametersBuilder {parent = parent}; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) { properties[nameOrId] = value; + return this; } public PagesCreateParametersBuilder AddPageContent(IBlock block) { children.Add(block); + return this; } public PagesCreateParametersBuilder SetIcon(IPageIcon pageIcon) { icon = pageIcon; + return this; } public PagesCreateParametersBuilder SetCover(FileObject pageCover) { cover = pageCover; + return this; } @@ -54,7 +55,7 @@ public PagesCreateParameters Build() Properties = properties, Children = children, Icon = icon, - Cover = cover + Cover = cover, }; } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs index 40f06b12..742ef8dd 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs @@ -5,16 +5,16 @@ namespace Notion.Client { public class PagesUpdateParameters : IPagesUpdateBodyParameters { - [JsonProperty("archived")] - public bool Archived { get; set; } - - [JsonProperty("properties")] - public IDictionary Properties { get; set; } - [JsonProperty("icon")] public IPageIcon Icon { get; set; } [JsonProperty("cover")] public FileObject Cover { get; set; } + + [JsonProperty("archived")] + public bool Archived { get; set; } + + [JsonProperty("properties")] + public IDictionary Properties { get; set; } } } diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 9eb487d5..8071db6d 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -5,12 +5,13 @@ namespace Notion.Client public interface ISearchClient { /// - /// Searches all original pages, databases, and child pages/databases that are shared with the integration. - /// - /// It will not return linked databases, since these duplicate their source databases. + /// Searches all original pages, databases, and child pages/databases that are shared with the integration. + /// It will not return linked databases, since these duplicate their source databases. /// /// Search filters and body parameters - /// + /// + /// + /// Task> SearchAsync(SearchParameters parameters); } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index fdac0b59..0bde8d23 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -8,6 +8,6 @@ public enum SearchDirection Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs index cc84a9a3..dbd5cf5f 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs @@ -7,6 +7,7 @@ public class SearchFilter { [JsonConverter(typeof(StringEnumConverter))] public SearchObjectType Value { get; set; } + public string Property => "object"; } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 78a012df..773ef95a 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -8,6 +8,6 @@ public enum SearchObjectType Page, [EnumMember(Value = "database")] - Database + Database, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs index ae02c0f4..e1c8ced8 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs @@ -3,9 +3,13 @@ public class SearchParameters : ISearchBodyParameters { public string Query { get; set; } + public SearchSort Sort { get; set; } + public SearchFilter Filter { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 41443678..69981022 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -5,24 +5,30 @@ namespace Notion.Client public interface IUsersClient { /// - /// Retrieves a User using the ID specified. + /// Retrieves a User using the ID specified. /// /// Identifier for a Notion user - /// + /// + /// + /// Task RetrieveAsync(string userId); /// - /// Returns a paginated list of Users for the workspace. - /// - /// The response may contain fewer than page_size of results. + /// Returns a paginated list of Users for the workspace. + /// The response may contain fewer than page_size of results. /// - /// + /// + /// + /// Task> ListAsync(); /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// object of type bot having an owner field with information about the person who authorized the integration. + /// + /// object of type bot having an owner field with information about the person who authorized + /// the integration. + /// Task MeAsync(); } } diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 5c745f72..957ac45e 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -23,9 +23,12 @@ public async Task> ListAsync() } /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// User object of type bot having an owner field with information about the person who authorized the integration. + /// + /// User object of type bot having an owner field with information about the person who authorized the + /// integration. + /// public async Task MeAsync() { return await _client.GetAsync(UsersApiUrls.Me()); diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 5034edae..072291e1 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Notion.UnitTests")] + namespace Notion.Client { internal class Constants diff --git a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs index a4aed7fd..866dc92d 100644 --- a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs +++ b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs @@ -5,7 +5,9 @@ namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { - public static IServiceCollection AddNotionClient(this IServiceCollection services, Action options) + public static IServiceCollection AddNotionClient( + this IServiceCollection services, + Action options) { services.AddSingleton(sp => { diff --git a/Src/Notion.Client/Extensions/EnumExtensions.cs b/Src/Notion.Client/Extensions/EnumExtensions.cs index 987104b8..cd60aebd 100644 --- a/Src/Notion.Client/Extensions/EnumExtensions.cs +++ b/Src/Notion.Client/Extensions/EnumExtensions.cs @@ -1,15 +1,18 @@ -using System.Linq; +using System; +using System.Linq; using System.Runtime.Serialization; namespace Notion.Client.Extensions { public static class EnumExtensions { - public static string GetEnumMemberValue(this T enumValue) where T : System.Enum + public static string GetEnumMemberValue(this T enumValue) where T : Enum { var enumType = typeof(T); var memInfo = enumType.GetMember(enumValue.ToString()); - var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType().FirstOrDefault(); + + var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType() + .FirstOrDefault(); if (attr != null) { diff --git a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs index 9b01580d..b6a9396d 100644 --- a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs +++ b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs @@ -7,11 +7,13 @@ namespace Notion.Client.Extensions { internal static class HttpResponseMessageExtensions { - internal static async Task ParseStreamAsync(this HttpResponseMessage response, JsonSerializerSettings serializerSettings = null) + internal static async Task ParseStreamAsync( + this HttpResponseMessage response, + JsonSerializerSettings serializerSettings = null) { - using (Stream stream = await response.Content.ReadAsStreamAsync()) + using (var stream = await response.Content.ReadAsStreamAsync()) { - using (StreamReader streamReader = new StreamReader(stream)) + using (var streamReader = new StreamReader(stream)) { using (JsonReader jsonReader = new JsonTextReader(streamReader)) { diff --git a/Src/Notion.Client/Models/Blocks/AudioBlock.cs b/Src/Notion.Client/Models/Blocks/AudioBlock.cs index 040f346b..1ba1a4a3 100644 --- a/Src/Notion.Client/Models/Blocks/AudioBlock.cs +++ b/Src/Notion.Client/Models/Blocks/AudioBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Audio; - [JsonProperty("audio")] public FileObject Audio { get; set; } + + public override BlockType Type => BlockType.Audio; } } diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 81bcd6bb..883399df 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -21,7 +21,7 @@ public abstract class Block : IBlock public PartialUser LastEditedBy { get; set; } /// - /// Information about the block's parent. + /// Information about the block's parent. /// public IBlockParent Parent { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 8a2c626a..f15c3b37 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -101,6 +101,6 @@ public enum BlockType LinkPreview, [EnumMember(Value = "unsupported")] - Unsupported + Unsupported, } } diff --git a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs index 735b1725..73099c82 100644 --- a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Bookmark; - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public override BlockType Type => BlockType.Bookmark; + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs index 73ae614d..d5585a40 100644 --- a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Breadcrumb; - [JsonProperty("breadcrumb")] public Data Breadcrumb { get; set; } + public override BlockType Type => BlockType.Breadcrumb; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 7eca3397..c823b4bd 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.BulletedListItem; - [JsonProperty("bulleted_list_item")] public Info BulletedListItem { get; set; } + public override BlockType Type => BlockType.BulletedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index 8cc4bb7a..d4ef61c4 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Callout; - [JsonProperty("callout")] public Info Callout { get; set; } + public override BlockType Type => BlockType.Callout; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs index 273836a9..e56fcadb 100644 --- a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildDatabase; - [JsonProperty("child_database")] public Info ChildDatabase { get; set; } + public override BlockType Type => BlockType.ChildDatabase; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs index 91c8f343..216b0d82 100644 --- a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildPage; - [JsonProperty("child_page")] public Info ChildPage { get; set; } + public override BlockType Type => BlockType.ChildPage; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 5eb1456b..9cb2c350 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Code; - [JsonProperty("code")] public Info Code { get; set; } + public override BlockType Type => BlockType.Code; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs index f86ecba0..59bd6245 100644 --- a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class ColumnListBlock : Block, INonColumnBlock { - public override BlockType Type => BlockType.ColumnList; - [JsonProperty("column_list")] public Info ColumnList { get; set; } + public override BlockType Type => BlockType.ColumnList; + public class Info { [JsonProperty("children")] diff --git a/Src/Notion.Client/Models/Blocks/DividerBlock.cs b/Src/Notion.Client/Models/Blocks/DividerBlock.cs index 61e0301b..26c55783 100644 --- a/Src/Notion.Client/Models/Blocks/DividerBlock.cs +++ b/Src/Notion.Client/Models/Blocks/DividerBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Divider; - [JsonProperty("divider")] public Data Divider { get; set; } + public override BlockType Type => BlockType.Divider; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs index bbd93e10..92c1dfdd 100644 --- a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Embed; - [JsonProperty("embed")] public Info Embed { get; set; } + public override BlockType Type => BlockType.Embed; + public class Info { [JsonProperty("url")] @@ -17,7 +17,6 @@ public class Info [JsonProperty("caption")] public IEnumerable Caption { get; set; } - } } } diff --git a/Src/Notion.Client/Models/Blocks/EquationBlock.cs b/Src/Notion.Client/Models/Blocks/EquationBlock.cs index 310a76df..411c4e3b 100644 --- a/Src/Notion.Client/Models/Blocks/EquationBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EquationBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Equation; - [JsonProperty("equation")] public Info Equation { get; set; } + public override BlockType Type => BlockType.Equation; + public class Info { [JsonProperty("expression")] diff --git a/Src/Notion.Client/Models/Blocks/FileBlock.cs b/Src/Notion.Client/Models/Blocks/FileBlock.cs index 5495e4bc..7749a693 100644 --- a/Src/Notion.Client/Models/Blocks/FileBlock.cs +++ b/Src/Notion.Client/Models/Blocks/FileBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.File; - [JsonProperty("file")] public FileObject File { get; set; } + + public override BlockType Type => BlockType.File; } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 853f9ae5..aced5461 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_1; - [JsonProperty("heading_1")] public Info Heading_1 { get; set; } + public override BlockType Type => BlockType.Heading_1; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 99d9b861..10999e0e 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_3; - [JsonProperty("heading_3")] public Info Heading_3 { get; set; } + public override BlockType Type => BlockType.Heading_3; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index ea074e8a..553d56f2 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_2; - [JsonProperty("heading_2")] public Info Heading_2 { get; set; } + public override BlockType Type => BlockType.Heading_2; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index a09f923a..fcf5364d 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -5,38 +5,38 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] - [JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] - [JsonSubtypes.KnownSubType(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] - [JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] - [JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)] - [JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] - [JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] - [JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)] - [JsonSubtypes.KnownSubType(typeof(ColumnBlock), BlockType.Column)] - [JsonSubtypes.KnownSubType(typeof(ColumnListBlock), BlockType.ColumnList)] - [JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)] - [JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)] - [JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)] - [JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)] - [JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)] - [JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] - [JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] - [JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] - [JsonSubtypes.KnownSubType(typeof(LinkPreviewBlock), BlockType.LinkPreview)] - [JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)] - [JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] - [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] - [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] - [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] - [JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)] - [JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)] - [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] - [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] - [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] - [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] - [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] - [JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(AudioBlock), BlockType.Audio)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BookmarkBlock), BlockType.Bookmark)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CalloutBlock), BlockType.Callout)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildPageBlock), BlockType.ChildPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CodeBlock), BlockType.Code)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnBlock), BlockType.Column)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnListBlock), BlockType.ColumnList)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DividerBlock), BlockType.Divider)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmbedBlock), BlockType.Embed)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EquationBlock), BlockType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileBlock), BlockType.File)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingOneBlock), BlockType.Heading_1)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingTwoBlock), BlockType.Heading_2)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingThreeeBlock), BlockType.Heading_3)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ImageBlock), BlockType.Image)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkPreviewBlock), BlockType.LinkPreview)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkToPageBlock), BlockType.LinkToPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TemplateBlock), BlockType.Template)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToDoBlock), BlockType.ToDo)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToggleBlock), BlockType.Toggle)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(VideoBlock), BlockType.Video)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.Unsupported)] public interface IBlock : IObject, IObjectModificationData { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Blocks/IBlockParent.cs b/Src/Notion.Client/Models/Blocks/IBlockParent.cs index 73634400..b2f8783f 100644 --- a/Src/Notion.Client/Models/Blocks/IBlockParent.cs +++ b/Src/Notion.Client/Models/Blocks/IBlockParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IBlockParent : IParent { } diff --git a/Src/Notion.Client/Models/Blocks/ImageBlock.cs b/Src/Notion.Client/Models/Blocks/ImageBlock.cs index 17aa6bae..cd6b055f 100644 --- a/Src/Notion.Client/Models/Blocks/ImageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ImageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class ImageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Image; - [JsonProperty("image")] public FileObject Image { get; set; } + + public override BlockType Type => BlockType.Image; } } diff --git a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs index 83f138c6..72107e48 100644 --- a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs @@ -4,13 +4,15 @@ namespace Notion.Client { public class LinkPreviewBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkPreview; + [JsonProperty("link_preview")] + public Data LinkPreview { get; set; } - [JsonProperty("link_preview")] public Data LinkPreview { get; set; } + public override BlockType Type => BlockType.LinkPreview; public class Data { - [JsonProperty("url")] public string Url { get; set; } + [JsonProperty("url")] + public string Url { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs index 30d3d7dd..ad688ca2 100644 --- a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class LinkToPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkToPage; - [JsonProperty("link_to_page")] public IPageParent LinkToPage { get; set; } + + public override BlockType Type => BlockType.LinkToPage; } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 3fe0d76a..f4a645e9 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class NumberedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.NumberedListItem; - [JsonProperty("numbered_list_item")] public Info NumberedListItem { get; set; } + public override BlockType Type => BlockType.NumberedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/PDFBlock.cs b/Src/Notion.Client/Models/Blocks/PDFBlock.cs index 85458796..55e3ce42 100644 --- a/Src/Notion.Client/Models/Blocks/PDFBlock.cs +++ b/Src/Notion.Client/Models/Blocks/PDFBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class PDFBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.PDF; - [JsonProperty("pdf")] public FileObject PDF { get; set; } + + public override BlockType Type => BlockType.PDF; } } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 67458b3c..f3b73f36 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ParagraphBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Paragraph; - [JsonProperty("paragraph")] public Info Paragraph { get; set; } + public override BlockType Type => BlockType.Paragraph; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 5fdad7da..e1466be6 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Quote; - [JsonProperty("quote")] public Info Quote { get; set; } + public override BlockType Type => BlockType.Quote; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs index 33c4dd25..98aa1d0f 100644 --- a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs +++ b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class SyncedBlockBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.SyncedBlock; - [JsonProperty("synced_block")] public Data SyncedBlock { get; set; } + public override BlockType Type => BlockType.SyncedBlock; + public class Data { [JsonProperty("synced_from")] diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index dd20d94b..cf41440c 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Table; - [JsonProperty("table")] public TableInfo Table { get; set; } + public override BlockType Type => BlockType.Table; + public class TableInfo { [JsonProperty("table_width")] diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 991ff903..0a6c9f26 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableOfContents; - [JsonProperty("table_of_contents")] public Data TableOfContents { get; set; } + public override BlockType Type => BlockType.TableOfContents; + public class Data { [JsonProperty("color")] diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs index e7214e6c..be105447 100644 --- a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableRow; - [JsonProperty("table_row")] public Info TableRow { get; set; } + public override BlockType Type => BlockType.TableRow; + public class Info { [JsonProperty("cells")] diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs index 69a78b62..705eaac3 100644 --- a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TemplateBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Template; - [JsonProperty("template")] public Data Template { get; set; } + public override BlockType Type => BlockType.Template; + public class Data { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 8b153f3b..0c52201a 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToDoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ToDo; - [JsonProperty("to_do")] public Info ToDo { get; set; } + public override BlockType Type => BlockType.ToDo; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 6646e9be..f61a1368 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToggleBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Toggle; - [JsonProperty("toggle")] public Info Toggle { get; set; } + public override BlockType Type => BlockType.Toggle; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/VideoBlock.cs b/Src/Notion.Client/Models/Blocks/VideoBlock.cs index 015bed96..7713ff7b 100644 --- a/Src/Notion.Client/Models/Blocks/VideoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/VideoBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class VideoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Video; - [JsonProperty("video")] public FileObject Video { get; set; } + + public override BlockType Type => BlockType.Video; } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs index 06177ccd..0e70ffcf 100644 --- a/Src/Notion.Client/Models/Common/IObjectModificationData.cs +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -6,25 +6,25 @@ namespace Notion.Client public interface IObjectModificationData { /// - /// Date and time when this object was created. + /// Date and time when this object was created. /// [JsonProperty("created_time")] DateTime CreatedTime { get; set; } /// - /// Date and time when this object was updated. + /// Date and time when this object was updated. /// [JsonProperty("last_edited_time")] DateTime LastEditedTime { get; set; } /// - /// User who created the object. + /// User who created the object. /// [JsonProperty("created_by")] PartialUser CreatedBy { get; set; } /// - /// User who last modified the object. + /// User who last modified the object. /// [JsonProperty("last_edited_by")] PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 502d8a5a..33da29b7 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -6,16 +6,6 @@ namespace Notion.Client { public class Database : IObject, IObjectModificationData { - public ObjectType Object => ObjectType.Database; - - public string Id { get; set; } - - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - [JsonProperty("title")] public List Title { get; set; } @@ -32,25 +22,35 @@ public class Database : IObject, IObjectModificationData public FileObject Cover { get; set; } /// - /// The URL of the Notion database. + /// The URL of the Notion database. /// [JsonProperty("url")] public string Url { get; set; } /// - /// The archived status of the database. + /// The archived status of the database. /// [JsonProperty("archived")] public bool Archived { get; set; } - public PartialUser CreatedBy { get; set; } - - public PartialUser LastEditedBy { get; set; } - [JsonProperty("is_inline")] public bool IsInline { get; set; } [JsonProperty("description")] public IEnumerable Description { get; set; } + + public ObjectType Object => ObjectType.Database; + + public string Id { get; set; } + + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/IDatabaseParent.cs b/Src/Notion.Client/Models/Database/IDatabaseParent.cs index 59233c38..768f815b 100644 --- a/Src/Notion.Client/Models/Database/IDatabaseParent.cs +++ b/Src/Notion.Client/Models/Database/IDatabaseParent.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IDatabaseParent : IParent { } diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 1f61b0dc..163b7ef0 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -5,26 +5,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxProperty), PropertyType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DateProperty), PropertyType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailProperty), PropertyType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesProperty), PropertyType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaProperty), PropertyType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectProperty), PropertyType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberProperty), PropertyType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeopleProperty), PropertyType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationProperty), PropertyType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextProperty), PropertyType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupProperty), PropertyType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectProperty), PropertyType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusProperty), PropertyType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitleProperty), PropertyType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlProperty), PropertyType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxProperty), PropertyType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DateProperty), PropertyType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailProperty), PropertyType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesProperty), PropertyType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaProperty), PropertyType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectProperty), PropertyType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberProperty), PropertyType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeopleProperty), PropertyType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationProperty), PropertyType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextProperty), PropertyType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupProperty), PropertyType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectProperty), PropertyType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs index 87e4b10a..d129acc6 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs @@ -5,8 +5,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(SinglePropertyRelation), RelationType.Single)] - [JsonSubtypes.KnownSubType(typeof(DualPropertyRelation), RelationType.Dual)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SinglePropertyRelation), RelationType.Single)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DualPropertyRelation), RelationType.Dual)] public abstract class RelationData { [JsonProperty("database_id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs index 103cdc0c..382e7088 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs index 89ce1c56..a0a58a47 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -8,6 +8,6 @@ public enum RelationType Single, [EnumMember(Value = "dual_property")] - Dual + Dual, } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 3ed99234..9af6397b 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -7,6 +7,7 @@ namespace Notion.Client public class SelectProperty : Property { public override PropertyType Type => PropertyType.Select; + public OptionWrapper Select { get; set; } } @@ -19,19 +20,20 @@ public class OptionWrapper public class SelectOption { /// - /// Name of the option as it appears in Notion. + /// Name of the option as it appears in Notion. /// [JsonProperty("name")] public string Name { get; set; } /// - /// ID of the option. + /// ID of the option. /// [JsonProperty("id")] public string Id { get; set; } /// - /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". + /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", + /// "purple", "pink". Defaults to "default". /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 88af1acd..3f10d578 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -5,9 +5,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(RichTextText), RichTextType.Text)] - [JsonSubtypes.KnownSubType(typeof(RichTextEquation), RichTextType.Equation)] - [JsonSubtypes.KnownSubType(typeof(RichTextMention), RichTextType.Mention)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextText), RichTextType.Text)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextEquation), RichTextType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextMention), RichTextType.Mention)] public class RichTextBase { [JsonProperty("plain_text")] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 59bc414f..58406612 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -14,6 +14,6 @@ public enum RichTextType Mention, [EnumMember(Value = "equation")] - Equation + Equation, } } diff --git a/Src/Notion.Client/Models/EmojiObject.cs b/Src/Notion.Client/Models/EmojiObject.cs index 95c67b61..9b5c64df 100644 --- a/Src/Notion.Client/Models/EmojiObject.cs +++ b/Src/Notion.Client/Models/EmojiObject.cs @@ -4,10 +4,10 @@ namespace Notion.Client { public class EmojiObject : IPageIcon { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("emoji")] public string Emoji { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index ce4d02f0..9ed206de 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -5,14 +5,14 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFile), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFile), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFile), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFile), "external")] public abstract class FileObject : IPageIcon { - [JsonProperty("type")] - public virtual string Type { get; set; } - [JsonProperty("caption")] public IEnumerable Caption { get; set; } + + [JsonProperty("type")] + public virtual string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObjectWithName.cs b/Src/Notion.Client/Models/File/FileObjectWithName.cs index a7381929..855a5e0f 100644 --- a/Src/Notion.Client/Models/File/FileObjectWithName.cs +++ b/Src/Notion.Client/Models/File/FileObjectWithName.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFileWithName), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFileWithName), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFileWithName), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFileWithName), "external")] public abstract class FileObjectWithName { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs index da144aec..53343e35 100644 --- a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs +++ b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs @@ -1,35 +1,34 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class CheckboxFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("checkbox")] - public Condition Checkbox { get; set; } - public CheckboxFilter( string propertyName, bool? equal = null, bool? doesNotEqual = null) { Property = propertyName; - Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual); + Checkbox = new Condition(equal, doesNotEqual); } + [JsonProperty("checkbox")] + public Condition Checkbox { get; set; } + public class Condition { + public Condition(bool? equal = null, bool? doesNotEqual = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + } + [JsonProperty("equals")] public bool? Equal { get; set; } [JsonProperty("does_not_equal")] public bool? DoesNotEqual { get; set; } - - public Condition(Nullable equal = null, Nullable doesNotEqual = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - } } } } diff --git a/Src/Notion.Client/Models/Filters/DateFilter.cs b/Src/Notion.Client/Models/Filters/DateFilter.cs index 51b38dc2..dde7ad47 100644 --- a/Src/Notion.Client/Models/Filters/DateFilter.cs +++ b/Src/Notion.Client/Models/Filters/DateFilter.cs @@ -7,9 +7,6 @@ namespace Notion.Client { public class DateFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("date")] - public Condition Date { get; set; } - public DateFilter( string propertyName, DateTime? equal = null, @@ -27,25 +24,59 @@ public DateFilter( bool? isNotEmpty = null) { Property = propertyName; + Date = new Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + [JsonProperty("date")] + public Condition Date { get; set; } + public class Condition { + public Condition( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + Before = before; + After = after; + OnOrBefore = onOrBefore; + OnOrAfter = onOrAfter; + PastWeek = pastWeek; + PastMonth = pastMonth; + PastYear = pastYear; + NextWeek = nextWeek; + NextMonth = nextMonth; + NextYear = nextYear; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime? Equal { get; set; } @@ -89,36 +120,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - DateTime? equal = null, - DateTime? before = null, - DateTime? after = null, - DateTime? onOrBefore = null, - DateTime? onOrAfter = null, - Dictionary pastWeek = null, - Dictionary pastMonth = null, - Dictionary pastYear = null, - Dictionary nextWeek = null, - Dictionary nextMonth = null, - Dictionary nextYear = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - Before = before; - After = after; - OnOrBefore = onOrBefore; - OnOrAfter = onOrAfter; - PastWeek = pastWeek; - PastMonth = pastMonth; - PastYear = pastYear; - NextWeek = nextWeek; - NextMonth = nextMonth; - NextYear = nextYear; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/EmailFilter.cs b/Src/Notion.Client/Models/Filters/EmailFilter.cs index ff5feda9..36bc3dde 100644 --- a/Src/Notion.Client/Models/Filters/EmailFilter.cs +++ b/Src/Notion.Client/Models/Filters/EmailFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class EmailFilter : SinglePropertyFilter { - [JsonProperty("email")] - public TextFilter.Condition Email { get; set; } - public EmailFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public EmailFilter( bool? isNotEmpty = null) { Property = propertyName; + Email = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("email")] + public TextFilter.Condition Email { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FilesFilter.cs b/Src/Notion.Client/Models/Filters/FilesFilter.cs index a32d4d7b..6c4b23c6 100644 --- a/Src/Notion.Client/Models/Filters/FilesFilter.cs +++ b/Src/Notion.Client/Models/Filters/FilesFilter.cs @@ -4,26 +4,20 @@ namespace Notion.Client { public class FilesFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("files")] - public Condition Files { get; set; } - public FilesFilter( string propertyName, bool? isEmpty = null, bool? isNotEmpty = null) { Property = propertyName; - Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty); + Files = new Condition(isEmpty, isNotEmpty); } + [JsonProperty("files")] + public Condition Files { get; set; } + public class Condition { - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( bool? isEmpty = null, bool? isNotEmpty = null) @@ -31,6 +25,12 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/Filter.cs b/Src/Notion.Client/Models/Filters/Filter.cs index 61f81f7e..47eced53 100644 --- a/Src/Notion.Client/Models/Filters/Filter.cs +++ b/Src/Notion.Client/Models/Filters/Filter.cs @@ -5,7 +5,6 @@ namespace Notion.Client { public class Filter { - } public class SinglePropertyFilter : Filter @@ -16,16 +15,16 @@ public class SinglePropertyFilter : Filter public class CompoundFilter : Filter { - [JsonProperty("or")] - public List Or { get; set; } - - [JsonProperty("and")] - public List And { get; set; } - public CompoundFilter(List or = null, List and = null) { Or = or; And = and; } + + [JsonProperty("or")] + public List Or { get; set; } + + [JsonProperty("and")] + public List And { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FormulaFilter.cs b/Src/Notion.Client/Models/Filters/FormulaFilter.cs index eee9fc52..5aec5e00 100644 --- a/Src/Notion.Client/Models/Filters/FormulaFilter.cs +++ b/Src/Notion.Client/Models/Filters/FormulaFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class FormulaFilter : SinglePropertyFilter { - [JsonProperty("formula")] - public Condition Formula { get; set; } - public FormulaFilter( string propertyName, TextFilter.Condition @string = null, @@ -15,28 +12,20 @@ public FormulaFilter( DateFilter.Condition date = null) { Property = propertyName; + Formula = new Condition( - @string: @string, - checkbox: checkbox, - number: number, - date: date + @string, + checkbox, + number, + date ); } + [JsonProperty("formula")] + public Condition Formula { get; set; } + public class Condition { - [JsonProperty("string")] - public TextFilter.Condition String { get; set; } - - [JsonProperty("checkbox")] - public CheckboxFilter.Condition Checkbox { get; set; } - - [JsonProperty("number")] - public NumberFilter.Condition Number { get; set; } - - [JsonProperty("date")] - public DateFilter.Condition Date { get; set; } - public Condition( TextFilter.Condition @string = null, CheckboxFilter.Condition checkbox = null, @@ -48,6 +37,18 @@ public Condition( Number = number; Date = date; } + + [JsonProperty("string")] + public TextFilter.Condition String { get; set; } + + [JsonProperty("checkbox")] + public CheckboxFilter.Condition Checkbox { get; set; } + + [JsonProperty("number")] + public NumberFilter.Condition Number { get; set; } + + [JsonProperty("date")] + public DateFilter.Condition Date { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs index 14aec6d5..011a127e 100644 --- a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class MultiSelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("multi_select")] - public Condition MultiSelect { get; set; } - public MultiSelectFilter( string propertyName, string contains = null, @@ -15,29 +12,20 @@ public MultiSelectFilter( bool? isNotEmpty = null) { Property = propertyName; + MultiSelect = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("multi_select")] + public Condition MultiSelect { get; set; } public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -49,7 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } - } + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Filters/NumberFilter.cs b/Src/Notion.Client/Models/Filters/NumberFilter.cs index 4895d3e8..1a2f6879 100644 --- a/Src/Notion.Client/Models/Filters/NumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/NumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class NumberFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("number")] - public Condition Number { get; set; } - public NumberFilter( string propertyName, double? equal = null, @@ -19,20 +16,44 @@ public NumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Number = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - greaterThan: greaterThan, - lessThan: lessThan, - greaterThanOrEqualTo: greaterThanOrEqualTo, - lessThanOrEqualTo: lessThanOrEqualTo, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + greaterThan, + lessThan, + greaterThanOrEqualTo, + lessThanOrEqualTo, + isEmpty, + isNotEmpty ); } + [JsonProperty("number")] + public Condition Number { get; set; } + public class Condition { + public Condition( + double? equal = null, + double? doesNotEqual = null, + double? greaterThan = null, + double? lessThan = null, + double? greaterThanOrEqualTo = null, + double? lessThanOrEqualTo = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + GreaterThan = greaterThan; + LessThan = lessThan; + GreaterThanOrEqualTo = greaterThanOrEqualTo; + LessThanOrEqualTo = lessThanOrEqualTo; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public double? Equal { get; set; } @@ -56,27 +77,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - double? equal = null, - double? doesNotEqual = null, - double? greaterThan = null, - double? lessThan = null, - double? greaterThanOrEqualTo = null, - double? lessThanOrEqualTo = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - GreaterThan = greaterThan; - LessThan = lessThan; - GreaterThanOrEqualTo = greaterThanOrEqualTo; - LessThanOrEqualTo = lessThanOrEqualTo; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } - } } diff --git a/Src/Notion.Client/Models/Filters/PeopleFilter.cs b/Src/Notion.Client/Models/Filters/PeopleFilter.cs index af1067c4..6b83dda4 100644 --- a/Src/Notion.Client/Models/Filters/PeopleFilter.cs +++ b/Src/Notion.Client/Models/Filters/PeopleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PeopleFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("people")] - public Condition People { get; set; } - public PeopleFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public PeopleFilter( bool? isNotEmpty = null) { Property = propertyName; + People = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("people")] + public Condition People { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs index 758a65db..9ea9cf68 100644 --- a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PhoneNumberFilter : SinglePropertyFilter { - [JsonProperty("phone_number")] - public TextFilter.Condition Text { get; set; } - public PhoneNumberFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public PhoneNumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Text = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("phone_number")] + public TextFilter.Condition Text { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/RelationFilter.cs b/Src/Notion.Client/Models/Filters/RelationFilter.cs index b7e2924d..bff5f498 100644 --- a/Src/Notion.Client/Models/Filters/RelationFilter.cs +++ b/Src/Notion.Client/Models/Filters/RelationFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RelationFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("relation")] - public Condition Relation { get; set; } - public RelationFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public RelationFilter( bool? isNotEmpty = null) { Property = propertyName; + Relation = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("relation")] + public Condition Relation { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/RichTextFilter.cs b/Src/Notion.Client/Models/Filters/RichTextFilter.cs index 90bae02e..733b93ba 100644 --- a/Src/Notion.Client/Models/Filters/RichTextFilter.cs +++ b/Src/Notion.Client/Models/Filters/RichTextFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RichTextFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("rich_text")] - public TextFilter.Condition RichText { get; set; } - public RichTextFilter( string propertyName, string equal = null, @@ -19,23 +16,47 @@ public RichTextFilter( bool? isNotEmpty = null) { Property = propertyName; + RichText = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("rich_text")] + public TextFilter.Condition RichText { get; set; } } public static class TextFilter { public class Condition { + public Condition( + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + Contains = contains; + DoesNotContain = doesNotContain; + StartsWith = startsWith; + EndsWith = endsWith; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public string Equal { get; set; } @@ -59,26 +80,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - string equal = null, - string doesNotEqual = null, - string contains = null, - string doesNotContain = null, - string startsWith = null, - string endsWith = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - Contains = contains; - DoesNotContain = doesNotContain; - StartsWith = startsWith; - EndsWith = endsWith; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs index 41cb759e..df641729 100644 --- a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs +++ b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs @@ -4,18 +4,16 @@ namespace Notion.Client { public class RollupFilter : SinglePropertyFilter { - [JsonProperty("rollup")] - public Condition Rollup { get; set; } - public RollupFilter( - string propertyName - , IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + string propertyName, + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Property = propertyName; + Rollup = new Condition( any, none, @@ -25,14 +23,17 @@ string propertyName ); } + [JsonProperty("rollup")] + public Condition Rollup { get; set; } + public class Condition { public Condition( - IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Any = any; None = none; diff --git a/Src/Notion.Client/Models/Filters/SelectFilter.cs b/Src/Notion.Client/Models/Filters/SelectFilter.cs index 6f0887a4..064334f1 100644 --- a/Src/Notion.Client/Models/Filters/SelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/SelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class SelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("select")] - public Condition Select { get; set; } - public SelectFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public SelectFilter( bool? isNotEmpty = null) { Property = propertyName; + Select = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("select")] + public Condition Select { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/StatusFilter.cs b/Src/Notion.Client/Models/Filters/StatusFilter.cs index 7ed9b23f..0af0a22c 100644 --- a/Src/Notion.Client/Models/Filters/StatusFilter.cs +++ b/Src/Notion.Client/Models/Filters/StatusFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class StatusFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("status")] - public Condition Status { get; set; } - public StatusFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public StatusFilter( bool? isNotEmpty = null) { Property = propertyName; + Status = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("status")] + public Condition Status { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs index ac8f2244..d550817e 100644 --- a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampCreatedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "created_time"; - [JsonProperty("created_time")] - public DateFilter.Condition CreatedTime { get; set; } - public TimestampCreatedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampCreatedTimeFilter( bool? isNotEmpty = null) { CreatedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("created_time")] + public DateFilter.Condition CreatedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs index 1d6acb7f..51a6e39f 100644 --- a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampLastEditedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "last_modified_time"; - [JsonProperty("last_edited_time")] - public DateFilter.Condition LastEditedTime { get; set; } - public TimestampLastEditedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampLastEditedTimeFilter( bool? isNotEmpty = null) { LastEditedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("last_edited_time")] + public DateFilter.Condition LastEditedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TitleFilter.cs b/Src/Notion.Client/Models/Filters/TitleFilter.cs index 7c21bb33..1e0d4303 100644 --- a/Src/Notion.Client/Models/Filters/TitleFilter.cs +++ b/Src/Notion.Client/Models/Filters/TitleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class TitleFilter : SinglePropertyFilter { - [JsonProperty("title")] - public TextFilter.Condition Title { get; set; } - public TitleFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public TitleFilter( bool? isNotEmpty = null) { Property = propertyName; + Title = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("title")] + public TextFilter.Condition Title { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/URLFilter.cs b/Src/Notion.Client/Models/Filters/URLFilter.cs index b6a1fe6b..b2d4c611 100644 --- a/Src/Notion.Client/Models/Filters/URLFilter.cs +++ b/Src/Notion.Client/Models/Filters/URLFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class URLFilter : SinglePropertyFilter { - [JsonProperty("url")] - public TextFilter.Condition URL { get; set; } - public URLFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public URLFilter( bool? isNotEmpty = null) { Property = propertyName; + URL = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("url")] + public TextFilter.Condition URL { get; set; } } } diff --git a/Src/Notion.Client/Models/IObject.cs b/Src/Notion.Client/Models/IObject.cs index 2f72f929..b8ab1108 100644 --- a/Src/Notion.Client/Models/IObject.cs +++ b/Src/Notion.Client/Models/IObject.cs @@ -5,10 +5,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(Page), ObjectType.Page)] - [JsonSubtypes.KnownSubType(typeof(Database), ObjectType.Database)] - [JsonSubtypes.KnownSubType(typeof(IBlock), ObjectType.Block)] - [JsonSubtypes.KnownSubType(typeof(User), ObjectType.User)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Page), ObjectType.Page)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Database), ObjectType.Database)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(IBlock), ObjectType.Block)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(User), ObjectType.User)] public interface IObject { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Page/IPageIcon.cs b/Src/Notion.Client/Models/Page/IPageIcon.cs index a89184fe..b9ebea56 100644 --- a/Src/Notion.Client/Models/Page/IPageIcon.cs +++ b/Src/Notion.Client/Models/Page/IPageIcon.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(EmojiObject), "emoji")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "file")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmojiObject), "emoji")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "external")] public interface IPageIcon { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Page/IPageParent.cs b/Src/Notion.Client/Models/Page/IPageParent.cs index 439b1a3f..b9111d91 100644 --- a/Src/Notion.Client/Models/Page/IPageParent.cs +++ b/Src/Notion.Client/Models/Page/IPageParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IPageParent : IParent { } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index d96fef8a..996bdd46 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -7,63 +7,63 @@ namespace Notion.Client public class Page : IObject, IObjectModificationData { /// - /// Object type - /// - public ObjectType Object => ObjectType.Page; - - /// - /// Unique identifier of the page. - /// - public string Id { get; set; } - - /// - /// The parent of this page. Can be a database, page, or workspace. + /// The parent of this page. Can be a database, page, or workspace. /// [JsonProperty("parent")] public IPageParent Parent { get; set; } /// - /// Date and time when this page was created. - /// - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - /// - /// Date and time when this page was updated. - /// - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - - /// - /// The archived status of the page. + /// The archived status of the page. /// [JsonProperty("archived")] public bool IsArchived { get; set; } /// - /// Property values of this page. + /// Property values of this page. /// [JsonProperty("properties")] public IDictionary Properties { get; set; } /// - /// The URL of the Notion page. + /// The URL of the Notion page. /// [JsonProperty("url")] public string Url { get; set; } /// - /// Page icon. + /// Page icon. /// [JsonProperty("icon")] public IPageIcon Icon { get; set; } /// - /// Page cover image. + /// Page cover image. /// [JsonProperty("cover")] public FileObject Cover { get; set; } + /// + /// Object type + /// + public ObjectType Object => ObjectType.Page; + + /// + /// Unique identifier of the page. + /// + public string Id { get; set; } + + /// + /// Date and time when this page was created. + /// + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + /// + /// Date and time when this page was updated. + /// + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs index 1ac1fd51..e3fd7749 100644 --- a/Src/Notion.Client/Models/Parents/BlockParent.cs +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class BlockParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always has a value "block_id" + /// The ID of the block that the element belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("block_id")] + public string BlockId { get; set; } /// - /// The ID of the block that the element belongs to. + /// Always has a value "block_id" /// - [JsonProperty("block_id")] - public string BlockId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/DatabaseParent.cs b/Src/Notion.Client/Models/Parents/DatabaseParent.cs index 2e680655..878dbe89 100644 --- a/Src/Notion.Client/Models/Parents/DatabaseParent.cs +++ b/Src/Notion.Client/Models/Parents/DatabaseParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class DatabaseParent : IPageParent, IBlockParent { /// - /// Always "database_id" + /// The ID of the database that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("database_id")] + public string DatabaseId { get; set; } /// - /// The ID of the database that this page belongs to. + /// Always "database_id" /// - [JsonProperty("database_id")] - public string DatabaseId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/PageParent.cs b/Src/Notion.Client/Models/Parents/PageParent.cs index 13b1c95a..565f7ccc 100644 --- a/Src/Notion.Client/Models/Parents/PageParent.cs +++ b/Src/Notion.Client/Models/Parents/PageParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class PageParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always "page_id". + /// The ID of the page that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("page_id")] + public string PageId { get; set; } /// - /// The ID of the page that this page belongs to. + /// Always "page_id". /// - [JsonProperty("page_id")] - public string PageId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs index 86c60a54..a0b5e1c4 100644 --- a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs +++ b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs @@ -3,7 +3,7 @@ public class WorkspaceParent : IPageParent, IDatabaseParent, IBlockParent { /// - /// Always "workspace". + /// Always "workspace". /// public ParentType Type { get; set; } } diff --git a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs index 5ebc7730..58db1a7d 100644 --- a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs +++ b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(SimplePropertyItem), "property_item")] - [JsonSubtypes.KnownSubType(typeof(ListPropertyItem), "list")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SimplePropertyItem), "property_item")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ListPropertyItem), "list")] public interface IPropertyItemObject { [JsonProperty("object")] @@ -18,7 +18,8 @@ public interface IPropertyItemObject string Id { get; } /// - /// Only present in paginated property values with another page of results. If present, the url the user can request to get the next page of results. + /// Only present in paginated property values with another page of results. If present, the url the user can request to + /// get the next page of results. /// [JsonProperty("next_url")] string NextURL { get; } diff --git a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs index f539fcd6..5e35159c 100644 --- a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs @@ -1,19 +1,10 @@ using System.Collections.Generic; -using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client { public class ListPropertyItem : IPropertyItemObject { - public string Object => "list"; - - public virtual string Type { get; set; } - - public string Id { get; set; } - - public string NextURL { get; set; } - [JsonProperty("results")] public IEnumerable Results { get; set; } @@ -25,5 +16,13 @@ public class ListPropertyItem : IPropertyItemObject [JsonProperty("property_item")] public SimplePropertyItem PropertyItem { get; set; } + + public string Object => "list"; + + public virtual string Type { get; set; } + + public string Id { get; set; } + + public string NextURL { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs index 3df75fd7..04d7da7b 100644 --- a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs @@ -7,23 +7,31 @@ public class RollupPropertyItem : SimplePropertyItem { public override string Type => "rollup"; - [JsonProperty("rollup")] public Data Rollup { get; set; } + [JsonProperty("rollup")] + public Data Rollup { get; set; } public class Data { - [JsonProperty("type")] public string Type { get; set; } + [JsonProperty("type")] + public string Type { get; set; } - [JsonProperty("function")] public string Function { get; set; } + [JsonProperty("function")] + public string Function { get; set; } - [JsonProperty("number")] public double? Number { get; set; } + [JsonProperty("number")] + public double? Number { get; set; } - [JsonProperty("date")] public Date Date { get; set; } + [JsonProperty("date")] + public Date Date { get; set; } - [JsonProperty("array")] public IEnumerable> Array { get; set; } + [JsonProperty("array")] + public IEnumerable> Array { get; set; } - [JsonProperty("unsupported")] public Dictionary Unsupported { get; set; } + [JsonProperty("unsupported")] + public Dictionary Unsupported { get; set; } - [JsonProperty("incomplete")] public Dictionary Incomplete { get; set; } + [JsonProperty("incomplete")] + public Dictionary Incomplete { get; set; } } } } diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index 50d95184..ed3bef38 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -4,26 +4,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyItem), "number")] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyItem), "url")] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyItem), "select")] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyItem), "multi_select")] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyItem), "status")] - [JsonSubtypes.KnownSubType(typeof(DatePropertyItem), "date")] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyItem), "email")] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyItem), "phone_number")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyItem), "checkbox")] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyItem), "files")] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyItem), "created_by")] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyItem), "created_time")] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyItem), "last_edited_by")] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyItem), "last_edited_time")] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyItem), "formula")] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyItem), "title")] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyItem), "rich_text")] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyItem), "people")] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyItem), "relation")] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyItem), "number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyItem), "url")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyItem), "select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyItem), "multi_select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyItem), "status")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyItem), "date")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyItem), "email")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyItem), "phone_number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyItem), "checkbox")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyItem), "files")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyItem), "created_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyItem), "created_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyItem), "last_edited_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyItem), "last_edited_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyItem), "formula")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyItem), "title")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyItem), "rich_text")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyItem), "people")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyItem), "relation")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyItem), "rollup")] public abstract class SimplePropertyItem : IPropertyItemObject { public string Object => "property_item"; diff --git a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs index 46e70108..6b6b863c 100644 --- a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs @@ -6,6 +6,7 @@ public class StatusPropertyItem : SimplePropertyItem { public override string Type => "status"; - [JsonProperty("status")] public SelectOption Status { get; set; } + [JsonProperty("status")] + public SelectOption Status { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs index 1f3fec50..422eb9b7 100644 --- a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Checkbox property value objects contain a boolean within the checkbox property. + /// Checkbox property value objects contain a boolean within the checkbox property. /// public class CheckboxPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs index 17fa4ef4..31cf5f5b 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created by property value object + /// Created by property value object /// public class CreatedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedBy; /// - /// Describes the user who created this page. + /// Describes the user who created this page. /// [JsonProperty("created_by")] public User CreatedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs index 0b20b2dc..e0550d13 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created time property value object. + /// Created time property value object. /// public class CreatedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedTime; /// - /// The date and time when this page was created. + /// The date and time when this page was created. /// [JsonProperty("created_time")] public string CreatedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index aeb3cd8e..22715b2e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -4,38 +4,39 @@ namespace Notion.Client { /// - /// Date property value object. + /// Date property value object. /// public class DatePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Date; /// - /// Date + /// Date /// [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } /// - /// Date value object. + /// Date value object. /// public class Date { /// - /// Start date with optional time. + /// Start date with optional time. /// [JsonProperty("start")] public DateTime? Start { get; set; } /// - /// End date with optional time. + /// End date with optional time. /// [JsonProperty("end")] public DateTime? End { get; set; } /// - /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js. + /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are + /// based on the time zones from Moment.js. /// [JsonProperty("time_zone")] public string TimeZone { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs index 1869fc85..5a8e2c7a 100644 --- a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Email property value object. + /// Email property value object. /// public class EmailPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Email; /// - /// Describes an email address. + /// Describes an email address. /// [JsonProperty("email")] public string Email { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs index 41580fdb..67bc864a 100644 --- a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// File property value object. + /// File property value object. /// public class FilesPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Files; /// - /// Array of File Object with name. + /// Array of File Object with name. /// [JsonProperty("files")] public List Files { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs index e85fd5bd..a1242f47 100644 --- a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs @@ -3,50 +3,50 @@ namespace Notion.Client { /// - /// Formula property value object. + /// Formula property value object. /// public class FormulaPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Formula; /// - /// A formula described in the database's properties. + /// A formula described in the database's properties. /// [JsonProperty("formula")] public FormulaValue Formula { get; set; } } /// - /// Formula value object. + /// Formula value object. /// public class FormulaValue { /// - /// Formula value type + /// Formula value type /// [JsonProperty("type")] public string Type { get; set; } /// - /// String formula value. + /// String formula value. /// [JsonProperty("string")] public string String { get; set; } /// - /// Number formula value. + /// Number formula value. /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Boolean formula value. + /// Boolean formula value. /// [JsonProperty("boolean")] public bool? Boolean { get; set; } /// - /// Date formula value + /// Date formula value /// [JsonProperty("date")] public Date Date { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs index b5e26efc..a536ad60 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited by property value object. + /// Last edited by property value object. /// public class LastEditedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedBy; /// - /// Describes the user who last updated this page. + /// Describes the user who last updated this page. /// [JsonProperty("last_edited_by")] public User LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs index 785ac3bc..25d3100d 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited time property value object. + /// Last edited time property value object. /// public class LastEditedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedTime; /// - /// The date and time when this page was last updated. + /// The date and time when this page was last updated. /// [JsonProperty("last_edited_time")] public string LastEditedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs index a5ee4f0a..ff820527 100644 --- a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Multi-select property value object. + /// Multi-select property value object. /// public class MultiSelectPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.MultiSelect; /// - /// An array of multi-select option values. + /// An array of multi-select option values. /// [JsonProperty("multi_select")] public List MultiSelect { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs index a98a34d4..15f9c768 100644 --- a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Number formula property value object. + /// Number formula property value object. /// public class NumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Number; /// - /// Value of number + /// Value of number /// [JsonProperty("number")] public double? Number { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs index 047d33ee..62557560 100644 --- a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// People property value object. + /// People property value object. /// public class PeoplePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.People; /// - /// List of users. + /// List of users. /// [JsonProperty("people")] public List People { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs index be5e482e..79a24dac 100644 --- a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Phone number property value object. + /// Phone number property value object. /// public class PhoneNumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.PhoneNumber; /// - /// Phone number value + /// Phone number value /// [JsonProperty("phone_number")] public string PhoneNumber { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index 8437b4f8..f893e47a 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -5,33 +5,33 @@ namespace Notion.Client { /// - /// An object describing the identifier, type, and value of a page property. + /// An object describing the identifier, type, and value of a page property. /// [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DatePropertyValue), PropertyValueType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyValue), PropertyValueType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyValue), PropertyValueType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyValue), PropertyValueType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyValue), PropertyValueType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyValue), PropertyValueType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyValue), PropertyValueType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyValue), PropertyValueType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyValue), PropertyValueType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyValue), PropertyValueType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyValue), PropertyValueType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyValue), PropertyValueType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyValue), PropertyValueType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyValue), PropertyValueType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyValue), PropertyValueType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyValue), PropertyValueType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyValue), PropertyValueType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyValue), PropertyValueType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyValue), PropertyValueType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyValue), PropertyValueType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyValue), PropertyValueType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyValue), PropertyValueType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyValue), PropertyValueType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] public class PropertyValue { /// - /// Underlying identifier of the property. + /// Underlying identifier of the property. /// [JsonProperty("id")] public string Id { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index fcbeae61..93a8d63e 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Types of Property Value + /// Types of Property Value /// public enum PropertyValueType { diff --git a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs index 3d11a096..6f9e0ec8 100644 --- a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Relation property value object. + /// Relation property value object. /// public class RelationPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Relation; /// - /// Array of page references + /// Array of page references /// [JsonProperty("relation")] public List Relation { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs index 028ed046..90e8d0be 100644 --- a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Rich Text property value object. + /// Rich Text property value object. /// public class RichTextPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.RichText; /// - /// List of rich text objects + /// List of rich text objects /// [JsonProperty("rich_text")] public List RichText { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs index 7c573081..2eb104fb 100644 --- a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs @@ -4,7 +4,7 @@ namespace Notion.Client { /// - /// Rollup property value object. + /// Rollup property value object. /// public class RollupPropertyValue : PropertyValue { @@ -15,31 +15,31 @@ public class RollupPropertyValue : PropertyValue } /// - /// Object containing rollup type-specific data. + /// Object containing rollup type-specific data. /// public class RollupValue { /// - /// The type of rollup. Possible values are "number", "date", and "array". + /// The type of rollup. Possible values are "number", "date", and "array". /// [JsonProperty("type")] public string Type { get; set; } /// - /// Number rollup property values contain a number + /// Number rollup property values contain a number /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Date rollup property values contain a date property value. + /// Date rollup property values contain a date property value. /// [JsonProperty("date")] public DatePropertyValue Date { get; set; } /// - /// Array rollup property values contain an array of element objects. - /// Array containing the property value object will not contain value for Id field + /// Array rollup property values contain an array of element objects. + /// Array containing the property value object will not contain value for Id field /// [JsonProperty("array")] public List Array { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs index 07b2a346..74c94c82 100644 --- a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Select property value object. + /// Select property value object. /// public class SelectPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index 497e4c18..f4a82e48 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -5,37 +5,10 @@ namespace Notion.Client { /// - /// Status property value objects contain page status + /// Status property value objects contain page status /// public class StatusPropertyValue : PropertyValue { - public override PropertyValueType Type => PropertyValueType.Status; - - [JsonProperty("status")] - public Data Status { get; set; } - - public class Data - { - /// - /// ID of the option. - /// - [JsonProperty("id")] - public string Id { get; set; } - - /// - /// Name of the option as it appears in Notion. - /// - [JsonProperty("name")] - public string Name { get; set; } - - /// - /// Color of the option. - /// - [JsonProperty("color")] - [JsonConverter(typeof(StringEnumConverter))] - public Color? Color { get; set; } - } - public enum Color { [EnumMember(Value = "default")] @@ -68,5 +41,32 @@ public enum Color [EnumMember(Value = "red")] Red, } + + public override PropertyValueType Type => PropertyValueType.Status; + + [JsonProperty("status")] + public Data Status { get; set; } + + public class Data + { + /// + /// ID of the option. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Name of the option as it appears in Notion. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Color of the option. + /// + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs index 58b7842d..e72a2a08 100644 --- a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Title property value object. + /// Title property value object. /// public class TitlePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Title; /// - /// An array of rich text objects + /// An array of rich text objects /// [JsonProperty("title")] public List Title { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs index 08b800e6..5fc8f8bb 100644 --- a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// URL property value object. + /// URL property value object. /// public class UrlPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Url; /// - /// Describes a web address + /// Describes a web address /// [JsonProperty("url")] public string Url { get; set; } diff --git a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs index 61a7a887..062d75c0 100644 --- a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UserOwner), "user")] - [JsonSubtypes.KnownSubType(typeof(WorkspaceIntegrationOwner), "workspace")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UserOwner), "user")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceIntegrationOwner), "workspace")] public interface IBotOwner { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs index 40d69867..e60a4fab 100644 --- a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class UserOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("user")] public User User { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs index 78a84f6f..b5304157 100644 --- a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class WorkspaceIntegrationOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("workspace")] public bool Workspace { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/User.cs b/Src/Notion.Client/Models/User/User.cs index 7f336929..6ae9efef 100644 --- a/Src/Notion.Client/Models/User/User.cs +++ b/Src/Notion.Client/Models/User/User.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class User : IObject { - public ObjectType Object => ObjectType.User; - public string Id { get; set; } - [JsonProperty("type")] public string Type { get; set; } @@ -21,5 +18,9 @@ public class User : IObject [JsonProperty("bot")] public Bot Bot { get; set; } + + public ObjectType Object => ObjectType.User; + + public string Id { get; set; } } } diff --git a/Src/Notion.Client/NotionApiErrorResponse.cs b/Src/Notion.Client/NotionApiErrorResponse.cs index f27288fb..44a225b2 100644 --- a/Src/Notion.Client/NotionApiErrorResponse.cs +++ b/Src/Notion.Client/NotionApiErrorResponse.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - class NotionApiErrorResponse + internal class NotionApiErrorResponse { [JsonProperty("code")] public NotionAPIErrorCode ErrorCode { get; set; } diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index 358db384..c7c9d7d4 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -29,6 +29,7 @@ public NotionApiException( } public NotionAPIErrorCode? NotionAPIErrorCode { get; } + public HttpStatusCode StatusCode { get; } } } diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index f1650b29..f752413a 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -3,11 +3,17 @@ public interface INotionClient { IUsersClient Users { get; } + IDatabasesClient Databases { get; } + IPagesClient Pages { get; } + ISearchClient Search { get; } + IBlocksClient Blocks { get; } + ICommentsClient Comments { get; } + IRestClient RestClient { get; } } @@ -32,11 +38,17 @@ public NotionClient( } public IUsersClient Users { get; } + public IDatabasesClient Databases { get; } + public IPagesClient Pages { get; } + public ISearchClient Search { get; } + public IBlocksClient Blocks { get; } + public ICommentsClient Comments { get; } + public IRestClient RestClient { get; } } } diff --git a/Src/Notion.Client/NotionClientFactory.cs b/Src/Notion.Client/NotionClientFactory.cs index 0a02eb3c..e82ba2de 100644 --- a/Src/Notion.Client/NotionClientFactory.cs +++ b/Src/Notion.Client/NotionClientFactory.cs @@ -7,11 +7,11 @@ public static NotionClient Create(ClientOptions options) var restClient = new RestClient(options); return new NotionClient( - restClient: restClient - , users: new UsersClient(restClient) - , databases: new DatabasesClient(restClient) - , pages: new PagesClient(restClient) - , search: new SearchClient(restClient) + restClient + , new UsersClient(restClient) + , new DatabasesClient(restClient) + , new PagesClient(restClient) + , new SearchClient(restClient) , blocks: new BlocksClient(restClient) , comments: new CommentsClient(restClient) ); diff --git a/Src/Notion.Client/RestClient/ClientOptions.cs b/Src/Notion.Client/RestClient/ClientOptions.cs index 3c6be1bc..d0015767 100644 --- a/Src/Notion.Client/RestClient/ClientOptions.cs +++ b/Src/Notion.Client/RestClient/ClientOptions.cs @@ -3,7 +3,9 @@ public class ClientOptions { public string BaseUrl { get; set; } + public string NotionVersion { get; set; } + public string AuthToken { get; set; } } } diff --git a/Src/Notion.Client/RestClient/LoggingHandler.cs b/Src/Notion.Client/RestClient/LoggingHandler.cs index 8655bb97..a6001d10 100644 --- a/Src/Notion.Client/RestClient/LoggingHandler.cs +++ b/Src/Notion.Client/RestClient/LoggingHandler.cs @@ -7,7 +7,9 @@ namespace Notion.Client { public class LoggingHandler : DelegatingHandler { - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) { Log.Trace("Request: {request}", request); @@ -22,6 +24,7 @@ protected override async Task SendAsync(HttpRequestMessage catch (Exception ex) { Log.Error(ex, "Failed to get response: {exception}", ex); + throw; } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index bba3a866..5da38f61 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -14,50 +14,98 @@ namespace Notion.Client { public class RestClient : IRestClient { - private HttpClient _httpClient; private readonly ClientOptions _options; - protected readonly JsonSerializerSettings defaultSerializerSettings = new JsonSerializerSettings + protected readonly JsonSerializerSettings defaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, }; + private HttpClient _httpClient; + public RestClient(ClientOptions options) { _options = MergeOptions(options); } - private static ClientOptions MergeOptions(ClientOptions options) + public async Task GetAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) { - return new ClientOptions - { - AuthToken = options.AuthToken, - BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION - }; + var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, + cancellationToken: cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); } - public async Task GetAsync( + public async Task PostAsync( string uri, + object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { - var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, cancellationToken: cancellationToken); + void AttachContent(HttpRequestMessage httpRequest) => + httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), + Encoding.UTF8, "application/json"); + + var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, + cancellationToken); return await response.ParseStreamAsync(serializerSettings); } + public async Task PatchAsync( + string uri, + object body, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + void AttachContent(HttpRequestMessage httpRequest) + { + var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); + httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); + } + + var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, + cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); + } + + public async Task DeleteAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); + } + + private static ClientOptions MergeOptions(ClientOptions options) + { + return new ClientOptions + { + AuthToken = options.AuthToken, + BaseUrl = options.BaseUrl ?? Constants.BASE_URL, + NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION, + }; + } + private static async Task BuildException(HttpResponseMessage response) { var errorBody = await response.Content.ReadAsStringAsync(); NotionApiErrorResponse errorResponse = null; + if (!string.IsNullOrWhiteSpace(errorBody)) { try @@ -114,47 +162,11 @@ private static void AddHeaders(HttpRequestMessage request, IDictionary PostAsync( - string uri, - object body, - IDictionary queryParams = null, - IDictionary headers = null, - JsonSerializerSettings serializerSettings = null, - CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task PatchAsync(string uri, object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); - httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task DeleteAsync(string uri, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); - } - private HttpClient EnsureHttpClient() { if (_httpClient == null) { - var pipeline = new LoggingHandler() { InnerHandler = new HttpClientHandler() }; + var pipeline = new LoggingHandler {InnerHandler = new HttpClientHandler()}; _httpClient = new HttpClient(pipeline); _httpClient.BaseAddress = new Uri(_options.BaseUrl); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 783ae20e..86a2f0fb 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -25,7 +25,7 @@ public static string AddQueryString(string uri, string name, string value) throw new ArgumentNullException(nameof(value)); } - return AddQueryString(uri, new[] { new KeyValuePair(name, value) }); + return AddQueryString(uri, new[] {new KeyValuePair(name, value)}); } public static string AddQueryString(string uri, IDictionary queryParams) @@ -74,6 +74,7 @@ private static string AddQueryString( var sb = new StringBuilder(); sb.Append(uriToBeAppended); + foreach (var parameter in queryParams) { sb.Append(hasQuery ? '&' : '?'); @@ -84,13 +85,14 @@ private static string AddQueryString( } sb.Append(anchorText); + return sb.ToString(); } - private static IEnumerable> RemoveEmptyValueQueryParams(IEnumerable> queryParams) + private static IEnumerable> RemoveEmptyValueQueryParams( + IEnumerable> queryParams) { return queryParams.Where(x => !string.IsNullOrWhiteSpace(x.Value)); } - } } diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 2ac7219d..32d887eb 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -5,130 +5,95 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class CommentsClientTests : IDisposable { - public class CommentsClientTests : IDisposable + private readonly INotionClient _client; + private readonly Page _page; + private readonly string _pageParentId; + + public CommentsClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + + _client = NotionClientFactory.Create(options); + + _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? + throw new ArgumentNullException("Page parent id is required."); + + _page = _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = _pageParentId} + ).Build() + ).Result; + } + + public void Dispose() + { + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters {Archived = true}).Wait(); + } + + [Fact] + public async Task ShouldCreatePageComment() { - private readonly INotionClient _client; - private readonly string _pageParentId; - private readonly Page _page; - - public CommentsClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; - - _client = NotionClientFactory.Create(options); - _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? throw new ArgumentNullException("Page parent id is required."); - - _page = _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = _pageParentId - } - ).Build() - ).Result; - } - - [Fact] - public async Task ShouldCreatePageComment() - { - // Arrange - var parameters = CreateCommentParameters.CreatePageComment( - new ParentPageInput + // Arrange + var parameters = CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ); + + // Act + var response = await _client.Comments.Create(parameters); + + // Arrange + + Assert.NotNull(response.Parent); + Assert.NotNull(response.Id); + Assert.NotNull(response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); + } + + [Fact] + public async Task ShouldCreateADiscussionComment() + { + // Arrange + var comment = await _client.Comments.Create( + CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ) + ); + + // Act + var response = await _client.Comments.Create( + CreateCommentParameters.CreateDiscussionComment( + comment.DiscussionId, + new List { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } + new RichTextTextInput {Text = new Text {Content = "This is a sub comment"}}, } - ); - - // Act - var response = await _client.Comments.Create(parameters); - - // Arrange - - Assert.NotNull(response.Parent); - Assert.NotNull(response.Id); - Assert.NotNull(response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - [Fact] - public async Task ShouldCreateADiscussionComment() - { - // Arrange - var comment = await _client.Comments.Create( - CreateCommentParameters.CreatePageComment( - new ParentPageInput - { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } - } - ) - ); - - // Act - var response = await _client.Comments.Create( - CreateCommentParameters.CreateDiscussionComment( - comment.DiscussionId, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a sub comment" - } - } - } - ) - ); - - // Arrange - Assert.Null(response.Parent); - Assert.NotNull(response.Id); - Assert.Equal(comment.DiscussionId, response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a sub comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - public void Dispose() - { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters - { - Archived = true, - }).Wait(); - } + ) + ); + + // Arrange + Assert.Null(response.Parent); + Assert.NotNull(response.Id); + Assert.Equal(comment.DiscussionId, response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a sub comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index eabef5b4..1aaa2726 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -6,537 +6,430 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IBlocksClientTests { - public class IBlocksClientTests + private readonly INotionClient _client; + + public IBlocksClientTests() { - private readonly INotionClient _client; + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - public IBlocksClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + _client = NotionClientFactory.Create(options); + } - _client = NotionClientFactory.Create(options); - } + [Fact] + public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Fact] - public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() + new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}, + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new CalloutBlock { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - }, - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - new CalloutBlock + Callout = new CalloutBlock.Info { - Callout = new CalloutBlock.Info + RichText = new List { - RichText = new List { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } - } - } - } - ); - - blocks.Results.Should().HaveCount(4); - - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, + }, + }, + }, + } + ); - [Fact] - public async Task UpdateBlockAsync_UpdatesGivenBlock() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + blocks.Results.Should().HaveCount(4); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - } - } - } - ); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); + [Fact] + public async Task UpdateBlockAsync_UpdatesGivenBlock() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters { - Archived = true - }); - } + Children = new List {new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}}, + } + ); - [Fact] - public async Task DeleteAsync_DeleteBlockWithGivenId() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - } - } - ); + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); - blocks.Results.Should().HaveCount(2); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + [Fact] + public async Task DeleteAsync_DeleteBlockWithGivenId() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Theory] - [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() - { - block - } - } - ); + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + }, + } + ); + + blocks.Results.Should().HaveCount(2); - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, updateBlock); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + [Theory] + [MemberData(nameof(BlockData))] + public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - var updatedBlock = blocks.Results.First(); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - assert.Invoke(updatedBlock); + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters {Children = new List {block}} + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, updateBlock); + + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); + + var updatedBlock = blocks.Results.First(); + + assert.Invoke(updatedBlock); + + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - private static IEnumerable BlockData() + private static IEnumerable BlockData() + { + return new List { - return new List + new object[] { - new object[] { - new BookmarkBlock + new BookmarkBlock + { + Bookmark = new BookmarkBlock.Info { - Bookmark = new BookmarkBlock.Info - { - Url = "https://developers.notion.com/reference/rich-text", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Notion API" - } - } - } - } - }, - new BookmarkUpdateBlock { - Bookmark = new BookmarkUpdateBlock.Info + Url = "https://developers.notion.com/reference/rich-text", + Caption = new List { - Url = "https://github.com/notion-dotnet/notion-sdk-net", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Github" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Notion API"}}, + }, }, - new Action((block) => { - var updatedBlock = (BookmarkBlock)block; - Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); - Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); - }) }, - new object[] { - new EquationBlock + new BookmarkUpdateBlock + { + Bookmark = new BookmarkUpdateBlock.Info { - Equation = new EquationBlock.Info + Url = "https://github.com/notion-dotnet/notion-sdk-net", + Caption = new List { - Expression = "e=mc^3" - } - }, - new EquationUpdateBlock { - Equation = new EquationUpdateBlock.Info - { - Expression = "e=mc^2" - } - }, - new Action((block) => { - var updatedBlock = (EquationBlock)block; - Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); - }) - }, - new object[] { - new DividerBlock { - Divider = new DividerBlock.Data() - }, - new DividerUpdateBlock(), - new Action((block) => { - Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] { - new AudioBlock { - Audio = new ExternalFile { - External = new ExternalFile.Info { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" - } - } - }, - new AudioUpdateBlock { - Audio = new ExternalFileInput { - External = new ExternalFileInput.Data { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" - } - } + new RichTextTextInput {Text = new Text {Content = "Github"}}, + }, }, - new Action((block) => { - block.Should().NotBeNull(); - - block.Should().BeOfType().Subject - .Audio.Should().BeOfType().Subject - .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); - }) }, - new object[] + new Action(block => { - new TableOfContentsBlock { - TableOfContents = new TableOfContentsBlock.Data() - }, - new TableOfContentsUpdateBlock(), - new Action((block) => + var updatedBlock = (BookmarkBlock)block; + Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); + Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); + }), + }, + new object[] + { + new EquationBlock {Equation = new EquationBlock.Info {Expression = "e=mc^3"}}, + new EquationUpdateBlock {Equation = new EquationUpdateBlock.Info {Expression = "e=mc^2"}}, + new Action(block => + { + var updatedBlock = (EquationBlock)block; + Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); + }), + }, + new object[] + { + new DividerBlock {Divider = new DividerBlock.Data()}, new DividerUpdateBlock(), new Action( + block => { Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] + Assert.IsType(block); + }), + }, + new object[] + { + new AudioBlock { - new CalloutBlock + Audio = new ExternalFile { - Callout = new CalloutBlock.Info + External = new ExternalFile.Info { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", + }, }, - new CalloutUpdateBlock() + }, + new AudioUpdateBlock + { + Audio = new ExternalFileInput { - Callout = new CalloutUpdateBlock.Info + External = new ExternalFileInput.Data { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", + }, }, - new Action((block) => - { - Assert.NotNull(block); - var calloutBlock = Assert.IsType(block); - - Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new QuoteBlock + block.Should().NotBeNull(); + + block.Should().BeOfType().Subject + .Audio.Should().BeOfType().Subject + .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); + }), + }, + new object[] + { + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new TableOfContentsUpdateBlock(), new Action(block => + { + Assert.NotNull(block); + Assert.IsType(block); + }), + }, + new object[] + { + new CalloutBlock + { + Callout = new CalloutBlock.Info { - Quote = new QuoteBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new QuoteUpdateBlock() + }, + new CalloutUpdateBlock + { + Callout = new CalloutUpdateBlock.Info { - Quote = new QuoteUpdateBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action((block) => - { - Assert.NotNull(block); - var quoteBlock = Assert.IsType(block); - - Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new ImageBlock() { - Image = new ExternalFile + Assert.NotNull(block); + var calloutBlock = Assert.IsType(block); + + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new QuoteBlock + { + Quote = new QuoteBlock.Info + { + RichText = new List { - External = new ExternalFile.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new ImageUpdateBlock() + }, + new QuoteUpdateBlock + { + Quote = new QuoteUpdateBlock.Info { - Image = new ExternalFileInput + RichText = new List { - External = new ExternalFileInput.Data - { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action (block => - { - Assert.NotNull(block); - var imageBlock = Assert.IsType(block); - var imageFile = Assert.IsType(imageBlock.Image); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); - }) }, - new object[] + new Action(block => + { + Assert.NotNull(block); + var quoteBlock = Assert.IsType(block); + + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new ImageBlock { - new EmbedBlock() + Image = new ExternalFile { - Embed = new EmbedBlock.Info + External = new ExternalFile.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new EmbedUpdateBlock() + }, + new ImageUpdateBlock + { + Image = new ExternalFileInput { - Embed = new EmbedUpdateBlock.Info + External = new ExternalFileInput.Data { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } + Url + = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + }, }, - new Action (block => + }, + new Action(block => + { + Assert.NotNull(block); + var imageBlock = Assert.IsType(block); + var imageFile = Assert.IsType(imageBlock.Image); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + imageFile.External.Url); + }), + }, + new object[] + { + new EmbedBlock + { + Embed = new EmbedBlock.Info { - Assert.NotNull(block); - var embedBlock = Assert.IsType(block); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); - }) + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new object[] + new EmbedUpdateBlock { - new TemplateBlock() + Embed = new EmbedUpdateBlock.Info { - Template = new TemplateBlock.Data - { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Template" - } - } - }, - Children = new List - { - new EmbedBlock() - { - Embed = new EmbedBlock.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } - } - } + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", }, - new TemplateUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var embedBlock = Assert.IsType(block); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + embedBlock.Embed.Url); + }), + }, + new object[] + { + new TemplateBlock + { + Template = new TemplateBlock.Data { - Template = new TemplateUpdateBlock.Info + RichText = new List { - RichText = new List + new RichTextText {Text = new Text {Content = "Test Template"}}, + }, + Children = new List + { + new EmbedBlock { - new RichTextTextInput + Embed = new EmbedBlock.Info { - Text = new Text - { - Content = "Test Template 2" - } - } - } - } + Url + = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, + }, + }, }, - new Action (block => - { - Assert.NotNull(block); - var templateBlock = Assert.IsType(block); - - Assert.Single(templateBlock.Template.RichText); - Assert.Null(templateBlock.Template.Children); - Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); - }) }, - new object[] + new TemplateUpdateBlock { - new LinkToPageBlock() + Template = new TemplateUpdateBlock.Info { - LinkToPage = new PageParent + RichText = new List { - Type = ParentType.PageId, - PageId = "533578e3edf14c0a91a9da6b09bac3ee" - } + new RichTextTextInput {Text = new Text {Content = "Test Template 2"}}, + }, }, - new LinkToPageUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var templateBlock = Assert.IsType(block); + + Assert.Single(templateBlock.Template.RichText); + Assert.Null(templateBlock.Template.Children); + + Assert.Equal("Test Template 2", + templateBlock.Template.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new LinkToPageBlock + { + LinkToPage = new PageParent { - LinkToPage = new ParentPageInput - { - PageId = "3c357473a28149a488c010d2b245a589" - } + Type = ParentType.PageId, PageId = "533578e3edf14c0a91a9da6b09bac3ee", }, - new Action(block => - { - Assert.NotNull(block); - var linkToPageBlock = Assert.IsType(block); + }, + new LinkToPageUpdateBlock + { + LinkToPage = new ParentPageInput {PageId = "3c357473a28149a488c010d2b245a589"}, + }, + new Action(block => + { + Assert.NotNull(block); + var linkToPageBlock = Assert.IsType(block); - var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - // TODO: Currently the api doesn't allow to update the link_to_page block type - // This will change to updated ID once api start to support - Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); - }) - } - }; - } + // TODO: Currently the api doesn't allow to update the link_to_page block type + // This will change to updated ID once api start to support + Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); + }), + }, + }; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index dbf74a90..24f11940 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -6,297 +6,228 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IPageClientTests { - public class IPageClientTests - { - private readonly INotionClient _client; - private readonly string _databaseId; + private readonly INotionClient _client; + private readonly string _databaseId; - public IPageClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + public IPageClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - _client = NotionClientFactory.Create(options); - _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - } + _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + } - [Fact] - public async Task CreateAsync_CreatesANewPage() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task CreateAsync_CreatesANewPage() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Bug_unable_to_create_page_with_select_property() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty("TestSelect", new SelectPropertyValue - { - Select = new SelectOption + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Bug_unable_to_create_page_with_select_property() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - Id = "dfbfbe65-6f67-4876-9f75-699124334d06" - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty("TestSelect", + new SelectPropertyValue {Select = new SelectOption {Id = "dfbfbe65-6f67-4876-9f75-699124334d06"}}) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Test_RetrievePagePropertyItemAsync() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Test_RetrievePagePropertyItemAsync() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText + Title = new List { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = "title" - }); + var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = "title", + }); - property.Should().NotBeNull(); - property.Should().BeOfType(); + property.Should().NotBeNull(); + property.Should().BeOfType(); - var listProperty = (ListPropertyItem)property; + var listProperty = (ListPropertyItem)property; - listProperty.Type.Should().NotBeNull(); - listProperty.Results.Should().SatisfyRespectively(p => - { - p.Should().BeOfType(); - var titleProperty = (TitlePropertyItem)p; + listProperty.Type.Should().NotBeNull(); - titleProperty.Title.PlainText.Should().Be("Test Page Title"); - }); + listProperty.Results.Should().SatisfyRespectively(p => + { + p.Should().BeOfType(); + var titleProperty = (TitlePropertyItem)p; - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Title.PlainText.Should().Be("Test Page Title"); + }); - [Fact] - public async Task Test_UpdatePageProperty_with_date_as_null() - { - // setup - add property to db and create a page with the property having a date + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - string datePropertyName = "Test Date Property"; - var updateDatabaseParameters = new DatabasesUpdateParameters(); - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty(datePropertyName, new DatePropertyValue - { - Date = new Date() + var datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Test Date Property", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue + { + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty(datePropertyName, + new DatePropertyValue { - Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z") - } - }) + Date = new Date + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z"), + }, + }) .Build(); - var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties[datePropertyName].Id - }); + var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = page.Properties[datePropertyName].Id, + }); - setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); - // verify - IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue {Date = null}); - var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Properties = testProps - }); + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Properties = testProps}); - var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters { - PageId = page.Id, - PropertyId = updatedPage.Properties[datePropertyName].Id + PageId = page.Id, PropertyId = updatedPage.Properties[datePropertyName].Id, }); - verifyDate?.Date.Should().BeNull(); + verifyDate?.Date.Should().BeNull(); - //cleanup - await _client.Blocks.DeleteAsync(page.Id); - } + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } - [Fact] - public async Task Bug_Unable_To_Parse_NumberPropertyItem() - { - // Arrange - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }).AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task Bug_Unable_To_Parse_NumberPropertyItem() + { + // Arrange + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}).AddProperty("Name", + new TitlePropertyValue + { + Title = new List { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }).AddProperty("Number", new NumberPropertyValue - { - Number = 200.00 - }).Build(); + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }).AddProperty("Number", new NumberPropertyValue {Number = 200.00}).Build(); - // Act - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + // Act + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - // Assert - Assert.NotNull(page); - var pageParent = Assert.IsType(page.Parent); - Assert.Equal(_databaseId, pageParent.DatabaseId); + // Assert + Assert.NotNull(page); + var pageParent = Assert.IsType(page.Parent); + Assert.Equal(_databaseId, pageParent.DatabaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Name"].Id - }); + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Name"].Id}); - Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); + Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); - var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Number"].Id - }); + var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Number"].Id}); - Assert.Equal(200.00, numberProperty.Number); + Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); } } diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index e593a47c..ceb415d2 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -7,64 +7,55 @@ using WireMock.RequestBuilders; using WireMock.Server; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class ApiTestBase : IDisposable { - public class ApiTestBase : IDisposable + protected static readonly JsonSerializerSettings JsonSerializerSettings = new() { - protected readonly WireMockServer Server; - - protected static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings() - { - Formatting = Newtonsoft.Json.Formatting.Indented, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } - }; + Formatting = Formatting.Indented, + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + }; - protected readonly ClientOptions ClientOptions; + protected readonly ClientOptions ClientOptions; + protected readonly WireMockServer Server; - protected ApiTestBase() - { - Server = WireMockServer.Start(); - ClientOptions = new ClientOptions() - { - BaseUrl = Server.Urls.First(), - AuthToken = "" - }; - } + protected ApiTestBase() + { + Server = WireMockServer.Start(); + ClientOptions = new ClientOptions {BaseUrl = Server.Urls.First(), AuthToken = ""}; + } - public void Dispose() - { - Server.Stop(); - Server.Dispose(); - } + public void Dispose() + { + Server.Stop(); + Server.Dispose(); + } - protected IRequestBuilder CreateGetRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingGet() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreateGetRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingGet() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePostRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPost() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePostRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPost() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePatchRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPatch() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePatchRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPatch() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); } } diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 753e5464..8a568a13 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -7,191 +7,184 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class BlocksClientTests : ApiTestBase { - public class BlocksClientTests : ApiTestBase - { - private readonly IBlocksClient _client; + private readonly IBlocksClient _client; - public BlocksClientTests() - { - _client = new BlocksClient(new RestClient(ClientOptions)); - } + public BlocksClientTests() + { + _client = new BlocksClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveBlockChildren() - { - // Arrange - string blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; - var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); + [Fact] + public async Task RetrieveBlockChildren() + { + // Arrange + var blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; + var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); + // Act + var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); - // Assert - var children = childrenResult.Results; - children.Should().HaveCount(8); - } + // Assert + var children = childrenResult.Results; + children.Should().HaveCount(8); + } - [Fact] - public async Task AppendBlockChildren() - { - // Arrange - string blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; - var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); + [Fact] + public async Task AppendBlockChildren() + { + // Arrange + var blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; + var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var parameters = new BlocksAppendChildrenParameters() + var parameters = new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List + new HeadingTwoBlock { - new HeadingTwoBlock() + Heading_2 = new HeadingTwoBlock.Info { - Heading_2 = new HeadingTwoBlock.Info + RichText = new List { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Lacinato kale" - } - } - } - } + new RichTextText {Text = new Text {Content = "Lacinato kale"}}, + }, }, - new ParagraphBlock() + }, + new ParagraphBlock + { + Paragraph = new ParagraphBlock.Info { - Paragraph = new ParagraphBlock.Info + RichText = new List { - RichText = new List + new RichTextText { - new RichTextText + Text = new Text { - Text = new Text + Content + = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", + Link = new Link { - Content = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", - Link = new Link - { - Url = "https://en.wikipedia.org/wiki/Lacinato_kale" - } - } - } - } - } - } - } - }; - - // Act - var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); - - // Assert - var blocks = blocksResult.Results; - blocks.Should().SatisfyRespectively( - block => - { - block.Type.Should().Be(BlockType.Heading_2); - var headingBlock = (HeadingTwoBlock)block; - var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); - text.Text.Content.Should().Be("Lacinato kale"); + Url + = "https://en.wikipedia.org/wiki/Lacinato_kale", + }, + }, + }, + }, + }, }, - block => - { - block.Type.Should().Be(BlockType.Paragraph); - var paragraphBlock = (ParagraphBlock)block; - var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); - text.Text.Content.Should().Be("Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); - text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); - } - ); - } + }, + }; - [Fact] - public async Task RetrieveAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); + // Act + var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); + + // Assert + var blocks = blocksResult.Results; + + blocks.Should().SatisfyRespectively( + block => + { + block.Type.Should().Be(BlockType.Heading_2); + var headingBlock = (HeadingTwoBlock)block; + var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); + text.Text.Content.Should().Be("Lacinato kale"); + }, + block => + { + block.Type.Should().Be(BlockType.Paragraph); + var paragraphBlock = (ParagraphBlock)block; + var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); + + text.Text.Content.Should().Be( + "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); + + text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); + } + ); + } + + [Fact] + public async Task RetrieveAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var block = await _client.RetrieveAsync(blockId); + var block = await _client.RetrieveAsync(blockId); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); + } - [Fact] - public async Task UpdateAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Update(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); + [Fact] + public async Task UpdateAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Update(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateBlock = new ToDoUpdateBlock + var updateBlock = new ToDoUpdateBlock + { + ToDo = new ToDoUpdateBlock.Info { - ToDo = new ToDoUpdateBlock.Info + RichText = new List { - RichText = new List() - { - new RichTextTextInput - { - Text = new Text - { - Content = "Lacinato kale" - }, - } - }, - IsChecked = true - } - }; + new RichTextTextInput {Text = new Text {Content = "Lacinato kale"}}, + }, + IsChecked = true, + }, + }; - var block = await _client.UpdateAsync(blockId, updateBlock); + var block = await _client.UpdateAsync(blockId, updateBlock); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index cc4c2396..e78d0e68 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -7,483 +7,437 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class DatabasesClientTests : ApiTestBase { - public class DatabasesClientTests : ApiTestBase + private readonly IDatabasesClient _client; + private readonly IPagesClient _pagesClient; + + public DatabasesClientTests() { - private readonly IDatabasesClient _client; - private readonly IPagesClient _pagesClient; - public DatabasesClientTests() - { - _client = new DatabasesClient(new RestClient(ClientOptions)); - _pagesClient = new PagesClient(new RestClient(ClientOptions)); - } + _client = new DatabasesClient(new RestClient(ClientOptions)); + _pagesClient = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task QueryAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); + [Fact] + public async Task QueryAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); - } + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); } + } - [Fact] - public async Task RetrieveDatabaseAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); + [Fact] + public async Task RetrieveDatabaseAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - HelperAsserts.IPageIconAsserts(database.Icon); - HelperAsserts.FileObjectAsserts(database.Cover); + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } - [Fact] - public async Task DatabasePropertyObjectContainNameProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + HelperAsserts.IPageIconAsserts(database.Icon); + HelperAsserts.FileObjectAsserts(database.Cover); + } - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task DatabasePropertyObjectContainNameProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } + } - [Fact] - public async Task DatabasePropertyObjectContainRelationProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); + [Fact] + public async Task DatabasePropertyObjectContainRelationProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( - new RelationProperty() + database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( + new RelationProperty + { + Id = "zDGa", + Name = "Property", + Relation = new DualPropertyRelation + { + DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", + DualProperty = new DualPropertyRelation.Data { - Id = "zDGa", - Name = "Property", - Relation = new DualPropertyRelation() - { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - DualProperty = new DualPropertyRelation.Data - { - SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{" - } - } - }); - } + SyncedPropertyName = "Related to sample table (Property)", + SyncedPropertyId = "VQ}{", + }, + }, + }); + } - [Fact] - public async Task DatabasePropertyObjectContainParentProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); + [Fact] + public async Task DatabasePropertyObjectContainParentProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); + } - [Fact] - public async Task CreateDatabaseAsync() - { - var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); + [Fact] + public async Task CreateDatabaseAsync() + { + var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; - createDatabaseParameters.Title = new List + createDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitlePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, { - new RichTextTextInput + "Food group", + new SelectPropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetable"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DatePropertySchema {Date = new Dictionary()}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitlePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, - { "Food group", new SelectPropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOptionSchema - { - Color = Color.Green, - Name = "🥦Vegetable" - }, - new SelectOptionSchema - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOptionSchema - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetable"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); + } - [Fact] - public async Task UpdateDatabaseAsync() - { - var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; - var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); + [Fact] + public async Task UpdateDatabaseAsync() + { + var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; + var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateDatabaseParameters = new DatabasesUpdateParameters(); + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List New", Link = null}}, + }; - updateDatabaseParameters.Title = new List + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberUpdatePropertySchema {Number = new Number {Format = "yen"}}}, { - new RichTextTextInput + "Food group", + new SelectUpdatePropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List New", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetables"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, - { "Food group", new SelectUpdatePropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOption - { - Color = Color.Green, - Name = "🥦Vegetables" - }, - new SelectOption - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOption - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); - var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + database.Title.Should().ContainSingle(); - database.Title.Should().ContainSingle(); - database.Title.Should().SatisfyRespectively( - title => - { - title.Should().BeAssignableTo(); - ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); - } - ); + database.Title.Should().SatisfyRespectively( + title => + { + title.Should().BeAssignableTo(); + ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); + } + ); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var price = (NumberProperty)database.Properties["Price"]; - price.Number.Format.Should().Be("yen"); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetables"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); - [Fact] - public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() - { - var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + var price = (NumberProperty)database.Properties["Price"]; + price.Number.Format.Should().Be("yen"); + } - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() + { + var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + + var jsonData + = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; - createDatabaseParameters.Title = new List + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; + + createDatabaseParameters.Properties = new Dictionary + { { - new RichTextTextInput + "Cost of next trip", + new FormulaPropertySchema { - Text = new Text - { - Content = "Grocery List", - Link = null - } + Formula = new Formula {Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))"}, } - }; + }, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(2); - database.Properties.Should().HaveCount(2); + var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; + formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); + } - var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; - formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); - } + [Fact] + public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() + { + var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - [Fact] - public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() - { - var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); + var jsonData + = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) + Server.Given(CreateGetRequestBuilder( + ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) .RespondWith( Response.Create() - .WithStatusCode(200) - .WithBody("{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") + .WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") ); - var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["FormulaProp"].Id - }); + var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id}); - //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; - formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); - formulaPropertyValue.Formula.Date.End.Should().BeNull(); - } + //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; + formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); + formulaPropertyValue.Formula.Date.End.Should().BeNull(); } } } diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 5b4650a5..b31a6530 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -4,131 +4,138 @@ using Notion.Client; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SerializerSettingsSource : RestClient +{ + public SerializerSettingsSource(ClientOptions options) : base(options) + { + } + + public JsonSerializerSettings GetSerializerSettings() + { + return defaultSerializerSettings; + } +} + +public class FilterTests { - public class SerializerSettingsSource : RestClient + private readonly SerializerSettingsSource _settingsSource = new(new ClientOptions()); + + private string SerializeFilter(Filter filter) + { + return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); + } + + [Fact] + public void CompoundFilterTest() + { + var selectFilter = new SelectFilter("A select", "Option"); + var relationFilter = new RelationFilter("Link", "subtask#1"); + var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); + + var filterGroup = new List {relationFilter, selectFilter}; + + var complexFiler = new CompoundFilter( + and: new List {dateFilter, new CompoundFilter(filterGroup)} + ); + + Assert.Equal( + "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," + + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + + "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", + SerializeFilter(complexFiler) + ); + } + + [Fact] + public void CheckboxFilterTest() + { + var filter = new CheckboxFilter("Property name", false); + + Assert.Equal( + "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void DateFilterTest() { - public SerializerSettingsSource(ClientOptions options) : base(options) - { + var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - } + Assert.Equal( + "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void FilesFilterTest() + { + var filter = new FilesFilter("Attachments", isNotEmpty: false); + + Assert.Equal( + "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", + SerializeFilter(filter) + ); + } - public JsonSerializerSettings GetSerializerSettings() - { - return defaultSerializerSettings; - } + [Fact] + public void FormulaFilterTest() + { + var filter = new FormulaFilter( + "Some", + number: new NumberFilter.Condition(isEmpty: true) + ); + + Assert.Equal( + "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", + SerializeFilter(filter) + ); + } + [Fact] + public void MultiSelectFilterTest() + { + var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); + + Assert.Equal( + "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", + SerializeFilter(filter) + ); } - public class FilterTests + + [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] + public void NumberFilterTest() { - private readonly SerializerSettingsSource _settingsSource = new SerializerSettingsSource(new ClientOptions()); - - private string SerializeFilter(Filter filter) - { - return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); - } - - [Fact] - public void CompoundFilterTest() - { - var selectFilter = new SelectFilter("A select", equal: "Option"); - var relationFilter = new RelationFilter("Link", contains: "subtask#1"); - var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); - - var filterGroup = new List { relationFilter, selectFilter }; - var complexFiler = new CompoundFilter( - and: new List { dateFilter, new CompoundFilter(or: filterGroup) } - ); - - Assert.Equal( - "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," - + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + - "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", - SerializeFilter(complexFiler) - ); - } - - [Fact] - public void CheckboxFilterTest() - { - var filter = new CheckboxFilter("Property name", equal: false); - Assert.Equal( - "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void DateFilterTest() - { - var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - Assert.Equal( - "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FilesFilterTest() - { - var filter = new FilesFilter("Attachments", isNotEmpty: false); - Assert.Equal( - "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FormulaFilterTest() - { - var filter = new FormulaFilter( - "Some", - number: new NumberFilter.Condition(isEmpty: true) - ); - Assert.Equal( - "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void MultiSelectFilterTest() - { - var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); - Assert.Equal( - "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", - SerializeFilter(filter) - ); - } - - [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] - public void NumberFilterTest() - { - var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); - Assert.Equal( - "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void PeopleFilter() - { - var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); - Assert.Equal( - "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void RichTextFilterTest() - { - var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); - Assert.Equal( - "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", - SerializeFilter(filter) - ); - } + var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); + + Assert.Equal( + "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void PeopleFilter() + { + var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); + + Assert.Equal( + "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void RichTextFilterTest() + { + var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); + + Assert.Equal( + "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", + SerializeFilter(filter) + ); } -} +} diff --git a/Test/Notion.UnitTests/HelperAsserts.cs b/Test/Notion.UnitTests/HelperAsserts.cs index 1b07fbf5..3b1a29ec 100644 --- a/Test/Notion.UnitTests/HelperAsserts.cs +++ b/Test/Notion.UnitTests/HelperAsserts.cs @@ -1,41 +1,44 @@ using FluentAssertions; using Notion.Client; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public static class HelperAsserts { - public static class HelperAsserts + public static void IPageIconAsserts(IPageIcon icon) { - public static void IPageIconAsserts(IPageIcon icon) + icon.Should().NotBeNull(); + + switch (icon) { - icon.Should().NotBeNull(); - - switch (icon) - { - case EmojiObject emoji: - emoji.Emoji.Should().NotBeNull(); - break; - case FileObject fileObject: - FileObjectAsserts(fileObject); - break; - } + case EmojiObject emoji: + emoji.Emoji.Should().NotBeNull(); + + break; + case FileObject fileObject: + FileObjectAsserts(fileObject); + + break; } + } - public static void FileObjectAsserts(FileObject fileObject) + public static void FileObjectAsserts(FileObject fileObject) + { + fileObject.Should().NotBeNull(); + + switch (fileObject) { - fileObject.Should().NotBeNull(); - - switch (fileObject) - { - case UploadedFile uploadedFile: - uploadedFile.File.Should().NotBeNull(); - uploadedFile.File.Url.Should().NotBeNull(); - uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); - break; - case ExternalFile externalFile: - externalFile.External.Should().NotBeNull(); - externalFile.External.Url.Should().NotBeNull(); - break; - } + case UploadedFile uploadedFile: + uploadedFile.File.Should().NotBeNull(); + uploadedFile.File.Url.Should().NotBeNull(); + uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); + + break; + case ExternalFile externalFile: + externalFile.External.Should().NotBeNull(); + externalFile.External.Url.Should().NotBeNull(); + + break; } } } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 13598b0f..3f6710a5 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -8,264 +8,246 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PagesClientTests : ApiTestBase { - public class PagesClientTests : ApiTestBase - { - private readonly IPagesClient _client; + private readonly IPagesClient _client; - public PagesClientTests() - { - _client = new PagesClient(new RestClient(ClientOptions)); - } + public PagesClientTests() + { + _client = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task RetrieveAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - page.Id.Should().Be(pageId); - page.Parent.Type.Should().Be(ParentType.DatabaseId); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); - page.IsArchived.Should().BeFalse(); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + page.Id.Should().Be(pageId); + page.Parent.Type.Should().Be(ParentType.DatabaseId); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); + page.IsArchived.Should().BeFalse(); + } - [Fact] - public async Task CreateAsync() - { - var path = ApiEndpoints.PagesApiUrls.Create(); + [Fact] + public async Task CreateAsync() + { + var path = ApiEndpoints.PagesApiUrls.Create(); - var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589" - }).AddProperty("Name", new TitlePropertyValue() - { - Title = new List() + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"}).AddProperty("Name", + new TitlePropertyValue { - new RichTextText() - { - Text = new Text - { - Content = "Test" - } - } - } - }).Build(); - - var page = await _client.CreateAsync(pagesCreateParameters); - - page.Id.Should().NotBeNullOrEmpty(); - page.Url.Should().NotBeNullOrEmpty(); - page.Properties.Should().HaveCount(1); - page.Properties.First().Key.Should().Be("Name"); - page.IsArchived.Should().BeFalse(); - page.Parent.Should().NotBeNull(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); - } - - [Fact] - public async Task UpdatePropertiesAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + Title = new List {new RichTextText {Text = new Text {Content = "Test"}}}, + }).Build(); + + var page = await _client.CreateAsync(pagesCreateParameters); + + page.Id.Should().NotBeNullOrEmpty(); + page.Url.Should().NotBeNullOrEmpty(); + page.Properties.Should().HaveCount(1); + page.Properties.First().Key.Should().Be("Name"); + page.IsArchived.Should().BeFalse(); + page.Parent.Should().NotBeNull(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); + } - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + [Fact] + public async Task UpdatePropertiesAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var updatedProperties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - }; + var updatedProperties = new Dictionary + { + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }; - var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); + var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); - page.Id.Should().Be(pageId); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task PageObjectShouldHaveUrlProperty() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task PageObjectShouldHaveUrlProperty() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + } - [Fact] - public async Task UpdatePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + [Fact] + public async Task UpdatePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Properties = new Dictionary { - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task ArchivePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; + [Fact] + public async Task ArchivePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Archived = true, + Properties = new Dictionary { - Archived = true, - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeTrue(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeTrue(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() - { - Func act = async () => await _client.CreateAsync(null); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() + { + Func act = async () => await _client.CreateAsync(null); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() - { - var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() + { + var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + { + var pagesCreateParameters = new PagesCreateParameters { - var pagesCreateParameters = new PagesCreateParameters - { - Parent = new ParentPageInput() - { - PageId = "3c357473-a281-49a4-88c0-10d2b245a589", - }, - Properties = null - }; + Parent = new ParentPageInput {PageId = "3c357473-a281-49a4-88c0-10d2b245a589"}, Properties = null, + }; - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); } } diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index d09e4a87..c8196f15 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -1,67 +1,65 @@ using System; -using FluentAssertions; using Notion.Client; using Notion.Client.Extensions; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PropertyTests { - public class PropertyTests + [Theory] + [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] + [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [InlineData(typeof(DateProperty), PropertyType.Date)] + [InlineData(typeof(EmailProperty), PropertyType.Email)] + [InlineData(typeof(FilesProperty), PropertyType.Files)] + [InlineData(typeof(FormulaProperty), PropertyType.Formula)] + [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [InlineData(typeof(NumberProperty), PropertyType.Number)] + [InlineData(typeof(PeopleProperty), PropertyType.People)] + [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [InlineData(typeof(RelationProperty), PropertyType.Relation)] + [InlineData(typeof(RichTextProperty), PropertyType.RichText)] + [InlineData(typeof(RollupProperty), PropertyType.Rollup)] + [InlineData(typeof(SelectProperty), PropertyType.Select)] + [InlineData(typeof(TitleProperty), PropertyType.Title)] + [InlineData(typeof(UrlProperty), PropertyType.Url)] + public void TestPropertyType(Type type, PropertyType expectedPropertyType) { - [Theory] - [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] - [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [InlineData(typeof(DateProperty), PropertyType.Date)] - [InlineData(typeof(EmailProperty), PropertyType.Email)] - [InlineData(typeof(FilesProperty), PropertyType.Files)] - [InlineData(typeof(FormulaProperty), PropertyType.Formula)] - [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [InlineData(typeof(NumberProperty), PropertyType.Number)] - [InlineData(typeof(PeopleProperty), PropertyType.People)] - [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [InlineData(typeof(RelationProperty), PropertyType.Relation)] - [InlineData(typeof(RichTextProperty), PropertyType.RichText)] - [InlineData(typeof(RollupProperty), PropertyType.Rollup)] - [InlineData(typeof(SelectProperty), PropertyType.Select)] - [InlineData(typeof(TitleProperty), PropertyType.Title)] - [InlineData(typeof(UrlProperty), PropertyType.Url)] - public void TestPropertyType(Type type, PropertyType expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type; + var actualPropertyType = typeInstance.Type; - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); + } - [Theory] - [InlineData(typeof(CheckboxProperty), "checkbox")] - [InlineData(typeof(CreatedByProperty), "created_by")] - [InlineData(typeof(CreatedTimeProperty), "created_time")] - [InlineData(typeof(DateProperty), "date")] - [InlineData(typeof(EmailProperty), "email")] - [InlineData(typeof(FilesProperty), "files")] - [InlineData(typeof(FormulaProperty), "formula")] - [InlineData(typeof(LastEditedByProperty), "last_edited_by")] - [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] - [InlineData(typeof(NumberProperty), "number")] - [InlineData(typeof(PeopleProperty), "people")] - [InlineData(typeof(PhoneNumberProperty), "phone_number")] - [InlineData(typeof(RelationProperty), "relation")] - [InlineData(typeof(RichTextProperty), "rich_text")] - [InlineData(typeof(RollupProperty), "rollup")] - [InlineData(typeof(SelectProperty), "select")] - [InlineData(typeof(TitleProperty), "title")] - [InlineData(typeof(UrlProperty), "url")] - public void TestPropertyTypeText(Type type, string expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + [Theory] + [InlineData(typeof(CheckboxProperty), "checkbox")] + [InlineData(typeof(CreatedByProperty), "created_by")] + [InlineData(typeof(CreatedTimeProperty), "created_time")] + [InlineData(typeof(DateProperty), "date")] + [InlineData(typeof(EmailProperty), "email")] + [InlineData(typeof(FilesProperty), "files")] + [InlineData(typeof(FormulaProperty), "formula")] + [InlineData(typeof(LastEditedByProperty), "last_edited_by")] + [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] + [InlineData(typeof(NumberProperty), "number")] + [InlineData(typeof(PeopleProperty), "people")] + [InlineData(typeof(PhoneNumberProperty), "phone_number")] + [InlineData(typeof(RelationProperty), "relation")] + [InlineData(typeof(RichTextProperty), "rich_text")] + [InlineData(typeof(RollupProperty), "rollup")] + [InlineData(typeof(SelectProperty), "select")] + [InlineData(typeof(TitleProperty), "title")] + [InlineData(typeof(UrlProperty), "url")] + public void TestPropertyTypeText(Type type, string expectedPropertyType) + { + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); + var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); } } diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index aa506572..3ca7dd27 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -1,71 +1,65 @@ -using System; -using System.IO; +using System.IO; using System.Threading.Tasks; using FluentAssertions; using Notion.Client; using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SearchClientTest : ApiTestBase { - public class SearchClientTest : ApiTestBase - { - private readonly SearchClient _client; + private readonly SearchClient _client; - public SearchClientTest() - { - _client = new SearchClient(new RestClient(ClientOptions)); - } + public SearchClientTest() + { + _client = new SearchClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task Search() - { - // Arrange - var path = ApiEndpoints.SearchApiUrls.Search(); - var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); + [Fact] + public async Task Search() + { + // Arrange + var path = ApiEndpoints.SearchApiUrls.Search(); + var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - SearchParameters searchParameters = new SearchParameters() - { - Query = "External tasks", - Sort = new SearchSort - { - Direction = SearchDirection.Ascending, - Timestamp = "last_edited_time" - } - }; + var searchParameters = new SearchParameters + { + Query = "External tasks", + Sort = new SearchSort {Direction = SearchDirection.Ascending, Timestamp = "last_edited_time"}, + }; - // Act - var searchResult = await _client.SearchAsync(searchParameters); + // Act + var searchResult = await _client.SearchAsync(searchParameters); - // Assert - var results = searchResult.Results; + // Assert + var results = searchResult.Results; - results.Should().SatisfyRespectively( - obj => - { - obj.Object.Should().Be(ObjectType.Database); + results.Should().SatisfyRespectively( + obj => + { + obj.Object.Should().Be(ObjectType.Database); - var database = (Database)obj; - database.Properties.Should().HaveCount(2); - }, - obj => - { - obj.Object.Should().Be(ObjectType.Page); + var database = (Database)obj; + database.Properties.Should().HaveCount(2); + }, + obj => + { + obj.Object.Should().Be(ObjectType.Page); - var page = (Page)obj; - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(1); - page.Parent.Should().BeAssignableTo(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); - } - ); - } + var page = (Page)obj; + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(1); + page.Parent.Should().BeAssignableTo(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); + } + ); } } diff --git a/Test/Notion.UnitTests/UserClientTest.cs b/Test/Notion.UnitTests/UserClientTest.cs index d9b27984..6e93decc 100644 --- a/Test/Notion.UnitTests/UserClientTest.cs +++ b/Test/Notion.UnitTests/UserClientTest.cs @@ -5,145 +5,144 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class UserClientTest : ApiTestBase { - public class UserClientTest : ApiTestBase + private readonly IUsersClient _client; + + public UserClientTest() + { + _client = new UsersClient(new RestClient(ClientOptions)); + } + + [Fact] + public async Task ListUsers() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); + var path = ApiEndpoints.UsersApiUrls.List(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) + ); + + // Act + var users = await _client.ListAsync(); + + // Assert + users.Results.Should().SatisfyRespectively( + user => + { + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + }, + user => + { + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + } + ); + } + + [Fact] + public async Task RetrieveUser() { - private readonly IUsersClient _client; - - public UserClientTest() - { - _client = new UsersClient(new RestClient(ClientOptions)); - } - - [Fact] - public async Task ListUsers() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); - var path = ApiEndpoints.UsersApiUrls.List(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); + var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; + var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var users = await _client.ListAsync(); - - // Assert - users.Results.Should().SatisfyRespectively( - user => - { - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - }, - user => - { - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - } + // Act + var user = await _client.RetrieveAsync(userId); + + // Assert + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + } + + [Fact] + public async Task RetrieveTokenUser_WorkspaceInternalToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) ); - } - - [Fact] - public async Task RetrieveUser() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); - var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; - var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; + owner.Workspace.Should().BeTrue(); + } + + [Fact] + public async Task RetrieveTokenUser_UserLevelToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var user = await _client.RetrieveAsync(userId); - - // Assert - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - } - - [Fact] - public async Task RetrieveTokenUser_WorkspaceInternalToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; - owner.Workspace.Should().BeTrue(); - } - - [Fact] - public async Task RetrieveTokenUser_UserLevelToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); - user.Name.Should().Be("pied piper"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (UserOwner)user.Bot.Owner; - owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); - owner.User.Name.Should().Be("christine makenotion"); - owner.User.AvatarUrl.Should().BeNull(); - owner.User.Type.Should().Be("person"); - owner.User.Person.Email.Should().Be("christine@makenotion.com"); - owner.User.Bot.Should().BeNull(); - } + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); + user.Name.Should().Be("pied piper"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (UserOwner)user.Bot.Owner; + owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); + owner.User.Name.Should().Be("christine makenotion"); + owner.User.AvatarUrl.Should().BeNull(); + owner.User.Type.Should().Be("person"); + owner.User.Person.Email.Should().Be("christine@makenotion.com"); + owner.User.Bot.Should().BeNull(); } } From e740f751c8c0a311ddf968ff72f9517551d17a9c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:11:39 +0530 Subject: [PATCH 7/7] =?UTF-8?q?Update=20editor=20config=20and=20fix=20lint?= =?UTF-8?q?er=20issues=20=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 110 ++++-------- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 4 +- .../Create/Request/CreateCommentParameters.cs | 12 +- .../Api/Comments/Retrieve/CommentsClient.cs | 4 +- .../Api/Databases/RequestParams/Direction.cs | 2 +- .../Api/Databases/RequestParams/Timestamp.cs | 2 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 7 +- .../PagesCreateParametersBuilder.cs | 4 +- .../Api/Search/Parameters/SearchDirection.cs | 2 +- .../Api/Search/Parameters/SearchObjectType.cs | 2 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 2 +- Src/Notion.Client/Models/Blocks/Color.cs | 2 +- .../Database/Properties/PropertyType.cs | 2 +- .../RelationProperty/RelationType.cs | 2 +- .../Models/Database/RichText/RichTextType.cs | 2 +- Src/Notion.Client/Models/ObjectType.cs | 2 +- .../Models/Parents/ParentType.cs | 2 +- .../Models/PropertyValue/PropertyValueType.cs | 2 +- .../PropertyValue/StatusPropertyValue.cs | 2 +- Src/Notion.Client/NotionAPIErrorCode.cs | 2 +- Src/Notion.Client/RestClient/RestClient.cs | 11 +- Src/Notion.Client/http/QueryHelpers.cs | 2 +- .../CommentsClientTests.cs | 19 +- .../IBlocksClientTests.cs | 169 +++++++++--------- .../IPageClientTests.cs | 91 ++++++---- Test/Notion.UnitTests/ApiTestBase.cs | 9 +- Test/Notion.UnitTests/BlocksClientTests.cs | 28 +-- Test/Notion.UnitTests/DatabasesClientTests.cs | 129 +++++++++---- Test/Notion.UnitTests/FilterTests.cs | 12 +- Test/Notion.UnitTests/PagesClientTests.cs | 40 +++-- Test/Notion.UnitTests/SearchClientTest.cs | 6 +- 31 files changed, 392 insertions(+), 293 deletions(-) diff --git a/.editorconfig b/.editorconfig index 7e8f258c..76a523b0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,43 @@ root = true indent_style = space [*.cs] + +# ReSharper properties + +# Blank lines +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_before_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 + +# Baces +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_max_enum_members_on_line = 1 + +resharper_csharp_force_attribute_style=separate +resharper_csharp_method_or_operator_body=expression_body +resharper_csharp_max_enum_members_on_line=1 +resharper_csharp_place_attribute_on_same_line=false +resharper_csharp_wrap_object_and_collection_initializer_style=chop_always +resharper_csharp_use_heuristics_for_body_style=true + +resharper_csharp_max_initializer_elements_on_line=0 + # Microsoft .NET properties csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion csharp_style_var_elsewhere = true:suggestion @@ -181,79 +218,6 @@ dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion dotnet_style_predefined_type_for_member_access = true:suggestion dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion -# ReSharper properties -# resharper_arguments_anonymous_function = named -# resharper_arguments_literal = named -# resharper_arguments_named = named -# resharper_arguments_other = named -# resharper_arguments_string_literal = named -resharper_blank_lines_after_control_transfer_statements = 1 -resharper_blank_lines_after_multiline_statements = 1 -resharper_blank_lines_around_single_line_auto_property = 1 -resharper_blank_lines_around_single_line_local_method = 1 -resharper_blank_lines_around_single_line_property = 1 -resharper_blank_lines_before_block_statements = 1 -resharper_blank_lines_before_control_transfer_statements = 1 -resharper_blank_lines_before_multiline_statements = 1 -resharper_blank_lines_before_single_line_comment = 1 -resharper_braces_for_for = required -resharper_braces_for_foreach = required -resharper_braces_for_ifelse = required -resharper_braces_for_while = required -resharper_braces_redundant = false -resharper_case_block_braces = next_line_shifted_2 -resharper_csharp_blank_lines_around_single_line_invocable = 1 -resharper_csharp_keep_blank_lines_in_code = 1 -resharper_csharp_keep_blank_lines_in_declarations = 1 -resharper_csharp_wrap_after_declaration_lpar = true -resharper_csharp_wrap_extends_list_style = chop_if_long -resharper_csharp_wrap_parameters_style = chop_if_long -resharper_indent_nested_fixed_stmt = true -resharper_indent_nested_foreach_stmt = true -resharper_indent_nested_for_stmt = true -resharper_indent_nested_lock_stmt = true -resharper_indent_nested_usings_stmt = true -resharper_indent_nested_while_stmt = true -resharper_keep_existing_declaration_block_arrangement = true -resharper_keep_existing_declaration_parens_arrangement = false -resharper_keep_existing_embedded_block_arrangement = true -resharper_keep_existing_enum_arrangement = true -resharper_keep_existing_expr_member_arrangement = false -resharper_keep_existing_initializer_arrangement = false -resharper_local_function_body = expression_body -resharper_max_enum_members_on_line = 1 -resharper_max_formal_parameters_on_line = 4 -resharper_place_field_attribute_on_same_line = if_owner_is_single_line -resharper_space_within_single_line_array_initializer_braces = false -resharper_trailing_comma_in_multiline_lists = true -resharper_use_heuristics_for_body_style = false -resharper_use_indent_from_vs = false -resharper_wrap_before_eq = true -resharper_wrap_before_first_type_parameter_constraint = true - -# ReSharper inspection severities -resharper_arrange_accessor_owner_body_highlighting = none -resharper_arrange_local_function_body_highlighting = suggestion -resharper_arrange_namespace_body_highlighting = suggestion -resharper_arrange_redundant_parentheses_highlighting = hint -resharper_arrange_this_qualifier_highlighting = none -resharper_arrange_type_member_modifiers_highlighting = hint -resharper_arrange_type_modifiers_highlighting = hint -resharper_built_in_type_reference_style_for_member_access_highlighting = suggestion -resharper_built_in_type_reference_style_highlighting = suggestion -resharper_inconsistent_naming_highlighting = suggestion -resharper_redundant_base_qualifier_highlighting = none -resharper_suggest_var_or_type_built_in_types_highlighting = suggestion -resharper_suggest_var_or_type_elsewhere_highlighting = suggestion -resharper_suggest_var_or_type_simple_types_highlighting = suggestion - -resharper_csharp_force_attribute_style=separate -resharper_csharp_method_or_operator_body=expression_body -resharper_csharp_max_enum_members_on_line=1 -resharper_csharp_place_attribute_on_same_line=false -resharper_csharp_wrap_object_and_collection_initializer_style=chop_always -resharper_csharp_use_heuristics_for_body_style=true - # Standard properties insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 8fbdcd26..1282a346 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -29,8 +29,8 @@ public async Task> RetrieveChildrenAsync( var queryParams = new Dictionary { - {"start_cursor", queryParameters?.StartCursor}, - {"page_size", queryParameters?.PageSize?.ToString()}, + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } }; return await _client.GetAsync>(url, queryParams); diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs index 3b676133..f9532726 100644 --- a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -33,14 +33,22 @@ public static CreateCommentParameters CreatePageComment( ParentPageInput parent, IEnumerable richText) { - return new CreateCommentParameters {Parent = parent, RichText = richText}; + return new CreateCommentParameters + { + Parent = parent, + RichText = richText + }; } public static CreateCommentParameters CreateDiscussionComment( string discussionId, IEnumerable richText) { - return new CreateCommentParameters {DiscussionId = discussionId, RichText = richText}; + return new CreateCommentParameters + { + DiscussionId = discussionId, + RichText = richText + }; } } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index b979086f..cb32978e 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -11,7 +11,9 @@ public async Task Retrieve(RetrieveCommentsParameters var queryParams = new Dictionary { - {"block_id", qp.BlockId}, {"start_cursor", qp.StartCursor}, {"page_size", qp.PageSize.ToString()}, + { "block_id", qp.BlockId }, + { "start_cursor", qp.StartCursor }, + { "page_size", qp.PageSize.ToString() } }; return await _client.GetAsync( diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index 76b87da3..c79d501d 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -11,6 +11,6 @@ public enum Direction Ascending, [EnumMember(Value = "descending")] - Descending, + Descending } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 4eb359d4..334b8c22 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -11,6 +11,6 @@ public enum Timestamp CreatedTime, [EnumMember(Value = "last_edited_time")] - LastEditedTime, + LastEditedTime } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index b71f924f..b4a3c58f 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -63,8 +63,8 @@ public async Task RetrievePagePropertyItem( var queryParams = new Dictionary { - {"start_cursor", queryParameters?.StartCursor}, - {"page_size", queryParameters?.PageSize?.ToString()}, + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } }; return await _client.GetAsync(url, queryParams); @@ -84,7 +84,8 @@ public async Task UpdatePropertiesAsync( IDictionary updatedProperties) { var url = PagesApiUrls.UpdateProperties(pageId); - var body = new UpdatePropertiesParameters {Properties = updatedProperties}; + + var body = new UpdatePropertiesParameters { Properties = updatedProperties }; return await _client.PatchAsync(url, body); } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index 7df2fe4c..6b263beb 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -16,7 +16,7 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder {parent = parent}; + return new PagesCreateParametersBuilder { parent = parent }; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) @@ -55,7 +55,7 @@ public PagesCreateParameters Build() Properties = properties, Children = children, Icon = icon, - Cover = cover, + Cover = cover }; } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index 0bde8d23..fdac0b59 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -8,6 +8,6 @@ public enum SearchDirection Ascending, [EnumMember(Value = "descending")] - Descending, + Descending } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 773ef95a..78a012df 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -8,6 +8,6 @@ public enum SearchObjectType Page, [EnumMember(Value = "database")] - Database, + Database } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index f15c3b37..8a2c626a 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -101,6 +101,6 @@ public enum BlockType LinkPreview, [EnumMember(Value = "unsupported")] - Unsupported, + Unsupported } } diff --git a/Src/Notion.Client/Models/Blocks/Color.cs b/Src/Notion.Client/Models/Blocks/Color.cs index b4682a7b..ec22b0dc 100644 --- a/Src/Notion.Client/Models/Blocks/Color.cs +++ b/Src/Notion.Client/Models/Blocks/Color.cs @@ -59,6 +59,6 @@ public enum Color PinkBackground, [EnumMember(Value = "red_background")] - RedBackground, + RedBackground } } diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index a67b8cd8..5ca4c7f8 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -65,6 +65,6 @@ public enum PropertyType LastEditedTime, [EnumMember(Value = "status")] - Status, + Status } } diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs index a0a58a47..89ce1c56 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -8,6 +8,6 @@ public enum RelationType Single, [EnumMember(Value = "dual_property")] - Dual, + Dual } } diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 58406612..59bc414f 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -14,6 +14,6 @@ public enum RichTextType Mention, [EnumMember(Value = "equation")] - Equation, + Equation } } diff --git a/Src/Notion.Client/Models/ObjectType.cs b/Src/Notion.Client/Models/ObjectType.cs index 21995840..4a9dc77d 100644 --- a/Src/Notion.Client/Models/ObjectType.cs +++ b/Src/Notion.Client/Models/ObjectType.cs @@ -17,6 +17,6 @@ public enum ObjectType User, [EnumMember(Value = "comment")] - Comment, + Comment } } diff --git a/Src/Notion.Client/Models/Parents/ParentType.cs b/Src/Notion.Client/Models/Parents/ParentType.cs index 96c2a00d..29126694 100644 --- a/Src/Notion.Client/Models/Parents/ParentType.cs +++ b/Src/Notion.Client/Models/Parents/ParentType.cs @@ -17,6 +17,6 @@ public enum ParentType Workspace, [EnumMember(Value = "block_id")] - BlockId, + BlockId } } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index 93a8d63e..f8fb0a30 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -68,6 +68,6 @@ public enum PropertyValueType LastEditedBy, [EnumMember(Value = "status")] - Status, + Status } } diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index f4a82e48..487b27c8 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -39,7 +39,7 @@ public enum Color Pink, [EnumMember(Value = "red")] - Red, + Red } public override PropertyValueType Type => PropertyValueType.Status; diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index f4cf699c..71e99d29 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -38,6 +38,6 @@ public enum NotionAPIErrorCode InternalServerError, [EnumMember(Value = "service_unavailable")] - ServiceUnavailable, + ServiceUnavailable } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index 5da38f61..23993086 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -19,7 +19,7 @@ public class RestClient : IRestClient protected readonly JsonSerializerSettings defaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; private HttpClient _httpClient; @@ -50,9 +50,11 @@ public async Task PostAsync( JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { - void AttachContent(HttpRequestMessage httpRequest) => + void AttachContent(HttpRequestMessage httpRequest) + { httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), Encoding.UTF8, "application/json"); + } var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, cancellationToken); @@ -96,7 +98,7 @@ private static ClientOptions MergeOptions(ClientOptions options) { AuthToken = options.AuthToken, BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION, + NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION }; } @@ -166,7 +168,8 @@ private HttpClient EnsureHttpClient() { if (_httpClient == null) { - var pipeline = new LoggingHandler {InnerHandler = new HttpClientHandler()}; + var pipeline = new LoggingHandler { InnerHandler = new HttpClientHandler() }; + _httpClient = new HttpClient(pipeline); _httpClient.BaseAddress = new Uri(_options.BaseUrl); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 86a2f0fb..243bfbcd 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -25,7 +25,7 @@ public static string AddQueryString(string uri, string name, string value) throw new ArgumentNullException(nameof(value)); } - return AddQueryString(uri, new[] {new KeyValuePair(name, value)}); + return AddQueryString(uri, new[] { new KeyValuePair(name, value) }); } public static string AddQueryString(string uri, IDictionary queryParams) diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 32d887eb..118a09d6 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -15,7 +15,7 @@ public class CommentsClientTests : IDisposable public CommentsClientTests() { - var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; _client = NotionClientFactory.Create(options); @@ -24,14 +24,14 @@ public CommentsClientTests() _page = _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = _pageParentId} + new ParentPageInput { PageId = _pageParentId } ).Build() ).Result; } public void Dispose() { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters {Archived = true}).Wait(); + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); } [Fact] @@ -39,8 +39,8 @@ public async Task ShouldCreatePageComment() { // Arrange var parameters = CreateCommentParameters.CreatePageComment( - new ParentPageInput {PageId = _page.Id}, - new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + new ParentPageInput { PageId = _page.Id }, + new List { new RichTextTextInput { Text = new Text { Content = "This is a comment" } } } ); // Act @@ -67,8 +67,11 @@ public async Task ShouldCreateADiscussionComment() // Arrange var comment = await _client.Comments.Create( CreateCommentParameters.CreatePageComment( - new ParentPageInput {PageId = _page.Id}, - new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + new ParentPageInput { PageId = _page.Id }, + new List + { + new RichTextTextInput { Text = new Text { Content = "This is a comment" } } + } ) ); @@ -78,7 +81,7 @@ public async Task ShouldCreateADiscussionComment() comment.DiscussionId, new List { - new RichTextTextInput {Text = new Text {Content = "This is a sub comment"}}, + new RichTextTextInput { Text = new Text { Content = "This is a sub comment" } } } ) ); diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 1aaa2726..6fc53999 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -14,7 +14,7 @@ public class IBlocksClientTests public IBlocksClientTests() { - var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; _client = NotionClientFactory.Create(options); } @@ -26,7 +26,7 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); @@ -36,27 +36,27 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() { Children = new List { - new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}, - new DividerBlock {Divider = new DividerBlock.Data()}, - new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() }, + new DividerBlock { Divider = new DividerBlock.Data() }, + new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, new CalloutBlock { Callout = new CalloutBlock.Info { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test"}}, - }, - }, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + } + } + } } ); blocks.Results.Should().HaveCount(4); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -66,7 +66,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); @@ -74,7 +74,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() page.Id, new BlocksAppendChildrenParameters { - Children = new List {new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}}, + Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } } } ); @@ -85,7 +85,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() blocks.Results.Should().HaveCount(1); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -95,7 +95,7 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); @@ -105,16 +105,16 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() { Children = new List { - new DividerBlock {Divider = new DividerBlock.Data()}, - new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, - }, + new DividerBlock { Divider = new DividerBlock.Data() }, + new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() } + } } ); blocks.Results.Should().HaveCount(2); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Theory] @@ -125,13 +125,13 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); var blocks = await _client.Blocks.AppendChildrenAsync( page.Id, - new BlocksAppendChildrenParameters {Children = new List {block}} + new BlocksAppendChildrenParameters { Children = new List { block } } ); var blockId = blocks.Results.First().Id; @@ -145,7 +145,7 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat assert.Invoke(updatedBlock); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } private static IEnumerable BlockData() @@ -161,9 +161,9 @@ private static IEnumerable BlockData() Url = "https://developers.notion.com/reference/rich-text", Caption = new List { - new RichTextTextInput {Text = new Text {Content = "Notion API"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Notion API" } } + } + } }, new BookmarkUpdateBlock { @@ -172,35 +172,35 @@ private static IEnumerable BlockData() Url = "https://github.com/notion-dotnet/notion-sdk-net", Caption = new List { - new RichTextTextInput {Text = new Text {Content = "Github"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Github" } } + } + } }, new Action(block => { var updatedBlock = (BookmarkBlock)block; Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); - }), + }) }, new object[] { - new EquationBlock {Equation = new EquationBlock.Info {Expression = "e=mc^3"}}, - new EquationUpdateBlock {Equation = new EquationUpdateBlock.Info {Expression = "e=mc^2"}}, + new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } }, + new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } }, new Action(block => { var updatedBlock = (EquationBlock)block; Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); - }), + }) }, new object[] { - new DividerBlock {Divider = new DividerBlock.Data()}, new DividerUpdateBlock(), new Action( + new DividerBlock { Divider = new DividerBlock.Data() }, new DividerUpdateBlock(), new Action( block => { Assert.NotNull(block); Assert.IsType(block); - }), + }) }, new object[] { @@ -210,9 +210,9 @@ private static IEnumerable BlockData() { External = new ExternalFile.Info { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", - }, - }, + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" + } + } }, new AudioUpdateBlock { @@ -220,9 +220,9 @@ private static IEnumerable BlockData() { External = new ExternalFileInput.Data { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", - }, - }, + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" + } + } }, new Action(block => { @@ -231,16 +231,16 @@ private static IEnumerable BlockData() block.Should().BeOfType().Subject .Audio.Should().BeOfType().Subject .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); - }), + }) }, new object[] { - new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, new TableOfContentsUpdateBlock(), new Action(block => { Assert.NotNull(block); Assert.IsType(block); - }), + }) }, new object[] { @@ -250,9 +250,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + } }, new CalloutUpdateBlock { @@ -260,9 +260,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test 2"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test 2" } } + } + } }, new Action(block => { @@ -270,7 +270,7 @@ private static IEnumerable BlockData() var calloutBlock = Assert.IsType(block); Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); - }), + }) }, new object[] { @@ -280,9 +280,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + } }, new QuoteUpdateBlock { @@ -290,9 +290,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test 2"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test 2" } } + } + } }, new Action(block => { @@ -300,7 +300,7 @@ private static IEnumerable BlockData() var quoteBlock = Assert.IsType(block); Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); - }), + }) }, new object[] { @@ -310,9 +310,9 @@ private static IEnumerable BlockData() { External = new ExternalFile.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", - }, - }, + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + } }, new ImageUpdateBlock { @@ -321,9 +321,9 @@ private static IEnumerable BlockData() External = new ExternalFileInput.Data { Url - = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", - }, - }, + = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + } + } }, new Action(block => { @@ -333,7 +333,7 @@ private static IEnumerable BlockData() Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); - }), + }) }, new object[] { @@ -341,15 +341,15 @@ private static IEnumerable BlockData() { Embed = new EmbedBlock.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", - }, + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } }, new EmbedUpdateBlock { Embed = new EmbedUpdateBlock.Info { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", - }, + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + } }, new Action(block => { @@ -358,7 +358,7 @@ private static IEnumerable BlockData() Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); - }), + }) }, new object[] { @@ -368,7 +368,7 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextText {Text = new Text {Content = "Test Template"}}, + new RichTextText { Text = new Text { Content = "Test Template" } } }, Children = new List { @@ -377,11 +377,11 @@ private static IEnumerable BlockData() Embed = new EmbedBlock.Info { Url - = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", - }, - }, - }, - }, + = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + } + } + } }, new TemplateUpdateBlock { @@ -389,9 +389,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test Template 2"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test Template 2" } } + } + } }, new Action(block => { @@ -403,7 +403,7 @@ private static IEnumerable BlockData() Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); - }), + }) }, new object[] { @@ -411,12 +411,13 @@ private static IEnumerable BlockData() { LinkToPage = new PageParent { - Type = ParentType.PageId, PageId = "533578e3edf14c0a91a9da6b09bac3ee", - }, + Type = ParentType.PageId, + PageId = "533578e3edf14c0a91a9da6b09bac3ee" + } }, new LinkToPageUpdateBlock { - LinkToPage = new ParentPageInput {PageId = "3c357473a28149a488c010d2b245a589"}, + LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" } }, new Action(block => { @@ -428,8 +429,8 @@ private static IEnumerable BlockData() // TODO: Currently the api doesn't allow to update the link_to_page block type // This will change to updated ID once api start to support Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); - }), - }, + }) + } }; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index 24f11940..3b861f8e 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -15,7 +15,7 @@ public class IPageClientTests public IPageClientTests() { - var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; _client = NotionClientFactory.Create(options); _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; @@ -25,14 +25,14 @@ public IPageClientTests() public async Task CreateAsync_CreatesANewPage() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .Build(); @@ -48,28 +48,32 @@ public async Task CreateAsync_CreatesANewPage() var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Bug_unable_to_create_page_with_select_property() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .AddProperty("TestSelect", - new SelectPropertyValue {Select = new SelectOption {Id = "dfbfbe65-6f67-4876-9f75-699124334d06"}}) + new SelectPropertyValue { Select = new SelectOption { Id = "dfbfbe65-6f67-4876-9f75-699124334d06" } }) .Build(); var page = await _client.Pages.CreateAsync(pagesCreateParameters); @@ -84,25 +88,29 @@ public async Task Bug_unable_to_create_page_with_select_property() var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Test_RetrievePagePropertyItemAsync() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .Build(); @@ -110,7 +118,8 @@ public async Task Test_RetrievePagePropertyItemAsync() var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { - PageId = page.Id, PropertyId = "title", + PageId = page.Id, + PropertyId = "title" }); property.Should().NotBeNull(); @@ -129,7 +138,7 @@ public async Task Test_RetrievePagePropertyItemAsync() }); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -142,19 +151,19 @@ public async Task Test_UpdatePageProperty_with_date_as_null() updateDatabaseParameters.Properties = new Dictionary { - {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, - {"Test Date Property", new DateUpdatePropertySchema {Date = new Dictionary()}}, + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Test Date Property", new DateUpdatePropertySchema { Date = new Dictionary() } } }; var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .AddProperty(datePropertyName, new DatePropertyValue @@ -162,8 +171,8 @@ public async Task Test_UpdatePageProperty_with_date_as_null() Date = new Date { Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z"), - }, + End = Convert.ToDateTime("2025-12-08T12:00:00Z") + } }) .Build(); @@ -173,21 +182,25 @@ public async Task Test_UpdatePageProperty_with_date_as_null() var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { - PageId = page.Id, PropertyId = page.Properties[datePropertyName].Id, + PageId = page.Id, + PropertyId = page.Properties[datePropertyName].Id }); setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); // verify IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue {Date = null}); - var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Properties = testProps}); + testProps.Add(datePropertyName, new DatePropertyValue { Date = null }); + + var updatedPage = + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( new RetrievePropertyItemParameters { - PageId = page.Id, PropertyId = updatedPage.Properties[datePropertyName].Id, + PageId = page.Id, + PropertyId = updatedPage.Properties[datePropertyName].Id }); verifyDate?.Date.Should().BeNull(); @@ -201,14 +214,14 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() { // Arrange var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}).AddProperty("Name", + .Create(new DatabaseParentInput { DatabaseId = _databaseId }).AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, - }).AddProperty("Number", new NumberPropertyValue {Number = 200.00}).Build(); + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } + }).AddProperty("Number", new NumberPropertyValue { Number = 200.00 }).Build(); // Act var page = await _client.Pages.CreateAsync(pagesCreateParameters); @@ -219,15 +232,23 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() Assert.Equal(_databaseId, pageParent.DatabaseId); var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Name"].Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["Name"].Id + }); Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Number"].Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["Number"].Id + }); Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } } diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index ceb415d2..6c0f3a97 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -14,7 +14,7 @@ public class ApiTestBase : IDisposable protected static readonly JsonSerializerSettings JsonSerializerSettings = new() { Formatting = Formatting.Indented, - ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; protected readonly ClientOptions ClientOptions; @@ -23,7 +23,12 @@ public class ApiTestBase : IDisposable protected ApiTestBase() { Server = WireMockServer.Start(); - ClientOptions = new ClientOptions {BaseUrl = Server.Urls.First(), AuthToken = ""}; + + ClientOptions = new ClientOptions + { + BaseUrl = Server.Urls.First(), + AuthToken = "" + }; } public void Dispose() diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 8a568a13..97e54404 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -67,9 +67,9 @@ public async Task AppendBlockChildren() { RichText = new List { - new RichTextText {Text = new Text {Content = "Lacinato kale"}}, - }, - }, + new RichTextText { Text = new Text { Content = "Lacinato kale" } } + } + } }, new ParagraphBlock { @@ -86,14 +86,14 @@ public async Task AppendBlockChildren() Link = new Link { Url - = "https://en.wikipedia.org/wiki/Lacinato_kale", - }, - }, - }, - }, - }, - }, - }, + = "https://en.wikipedia.org/wiki/Lacinato_kale" + } + } + } + } + } + } + } }; // Act @@ -170,10 +170,10 @@ public async Task UpdateAsync() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Lacinato kale"}}, + new RichTextTextInput { Text = new Text { Content = "Lacinato kale" } } }, - IsChecked = true, - }, + IsChecked = true + } }; var block = await _client.UpdateAsync(blockId, updateBlock); diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index e78d0e68..d29677ea 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -47,10 +47,17 @@ public async Task QueryAsync() new NumberFilter( "Cost of next trip", greaterThanOrEqualTo: 2 - ), - }, + ) + } }, - Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + Sorts = new List + { + new() + { + Property = "Last ordered", + Direction = Direction.Ascending + } + } }; var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); @@ -142,9 +149,9 @@ public async Task DatabasePropertyObjectContainRelationProperty() DualProperty = new DualPropertyRelation.Data { SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{", - }, - }, + SyncedPropertyId = "VQ}{" + } + } }); } @@ -185,17 +192,24 @@ public async Task CreateDatabaseAsync() var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + createDatabaseParameters.Parent = new ParentPageInput { PageId = pageId }; createDatabaseParameters.Title = new List { - new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List", + Link = null + } + } }; createDatabaseParameters.Properties = new Dictionary { - {"Name", new TitlePropertySchema {Title = new Dictionary()}}, - {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + { "Name", new TitlePropertySchema { Title = new Dictionary() } }, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, { "Food group", new SelectPropertySchema @@ -204,14 +218,26 @@ public async Task CreateDatabaseAsync() { Options = new List { - new() {Color = Color.Green, Name = "🥦Vegetable"}, - new() {Color = Color.Red, Name = "🍎Fruit"}, - new() {Color = Color.Yellow, Name = "💪Protein"}, - }, - }, + new() + { + Color = Color.Green, + Name = "🥦Vegetable" + }, + new() + { + Color = Color.Red, + Name = "🍎Fruit" + }, + new() + { + Color = Color.Yellow, + Name = "💪Protein" + } + } + } } }, - {"Last ordered", new DatePropertySchema {Date = new Dictionary()}}, + { "Last ordered", new DatePropertySchema { Date = new Dictionary() } } }; var database = await _client.CreateAsync(createDatabaseParameters); @@ -262,13 +288,20 @@ public async Task UpdateDatabaseAsync() updateDatabaseParameters.Title = new List { - new RichTextTextInput {Text = new Text {Content = "Grocery List New", Link = null}}, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List New", + Link = null + } + } }; updateDatabaseParameters.Properties = new Dictionary { - {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, - {"Price", new NumberUpdatePropertySchema {Number = new Number {Format = "yen"}}}, + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, { "Food group", new SelectUpdatePropertySchema @@ -277,14 +310,26 @@ public async Task UpdateDatabaseAsync() { Options = new List { - new() {Color = Color.Green, Name = "🥦Vegetables"}, - new() {Color = Color.Red, Name = "🍎Fruit"}, - new() {Color = Color.Yellow, Name = "💪Protein"}, - }, - }, + new() + { + Color = Color.Green, + Name = "🥦Vegetables" + }, + new() + { + Color = Color.Red, + Name = "🍎Fruit" + }, + new() + { + Color = Color.Yellow, + Name = "💪Protein" + } + } + } } }, - {"Last ordered", new DateUpdatePropertySchema {Date = new Dictionary()}}, + { "Last ordered", new DateUpdatePropertySchema { Date = new Dictionary() } } }; var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); @@ -348,11 +393,18 @@ var jsonData var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + createDatabaseParameters.Parent = new ParentPageInput { PageId = pageId }; createDatabaseParameters.Title = new List { - new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List", + Link = null + } + } }; createDatabaseParameters.Properties = new Dictionary @@ -361,10 +413,10 @@ var jsonData "Cost of next trip", new FormulaPropertySchema { - Formula = new Formula {Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))"}, + Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } }; var database = await _client.CreateAsync(createDatabaseParameters); @@ -408,10 +460,17 @@ var jsonData new NumberFilter( "Cost of next trip", greaterThanOrEqualTo: 2 - ), - }, + ) + } }, - Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + Sorts = new List + { + new() + { + Property = "Last ordered", + Direction = Direction.Ascending + } + } }; var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); @@ -433,7 +492,11 @@ var jsonData ); var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["FormulaProp"].Id + }); //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index b31a6530..6fab8aaa 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -34,10 +34,18 @@ public void CompoundFilterTest() var relationFilter = new RelationFilter("Link", "subtask#1"); var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); - var filterGroup = new List {relationFilter, selectFilter}; + var filterGroup = new List + { + relationFilter, + selectFilter + }; var complexFiler = new CompoundFilter( - and: new List {dateFilter, new CompoundFilter(filterGroup)} + and: new List + { + dateFilter, + new CompoundFilter(filterGroup) + } ); Assert.Equal( diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 3f6710a5..87c32dae 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -57,11 +57,14 @@ public async Task CreateAsync() ); var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"}).AddProperty("Name", + .Create(new DatabaseParentInput { DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589" }) + .AddProperty( + "Name", new TitlePropertyValue { - Title = new List {new RichTextText {Text = new Text {Content = "Test"}}}, - }).Build(); + Title = new List { new RichTextText { Text = new Text { Content = "Test" } } } + } + ).Build(); var page = await _client.CreateAsync(pagesCreateParameters); @@ -98,7 +101,7 @@ public async Task UpdatePropertiesAsync() var updatedProperties = new Dictionary { - {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + { "In stock", new CheckboxPropertyValue { Checkbox = true } } }; var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); @@ -108,7 +111,11 @@ public async Task UpdatePropertiesAsync() var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); checkboxPropertyValue.Checkbox.Should().BeTrue(); } @@ -158,8 +165,8 @@ public async Task UpdatePageAsync() { Properties = new Dictionary { - {"In stock", new CheckboxPropertyValue {Checkbox = true}}, - }, + { "In stock", new CheckboxPropertyValue { Checkbox = true } } + } }; var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); @@ -170,7 +177,11 @@ public async Task UpdatePageAsync() var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); checkboxPropertyValue.Checkbox.Should().BeTrue(); } @@ -203,8 +214,8 @@ public async Task ArchivePageAsync() Archived = true, Properties = new Dictionary { - {"In stock", new CheckboxPropertyValue {Checkbox = true}}, - }, + { "In stock", new CheckboxPropertyValue { Checkbox = true } } + } }; var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); @@ -215,7 +226,11 @@ public async Task ArchivePageAsync() var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); checkboxPropertyValue.Checkbox.Should().BeTrue(); } @@ -243,7 +258,8 @@ public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Mi { var pagesCreateParameters = new PagesCreateParameters { - Parent = new ParentPageInput {PageId = "3c357473-a281-49a4-88c0-10d2b245a589"}, Properties = null, + Parent = new ParentPageInput { PageId = "3c357473-a281-49a4-88c0-10d2b245a589" }, + Properties = null }; Func act = async () => await _client.CreateAsync(pagesCreateParameters); diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index 3ca7dd27..63fb4a94 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -33,7 +33,11 @@ public async Task Search() var searchParameters = new SearchParameters { Query = "External tasks", - Sort = new SearchSort {Direction = SearchDirection.Ascending, Timestamp = "last_edited_time"}, + Sort = new SearchSort + { + Direction = SearchDirection.Ascending, + Timestamp = "last_edited_time" + } }; // Act