├── vostok.devtools ├── Directory.Build.props ├── launchpad-templates │ ├── library-ordinary │ │ ├── template │ │ │ ├── CHANGELOG.md │ │ │ ├── {{ProjectName}} │ │ │ │ ├── PublicAPI.Shipped.txt │ │ │ │ ├── PublicAPI.Unshipped.txt │ │ │ │ └── Properties │ │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── .editorconfig │ │ │ ├── module.yaml │ │ │ ├── .github │ │ │ │ └── workflows │ │ │ │ │ └── ci.yml │ │ │ ├── README.md │ │ │ └── {{ProjectName}}.Tests │ │ │ │ └── {{ProjectName}}.Tests.csproj │ │ ├── pack.cmd │ │ └── push-to-nuget.cmd │ ├── library-source │ │ ├── template │ │ │ ├── CHANGELOG.md │ │ │ ├── .editorconfig │ │ │ ├── {{ProjectName}} │ │ │ │ ├── Properties │ │ │ │ │ └── AssemblyInfo.cs │ │ │ │ └── SampleClass.cs │ │ │ ├── .github │ │ │ │ └── workflows │ │ │ │ │ └── ci.yml │ │ │ ├── module.yaml │ │ │ ├── README.md │ │ │ └── {{ProjectName}}.Tests │ │ │ │ └── {{ProjectName}}.Tests.csproj │ │ ├── pack.cmd │ │ └── push-to-nuget.cmd │ └── readme.md ├── launchpad │ ├── install-local.cmd │ ├── push-to-nuget.cmd │ ├── src │ │ ├── TemplateDefinition.cs │ │ ├── VariableDefinition.cs │ │ ├── LaunchpadSpec.cs │ │ ├── LaunchpadConfig.cs │ │ └── LaunchpadSpecProvider.cs │ └── launchpad-config.json ├── vostok-release │ ├── install.cmd │ ├── install.sh │ └── readme.txt ├── assets │ ├── Vostok-icon.png │ ├── vostok-logo.png │ ├── vostok-white-black.png │ ├── vostok-konfur-black.png │ └── vostok-white-transparent.png ├── dotnetprojectrefs │ ├── install.cmd │ └── readme.txt ├── tcs-create-options │ ├── install.cmd │ ├── readme.txt │ └── tcscreateoptions.csproj ├── configure-await-false │ ├── install.cmd │ └── readme.txt ├── dotnetprojectorderer │ ├── install.cmd │ └── readme.txt ├── dotnetversionsuffix │ ├── install.cmd │ ├── readme.txt │ └── dotnetversionsuffix.csproj ├── publicize.roslyn │ ├── .editorconfig │ ├── Vostok.Tools.Publicize.Roslyn.v1.dll │ └── Vostok.Tools.Publicize.Roslyn │ │ └── Properties │ │ └── AssemblyInfo.cs ├── dotnetcementrefs │ ├── install.cmd │ ├── external │ │ └── Cement.Vostok.Devtools.dll │ ├── dotnetcementrefs.sln.DotSettings │ └── FileUtilities.cs ├── git-commit-to-assembly-title │ ├── Vostok.Tools.GitCommit2AssemblyTitle.dll │ ├── Vostok.Tools.GitCommit2AssemblyTitle.csproj │ └── readme.txt ├── library-common-props │ ├── Test-Project-new.props │ ├── Main-Project-app.props │ └── Main-Project-new.props ├── code-style-csharp │ ├── .editorconfig │ └── CSharpCodeStyle.SpaceIndent.DotSettings ├── library-ci │ └── github_ci.yml └── module.yaml ├── Kontur.Results.SourceGenerator ├── .editorconfig ├── Code │ └── Methods │ │ └── Conversion │ │ └── Map │ │ └── MethodNames.cs └── ExtensionsSourceGenerator.cs ├── Kontur.Tests.Results ├── Base.cs ├── Child.cs ├── ICounter.cs ├── LibraryNamespace │ ├── CustomFault.cs │ ├── CustomValue.cs │ ├── LibraryException.cs │ ├── EnsureNoneExtensions.cs │ ├── EnsureHasValueExtensions.cs │ └── GetValueOrThrowOptionalExtensions.cs ├── IConsumer.cs ├── Inheritance │ ├── IStringFaultConsumer.cs │ ├── StringFault.cs │ ├── StringFaultChild.cs │ ├── Extraction │ │ ├── TryGet │ │ │ └── Common.cs │ │ ├── Failure_Should.cs │ │ ├── Success_Should.cs │ │ ├── Get │ │ │ ├── Values │ │ │ │ └── Upcast │ │ │ │ │ ├── Both_Should.cs │ │ │ │ │ ├── Value_Should.cs │ │ │ │ │ └── Fault_Should.cs │ │ │ ├── Faults │ │ │ │ └── Upcast │ │ │ │ │ ├── Value_Should.cs │ │ │ │ │ ├── Both_Should.cs │ │ │ │ │ └── Fault_Should.cs │ │ │ ├── OrDefault │ │ │ │ ├── Value │ │ │ │ │ ├── Upcast │ │ │ │ │ │ ├── Both │ │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ │ ├── Value │ │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ │ └── Fault │ │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ ├── Struct │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ └── Class │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ └── Fault │ │ │ │ │ └── Upcast │ │ │ │ │ ├── Value │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ ├── Both │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ └── Fault │ │ │ │ │ └── NotNullable_Should.cs │ │ │ └── OrThrow │ │ │ │ ├── Value │ │ │ │ └── Standard_Exception_Should.cs │ │ │ │ └── Fault │ │ │ │ └── Standard_Exception_Should.cs │ │ └── Ensure │ │ │ ├── Failure │ │ │ └── Standard_Exception_Should.cs │ │ │ └── Success │ │ │ └── Standard_Exception_Should.cs │ ├── StringFaultResult.cs │ ├── UpcastExample.TValue.TResult.cs │ ├── Equality │ │ ├── GetHashCode_Should.cs │ │ └── Equals_Should.cs │ ├── StringFaultBase.cs │ ├── Conversion │ │ └── Upcast │ │ │ ├── Both_Should.cs │ │ │ ├── Value_Should.cs │ │ │ └── Fault_Should.cs │ └── StringFaultResult.TValue.cs ├── Conversion │ ├── Combinations │ │ ├── Linq │ │ │ ├── Optional │ │ │ │ ├── OptionalOptional │ │ │ │ │ ├── IConstantProvider.cs │ │ │ │ │ ├── IntConstantProvider.cs │ │ │ │ │ ├── IFixtureCase.cs │ │ │ │ │ ├── Select │ │ │ │ │ │ └── DifferentTypes │ │ │ │ │ │ │ ├── StringConstantProvider.cs │ │ │ │ │ │ │ └── LinqTestBase.TFixtureCase.cs │ │ │ │ │ ├── NoneFixtureCase.cs │ │ │ │ │ ├── SomeFixtureCase.cs │ │ │ │ │ ├── SomeConstantFixtureCase.cs │ │ │ │ │ └── LinqTestBase.ITestFixtureCase.cs │ │ │ │ ├── Optional │ │ │ │ │ ├── SelectCaseToTestCasesExtensions.cs │ │ │ │ │ ├── Where │ │ │ │ │ │ └── WhereCaseGenerator.cs │ │ │ │ │ └── Select │ │ │ │ │ │ └── DifferentTypes │ │ │ │ │ │ └── SelectCaseToDifferentTypeTestCasesExtensions.cs │ │ │ │ └── SelectCaseToTestCasesExtensions.cs │ │ │ └── Result │ │ │ │ ├── TValuePlain │ │ │ │ ├── IFixtureCase.cs │ │ │ │ ├── SuccessFixtureCase.cs │ │ │ │ ├── FailureConstantFixtureCase.cs │ │ │ │ ├── FailureVariableFixtureCase.cs │ │ │ │ └── LinqTestBase.cs │ │ │ │ ├── TValueTValue │ │ │ │ ├── IConstantProvider.cs │ │ │ │ ├── IFixtureCase.cs │ │ │ │ ├── Select │ │ │ │ │ └── DifferentTypes │ │ │ │ │ │ ├── StringConstantProvider.cs │ │ │ │ │ │ └── LinqTestBase.TFixtureCase.cs │ │ │ │ ├── IntConstantProvider.cs │ │ │ │ ├── FailureConstantFixtureCase.cs │ │ │ │ ├── SuccessVariableFixtureCase.cs │ │ │ │ ├── FailureVariableFixtureCase.cs │ │ │ │ ├── SuccessConstantFixtureCase.cs │ │ │ │ └── LinqTestBase.TFixtureCase.cs │ │ │ │ ├── TValue │ │ │ │ ├── SelectCaseToTestCasesExtensions.cs │ │ │ │ ├── Select │ │ │ │ │ └── DifferentTypes │ │ │ │ │ │ └── SelectCaseToDifferentTypeTestCasesExtensions.cs │ │ │ │ └── Where │ │ │ │ │ └── WhereCaseGenerator.cs │ │ │ │ └── SelectCaseToTestCasesExtensions.cs │ │ └── ResultFactory.cs │ └── Upcast │ │ ├── Plain_Should.cs │ │ ├── Optional_Should.cs │ │ └── TValue │ │ ├── Both_Should.cs │ │ ├── Fault_Should.cs │ │ └── Value_Should.cs ├── ValueTaskFactory.cs ├── UnreachableException.cs ├── Extraction │ ├── TryGet │ │ ├── Plain │ │ │ └── Common.cs │ │ ├── TValue │ │ │ └── Common.cs │ │ └── Optional │ │ │ └── Common.cs │ ├── Ensure │ │ ├── Failure │ │ │ ├── Plain │ │ │ │ └── Standard_Exception_Should.cs │ │ │ ├── None │ │ │ │ ├── Standard_Exception_Contain_Value_Should.cs │ │ │ │ └── Standard_Exception_Should.cs │ │ │ └── TValue │ │ │ │ ├── Standard_Exception_Contain_Value_Should.cs │ │ │ │ └── Standard_Exception_Should.cs │ │ └── Success │ │ │ ├── HasValue │ │ │ └── Standard_Exception_Should.cs │ │ │ ├── Plain │ │ │ ├── Standard_Exception_Contain_Fault_Should.cs │ │ │ └── Standard_Exception_Should.cs │ │ │ └── TValue │ │ │ ├── Standard_Exception_Contain_Fault_Should.cs │ │ │ └── Standard_Exception_Should.cs │ ├── Get │ │ ├── OrThrow │ │ │ ├── Optional │ │ │ │ └── Standard_Exception_Should.cs │ │ │ ├── Plain │ │ │ │ └── Standard_Exception_Should.cs │ │ │ └── TValue │ │ │ │ ├── Value │ │ │ │ ├── Standard_Exception_Contain_Fault_Should.cs │ │ │ │ └── Standard_Exception_Should.cs │ │ │ │ └── Fault │ │ │ │ ├── Standard_Exception_Contain_Value_Should.cs │ │ │ │ └── Standard_Exception_Should.cs │ │ ├── OrNull │ │ │ ├── Plain_Should.cs │ │ │ ├── Optional_Should.cs │ │ │ └── TValue │ │ │ │ ├── Fault_Should.cs │ │ │ │ └── Value_Should.cs │ │ ├── OrDefault │ │ │ ├── Plain │ │ │ │ ├── Upcast │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ ├── Struct │ │ │ │ │ ├── NotNullable_Should.cs │ │ │ │ │ └── Nullable_Should.cs │ │ │ │ └── Class │ │ │ │ │ ├── NonNullable_Should.cs │ │ │ │ │ └── Nullable_Should.cs │ │ │ ├── Optional │ │ │ │ ├── Upcast │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ ├── Struct │ │ │ │ │ ├── NotNullable_Should.cs │ │ │ │ │ └── Nullable_Should.cs │ │ │ │ └── Class │ │ │ │ │ └── NonNullable_Should.cs │ │ │ └── TValue │ │ │ │ ├── Fault │ │ │ │ ├── Struct │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ ├── Upcast │ │ │ │ │ ├── Both │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ ├── Fault │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ │ └── Value │ │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ └── Class │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ └── Value │ │ │ │ ├── Struct │ │ │ │ └── NotNullable_Should.cs │ │ │ │ ├── Upcast │ │ │ │ ├── Both │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ ├── Value │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ └── Fault │ │ │ │ │ └── NotNullable_Should.cs │ │ │ │ └── Class │ │ │ │ └── NotNullable_Should.cs │ │ ├── Faults │ │ │ └── TValue │ │ │ │ └── Upcast │ │ │ │ ├── Both_Should.cs │ │ │ │ ├── Fault_Should.cs │ │ │ │ └── Value_Should.cs │ │ └── Values │ │ │ └── TValue │ │ │ └── Upcast │ │ │ ├── Both_Should.cs │ │ │ ├── Fault_Should.cs │ │ │ └── Value_Should.cs │ ├── SelectMany │ │ └── FirstFault │ │ │ ├── Optional │ │ │ └── Using │ │ │ │ └── SelectManyOptionalExtensions.cs │ │ │ └── TValue │ │ │ └── Using │ │ │ └── SelectManyResultValueExtensions.cs │ ├── Failure │ │ ├── Plain_Should.cs │ │ ├── IsNone_Should.cs │ │ └── TValue_Should.cs │ ├── Success │ │ ├── Plain_Should.cs │ │ ├── HasSome_Should.cs │ │ └── TValue_Should.cs │ └── ToString │ │ ├── Optional_Should.cs │ │ └── Plain_Should.cs ├── Instantiation │ ├── Plain │ │ ├── Create_Via_Non_Generic │ │ │ └── Common.cs │ │ └── Implicit_Operator_Should.cs │ ├── Optional │ │ ├── Create_Via_Non_Generic │ │ │ └── Common.cs │ │ └── Implicit_Operator_Should.cs │ └── TValue │ │ └── Create_Via_Non_Generic │ │ └── Common.cs ├── UpcastPlainExample.TResult.cs ├── UpcastOptionalExample.TResult.cs ├── UpcastTValueExample.TFault.TValue.TResult.cs ├── Equality │ ├── Plain │ │ ├── GetHashCode_Should.cs │ │ └── Equals_Should.cs │ ├── Optional │ │ ├── GetHashCode_Should.cs │ │ └── Equals_Should.cs │ └── TValue │ │ ├── GetHashCode_Should.cs │ │ └── Equals_Should.cs ├── UpcastOptionalExamples.cs └── UpcastPlainExamples.cs ├── Kontur.Results.SourceGenerator.Monad ├── .editorconfig ├── Code │ └── Methods │ │ └── Conversion │ │ └── Combinations │ │ ├── Then │ │ └── MethodNames.cs │ │ ├── OrElse │ │ └── MethodNames.cs │ │ └── Linq │ │ ├── Where │ │ └── MethodNames.cs │ │ ├── Select │ │ └── MethodNames.cs │ │ └── SelectMany │ │ └── MethodNames.cs └── MonadSourceGenerator.cs ├── Kontur.Results.SourceGenerator.Shared ├── .editorconfig └── Code │ ├── Methods │ ├── IDescriptionProvider.cs │ ├── MethodsDescription.cs │ └── MethodsDescriptionProvider.cs │ ├── CompilationUnit.cs │ ├── CompilationFileProviderSettings.cs │ ├── Internal │ ├── MethodTypeGeneratorParameter.cs │ ├── MethodTypeGenericParameter.cs │ ├── MethodTypeInternal2.cs │ ├── InternalMethodsDescription.cs │ ├── InternalTypeParameter.cs │ ├── InternalPartialMethodDescription.cs │ ├── MethodTypeInternal3.cs │ └── InternalStandardMethodsDescription.cs │ ├── MethodGenericParameterDescription.cs │ ├── Parameters.cs │ ├── Public │ ├── PublicMethodsDescription.cs │ ├── MethodType2.cs │ └── MethodType3.cs │ ├── ClassNamesPass.cs │ ├── AccessModifierFactory.cs │ ├── ClassNamesPassExtensions.cs │ ├── TaskLikeTypeSyntaxFactory.cs │ ├── IMethodBodyFactory.cs │ ├── SelfParameter.cs │ ├── EnumerableExtensions.cs │ ├── ITypeParameterGenericMethodSyntaxGenerator.cs │ ├── IdentifierExtensions.cs │ ├── ClassNamesFactoryExtensions.cs │ ├── ParameterNames.cs │ └── ClassNamesFactory.cs ├── Kontur.Results ├── Implementation │ ├── Optional │ │ ├── NoneMarker.cs │ │ ├── IOptional.TValue.cs │ │ ├── Some.TValue.cs │ │ ├── None.TValue.cs │ │ └── Optional.cs │ ├── Result │ │ ├── SuccessMarker.cs │ │ ├── SuccessMarker.TValue.cs │ │ ├── IResult.TFault.cs │ │ ├── ResultFailure.TFault.TValue.cs │ │ ├── ResultSuccess.TFault.TValue.cs │ │ ├── IResult.TFault.TValue.cs │ │ ├── ResultSuccess.TValue.cs │ │ ├── ResultFailure.T.cs │ │ └── Result.cs │ └── Containers │ │ ├── Plain │ │ ├── IContainer.T.cs │ │ ├── FilledContainer.T.cs │ │ └── EmptyContainer.T.cs │ │ └── ResultValue │ │ ├── IContainer.TFault.TValue.cs │ │ ├── FailureContainer.TFault.TValue.cs │ │ └── SuccessContainer.TFault.TValue.cs ├── .editorconfig ├── .globalconfig └── Extensions │ ├── Extraction │ ├── ResultFailedException.cs │ ├── ValueExistsException.cs │ ├── ResultSucceedException.cs │ ├── ValueMissingException.cs │ ├── Actions │ │ ├── OnFailure │ │ │ ├── OnNoneExtensions.cs │ │ │ ├── OnFailureResultPlainExtensions.cs │ │ │ └── OnFailureResultValueExtensions.cs │ │ ├── OnSuccess │ │ │ ├── OnSuccessResultPlainExtensions.cs │ │ │ ├── OnSomeExtensions.cs │ │ │ └── OnSuccessResultValueExtensions.cs │ │ └── Switch │ │ │ ├── SwitchOptionalExtensions.cs │ │ │ └── SwitchResultPlainExtensions.cs │ ├── ValueExistsException.TValue.cs │ ├── ResultFailedException.TFault.cs │ ├── ResultSucceedException.TValue.cs │ ├── Get │ │ ├── OrDefault │ │ │ ├── Fault │ │ │ │ ├── GetFaultOrDefaultResultPlainExtensions.cs │ │ │ │ └── GetFaultOrDefaultResultValueExtensions.cs │ │ │ └── Value │ │ │ │ ├── GetValueOrDefaultOptionalExtensions.cs │ │ │ │ └── GetValueOrDefaultResultValueExtensions.cs │ │ ├── Enumerator │ │ │ ├── GetEnumeratorOptionalExtensions.cs │ │ │ └── GetEnumeratorResultValueExtensions.cs │ │ ├── OrNull │ │ │ ├── Fault │ │ │ │ ├── GetFaultOrNullResultPlainExtensions.cs │ │ │ │ └── GetFaultOrNullResultValueExtensions.cs │ │ │ └── Value │ │ │ │ ├── GetValueOrNullOptionalExtensions.cs │ │ │ │ └── GetValueOrNullResultValueExtensions.cs │ │ ├── Faults │ │ │ ├── GetFaultsResultPlainExtensions.cs │ │ │ └── GetFaultsResultValueExtensions.cs │ │ ├── Values │ │ │ ├── GetValuesOptionalExtensions.cs │ │ │ └── GetValuesResultValueExtensions.cs │ │ └── OrElse │ │ │ ├── Value │ │ │ └── GetValueOrElseOptionalExtensions.cs │ │ │ └── Fault │ │ │ └── GetFaultOrElseResultPlainExtensions.cs │ └── Ensure │ │ ├── Failure │ │ └── EnsureFailureResultPlainExtensions.cs │ │ └── Success │ │ └── EnsureHasValueExtensions.cs │ └── Conversion │ └── Upcast │ ├── UpcastResultPlainExtensions.cs │ ├── UpcastOptionalExtensions.cs │ └── UpcastResultValueExtensions.cs ├── Kontur.Results.Monad └── .globalconfig ├── .build_nuget.bat └── .editorconfig /vostok.devtools/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | TODO -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | TODO -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/{{ProjectName}}/PublicAPI.Shipped.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/{{ProjectName}}/PublicAPI.Unshipped.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/pack.cmd: -------------------------------------------------------------------------------- 1 | nuget pack pack.nuspec -OutputDirectory nupkg 2 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/pack.cmd: -------------------------------------------------------------------------------- 1 | nuget pack pack.nuspec -OutputDirectory nupkg 2 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{cs,vb}] 2 | 3 | dotnet_diagnostic.CA1812.severity = none 4 | 5 | 6 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Base.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results 2 | { 3 | public class Base 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{cs,vb}] 2 | 3 | dotnet_diagnostic.CA1812.severity = none 4 | 5 | 6 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{cs,vb}] 2 | 3 | dotnet_diagnostic.CA1812.severity = none 4 | 5 | 6 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad/install-local.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g Vostok.Launchpad -------------------------------------------------------------------------------- /vostok.devtools/vostok-release/install.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g vostok-release -------------------------------------------------------------------------------- /vostok.devtools/vostok-release/install.sh: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g vostok-release -------------------------------------------------------------------------------- /Kontur.Tests.Results/Child.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results 2 | { 3 | public class Child : Base 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /vostok.devtools/assets/Vostok-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/assets/Vostok-icon.png -------------------------------------------------------------------------------- /vostok.devtools/assets/vostok-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/assets/vostok-logo.png -------------------------------------------------------------------------------- /vostok.devtools/dotnetprojectrefs/install.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g dotnetprojectrefs -------------------------------------------------------------------------------- /vostok.devtools/tcs-create-options/install.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g tcscreateoptions -------------------------------------------------------------------------------- /vostok.devtools/configure-await-false/install.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g configureawaitfalse -------------------------------------------------------------------------------- /vostok.devtools/dotnetprojectorderer/install.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g dotnetprojectorderer -------------------------------------------------------------------------------- /vostok.devtools/dotnetversionsuffix/install.cmd: -------------------------------------------------------------------------------- 1 | dotnet build -c Release 2 | dotnet tool update --add-source nupkg -g dotnetversionsuffix -------------------------------------------------------------------------------- /vostok.devtools/publicize.roslyn/.editorconfig: -------------------------------------------------------------------------------- 1 | ; 4-column space indentation 2 | [*.{cs,tt}] 3 | indent_style = space 4 | indent_size = 4 -------------------------------------------------------------------------------- /vostok.devtools/assets/vostok-white-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/assets/vostok-white-black.png -------------------------------------------------------------------------------- /vostok.devtools/assets/vostok-konfur-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/assets/vostok-konfur-black.png -------------------------------------------------------------------------------- /vostok.devtools/assets/vostok-white-transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/assets/vostok-white-transparent.png -------------------------------------------------------------------------------- /vostok.devtools/dotnetcementrefs/install.cmd: -------------------------------------------------------------------------------- 1 | pushd %~dp0 2 | dotnet build -c Release 3 | dotnet tool update --add-source nupkg -g dotnetcementrefs 4 | popd -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Optional/NoneMarker.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results 2 | { 3 | public readonly ref struct NoneMarker 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/SuccessMarker.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results 2 | { 3 | public readonly ref struct SuccessMarker 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/.editorconfig: -------------------------------------------------------------------------------- 1 | ; 4-column space indentation 2 | [*.{cs,tt}] 3 | indent_style = space 4 | indent_size = 4 -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/.editorconfig: -------------------------------------------------------------------------------- 1 | ; 4-column space indentation 2 | [*.{cs,tt}] 3 | indent_style = space 4 | indent_size = 4 -------------------------------------------------------------------------------- /Kontur.Tests.Results/ICounter.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results 2 | { 3 | public interface ICounter 4 | { 5 | public void Increment(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/LibraryNamespace/CustomFault.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.LibraryNamespace 2 | { 3 | internal class CustomFault 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/LibraryNamespace/CustomValue.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.LibraryNamespace 2 | { 3 | internal class CustomValue 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad/push-to-nuget.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q nupkg 2 | dotnet build -c Release 3 | nuget push nupkg\*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey %1 -------------------------------------------------------------------------------- /Kontur.Tests.Results/IConsumer.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results 2 | { 3 | public interface IConsumer 4 | { 5 | public void Consume(string data); 6 | } 7 | } -------------------------------------------------------------------------------- /vostok.devtools/dotnetcementrefs/external/Cement.Vostok.Devtools.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/dotnetcementrefs/external/Cement.Vostok.Devtools.dll -------------------------------------------------------------------------------- /vostok.devtools/publicize.roslyn/Vostok.Tools.Publicize.Roslyn.v1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/publicize.roslyn/Vostok.Tools.Publicize.Roslyn.v1.dll -------------------------------------------------------------------------------- /vostok.devtools/git-commit-to-assembly-title/Vostok.Tools.GitCommit2AssemblyTitle.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skbkontur/results/HEAD/vostok.devtools/git-commit-to-assembly-title/Vostok.Tools.GitCommit2AssemblyTitle.dll -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/push-to-nuget.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q nupkg 2 | nuget pack pack.nuspec -OutputDirectory nupkg 3 | nuget push nupkg\*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey %1 -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/push-to-nuget.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q nupkg 2 | nuget pack pack.nuspec -OutputDirectory nupkg 3 | nuget push nupkg\*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey %1 -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/IStringFaultConsumer.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Inheritance 2 | { 3 | public interface IStringFaultConsumer 4 | { 5 | public void Consume(StringFault data); 6 | } 7 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Methods/IDescriptionProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods 2 | { 3 | internal interface IDescriptionProvider 4 | { 5 | MethodsDescription Get(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Results/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{cs,vb}] 2 | 3 | dotnet_diagnostic.CA2225.severity = none 4 | 5 | dotnet_code_quality.CA1716.analyzed_symbol_kinds = Namespace, Method, Property, Event, Parameter 6 | 7 | dotnet_diagnostic.S3453.severity = none 8 | 9 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/CompilationUnit.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code 4 | { 5 | internal record CompilationUnit(string Hint, CompilationUnitSyntax Content); 6 | } 7 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad/src/TemplateDefinition.cs: -------------------------------------------------------------------------------- 1 | namespace launchpad 2 | { 3 | internal class TemplateDefinition 4 | { 5 | public string Name { get; set; } 6 | 7 | public string PackageName { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad/src/VariableDefinition.cs: -------------------------------------------------------------------------------- 1 | namespace launchpad 2 | { 3 | internal class VariableDefinition 4 | { 5 | public string Name { get; set; } 6 | 7 | public string Description { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/{{ProjectName}}/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("{{ProjectName}}.Tests")] 4 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/{{ProjectName}}/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("{{ProjectName}}.Tests")] 4 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] -------------------------------------------------------------------------------- /vostok.devtools/publicize.roslyn/Vostok.Tools.Publicize.Roslyn/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Vostok.Tools.Publicize.Roslyn.Tests")] 4 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] -------------------------------------------------------------------------------- /vostok.devtools/library-common-props/Test-Project-new.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | enable 7 | latest 8 | 9 | 10 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/CompilationFileProviderSettings.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code 2 | { 3 | internal record CompilationFileProviderSettings( 4 | string GlobalExtensionsFileName, 5 | string LocalExtensionsFileName); 6 | } 7 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad/src/LaunchpadSpec.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace launchpad 4 | { 5 | internal class LaunchpadSpec 6 | { 7 | [JsonProperty("Variables")] 8 | public VariableDefinition[] Variables { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/StringFault.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Inheritance 2 | { 3 | public class StringFault : StringFaultBase 4 | { 5 | public StringFault(string fault) 6 | : base(fault) 7 | { 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/Code/Methods/Conversion/Combinations/Then/MethodNames.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods.Conversion.Combinations.Then 2 | { 3 | internal static class MethodNames 4 | { 5 | internal const string Then = "Then"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/IConstantProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 2 | { 3 | internal interface IConstantProvider 4 | { 5 | TValue Get(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Results/.globalconfig: -------------------------------------------------------------------------------- 1 | is_global=true 2 | 3 | dotnet_diagnostic.CA1062.severity = none 4 | 5 | dotnet_diagnostic.SA0001.severity = none 6 | 7 | dotnet_diagnostic.SA1200.severity = none 8 | 9 | dotnet_diagnostic.SA1633.severity = none 10 | 11 | dotnet_diagnostic.S3903.severity = none 12 | -------------------------------------------------------------------------------- /Kontur.Results.Monad/.globalconfig: -------------------------------------------------------------------------------- 1 | is_global=true 2 | 3 | dotnet_diagnostic.CA1062.severity = none 4 | 5 | dotnet_diagnostic.SA0001.severity = none 6 | 7 | dotnet_diagnostic.SA1200.severity = none 8 | 9 | dotnet_diagnostic.SA1633.severity = none 10 | 11 | dotnet_diagnostic.S3903.severity = none -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/Code/Methods/Conversion/Combinations/OrElse/MethodNames.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods.Conversion.Combinations.OrElse 2 | { 3 | internal static class MethodNames 4 | { 5 | internal const string OrElse = "OrElse"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/StringFaultChild.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Inheritance 2 | { 3 | public sealed class StringFaultChild : StringFault 4 | { 5 | public StringFaultChild(string fault) 6 | : base(fault) 7 | { 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /vostok.devtools/library-common-props/Main-Project-app.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | net6.0 7 | net6.0 8 | 9 | 10 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/Code/Methods/Conversion/Combinations/Linq/Where/MethodNames.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods.Conversion.Combinations.Linq.Where 2 | { 3 | internal static class MethodNames 4 | { 5 | internal const string Where = "Where"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/Code/Methods/Conversion/Combinations/Linq/Select/MethodNames.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods.Conversion.Combinations.Linq.Select 2 | { 3 | internal static class MethodNames 4 | { 5 | internal const string Select = "Select"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/MethodTypeGeneratorParameter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code.Internal 4 | { 5 | internal record MethodTypeGeneratorParameter( 6 | SimpleNameSyntax UpperBound, 7 | bool Sealed); 8 | } 9 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/IntConstantProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 2 | { 3 | internal class IntConstantProvider : IConstantProvider 4 | { 5 | public int Get() => 8888; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/ValueTaskFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Kontur.Tests.Results 4 | { 5 | internal static class ValueTaskFactory 6 | { 7 | internal static ValueTask Create(T result) 8 | { 9 | return new(result); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/Code/Methods/Conversion/Combinations/Linq/SelectMany/MethodNames.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods.Conversion.Combinations.Linq.SelectMany 2 | { 3 | internal static class MethodNames 4 | { 5 | internal const string SelectMany = "SelectMany"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator/Code/Methods/Conversion/Map/MethodNames.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code.Methods.Conversion.Map 2 | { 3 | internal static class MethodNames 4 | { 5 | internal const string MapFault = "MapFault"; 6 | internal const string MapValue = "MapValue"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValuePlain/IFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValuePlain 4 | { 5 | internal interface IFixtureCase 6 | { 7 | public Result GetResult(int value); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/IConstantProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 2 | { 3 | internal interface IConstantProvider 4 | { 5 | string GetError(); 6 | 7 | TValue GetValue(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/{{ProjectName}}/SampleClass.cs: -------------------------------------------------------------------------------- 1 | using JetBrains.Annotations; 2 | 3 | namespace {{ProjectName}} 4 | { 5 | /// 6 | /// A sample class. 7 | /// 8 | [PublicAPI] 9 | internal class SampleClass 10 | { 11 | 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ResultFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public class ResultFailedException : InvalidOperationException 6 | { 7 | internal ResultFailedException(string message) 8 | : base(message) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ValueExistsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public class ValueExistsException : InvalidOperationException 6 | { 7 | internal ValueExistsException(string message) 8 | : base(message) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/SuccessMarker.TValue.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results 2 | { 3 | public sealed class SuccessMarker 4 | { 5 | internal SuccessMarker(TValue value) 6 | { 7 | this.Value = value; 8 | } 9 | 10 | internal TValue Value { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/UnreachableException.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Kontur.Tests.Results 4 | { 5 | internal class UnreachableException : AssertionException 6 | { 7 | public UnreachableException() 8 | : base("Branch should be unreachable") 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ResultSucceedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public class ResultSucceedException : InvalidOperationException 6 | { 7 | internal ResultSucceedException(string message) 8 | : base(message) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/LibraryNamespace/LibraryException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Tests.Results.LibraryNamespace 4 | { 5 | internal static class LibraryException 6 | { 7 | internal const string Message = "Overriden"; 8 | 9 | internal static Exception Instance => new(Message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/MethodGenericParameterDescription.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal record MethodGenericParameterDescription( 7 | SyntaxToken Identifier, 8 | TypeSyntax? UpperBound); 9 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ValueMissingException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public sealed class ValueMissingException : InvalidOperationException 6 | { 7 | internal ValueMissingException(string message) 8 | : base(message) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /vostok.devtools/code-style-csharp/.editorconfig: -------------------------------------------------------------------------------- 1 | ; 4-column space indentation 2 | [*] 3 | indent_style = space 4 | 5 | [*.{cs,tt}] 6 | indent_size = 4 7 | 8 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 9 | indent_size = 2 10 | 11 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/MethodTypeGenericParameter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Internal 5 | { 6 | internal record MethodTypeGenericParameter( 7 | SyntaxToken Identifier, 8 | TypeSyntax? UpperBound); 9 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Parameters.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code 2 | { 3 | internal static class Parameters 4 | { 5 | internal static readonly SelfParameter SelfResultIdentifier = new("result"); 6 | internal static readonly SelfParameter SelfOptionalIdentifier = new("optional"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Containers/Plain/IContainer.T.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results.Containers.Plain 5 | { 6 | internal interface IContainer 7 | { 8 | [Pure] 9 | bool TryGet([MaybeNullWhen(false)] out T data); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/MethodTypeInternal2.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code.Internal 4 | { 5 | internal record MethodTypeInternal2( 6 | InternalTypeParameter Parameter1, 7 | InternalTypeParameter Parameter2, 8 | TypeSyntax ReturnType); 9 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/InternalMethodsDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code.Internal 4 | { 5 | internal record InternalMethodsDescription( 6 | IEnumerable Methods, 7 | InternalPartialMethodDescription Partial); 8 | } 9 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/InternalTypeParameter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code.Internal 4 | { 5 | internal record InternalTypeParameter( 6 | SimpleNameSyntax Type, 7 | bool IsTaskLike, 8 | MethodTypeGenericParameter? Generic); 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Optional/IOptional.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace Kontur.Results 5 | { 6 | [EditorBrowsable(EditorBrowsableState.Never)] 7 | public interface IOptional 8 | { 9 | internal TResult Match(Func onNone, Func onSome); 10 | } 11 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/IResult.TFault.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace Kontur.Results 5 | { 6 | [EditorBrowsable(EditorBrowsableState.Never)] 7 | public interface IResult 8 | { 9 | internal TResult Match(Func onFailure, Func onSuccess); 10 | } 11 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/IFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 4 | { 5 | internal interface IFixtureCase 6 | { 7 | public Optional GetOptional(TValue value, TValue constant); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/Select/DifferentTypes/StringConstantProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional.Select.DifferentTypes 2 | { 3 | internal class StringConstantProvider : IConstantProvider 4 | { 5 | public string Get() => "constant"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValuePlain/SuccessFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValuePlain 4 | { 5 | internal class SuccessFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(int value) => Result.Succeed(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/IFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 4 | { 5 | internal interface IFixtureCase 6 | { 7 | public Result GetResult(TValue value, IConstantProvider provider); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/OnFailure/OnNoneExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class OnNoneExtensions 6 | { 7 | public static Optional OnNone(this IOptional optional, Action action) 8 | { 9 | return optional.Switch(action, () => { }); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /vostok.devtools/launchpad/src/LaunchpadConfig.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace launchpad 4 | { 5 | internal class LaunchpadConfig 6 | { 7 | [JsonProperty("Definitions")] 8 | public TemplateDefinition[] Definitions { get; set; } 9 | 10 | [JsonProperty("NugetSources")] 11 | public string[] NugetSources { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/InternalPartialMethodDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Internal 5 | { 6 | internal record InternalPartialMethodDescription( 7 | string ClassName, 8 | IEnumerable Methods); 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Methods/MethodsDescription.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results.SourceGenerator.Code.Internal; 2 | using Kontur.Results.SourceGenerator.Code.Public; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Methods 5 | { 6 | internal record MethodsDescription( 7 | InternalMethodsDescription Internal, 8 | PublicMethodsDescription Public); 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/LibraryNamespace/EnsureNoneExtensions.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.LibraryNamespace 4 | { 5 | internal static class EnsureNoneExtensions 6 | { 7 | public static void EnsureNone(this Optional optional) 8 | { 9 | optional.EnsureNone(LibraryException.Instance); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValuePlain/FailureConstantFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValuePlain 4 | { 5 | internal class FailureConstantFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(int value) => Result.Fail("in the end"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValuePlain/FailureVariableFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValuePlain 4 | { 5 | internal class FailureVariableFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(int value) => ResultFactory.CreateFailure(value); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/LibraryNamespace/EnsureHasValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.LibraryNamespace 4 | { 5 | internal static class EnsureHasValueExtensions 6 | { 7 | public static void EnsureHasValue(this Optional optional) 8 | { 9 | optional.EnsureHasValue(LibraryException.Instance); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/MethodTypeInternal3.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp.Syntax; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code.Internal 4 | { 5 | internal record MethodTypeInternal3( 6 | InternalTypeParameter Parameter1, 7 | InternalTypeParameter ParameterNext, 8 | InternalTypeParameter Parameter2, 9 | TypeSyntax ReturnType); 10 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Public/PublicMethodsDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Public 5 | { 6 | internal record PublicMethodsDescription( 7 | IEnumerable Extensions, 8 | IEnumerable ExtensionsGlobal); 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/OnSuccess/OnSuccessResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class OnSuccessResultPlainExtensions 6 | { 7 | public static Result OnSuccess(this IResult result, Action action) 8 | { 9 | return result.Switch(() => { }, action); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/NoneFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 4 | { 5 | internal class NoneFixtureCase : IFixtureCase 6 | { 7 | public Optional GetOptional(TValue value, TValue constant) => Optional.None(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator/ExtensionsSourceGenerator.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Kontur.Results.SourceGenerator 4 | { 5 | [Generator] 6 | public class ExtensionsSourceGenerator : SourceGeneratorBase 7 | { 8 | public ExtensionsSourceGenerator() 9 | : base(new("KonturResultGlobalExtensions", "KonturResultExtensions")) 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/SomeFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 4 | { 5 | internal class SomeFixtureCase : IFixtureCase 6 | { 7 | public Optional GetOptional(TValue value, TValue constant) => Optional.Some(value); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ValueExistsException.TValue.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results 2 | { 3 | public sealed class ValueExistsException : ValueExistsException 4 | { 5 | internal ValueExistsException(TValue value, string message) 6 | : base(message) 7 | { 8 | this.Value = value; 9 | } 10 | 11 | public TValue Value { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Monad/MonadSourceGenerator.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Kontur.Results.SourceGenerator.Monad 4 | { 5 | [Generator] 6 | public class MonadSourceGenerator : SourceGeneratorBase 7 | { 8 | public MonadSourceGenerator() 9 | : base(new("KonturResultMonadGlobalExtensions", "KonturResultMonadExtensions")) 10 | { 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/ClassNamesPass.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code 2 | { 3 | internal class ClassNamesPass : ClassNamesFactory 4 | { 5 | internal ClassNamesPass(string methodName, string parameterTypes) 6 | : base(methodName, parameterTypes) 7 | { 8 | } 9 | 10 | internal string Pass => this.Create(nameof(this.Pass)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Public/MethodType2.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Public 5 | { 6 | internal record MethodType2( 7 | SimpleNameSyntax Parameter1, 8 | SimpleNameSyntax Parameter2, 9 | IEnumerable GenericArguments, 10 | TypeSyntax ReturnType); 11 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ResultFailedException.TFault.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results 2 | { 3 | public sealed class ResultFailedException : ResultFailedException 4 | { 5 | internal ResultFailedException(TFault fault, string message) 6 | : base(message) 7 | { 8 | this.Fault = fault; 9 | } 10 | 11 | public TFault Fault { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/TryGet/Common.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Kontur.Tests.Results.Inheritance.Extraction.TryGet 4 | { 5 | internal static class Common 6 | { 7 | internal static TestCaseData CreateReturnBooleanCase(StringFaultResult result, bool success) 8 | { 9 | return new(result) { ExpectedResult = success }; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/ResultSucceedException.TValue.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results 2 | { 3 | public sealed class ResultSucceedException : ResultSucceedException 4 | { 5 | internal ResultSucceedException(TValue value, string message) 6 | : base(message) 7 | { 8 | this.Value = value; 9 | } 10 | 11 | public TValue Value { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/TryGet/Plain/Common.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.TryGet.Plain 5 | { 6 | internal static class Common 7 | { 8 | internal static TestCaseData CreateReturnBooleanCase(Result result, bool success) 9 | { 10 | return new(result) { ExpectedResult = success }; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/SomeConstantFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 4 | { 5 | internal class SomeConstantFixtureCase : IFixtureCase 6 | { 7 | public Optional GetOptional(TValue value, TValue constant) => Optional.Some(constant); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/Select/DifferentTypes/StringConstantProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue.Select.DifferentTypes 2 | { 3 | internal class StringConstantProvider : IConstantProvider 4 | { 5 | public string GetError() => this.GetValue(); 6 | 7 | public string GetValue() => "constant"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/TryGet/TValue/Common.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.TryGet.TValue 5 | { 6 | internal static class Common 7 | { 8 | internal static TestCaseData CreateReturnBooleanCase(Result result, bool success) 9 | { 10 | return new(result) { ExpectedResult = success }; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Internal/InternalStandardMethodsDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Internal 5 | { 6 | internal record InternalStandardMethodsDescription( 7 | string ClassName, 8 | IEnumerable Using, 9 | IEnumerable Methods); 10 | } -------------------------------------------------------------------------------- /vostok.devtools/configure-await-false/readme.txt: -------------------------------------------------------------------------------- 1 | Installation for .NET Core 2.1+: 2 | 3 | dotnet build -c Release 4 | 5 | dotnet tool install --add-source nupkg -g configureawaitfalse 6 | 7 | Usage example: 8 | 9 | configureawaitfalse 10 | Recursively scans all *.cs files in given and prints any 'await' expressions 11 | without ConfigureAwait(false). Fails in the end if any incorrect awaits were found. 12 | 13 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/ResultFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using Kontur.Results; 3 | 4 | namespace Kontur.Tests.Results.Conversion.Combinations 5 | { 6 | internal static class ResultFactory 7 | { 8 | internal static Result CreateFailure(int value) 9 | { 10 | return Result.Fail(value.ToString(CultureInfo.InvariantCulture)); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/TryGet/Optional/Common.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.TryGet.Optional 5 | { 6 | internal static class Common 7 | { 8 | internal static TestCaseData CreateReturnBooleanCase(Optional optional, bool success) 9 | { 10 | return new(optional) { ExpectedResult = success }; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vostok.devtools/dotnetprojectorderer/readme.txt: -------------------------------------------------------------------------------- 1 | Installation for .NET Core 2.1+: 2 | 3 | dotnet build 4 | 5 | dotnet tool install --add-source nupkg -g dotnetprojectorderer 6 | 7 | Usage examples: 8 | 9 | dotnetprojectorderer - return projects in topological sort order relative to their dependencies. 10 | 11 | dotnetprojectorderer - return projects in topological sort order relative to their dependencies in . -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Conversion/Upcast/UpcastResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class UpcastResultPlainExtensions 6 | { 7 | [Pure] 8 | public static Result Upcast(this IResult result) 9 | { 10 | return result.Match(Result.Fail, Result.Succeed); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Conversion/Upcast/UpcastOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class UpcastOptionalExtensions 6 | { 7 | [Pure] 8 | public static Optional Upcast(this IOptional optional) 9 | { 10 | return optional.Match(Optional.None, Optional.Some); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/IntConstantProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 4 | { 5 | internal class IntConstantProvider : IConstantProvider 6 | { 7 | public string GetError() => this.GetValue().ToString(CultureInfo.InvariantCulture); 8 | 9 | public int GetValue() => 9999; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/module.yaml: -------------------------------------------------------------------------------- 1 | notests *default: 2 | build: 3 | target: {{ProjectName}}.sln 4 | configuration: NoTests 5 | tool: 6 | name: dotnet 7 | 8 | install: 9 | - {{ProjectName}}/bin/Release/netstandard2.0/{{ProjectName}}.dll 10 | 11 | deps: 12 | - vostok.devtools 13 | 14 | full-build > notests: 15 | build: 16 | target: {{ProjectName}}.sln 17 | configuration: Release -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrDefault/Fault/GetFaultOrDefaultResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetFaultOrDefaultResultPlainExtensions 6 | { 7 | [Pure] 8 | public static TFault? GetFaultOrDefault(this IResult result) 9 | { 10 | return result.GetFaultOrElse(default(TFault)); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrDefault/Value/GetValueOrDefaultOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetValueOrDefaultOptionalExtensions 6 | { 7 | [Pure] 8 | public static TValue? GetValueOrDefault(this IOptional optional) 9 | { 10 | return optional.GetValueOrElse(default(TValue)); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Containers/ResultValue/IContainer.TFault.TValue.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results.Containers.ResultValue 5 | { 6 | internal interface IContainer 7 | { 8 | [Pure] 9 | bool TryGet( 10 | [MaybeNullWhen(false)] out TValue value, 11 | [MaybeNullWhen(true)] out TFault fault); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/FailureConstantFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 4 | { 5 | internal class FailureConstantFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(TValue value, IConstantProvider provider) => Result.Fail("in the end"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vostok.devtools/dotnetversionsuffix/readme.txt: -------------------------------------------------------------------------------- 1 | Installation for .NET Core 2.1+: 2 | 3 | dotnet build 4 | 5 | dotnet tool install --add-source nupkg -g dotnetversionsuffix 6 | 7 | Usage example: 8 | 9 | dotnetversionsuffix pre0000001 - sets given version suffix for all projects included in current directory's solutions. 10 | 11 | dotnetversionsuffix pre0000001 vostok.devtools - sets given version suffix for all projects included in given directory's solutions. -------------------------------------------------------------------------------- /vostok.devtools/tcs-create-options/readme.txt: -------------------------------------------------------------------------------- 1 | Installation for .NET Core 2.1+: 2 | 3 | dotnet build -c Release 4 | 5 | dotnet tool install --add-source nupkg -g tcscreateoptions 6 | 7 | Usage example: 8 | 9 | tcscreateoptions 10 | Recursively scans all *.cs files in given and prints any 'TaskCompletionSource' creations 11 | without configured 'TaskCreationOptions'. Fails in the end if any incorrect creations were found. 12 | 13 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/AccessModifierFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp; 4 | 5 | namespace Kontur.Results.SourceGenerator.Code 6 | { 7 | internal static class AccessModifierFactory 8 | { 9 | internal static SyntaxToken[] Create(params SyntaxKind[] tokens) 10 | { 11 | return tokens.Select(SyntaxFactory.Token).ToArray(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/SuccessVariableFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 4 | { 5 | internal class SuccessVariableFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(TValue value, IConstantProvider provider) 8 | => Result.Succeed(value); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/StringFaultResult.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Inheritance 2 | { 3 | public static class StringFaultResult 4 | { 5 | public static StringFaultResult Fail(StringFault fault) 6 | { 7 | return new(fault); 8 | } 9 | 10 | public static StringFaultResult Succeed(TValue value) 11 | { 12 | return new(value); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Instantiation/Plain/Create_Via_Non_Generic/Common.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Instantiation.Plain.Create_Via_Non_Generic 5 | { 6 | internal static class Common 7 | { 8 | internal static TestCaseData CreateSuccessCase(Result result, bool success) 9 | { 10 | return new(result) { ExpectedResult = success }; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vostok.devtools/library-ci/github_ci.yml: -------------------------------------------------------------------------------- 1 | name: Build & Test & Publish 2 | 3 | on: [push, workflow_dispatch] 4 | 5 | jobs: 6 | build: 7 | uses: vostok/github.ci/.github/workflows/build.yml@master 8 | 9 | test: 10 | needs: build 11 | uses: vostok/github.ci/.github/workflows/test.yml@master 12 | 13 | publish: 14 | needs: test 15 | uses: vostok/github.ci/.github/workflows/publish.yml@master 16 | secrets: 17 | token: ${{ secrets.NUGET_TOKEN }} -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrDefault/Fault/GetFaultOrDefaultResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetFaultOrDefaultResultValueExtensions 6 | { 7 | [Pure] 8 | public static TFault? GetFaultOrDefault(this IResult result) 9 | { 10 | return result.GetFaultOrElse(default(TFault)); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrDefault/Value/GetValueOrDefaultResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetValueOrDefaultResultValueExtensions 6 | { 7 | [Pure] 8 | public static TValue? GetValueOrDefault(this IResult result) 9 | { 10 | return result.GetValueOrElse(default(TValue)); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/ClassNamesPassExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal static class ClassNamesPassExtensions 7 | { 8 | internal static IdentifierNameSyntax PassNameSyntax(this ClassNamesPass classNames) 9 | { 10 | return SyntaxFactory.IdentifierName(classNames.Pass); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/FailureVariableFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 4 | { 5 | internal class FailureVariableFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(TValue value, IConstantProvider provider) => 8 | Result.Fail(provider.GetError()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Conversion/Upcast/UpcastResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class UpcastResultValueExtensions 6 | { 7 | [Pure] 8 | public static Result Upcast(this IResult result) 9 | { 10 | return result.Match(Result.Fail, Result.Succeed); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/SuccessConstantFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 4 | { 5 | internal class SuccessConstantFixtureCase : IFixtureCase 6 | { 7 | public Result GetResult(TValue value, IConstantProvider provider) 8 | => Result.Succeed(provider.GetValue()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Instantiation/Optional/Create_Via_Non_Generic/Common.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Instantiation.Optional.Create_Via_Non_Generic 5 | { 6 | internal static class Common 7 | { 8 | internal static TestCaseData CreateHasValueCase(Optional optional, bool hasValue) 9 | { 10 | return new(optional) { ExpectedResult = hasValue }; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Instantiation/TValue/Create_Via_Non_Generic/Common.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Instantiation.TValue.Create_Via_Non_Generic 5 | { 6 | internal static class Common 7 | { 8 | internal static TestCaseData CreateHasValueCase(Result result, bool success) 9 | { 10 | return new(result) { ExpectedResult = success }; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/UpcastPlainExample.TResult.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results 4 | { 5 | internal class UpcastPlainExample 6 | { 7 | internal UpcastPlainExample(Result source, TResult result) 8 | { 9 | this.Source = source; 10 | this.Result = result; 11 | } 12 | 13 | internal Result Source { get; } 14 | 15 | internal TResult Result { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vostok.devtools/dotnetprojectrefs/readme.txt: -------------------------------------------------------------------------------- 1 | Installation for .NET Core 2.1+: 2 | 3 | dotnet build 4 | 5 | dotnet tool install --add-source nupkg -g dotnetprojectrefs 6 | 7 | Usage examples: 8 | 9 | dotnetprojectrefs - converts project references to nuget package references (with same version) for all solutions in current directory. 10 | 11 | dotnetprojectrefs - converts project references to nuget package references (with same version) for all solutions in . -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/Enumerator/GetEnumeratorOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results 5 | { 6 | public static class GetEnumeratorOptionalExtensions 7 | { 8 | [Pure] 9 | public static IEnumerator GetEnumerator(this IOptional optional) 10 | { 11 | return optional.GetValues().GetEnumerator(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrNull/Fault/GetFaultOrNullResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetFaultOrNullResultPlainExtensions 6 | { 7 | [Pure] 8 | public static TFault? GetFaultOrNull(this IResult result) 9 | where TFault : struct 10 | { 11 | return result.Match(fault => fault, () => null); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrNull/Value/GetValueOrNullOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetValueOrNullOptionalExtensions 6 | { 7 | [Pure] 8 | public static TValue? GetValueOrNull(this IOptional optional) 9 | where TValue : struct 10 | { 11 | return optional.Match(() => null, value => value); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/LibraryNamespace/GetValueOrThrowOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using JetBrains.Annotations; 2 | using Kontur.Results; 3 | 4 | namespace Kontur.Tests.Results.LibraryNamespace 5 | { 6 | internal static class GetValueOrThrowOptionalExtensions 7 | { 8 | [Pure] 9 | public static CustomValue GetValueOrThrow(this IOptional optional) 10 | { 11 | return optional.GetValueOrThrow(LibraryException.Instance); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Public/MethodType3.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Public 5 | { 6 | internal record MethodType3( 7 | SimpleNameSyntax Parameter1, 8 | SimpleNameSyntax ParameterNext, 9 | bool ParameterNextIsTask, 10 | SimpleNameSyntax Parameter2, 11 | IEnumerable GenericArguments, 12 | TypeSyntax ReturnType); 13 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/UpcastExample.TValue.TResult.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Inheritance 2 | { 3 | internal class UpcastExample 4 | { 5 | internal UpcastExample(StringFaultResult source, TResult result) 6 | { 7 | this.Source = source; 8 | this.Result = result; 9 | } 10 | 11 | internal StringFaultResult Source { get; } 12 | 13 | internal TResult Result { get; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/UpcastOptionalExample.TResult.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results 4 | { 5 | internal class UpcastOptionalExample 6 | { 7 | internal UpcastOptionalExample(Optional optional, TResult result) 8 | { 9 | this.Optional = optional; 10 | this.Result = result; 11 | } 12 | 13 | internal Optional Optional { get; } 14 | 15 | internal TResult Result { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/Enumerator/GetEnumeratorResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results 5 | { 6 | public static class GetEnumeratorResultValueExtensions 7 | { 8 | [Pure] 9 | public static IEnumerator GetEnumerator(this IResult result) 10 | { 11 | return result.GetValues().GetEnumerator(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrNull/Fault/GetFaultOrNullResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetFaultOrNullResultValueExtensions 6 | { 7 | [Pure] 8 | public static TFault? GetFaultOrNull(this IResult result) 9 | where TFault : struct 10 | { 11 | return result.Match(fault => fault, () => null); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrNull/Value/GetValueOrNullResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class GetValueOrNullResultValueExtensions 6 | { 7 | [Pure] 8 | public static TValue? GetValueOrNull(this IResult result) 9 | where TValue : struct 10 | { 11 | return result.Match(() => null, value => value); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Optional/Some.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | internal sealed class Some : Optional 6 | { 7 | private readonly TValue value; 8 | 9 | internal Some(TValue value) 10 | { 11 | this.value = value; 12 | } 13 | 14 | public override TResult Match(Func onNone, Func onSome) 15 | { 16 | return onSome(this.value); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/Faults/GetFaultsResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.Contracts; 3 | using System.Linq; 4 | 5 | namespace Kontur.Results 6 | { 7 | public static class GetFaultsResultPlainExtensions 8 | { 9 | [Pure] 10 | public static IEnumerable GetFaults(this IResult result) 11 | { 12 | return result.Match(fault => new[] { fault }, Enumerable.Empty); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/Values/GetValuesOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.Contracts; 3 | using System.Linq; 4 | 5 | namespace Kontur.Results 6 | { 7 | public static class GetValuesOptionalExtensions 8 | { 9 | [Pure] 10 | public static IEnumerable GetValues(this IOptional optional) 11 | { 12 | return optional.Match(Enumerable.Empty, value => new[] { value }); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/Optional/SelectCaseToTestCasesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.Optional 5 | { 6 | internal static class SelectCaseToTestCasesExtensions 7 | { 8 | internal static IEnumerable ToTestCases(this IEnumerable cases) 9 | { 10 | return cases.ToTestCases(option => option); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build & Test & Publish 2 | 3 | on: [push, pull_request, workflow_dispatch] 4 | 5 | jobs: 6 | build: 7 | uses: vostok/github.ci/.github/workflows/build.yml@master 8 | 9 | test: 10 | needs: build 11 | uses: vostok/github.ci/.github/workflows/test.yml@master 12 | 13 | publish: 14 | needs: test 15 | uses: vostok/github.ci/.github/workflows/publish.yml@master 16 | secrets: 17 | token: $\{{ secrets.NUGET_TOKEN }} -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build & Test & Publish 2 | 3 | on: [push, pull_request, workflow_dispatch] 4 | 5 | jobs: 6 | build: 7 | uses: vostok/github.ci/.github/workflows/build.yml@master 8 | 9 | test: 10 | needs: build 11 | uses: vostok/github.ci/.github/workflows/test.yml@master 12 | 13 | publish: 14 | needs: test 15 | uses: vostok/github.ci/.github/workflows/publish.yml@master 16 | secrets: 17 | token: $\{{ secrets.NUGET_TOKEN }} -------------------------------------------------------------------------------- /Kontur.Tests.Results/UpcastTValueExample.TFault.TValue.TResult.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | 3 | namespace Kontur.Tests.Results 4 | { 5 | internal class UpcastTValueExample 6 | { 7 | internal UpcastTValueExample(Result source, TResult result) 8 | { 9 | this.Source = source; 10 | this.Result = result; 11 | } 12 | 13 | internal Result Source { get; } 14 | 15 | internal TResult Result { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/module.yaml: -------------------------------------------------------------------------------- 1 | src: 2 | build: 3 | target: None 4 | configuration: None 5 | 6 | notests *default: 7 | build: 8 | target: {{ProjectName}}.sln 9 | configuration: NoTests 10 | tool: 11 | name: dotnet 12 | 13 | install: 14 | - {{ProjectName}}/bin/Release/netstandard2.0/{{ProjectName}}.dll 15 | 16 | deps: 17 | - vostok.devtools 18 | 19 | full-build > notests: 20 | build: 21 | target: {{ProjectName}}.sln 22 | configuration: Release 23 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/TaskLikeTypeSyntaxFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal static class TaskLikeTypeSyntaxFactory 7 | { 8 | internal static IEnumerable Create(TypeSyntax argument) 9 | { 10 | yield return TypeFactory.CreateTask(argument); 11 | yield return TypeFactory.CreateValueTask(argument); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/Values/GetValuesResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.Contracts; 3 | using System.Linq; 4 | 5 | namespace Kontur.Results 6 | { 7 | public static class GetValuesResultValueExtensions 8 | { 9 | [Pure] 10 | public static IEnumerable GetValues(this IResult result) 11 | { 12 | return result.Match(Enumerable.Empty, value => new[] { value }); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/Faults/GetFaultsResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics.Contracts; 3 | using System.Linq; 4 | 5 | namespace Kontur.Results 6 | { 7 | public static class GetFaultsResultValueExtensions 8 | { 9 | [Pure] 10 | public static IEnumerable GetFaults(this IResult result) 11 | { 12 | return result.Match(fault => new[] { fault }, Enumerable.Empty); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad/launchpad-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "NugetSources": [ 3 | "https://api.nuget.org/v3/index.json" 4 | ], 5 | "Definitions": [ 6 | { 7 | "Name": "vostok-library", 8 | "PackageName": "Vostok.Launchpad.Templates.Library" 9 | }, 10 | { 11 | "Name": "vostok-source-library", 12 | "PackageName": "Vostok.Launchpad.Templates.SourceLibrary" 13 | }, 14 | { 15 | "Name": "vostok-legacy-library", 16 | "PackageName": "Vostok.Launchpad.Templates.LegacyLibrary" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/IMethodBodyFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp.Syntax; 4 | 5 | namespace Kontur.Results.SourceGenerator.Code 6 | { 7 | internal interface IMethodBodyFactory 8 | { 9 | BlockSyntax CreateDelegateToOtherClass( 10 | SyntaxToken methodName, 11 | SimpleNameSyntax delegateClassName, 12 | IEnumerable genericArguments, 13 | IEnumerable arguments); 14 | } 15 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/SelfParameter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal class SelfParameter 7 | { 8 | internal SelfParameter(string name) 9 | { 10 | this.Name = SyntaxFactory.Identifier(name); 11 | this.TaskName = SyntaxFactory.Identifier(name + "Task"); 12 | } 13 | 14 | public SyntaxToken Name { get; } 15 | 16 | public SyntaxToken TaskName { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Containers/Plain/FilledContainer.T.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results.Containers.Plain 4 | { 5 | internal sealed class FilledContainer : IContainer 6 | { 7 | private readonly T stored; 8 | 9 | internal FilledContainer(T data) 10 | { 11 | this.stored = data; 12 | } 13 | 14 | [Pure] 15 | public bool TryGet(out T data) 16 | { 17 | data = this.stored; 18 | return true; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Optional/None.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | internal sealed class None : Optional 6 | { 7 | private static readonly Lazy> Provider = new(() => new()); 8 | 9 | private None() 10 | { 11 | } 12 | 13 | internal static Optional Instance => Provider.Value; 14 | 15 | public override TResult Match(Func onNone, Func onSome) 16 | { 17 | return onNone(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/ResultFailure.TFault.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | internal sealed class ResultFailure : Result 6 | { 7 | private readonly TFault fault; 8 | 9 | internal ResultFailure(TFault fault) 10 | { 11 | this.fault = fault; 12 | } 13 | 14 | public override TResult Match(Func onFailure, Func onSuccess) 15 | { 16 | return onFailure(this.fault); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/ResultSuccess.TFault.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | internal sealed class ResultSuccess : Result 6 | { 7 | private readonly TValue value; 8 | 9 | internal ResultSuccess(TValue value) 10 | { 11 | this.value = value; 12 | } 13 | 14 | public override TResult Match(Func onFailure, Func onSuccess) 15 | { 16 | return onSuccess(this.value); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code 4 | { 5 | internal static class EnumerableExtensions 6 | { 7 | internal static IEnumerable WhereNotNull(this IEnumerable source) 8 | { 9 | foreach (var element in source) 10 | { 11 | if (element != null) 12 | { 13 | yield return element; 14 | } 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/ITypeParameterGenericMethodSyntaxGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal interface ITypeParameterGenericMethodSyntaxGenerator 7 | { 8 | IEnumerable CreateTypeParameterConstraints(IEnumerable genericParameters); 9 | 10 | CompilationUnitSyntax FixMethodTypeParameterIndentation(CompilationUnitSyntax compilationUnit); 11 | } 12 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/OnSuccess/OnSomeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class OnSomeExtensions 6 | { 7 | public static Optional OnSome(this IOptional optional, Action action) 8 | { 9 | return optional.Switch(() => { }, action); 10 | } 11 | 12 | public static Optional OnSome(this IOptional optional, Action action) 13 | { 14 | return optional.OnSome(_ => action()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/README.md: -------------------------------------------------------------------------------- 1 | # {{ProjectName}} 2 | 3 | [![Build & Test & Publish](https://github.com/vostok/{{RepositoryName}}/actions/workflows/ci.yml/badge.svg)](https://github.com/vostok/{{RepositoryName}}/actions/workflows/ci.yml) 4 | [![NuGet](https://img.shields.io/nuget/v/{{ProjectName}}.svg)](https://www.nuget.org/packages/{{ProjectName}}) 5 | 6 | {{OneLineDescription}} 7 | 8 | 9 | **Build guide**: https://github.com/vostok/devtools/blob/master/library-dev-conventions/how-to-build-a-library.md 10 | 11 | **User documentation**: not written yet. -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/README.md: -------------------------------------------------------------------------------- 1 | # {{ProjectName}} 2 | 3 | [![Build & Test & Publish](https://github.com/vostok/{{RepositoryName}}/actions/workflows/ci.yml/badge.svg)](https://github.com/vostok/{{RepositoryName}}/actions/workflows/ci.yml) 4 | [![NuGet](https://img.shields.io/nuget/v/{{ProjectName}}.svg)](https://www.nuget.org/packages/{{ProjectName}}) 5 | 6 | {{OneLineDescription}} 7 | 8 | 9 | **Build guide**: https://github.com/vostok/devtools/blob/master/library-dev-conventions/how-to-build-a-library.md 10 | 11 | **User documentation**: not written yet. -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/IdentifierExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | 3 | namespace Kontur.Results.SourceGenerator.Code 4 | { 5 | internal static class IdentifierExtensions 6 | { 7 | internal static bool IsValueTask(this SyntaxToken identifier) 8 | { 9 | return identifier.IsEquivalentTo(Identifiers.ValueTaskIdentifier); 10 | } 11 | 12 | internal static bool IsTask(this SyntaxToken identifier) 13 | { 14 | return identifier.IsEquivalentTo(Identifiers.TaskIdentifier); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/IResult.TFault.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace Kontur.Results 5 | { 6 | [EditorBrowsable(EditorBrowsableState.Never)] 7 | public interface IResult 8 | { 9 | internal TResult Match(Func onFailure, Func onSuccess); 10 | 11 | internal TResult Match(Func onFailure, Func onSuccess); 12 | 13 | internal TResult Match(Func onFailure, Func onSuccess); 14 | } 15 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/OnFailure/OnFailureResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class OnFailureResultPlainExtensions 6 | { 7 | public static Result OnFailure(this IResult result, Action action) 8 | { 9 | return result.Switch(action, () => { }); 10 | } 11 | 12 | public static Result OnFailure(this IResult result, Action action) 13 | { 14 | return result.OnFailure(_ => action()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValue/SelectCaseToTestCasesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Kontur.Tests.Results.Conversion.Combinations.Linq.Result.SelectCaseGenerators; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValue 6 | { 7 | internal static class SelectCaseToTestCasesExtensions 8 | { 9 | internal static IEnumerable ToTestCases(this IEnumerable cases) 10 | { 11 | return cases.ToTestCases(result => result); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vostok.devtools/vostok-release/readme.txt: -------------------------------------------------------------------------------- 1 | Installation for .NET Core 2.1+: 2 | - Windows: `install` 3 | - Non-windows: `./install.sh` 4 | 5 | Usage: 6 | 7 | 1. Update `CHANGELOG.md`: describe the changes you've made in the current release (see VersionPrefix in .csproj) 8 | 2. Run `vostok-release` in solution directory. It will do several things: 9 | * new tag with current release version will be created and pushed, 10 | * VersionPrefix in csproj will be incremented, Unshipped file rolled to Shipped, commited and pushed, 11 | * new package will be built and pushed to NuGet from GitHub Actions CI 12 | -------------------------------------------------------------------------------- /vostok.devtools/library-common-props/Main-Project-new.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | enable 7 | latest 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/ResultSuccess.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | internal sealed class ResultSuccess : Result 6 | { 7 | private static readonly Lazy> Provider = new(() => new()); 8 | 9 | private ResultSuccess() 10 | { 11 | } 12 | 13 | internal static Result Instance => Provider.Value; 14 | 15 | public override TResult Match(Func onFailure, Func onSuccess) 16 | { 17 | return onSuccess(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/LinqTestBase.TFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue 5 | { 6 | internal abstract class LinqTestBase : LinqTestBase 7 | where TFixtureCase : IFixtureCase, new() 8 | { 9 | protected static IEnumerable CreateSelectCases(int argumentsCount) 10 | { 11 | return CreateSelectCases(argumentsCount, x => x); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/LinqTestBase.ITestFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional 5 | { 6 | internal abstract class LinqTestBase : LinqTestBase 7 | where TFixtureCase : IFixtureCase, new() 8 | { 9 | protected static IEnumerable CreateSelectCases(int argumentsCount) 10 | { 11 | return CreateSelectCases(argumentsCount, x => x); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vostok.devtools/module.yaml: -------------------------------------------------------------------------------- 1 | src: 2 | build: 3 | target: None 4 | configuration: None 5 | 6 | full-build: 7 | deps: 8 | - vostok.devtools.ilrepack.bin 9 | build: 10 | target: None 11 | configuration: None 12 | 13 | dotnetcementrefs: 14 | build: 15 | - name: Build 16 | tool: dotnet 17 | parameters: build 18 | target: dotnetcementrefs\dotnetcementrefs.sln 19 | configuration: Release 20 | - name: Install global tool 21 | tool: dotnet 22 | parameters: tool update --add-source dotnetcementrefs\nupkg -g dotnetcementrefs -- 23 | target: plz_fix_none 24 | configuration: None -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Optional/Optional.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class Optional 6 | { 7 | [Pure] 8 | public static NoneMarker None() 9 | { 10 | return default; 11 | } 12 | 13 | [Pure] 14 | public static Optional None() 15 | { 16 | return Optional.None(); 17 | } 18 | 19 | [Pure] 20 | public static Optional Some(TValue value) 21 | { 22 | return Optional.Some(value); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /vostok.devtools/dotnetcementrefs/dotnetcementrefs.sln.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | True -------------------------------------------------------------------------------- /.build_nuget.bat: -------------------------------------------------------------------------------- 1 | cd .\vostok.devtools\dotnetcementrefs 2 | dotnet build -c Release 3 | dotnet tool update --add-source nupkg -g dotnetcementrefs 4 | 5 | cd %~dp0 6 | dotnetcementrefs --source:https://api.nuget.org/v3/index.json --refPrefix:Kontur --ignoreMissingPackages --allowLocalProjects 7 | 8 | dotnet pack Kontur.Results\Kontur.Results.csproj 9 | dotnet nuget push .\Kontur.Results\bin\Release\*.nupkg --api-key %nugetapikey% --source https://api.nuget.org/v3/index.json 10 | 11 | dotnet pack Kontur.Results.Monad\Kontur.Results.Monad.csproj 12 | dotnet nuget push .\Kontur.Results.Monad\bin\Release\*.nupkg --api-key %nugetapikey% --source https://api.nuget.org/v3/index.json -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-source/template/{{ProjectName}}.Tests/{{ProjectName}}.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /vostok.devtools/git-commit-to-assembly-title/Vostok.Tools.GitCommit2AssemblyTitle.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | bin\ 6 | obj\ 7 | NETSDK1138 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/library-ordinary/template/{{ProjectName}}.Tests/{{ProjectName}}.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/Methods/MethodsDescriptionProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code.Methods 5 | { 6 | internal class MethodsDescriptionProvider 7 | { 8 | private readonly IEnumerable providers; 9 | 10 | public MethodsDescriptionProvider(IEnumerable providers) 11 | { 12 | this.providers = providers; 13 | } 14 | 15 | internal IEnumerable Get() 16 | { 17 | return this.providers.Select(provider => provider.Get()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/ResultFailure.T.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public sealed class ResultFailure : Result 6 | { 7 | internal ResultFailure(T fault) 8 | { 9 | this.Fault = fault; 10 | } 11 | 12 | internal T Fault { get; } 13 | 14 | public static Result Create(TFault fault) 15 | { 16 | return Result.Fail(fault); 17 | } 18 | 19 | public override TResult Match(Func onFailure, Func onSuccess) 20 | { 21 | return onFailure(this.Fault); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /vostok.devtools/launchpad/src/LaunchpadSpecProvider.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Newtonsoft.Json; 3 | 4 | namespace launchpad 5 | { 6 | internal class LaunchpadSpecProvider 7 | { 8 | private const string FileName = "launchpad.json"; 9 | 10 | public LaunchpadSpec ProvideFrom(string directory) 11 | { 12 | var specContent = File.ReadAllText(Path.Combine(directory, FileName)); 13 | 14 | return JsonConvert.DeserializeObject(specContent); 15 | } 16 | 17 | public void CleanupIn(string directory) 18 | { 19 | File.Delete(Path.Combine(directory, FileName)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/ClassNamesFactoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.CSharp; 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal static class ClassNamesFactoryExtensions 7 | { 8 | internal static IdentifierNameSyntax FactoryNameSyntax(this ClassNamesFactory classNames) 9 | { 10 | return SyntaxFactory.IdentifierName(classNames.Factory); 11 | } 12 | 13 | internal static IdentifierNameSyntax ValueNameSyntax(this ClassNamesFactory classNames) 14 | { 15 | return SyntaxFactory.IdentifierName(classNames.Value); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/ParameterNames.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp; 3 | 4 | namespace Kontur.Results.SourceGenerator.Code 5 | { 6 | internal class ParameterNames 7 | { 8 | private readonly string other; 9 | 10 | internal ParameterNames(SelfParameter self, string other) 11 | { 12 | this.other = other; 13 | this.Self = self; 14 | } 15 | 16 | internal SelfParameter Self { get; } 17 | 18 | internal SyntaxToken Value => SyntaxFactory.Identifier(this.other); 19 | 20 | internal SyntaxToken Factory => SyntaxFactory.Identifier(this.other + "Factory"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrElse/Value/GetValueOrElseOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results 5 | { 6 | public static class GetValueOrElseOptionalExtensions 7 | { 8 | public static TValue GetValueOrElse(this IOptional optional, Func onNoneValueFactory) 9 | { 10 | return optional.Match(onNoneValueFactory, value => value); 11 | } 12 | 13 | [Pure] 14 | public static TValue GetValueOrElse(this IOptional optional, TValue onNoneValue) 15 | { 16 | return optional.GetValueOrElse(() => onNoneValue); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Get/OrElse/Fault/GetFaultOrElseResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results 5 | { 6 | public static class GetFaultOrElseResultPlainExtensions 7 | { 8 | public static TFault GetFaultOrElse(this IResult result, Func onSuccessValueFactory) 9 | { 10 | return result.Match(fault => fault, onSuccessValueFactory); 11 | } 12 | 13 | [Pure] 14 | public static TFault GetFaultOrElse(this IResult result, TFault onSuccessValue) 15 | { 16 | return result.GetFaultOrElse(() => onSuccessValue); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/OnFailure/OnFailureResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class OnFailureResultValueExtensions 6 | { 7 | public static Result OnFailure( 8 | this IResult result, 9 | Action action) 10 | { 11 | return result.Switch(action, () => { }); 12 | } 13 | 14 | public static Result OnFailure( 15 | this IResult result, 16 | Action action) 17 | { 18 | return result.OnFailure(_ => action()); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/OnSuccess/OnSuccessResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class OnSuccessResultValueExtensions 6 | { 7 | public static Result OnSuccess( 8 | this IResult result, 9 | Action action) 10 | { 11 | return result.Switch(() => { }, action); 12 | } 13 | 14 | public static Result OnSuccess( 15 | this IResult result, 16 | Action action) 17 | { 18 | return result.OnSuccess(_ => action()); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Containers/Plain/EmptyContainer.T.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Diagnostics.Contracts; 4 | 5 | namespace Kontur.Results.Containers.Plain 6 | { 7 | internal sealed class EmptyContainer : IContainer 8 | { 9 | private static readonly Lazy> Provider = new(() => new()); 10 | 11 | private EmptyContainer() 12 | { 13 | } 14 | 15 | internal static IContainer Instance => Provider.Value; 16 | 17 | [Pure] 18 | public bool TryGet([MaybeNullWhen(false)] out T data) 19 | { 20 | data = default; 21 | return false; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Upcast/Plain_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Upcast 7 | { 8 | [TestFixture] 9 | internal class Plain_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastPlainExamples 13 | .Get() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(Result result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/Optional/Where/WhereCaseGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.Optional.Where 6 | { 7 | internal static class WhereCaseGenerator 8 | { 9 | internal static IEnumerable Create(int argumentsCount) 10 | { 11 | return SelectCasesGenerator.Create(argumentsCount).SelectMany(CreateCases); 12 | } 13 | 14 | private static IEnumerable CreateCases(SelectCase testCase) 15 | { 16 | return WhereCaseFactory.Create(testCase.Args, testCase.Result); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Upcast/Optional_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Upcast 7 | { 8 | [TestFixture] 9 | internal class Optional_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastOptionalExamples 13 | .Get() 14 | .Select(example => new TestCaseData(example.Optional).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Optional Process_Optional(Optional optional) 18 | { 19 | return optional.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Equality/Plain/GetHashCode_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Equality.Plain 7 | { 8 | [TestFixture] 9 | internal class GetHashCode_Should 10 | { 11 | public static readonly IEnumerable Cases = Common.CreateEqualsCases(); 12 | 13 | [TestCaseSource(nameof(Cases))] 14 | public void Calculate(Result result1, Result result2) 15 | { 16 | var hashCode1 = result1.GetHashCode(); 17 | var hashCode2 = result2.GetHashCode(); 18 | 19 | hashCode1.Should().Be(hashCode2); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Failure/Plain/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Failure.Plain 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultSucceedException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_Success() 15 | { 16 | var result = Result.Succeed(); 17 | 18 | Action action = () => result.EnsureFailure(); 19 | 20 | action.Should().Throw(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrThrow/Optional/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrThrow.Optional 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ValueMissingException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_None() 15 | { 16 | var option = Optional.None(); 17 | 18 | Func action = () => option.GetValueOrThrow(); 19 | 20 | action.Should().Throw(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrThrow/Plain/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrThrow.Plain 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultSucceedException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_Success() 15 | { 16 | var result = Result.Succeed(); 17 | 18 | Func action = () => result.GetFaultOrThrow(); 19 | 20 | action.Should().Throw(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Success/HasValue/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Success.HasValue 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ValueMissingException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_None() 15 | { 16 | var option = Optional.None(); 17 | 18 | Action action = () => option.EnsureHasValue(); 19 | 20 | action.Should().Throw(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Equality/GetHashCode_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using FluentAssertions; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Inheritance.Equality 6 | { 7 | [TestFixture] 8 | internal class GetHashCode_Should 9 | { 10 | public static readonly IEnumerable Cases = Common.CreateEqualsCases(); 11 | 12 | [TestCaseSource(nameof(Cases))] 13 | public void Calculate(StringFaultResult result1, StringFaultResult result2) 14 | { 15 | var hashCode1 = result1.GetHashCode(); 16 | var hashCode2 = result2.GetHashCode(); 17 | 18 | hashCode1.Should().Be(hashCode2); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Upcast/TValue/Both_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Upcast.TValue 7 | { 8 | [TestFixture] 9 | internal class Both_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastTValueExamples 13 | .GetBoth() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(Result result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Equality/Optional/GetHashCode_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Equality.Optional 7 | { 8 | [TestFixture] 9 | internal class GetHashCode_Should 10 | { 11 | public static readonly IEnumerable Cases = Common.CreateEqualsCases(); 12 | 13 | [TestCaseSource(nameof(Cases))] 14 | public void Calculate(Optional optional1, Optional optional2) 15 | { 16 | var hashCode1 = optional1.GetHashCode(); 17 | var hashCode2 = optional2.GetHashCode(); 18 | 19 | hashCode1.Should().Be(hashCode2); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/UpcastOptionalExamples.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Kontur.Results; 4 | 5 | namespace Kontur.Tests.Results 6 | { 7 | internal static class UpcastOptionalExamples 8 | { 9 | internal static IEnumerable>> Get() 10 | => Get(Optional.None(), Optional.Some); 11 | 12 | internal static IEnumerable> Get(TResult noneResult, Func someResultFactory) 13 | { 14 | Child child = new(); 15 | yield return new(Optional.Some(child), someResultFactory(child)); 16 | yield return new(Optional.None(), noneResult); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Upcast/TValue/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Upcast.TValue 7 | { 8 | [TestFixture] 9 | internal class Fault_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastTValueExamples 13 | .GetFaults() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(Result result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Upcast/TValue/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Upcast.TValue 7 | { 8 | [TestFixture] 9 | internal class Value_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastTValueExamples 13 | .GetValues() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(Result result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vostok.devtools/dotnetcementrefs/FileUtilities.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace dotnetcementrefs; 4 | 5 | internal static class FileUtilities 6 | { 7 | public static string? GetDirectoryNameOfDirectoryAbove(string startingDirectory, string directoryName) 8 | { 9 | var lookInDirectory = Path.GetFullPath(startingDirectory); 10 | 11 | do 12 | { 13 | var possibleDirectory = Path.Combine(lookInDirectory, directoryName); 14 | 15 | if (Directory.Exists(possibleDirectory)) 16 | { 17 | return lookInDirectory; 18 | } 19 | 20 | lookInDirectory = Path.GetDirectoryName(lookInDirectory); 21 | } while (lookInDirectory != null); 22 | 23 | return null; 24 | } 25 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValuePlain/LinqTestBase.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValuePlain 5 | { 6 | [TestFixture(typeof(FailureVariableFixtureCase))] 7 | [TestFixture(typeof(FailureConstantFixtureCase))] 8 | [TestFixture(typeof(SuccessFixtureCase))] 9 | internal abstract class LinqTestBase 10 | where TFixtureCase : IFixtureCase, new() 11 | { 12 | private protected LinqTestBase() 13 | { 14 | } 15 | 16 | protected static readonly TFixtureCase FixtureCase = new(); 17 | 18 | protected static Result GetResult(int value) => FixtureCase.GetResult(value); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/StringFaultBase.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Tests.Results.Inheritance 2 | { 3 | public class StringFaultBase 4 | { 5 | public StringFaultBase(string fault) 6 | { 7 | this.Fault = fault; 8 | } 9 | 10 | public string Fault { get; } 11 | 12 | public sealed override string ToString() 13 | { 14 | return this.Fault; 15 | } 16 | 17 | public sealed override bool Equals(object? obj) 18 | { 19 | return obj is StringFaultBase other && Equals(this.Fault, other.Fault); 20 | } 21 | 22 | public sealed override int GetHashCode() 23 | { 24 | return (this.GetType(), this.Fault).GetHashCode(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Equality/TValue/GetHashCode_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Equality.TValue 7 | { 8 | [TestFixture] 9 | internal class GetHashCode_Should 10 | { 11 | public static readonly IEnumerable Cases = Common.CreateEqualsCases(); 12 | 13 | [TestCaseSource(nameof(Cases))] 14 | public void Calculate(Result result1, Result result2) 15 | { 16 | var hashCode1 = result1.GetHashCode(); 17 | var hashCode2 = result2.GetHashCode(); 18 | 19 | hashCode1.Should().Be(hashCode2); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/SelectMany/FirstFault/Optional/Using/SelectManyOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Kontur.Results; 5 | 6 | namespace Kontur.Tests.Results.Extraction.SelectMany.FirstFault.Optional.Using 7 | { 8 | public static class SelectManyOptionalExtensions 9 | { 10 | public static Optional> SelectMany( 11 | this IOptional optional, 12 | Func> collectionSelector, 13 | Func resultSelector) 14 | { 15 | return optional.MapValue(value => collectionSelector(value).Select(item => resultSelector(value, item))); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/SelectCaseToTestCasesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Kontur.Results; 5 | using NUnit.Framework; 6 | 7 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional 8 | { 9 | internal static class SelectCaseToTestCasesExtensions 10 | { 11 | internal static IEnumerable ToTestCases( 12 | this IEnumerable cases, 13 | Func, Optional> resultSelector) 14 | { 15 | return cases.Select( 16 | testCase => new TestCaseData(testCase.Args.Cast().ToArray()) 17 | .Returns(resultSelector(testCase.Result))); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Conversion/Upcast/Both_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Conversion.Upcast 7 | { 8 | [TestFixture] 9 | internal class Both_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastExamples 13 | .GetBoth() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(StringFaultResult result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Conversion/Upcast/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Conversion.Upcast 7 | { 8 | [TestFixture] 9 | internal class Value_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastExamples 13 | .GetValues() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(StringFaultResult result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Containers/ResultValue/FailureContainer.TFault.TValue.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results.Containers.ResultValue 5 | { 6 | internal sealed class FailureContainer : IContainer 7 | { 8 | private readonly TFault storedFault; 9 | 10 | internal FailureContainer(TFault fault) 11 | { 12 | this.storedFault = fault; 13 | } 14 | 15 | [Pure] 16 | public bool TryGet( 17 | [MaybeNullWhen(false)] out TValue value, 18 | out TFault fault) 19 | { 20 | fault = this.storedFault; 21 | value = default; 22 | return false; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Containers/ResultValue/SuccessContainer.TFault.TValue.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace Kontur.Results.Containers.ResultValue 5 | { 6 | internal sealed class SuccessContainer : IContainer 7 | { 8 | private readonly TValue storedValue; 9 | 10 | internal SuccessContainer(TValue value) 11 | { 12 | this.storedValue = value; 13 | } 14 | 15 | [Pure] 16 | public bool TryGet( 17 | out TValue value, 18 | [MaybeNullWhen(true)] out TFault fault) 19 | { 20 | fault = default; 21 | value = this.storedValue; 22 | return true; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Results/Implementation/Result/Result.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Contracts; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class Result 6 | { 7 | [Pure] 8 | public static ResultFailure Fail(TFault fault) 9 | { 10 | return new(fault); 11 | } 12 | 13 | [Pure] 14 | public static SuccessMarker Succeed() 15 | { 16 | return default; 17 | } 18 | 19 | [Pure] 20 | public static Result Succeed() 21 | { 22 | return Result.Succeed(); 23 | } 24 | 25 | [Pure] 26 | public static SuccessMarker Succeed(TValue value) 27 | { 28 | return new(value); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Failure/Plain_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Failure 5 | { 6 | [TestFixture] 7 | internal class Plain_Should 8 | { 9 | private static TestCaseData Create(Result result, bool failure) 10 | { 11 | return new(result) { ExpectedResult = failure }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | Create(Result.Succeed(), false), 17 | Create(Result.Fail(10), true), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Pass_Failure(Result result) 22 | { 23 | return result.Failure; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Success/Plain_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Success 5 | { 6 | [TestFixture] 7 | internal class Plain_Should 8 | { 9 | private static TestCaseData Create(Result result, bool success) 10 | { 11 | return new(result) { ExpectedResult = success }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | Create(Result.Succeed(), true), 17 | Create(Result.Fail(10), false), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Pass_Success(Result result) 22 | { 23 | return result.Success; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Instantiation/Plain/Implicit_Operator_Should.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Kontur.Results; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Instantiation.Plain 6 | { 7 | [TestFixture] 8 | internal class Implicit_Operator_Should 9 | { 10 | [Test] 11 | public void Create_Failure() 12 | { 13 | const int expected = 10; 14 | 15 | Result result = expected; 16 | 17 | var fault = result.GetFaultOrThrow(); 18 | fault.Should().Be(expected); 19 | } 20 | 21 | [Test] 22 | public void Create_Success() 23 | { 24 | Result result = Result.Succeed(); 25 | 26 | result.Success.Should().BeTrue(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/UpcastPlainExamples.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Kontur.Results; 4 | 5 | namespace Kontur.Tests.Results 6 | { 7 | internal static class UpcastPlainExamples 8 | { 9 | internal static IEnumerable>> Get() 10 | => Get(Result.Fail, Result.Succeed()); 11 | 12 | internal static IEnumerable> Get( 13 | Func failureResultFactory, 14 | TResult successResult) 15 | { 16 | Child child = new(); 17 | yield return new(Result.Fail(child), failureResultFactory(child)); 18 | yield return new(Result.Succeed(), successResult); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Conversion/Upcast/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Conversion.Upcast 7 | { 8 | [TestFixture] 9 | internal class Fault_Should 10 | { 11 | private static IEnumerable GetCases() => 12 | UpcastExamples 13 | .GetFaults() 14 | .Select(example => new TestCaseData(example.Source).Returns(example.Result)); 15 | 16 | [TestCaseSource(nameof(GetCases))] 17 | public Result Process_Result(StringFaultResult result) 18 | { 19 | return result.Upcast(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/StringFaultResult.TValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Kontur.Results; 3 | 4 | namespace Kontur.Tests.Results.Inheritance 5 | { 6 | public class StringFaultResult : Result 7 | { 8 | private readonly Result result; 9 | 10 | public StringFaultResult(StringFault fault) 11 | { 12 | this.result = Fail(fault); 13 | } 14 | 15 | public StringFaultResult(TValue value) 16 | { 17 | this.result = Succeed(value); 18 | } 19 | 20 | public override TResult Match(Func onFailure, Func onSuccess) 21 | { 22 | return this.result.Match(onFailure, onSuccess); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Failure/IsNone_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Failure 5 | { 6 | [TestFixture] 7 | internal class IsNone_Should 8 | { 9 | private static TestCaseData Create(Optional optional, bool isNone) 10 | { 11 | return new(optional) { ExpectedResult = isNone }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | Create(Optional.None(), true), 17 | Create(Optional.Some(10), false), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Pass_HasValue(Optional optional) 22 | { 23 | return optional.IsNone; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/SelectMany/FirstFault/TValue/Using/SelectManyResultValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Kontur.Results; 5 | 6 | namespace Kontur.Tests.Results.Extraction.SelectMany.FirstFault.TValue.Using 7 | { 8 | public static class SelectManyResultValueExtensions 9 | { 10 | public static Result> SelectMany( 11 | this IResult result, 12 | Func> collectionSelector, 13 | Func resultSelector) 14 | { 15 | return result.MapValue(value => collectionSelector(value).Select(item => resultSelector(value, item))); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kontur.Results.SourceGenerator.Shared/Code/ClassNamesFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Kontur.Results.SourceGenerator.Code 2 | { 3 | internal class ClassNamesFactory 4 | { 5 | private readonly string methodName; 6 | private readonly string parameterTypes; 7 | 8 | internal ClassNamesFactory(string methodName, string parameterTypes) 9 | { 10 | this.methodName = methodName; 11 | this.parameterTypes = parameterTypes; 12 | } 13 | 14 | internal string Value => this.Create(nameof(this.Value)); 15 | 16 | internal string Factory => this.Create(nameof(this.Factory)); 17 | 18 | protected string Create(string suffix) 19 | { 20 | return $"{this.methodName}{this.parameterTypes}{suffix}Internal"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Success/HasSome_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Success 5 | { 6 | [TestFixture] 7 | internal class HasSome_Should 8 | { 9 | private static TestCaseData Create(Optional optional, bool hasSome) 10 | { 11 | return new(optional) { ExpectedResult = hasSome }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | Create(Optional.None(), false), 17 | Create(Optional.Some(10), true), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Pass_HasValue(Optional optional) 22 | { 23 | return optional.HasSome; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrNull/Plain_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrNull 5 | { 6 | [TestFixture] 7 | internal class Plain_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int? fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(), null), 17 | CreateCase(Result.Fail(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int? Process_Result(Result result) 22 | { 23 | return result.GetFaultOrNull(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vostok.devtools/git-commit-to-assembly-title/readme.txt: -------------------------------------------------------------------------------- 1 | An msbuild task that dynamically creates an auxiliary file with following assembly attributes during build process: 2 | 3 | 1. AssemblyTitle with current git commit hash, author, branch name, commit and build dates. 4 | 5 | 2. AssemblyInformationalVersion with a short commit hash suffix appended to current version. 6 | 7 | 8 | To install it into any project, just include the .props file directly into .csproj: 9 | 10 | 11 | 12 | It may look like this in a project that resides in a subdirectory of its cement module: 13 | 14 | 15 | 16 | Then include AssemblyTitle.cs to module's .gitignore file. -------------------------------------------------------------------------------- /vostok.devtools/launchpad-templates/readme.md: -------------------------------------------------------------------------------- 1 | ## Launchpad templates 2 | 3 | A template is a NuGet package with following properties: 4 | 5 | * All of its contents are located in `contentFiles` folder of the package. 6 | * It can contain nested files and directories. 7 | * It can contain variable placeholders in file/directory names and content. 8 | * Variable placeholders should be enсlosed in double curly braces: `{{VariableName}}` 9 | * It should contain a special file called `launchpad.json` in the root directory of template. 10 | * This file is called a template spec and should be in JSON format. 11 | * It should contain definitions of all the variables used in template ([example](library-ordinary/template/launchpad.json)). 12 | 13 | See [Vostok library template](library-ordinary) for a working example. 14 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Instantiation/Optional/Implicit_Operator_Should.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Kontur.Results; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Instantiation.Optional 6 | { 7 | [TestFixture] 8 | internal class Implicit_Operator_Should 9 | { 10 | [Test] 11 | public void Create_Some() 12 | { 13 | const int expected = 10; 14 | 15 | Optional optional = expected; 16 | 17 | var result = optional.GetValueOrThrow(); 18 | result.Should().Be(expected); 19 | } 20 | 21 | [Test] 22 | public void Create_None() 23 | { 24 | Optional optional = Kontur.Results.Optional.None(); 25 | 26 | optional.HasSome.Should().BeFalse(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Ensure/Failure/EnsureFailureResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class EnsureFailureResultPlainExtensions 6 | { 7 | public static void EnsureFailure(this IResult result, Func exceptionFactory) 8 | { 9 | result.OnSuccess(() => throw exceptionFactory()); 10 | } 11 | 12 | public static void EnsureFailure(this IResult result, Exception exception) 13 | { 14 | result.EnsureFailure(() => exception); 15 | } 16 | 17 | public static void EnsureFailure(this IResult result) 18 | { 19 | result.EnsureFailure(() => new ResultSucceedException($"No fault in {result}")); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Ensure/Success/EnsureHasValueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class EnsureHasValueExtensions 6 | { 7 | public static void EnsureHasValue(this IOptional optional, Func exceptionFactory) 8 | { 9 | optional.OnNone(() => throw exceptionFactory()); 10 | } 11 | 12 | public static void EnsureHasValue(this IOptional optional, Exception exception) 13 | { 14 | optional.EnsureHasValue(() => exception); 15 | } 16 | 17 | public static void EnsureHasValue(this IOptional optional) 18 | { 19 | optional.EnsureHasValue(() => new ValueMissingException($"No value in {optional}")); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Failure_Should.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Kontur.Tests.Results.Inheritance.Extraction 4 | { 5 | [TestFixture] 6 | internal class Failure_Should 7 | { 8 | private static TestCaseData Create(StringFaultResult result, bool success) 9 | { 10 | return new(result) { ExpectedResult = success }; 11 | } 12 | 13 | private static readonly TestCaseData[] Cases = 14 | { 15 | Create(StringFaultResult.Succeed(10), false), 16 | Create(StringFaultResult.Fail(new("fail")), true), 17 | }; 18 | 19 | [TestCaseSource(nameof(Cases))] 20 | public bool Pass_Failure(StringFaultResult result) 21 | { 22 | return result.Failure; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Success_Should.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Kontur.Tests.Results.Inheritance.Extraction 4 | { 5 | [TestFixture] 6 | internal class Success_Should 7 | { 8 | private static TestCaseData Create(StringFaultResult result, bool success) 9 | { 10 | return new(result) { ExpectedResult = success }; 11 | } 12 | 13 | private static readonly TestCaseData[] Cases = 14 | { 15 | Create(StringFaultResult.Fail(new("fail")), false), 16 | Create(StringFaultResult.Succeed(10), true), 17 | }; 18 | 19 | [TestCaseSource(nameof(Cases))] 20 | public bool Pass_HasValue(StringFaultResult result) 21 | { 22 | return result.Success; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Failure/TValue_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Failure 5 | { 6 | [TestFixture] 7 | internal class TValue_Should 8 | { 9 | private static TestCaseData Create(Result result, bool success) 10 | { 11 | return new(result) { ExpectedResult = success }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | Create(Result.Succeed(10), false), 17 | Create(Result.Fail("fail"), true), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Pass_Failure(Result result) 22 | { 23 | return result.Failure; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrNull/Optional_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrNull 5 | { 6 | [TestFixture] 7 | internal class Optional_Should 8 | { 9 | private static TestCaseData CreateCase(Optional optional, int? result) 10 | { 11 | return new(optional) { ExpectedResult = result }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Optional.None(), null), 17 | CreateCase(Optional.Some(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int? Process_Optional(Optional optional) 22 | { 23 | return optional.GetValueOrNull(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Success/TValue_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Success 5 | { 6 | [TestFixture] 7 | internal class TValue_Should 8 | { 9 | private static TestCaseData Create(Result result, bool success) 10 | { 11 | return new(result) { ExpectedResult = success }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | Create(Result.Fail("fail"), false), 17 | Create(Result.Succeed(10), true), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Pass_HasValue(Result result) 22 | { 23 | return result.Success; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Failure/None/Standard_Exception_Contain_Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Failure.None 7 | { 8 | [TestFixture] 9 | internal class Standard_Exception_Contain_Value_Should 10 | { 11 | [Test] 12 | public void Throw_If_Some() 13 | { 14 | var expected = Guid.NewGuid().ToString(); 15 | var option = Optional.Some(expected); 16 | 17 | Action action = () => option.EnsureNone(); 18 | 19 | action.Should() 20 | .Throw>() 21 | .WithMessage($"*{expected}*") 22 | .Which.Value.Should().Be(expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Plain/Upcast/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Plain.Upcast 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastPlainExamples 14 | .Get(fault => fault, null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(Result result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Success/Plain/Standard_Exception_Contain_Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Success.Plain 7 | { 8 | [TestFixture] 9 | internal class Standard_Exception_Contain_Fault_Should 10 | { 11 | [Test] 12 | public void Throw_If_Failure() 13 | { 14 | var expected = Guid.NewGuid().ToString(); 15 | var result = Result.Fail(expected); 16 | 17 | Action action = () => result.EnsureSuccess(); 18 | 19 | action.Should() 20 | .Throw>() 21 | .WithMessage($"*{expected}*") 22 | .Which.Fault.Should().Be(expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrNull/TValue/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrNull.TValue 5 | { 6 | [TestFixture] 7 | internal class Fault_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int? fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(1), null), 17 | CreateCase(Result.Fail(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int? Process_Result(Result result) 22 | { 23 | return result.GetFaultOrNull(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrNull/TValue/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrNull.TValue 5 | { 6 | [TestFixture] 7 | internal class Value_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int? value) 10 | { 11 | return new(result) { ExpectedResult = value }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Fail(1), null), 17 | CreateCase(Result.Succeed(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int? Process_Result(Result result) 22 | { 23 | return result.GetValueOrNull(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/Optional/Select/DifferentTypes/SelectCaseToDifferentTypeTestCasesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.Optional.Select.DifferentTypes 7 | { 8 | internal static class SelectCaseToDifferentTypeTestCasesExtensions 9 | { 10 | internal static IEnumerable ToDifferentTypeTestCases(this IEnumerable cases) 11 | { 12 | return cases.ToTestCases(result => result.MapValue(ConvertToString)); 13 | } 14 | 15 | internal static string ConvertToString(int value) 16 | { 17 | return value.ToString(CultureInfo.InvariantCulture); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Plain/Struct/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Plain.Struct 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(), 0), 17 | CreateCase(Result.Fail(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int Process_Result(Result result) 22 | { 23 | return result.GetFaultOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Failure/TValue/Standard_Exception_Contain_Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Failure.TValue 7 | { 8 | [TestFixture] 9 | internal class Standard_Exception_Contain_Value_Should 10 | { 11 | [Test] 12 | public void Throw_If_Success() 13 | { 14 | var expected = Guid.NewGuid().ToString(); 15 | var result = Result.Succeed(expected); 16 | 17 | Action action = () => result.EnsureFailure(); 18 | 19 | action.Should() 20 | .Throw>() 21 | .WithMessage($"*{expected}*") 22 | .Which.Value.Should().Be(expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Success/TValue/Standard_Exception_Contain_Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Success.TValue 7 | { 8 | [TestFixture] 9 | internal class Standard_Exception_Contain_Fault_Should 10 | { 11 | [Test] 12 | public void Throw_If_Failure() 13 | { 14 | var expected = Guid.NewGuid().ToString(); 15 | var result = Result.Fail(expected); 16 | 17 | Action action = () => result.EnsureSuccess(); 18 | 19 | action.Should() 20 | .Throw>() 21 | .WithMessage($"*{expected}*") 22 | .Which.Fault.Should().Be(expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Optional/Upcast/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Optional.Upcast 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastOptionalExamples 14 | .Get(null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Optional).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Optional(Optional optional) 20 | { 21 | return optional.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrThrow/TValue/Value/Standard_Exception_Contain_Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrThrow.TValue.Value 7 | { 8 | [TestFixture] 9 | internal class Standard_Exception_Contain_Fault_Should 10 | { 11 | [Test] 12 | public void Throw_If_Failure() 13 | { 14 | var expected = Guid.NewGuid().ToString(); 15 | var result = Result.Fail(expected); 16 | 17 | Func action = () => result.GetValueOrThrow(); 18 | 19 | action.Should() 20 | .Throw>() 21 | .WithMessage($"*{expected}*") 22 | .Which.Fault.Should().Be(expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/Faults/TValue/Upcast/Both_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.Faults.TValue.Upcast 7 | { 8 | [TestFixture] 9 | internal class Both_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(fault => new[] { fault }, _ => Enumerable.Empty()) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(Result result) 20 | { 21 | return result.GetFaults(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrThrow/TValue/Fault/Standard_Exception_Contain_Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrThrow.TValue.Fault 7 | { 8 | [TestFixture] 9 | internal class Standard_Exception_Contain_Value_Should 10 | { 11 | [Test] 12 | public void Throw_If_Success() 13 | { 14 | var expected = Guid.NewGuid().ToString(); 15 | var result = Result.Succeed(expected); 16 | 17 | Func action = () => result.GetFaultOrThrow(); 18 | 19 | action.Should() 20 | .Throw>() 21 | .WithMessage($"*{expected}*") 22 | .Which.Value.Should().Be(expected); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/Values/TValue/Upcast/Both_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.Values.TValue.Upcast 7 | { 8 | [TestFixture] 9 | internal class Both_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(_ => Enumerable.Empty(), value => new[] { value }) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(Result result) 20 | { 21 | return result.GetValues(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValueTValue/Select/DifferentTypes/LinqTestBase.TFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValueTValue.Select.DifferentTypes 6 | { 7 | internal abstract class LinqTestBase : LinqTestBase 8 | where TFixtureCase : IFixtureCase, new() 9 | { 10 | protected static IEnumerable CreateSelectCases(int argumentsCount) 11 | { 12 | return CreateSelectCases(argumentsCount, ConvertToString); 13 | } 14 | 15 | protected static string ConvertToString(int value) 16 | { 17 | return value.ToString(CultureInfo.InvariantCulture); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/Faults/TValue/Upcast/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.Faults.TValue.Upcast 7 | { 8 | [TestFixture] 9 | internal class Fault_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(fault => new[] { fault }, _ => Enumerable.Empty()) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(Result result) 20 | { 21 | return result.GetFaults(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/Faults/TValue/Upcast/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.Faults.TValue.Upcast 7 | { 8 | [TestFixture] 9 | internal class Value_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(fault => new[] { fault }, _ => Enumerable.Empty()) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(Result result) 20 | { 21 | return result.GetFaults(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Optional/Struct/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Optional.Struct 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Optional optional, int result) 10 | { 11 | return new(optional) { ExpectedResult = result }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Optional.None(), 0), 17 | CreateCase(Optional.Some(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int Process_Optional(Optional optional) 22 | { 23 | return optional.GetValueOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/Values/TValue/Upcast/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.Values.TValue.Upcast 7 | { 8 | [TestFixture] 9 | internal class Fault_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(_ => Enumerable.Empty(), value => new[] { value }) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(Result result) 20 | { 21 | return result.GetValues(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/Values/TValue/Upcast/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.Values.TValue.Upcast 7 | { 8 | [TestFixture] 9 | internal class Value_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(_ => Enumerable.Empty(), value => new[] { value }) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(Result result) 20 | { 21 | return result.GetValues(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/SelectCaseToTestCasesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Kontur.Results; 5 | using Kontur.Tests.Results.Conversion.Combinations.Linq.Result.SelectCaseGenerators; 6 | using NUnit.Framework; 7 | 8 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result 9 | { 10 | internal static class SelectCaseToTestCasesExtensions 11 | { 12 | internal static IEnumerable ToTestCases( 13 | this IEnumerable cases, 14 | Func, TResult> resultSelector) 15 | { 16 | return cases.Select( 17 | testCase => new TestCaseData(testCase.Args.Cast().ToArray()) 18 | .Returns(resultSelector(testCase.Result))); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Plain/Class/NonNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Plain.Class 5 | { 6 | [TestFixture] 7 | internal class NonNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, string? fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(), null), 17 | CreateCase(Result.Fail("foo"), "foo"), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public string? Process_Result(Result result) 22 | { 23 | return result.GetFaultOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Optional/OptionalOptional/Select/DifferentTypes/LinqTestBase.TFixtureCase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Optional.OptionalOptional.Select.DifferentTypes 6 | { 7 | internal abstract class LinqTestBase : LinqTestBase 8 | where TFixtureCase : IFixtureCase, new() 9 | { 10 | protected static IEnumerable CreateSelectCases(int argumentsCount) 11 | { 12 | return CreateSelectCases(argumentsCount, ConvertToString); 13 | } 14 | 15 | protected static string ConvertToString(int value) 16 | { 17 | return value.ToString(CultureInfo.InvariantCulture); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Fault/Struct/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Fault.Struct 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(1), 0), 17 | CreateCase(Result.Fail(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int Process_Result(Result result) 22 | { 23 | return result.GetFaultOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Value/Struct/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Value.Struct 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int value) 10 | { 11 | return new(result) { ExpectedResult = value }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Fail(1), 0), 17 | CreateCase(Result.Succeed(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int Process_Result(Result result) 22 | { 23 | return result.GetValueOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Fault/Upcast/Both/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Fault.Upcast.Both 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(fault => fault, _ => null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(Result result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Value/Upcast/Both/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Value.Upcast.Both 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetBoth(_ => null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(Result result) 20 | { 21 | return result.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/ToString/Optional_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.ToString 7 | { 8 | [TestFixture] 9 | internal class Optional_Should 10 | { 11 | [Test] 12 | public void Some() 13 | { 14 | var expected = Guid.NewGuid(); 15 | var option = Optional.Some(expected); 16 | 17 | var result = option.ToString(); 18 | 19 | result.Should().ContainAll(nameof(Guid), "Some", expected.ToString()); 20 | } 21 | 22 | [Test] 23 | public void None() 24 | { 25 | var option = Optional.None(); 26 | 27 | var result = option.ToString(); 28 | 29 | result.Should().ContainAll(nameof(Guid), "None"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/Values/Upcast/Both_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.Values.Upcast 7 | { 8 | [TestFixture] 9 | internal class Both_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(_ => Enumerable.Empty(), value => new[] { value }) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(StringFaultResult result) 20 | { 21 | return result.GetValues(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/Values/Upcast/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.Values.Upcast 7 | { 8 | [TestFixture] 9 | internal class Value_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(_ => Enumerable.Empty(), value => new[] { value }) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(StringFaultResult result) 20 | { 21 | return result.GetValues(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Fault/Upcast/Fault/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Fault.Upcast.Fault 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetFaults(fault => fault, _ => null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(Result result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Value/Upcast/Value/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Value.Upcast.Value 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetValues(_ => null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(Result result) 20 | { 21 | return result.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Ensure/Failure/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Ensure.Failure 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultSucceedException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_Success() 15 | { 16 | const string expected = "foo"; 17 | var result = StringFaultResult.Succeed(expected); 18 | 19 | Action action = () => result.EnsureFailure(); 20 | 21 | action.Should() 22 | .Throw() 23 | .WithMessage($"*{expected}*"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/Values/Upcast/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.Values.Upcast 7 | { 8 | [TestFixture] 9 | internal class Fault_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(_ => Enumerable.Empty(), value => new[] { value }) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(StringFaultResult result) 20 | { 21 | return result.GetValues(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Equality/Plain/Equals_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Equality.Plain 7 | { 8 | [TestFixture] 9 | internal class Equals_Should 10 | { 11 | private static readonly IEnumerable Cases = 12 | from pair in new[] 13 | { 14 | (Cases: Common.CreateNonEqualsCases(), Result: false), 15 | (Cases: Common.CreateEqualsCases(), Result: true), 16 | } 17 | from testCase in pair.Cases 18 | select testCase.Returns(pair.Result); 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Compare(Result result1, Result result2) 22 | { 23 | return result1.Equals(result2); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Fault/Upcast/Value/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Fault.Upcast.Value 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetValues(fault => fault, _ => null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public string? Process_Result(Result result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Value/Upcast/Fault/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Value.Upcast.Fault 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastTValueExamples 14 | .GetFaults(_ => null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public string? Process_Result(Result result) 20 | { 21 | return result.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Ensure/Success/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Ensure.Success 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultFailedException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_Failure() 15 | { 16 | const string expected = "bar"; 17 | var result = StringFaultResult.Fail(new(expected)); 18 | 19 | Action action = () => result.EnsureSuccess(); 20 | 21 | action.Should() 22 | .Throw() 23 | .WithMessage($"*{expected}*"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Optional/Class/NonNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Optional.Class 5 | { 6 | [TestFixture] 7 | internal class NonNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Optional optional, string? result) 10 | { 11 | return new(optional) { ExpectedResult = result }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Optional.None(), null), 17 | CreateCase(Optional.Some("foo"), "foo"), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public string? Process_Optional(Optional optional) 22 | { 23 | return optional.GetValueOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/Faults/Upcast/Value_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.Faults.Upcast 7 | { 8 | [TestFixture] 9 | internal class Value_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(fault => new[] { fault }, _ => Enumerable.Empty()) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(StringFaultResult result) 20 | { 21 | return result.GetFaults(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Value/Upcast/Both/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Value.Upcast.Both 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(_ => null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(StringFaultResult result) 20 | { 21 | return result.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Value/Upcast/Value/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Value.Upcast.Value 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastExamples 14 | .GetValues(_ => null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public Base? Process_Result(StringFaultResult result) 20 | { 21 | return result.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/ToString/Plain_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.ToString 7 | { 8 | [TestFixture] 9 | internal class Plain_Should 10 | { 11 | [Test] 12 | public void Failure() 13 | { 14 | var expected = Guid.NewGuid(); 15 | var result = Result.Fail(expected); 16 | 17 | var serialized = result.ToString(); 18 | 19 | serialized.Should().ContainAll(nameof(Guid), "fault", expected.ToString()); 20 | } 21 | 22 | [Test] 23 | public void Success() 24 | { 25 | var result = Result.Succeed(); 26 | 27 | var serialized = result.ToString(); 28 | 29 | serialized.Should().ContainAll(nameof(Guid), "Success"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Equality/Equals_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | 5 | namespace Kontur.Tests.Results.Inheritance.Equality 6 | { 7 | [TestFixture] 8 | internal class Equals_Should 9 | { 10 | private static readonly IEnumerable Cases = 11 | from pair in new[] 12 | { 13 | (Cases: Common.CreateNonEqualsCases(), Result: false), 14 | (Cases: Common.CreateEqualsCases(), Result: true), 15 | } 16 | from testCase in pair.Cases 17 | select testCase.Returns(pair.Result); 18 | 19 | [TestCaseSource(nameof(Cases))] 20 | public bool Compare(StringFaultResult result1, StringFaultResult result2) 21 | { 22 | return result1.Equals(result2); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/Faults/Upcast/Both_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.Faults.Upcast 7 | { 8 | [TestFixture] 9 | internal class Both_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(fault => new[] { fault }, _ => Enumerable.Empty()) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(StringFaultResult result) 20 | { 21 | return result.GetFaults(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrThrow/Value/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrThrow.Value 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultFailedException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_Failure() 15 | { 16 | const string expected = "foo"; 17 | var result = StringFaultResult.Fail(new(expected)); 18 | 19 | Func action = () => result.GetValueOrThrow(); 20 | 21 | action.Should() 22 | .Throw() 23 | .WithMessage($"*{expected}*"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Plain/Struct/Nullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Plain.Struct 5 | { 6 | [TestFixture] 7 | internal class Nullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, int? fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(), null), 17 | CreateCase(Result.Fail(null), null), 18 | CreateCase(Result.Fail(1), 1), 19 | }; 20 | 21 | [TestCaseSource(nameof(Cases))] 22 | public int? Process_Result(Result result) 23 | { 24 | return result.GetFaultOrDefault(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/Faults/Upcast/Fault_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.Faults.Upcast 7 | { 8 | [TestFixture] 9 | internal class Fault_Should 10 | { 11 | private static IEnumerable GetUpcastCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(fault => new[] { fault }, _ => Enumerable.Empty()) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetUpcastCases))] 19 | public IEnumerable Upcast(StringFaultResult result) 20 | { 21 | return result.GetFaults(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrThrow/Fault/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrThrow.Fault 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultSucceedException))] 10 | internal class Standard_Exception_Should 11 | where TException : Exception 12 | { 13 | [Test] 14 | public void Throw_If_Success() 15 | { 16 | const string expected = "bar"; 17 | var result = StringFaultResult.Succeed(expected); 18 | 19 | Func action = () => result.GetFaultOrThrow(); 20 | 21 | action.Should() 22 | .Throw() 23 | .WithMessage($"*{expected}*"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Fault/Upcast/Value/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Fault.Upcast.Value 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastExamples 14 | .GetValues(fault => fault, _ => null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public StringFault? Process_Result(StringFaultResult result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Value/Upcast/Fault/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Value.Upcast.Fault 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastExamples 14 | .GetFaults(_ => null, value => value) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public string? Process_Result(StringFaultResult result) 20 | { 21 | return result.GetValueOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Value/Struct/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Value.Struct 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(StringFaultResult result, int value) 10 | { 11 | return new(result) { ExpectedResult = value }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(StringFaultResult.Fail(new("bar")), 0), 17 | CreateCase(StringFaultResult.Succeed(1), 1), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public int Process_Result(StringFaultResult result) 22 | { 23 | return result.GetValueOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValue/Select/DifferentTypes/SelectCaseToDifferentTypeTestCasesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using Kontur.Results; 4 | using Kontur.Tests.Results.Conversion.Combinations.Linq.Result.SelectCaseGenerators; 5 | using NUnit.Framework; 6 | 7 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValue.Select.DifferentTypes 8 | { 9 | internal static class SelectCaseToDifferentTypeTestCasesExtensions 10 | { 11 | internal static IEnumerable ToDifferentTypeTestCases(this IEnumerable cases) 12 | { 13 | return cases.ToTestCases(result => result.MapValue(ConvertToString)); 14 | } 15 | 16 | internal static string ConvertToString(int value) 17 | { 18 | return value.ToString(CultureInfo.InvariantCulture); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Failure/None/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Failure.None 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ValueExistsException))] 10 | [TestFixture(typeof(ValueExistsException))] 11 | internal class Standard_Exception_Should 12 | where TException : Exception 13 | { 14 | [Test] 15 | public void Throw_If_Some() 16 | { 17 | const string expected = "value"; 18 | var option = Optional.Some(expected); 19 | 20 | Action action = () => option.EnsureNone(); 21 | 22 | action.Should() 23 | .Throw() 24 | .WithMessage($"*{expected}*"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Fault/Class/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Fault.Class 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, string? fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed("foo"), null), 17 | CreateCase(Result.Fail("foo"), "foo"), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public string? Process_Result(Result result) 22 | { 23 | return result.GetFaultOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/TValue/Value/Class/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.TValue.Value.Class 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, string? value) 10 | { 11 | return new(result) { ExpectedResult = value }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Fail("foo"), null), 17 | CreateCase(Result.Succeed("foo"), "foo"), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public string? Process_Result(Result result) 22 | { 23 | return result.GetValueOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Fault/Upcast/Both/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Fault.Upcast.Both 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastExamples 14 | .GetBoth(fault => fault, _ => null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public StringFaultBase? Process_Result(StringFaultResult result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Equality/Optional/Equals_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Equality.Optional 7 | { 8 | [TestFixture] 9 | internal class Equals_Should 10 | { 11 | private static readonly IEnumerable Cases = 12 | from pair in new[] 13 | { 14 | (Cases: Common.CreateNonEqualsCases(), Result: false), 15 | (Cases: Common.CreateEqualsCases(), Result: true), 16 | } 17 | from testCase in pair.Cases 18 | select testCase.Returns(pair.Result); 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Compare(Optional optional1, Optional optional2) 22 | { 23 | return optional1.Equals(optional2); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Success/Plain/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Success.Plain 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultFailedException))] 10 | [TestFixture(typeof(ResultFailedException))] 11 | internal class Standard_Exception_Should 12 | where TException : Exception 13 | { 14 | [Test] 15 | public void Throw_If_Failure() 16 | { 17 | const string expected = "bar"; 18 | var result = Result.Fail(expected); 19 | 20 | Action action = () => result.EnsureSuccess(); 21 | 22 | action.Should() 23 | .Throw() 24 | .WithMessage($"*{expected}*"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Fault/Upcast/Fault/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Fault.Upcast.Fault 7 | { 8 | [TestFixture] 9 | internal class NotNullable_Should 10 | { 11 | private static IEnumerable GetCases() 12 | { 13 | return UpcastExamples 14 | .GetFaults(fault => fault, _ => null) 15 | .Select(testCase => new TestCaseData(testCase.Source).Returns(testCase.Result)); 16 | } 17 | 18 | [TestCaseSource(nameof(GetCases))] 19 | public StringFaultBase? Process_Result(StringFaultResult result) 20 | { 21 | return result.GetFaultOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vostok.devtools/code-style-csharp/CSharpCodeStyle.SpaceIndent.DotSettings: -------------------------------------------------------------------------------- 1 | 4 | 5 | False 7 | USE_SPACES_ONLY 8 | 9 | True 11 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/Switch/SwitchOptionalExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class SwitchOptionalExtensions 6 | { 7 | public static Optional Switch(this IOptional optional, Action onNone, Action onSome) 8 | { 9 | return optional.Switch(onNone, _ => onSome()); 10 | } 11 | 12 | public static Optional Switch(this IOptional optional, Action onNone, Action onSome) 13 | { 14 | return optional.Match( 15 | () => 16 | { 17 | onNone(); 18 | return optional; 19 | }, 20 | value => 21 | { 22 | onSome(value); 23 | return optional; 24 | }) 25 | .Upcast(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Equality/TValue/Equals_Should.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Equality.TValue 7 | { 8 | [TestFixture] 9 | internal class Equals_Should 10 | { 11 | private static readonly IEnumerable Cases = 12 | from pair in new[] 13 | { 14 | (Cases: Common.CreateNonEqualsCases(), Result: false), 15 | (Cases: Common.CreateEqualsCases(), Result: true), 16 | } 17 | from testCase in pair.Cases 18 | select testCase.Returns(pair.Result); 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public bool Compare(Result result1, Result result2) 22 | { 23 | return result1.Equals(result2); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Optional/Struct/Nullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Optional.Struct 5 | { 6 | [TestFixture] 7 | internal class Nullable_Should 8 | { 9 | private static TestCaseData CreateCase(Optional optional, int? result) 10 | { 11 | return new(optional) { ExpectedResult = result }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Optional.None(), null), 17 | CreateCase(Optional.Some(null), null), 18 | CreateCase(Optional.Some(1), 1), 19 | }; 20 | 21 | [TestCaseSource(nameof(Cases))] 22 | public int? Process_Optional(Optional optional) 23 | { 24 | return optional.GetValueOrDefault(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrDefault/Plain/Class/Nullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Extraction.Get.OrDefault.Plain.Class 5 | { 6 | [TestFixture] 7 | internal class Nullable_Should 8 | { 9 | private static TestCaseData CreateCase(Result result, string? fault) 10 | { 11 | return new(result) { ExpectedResult = fault }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(Result.Succeed(), null), 17 | CreateCase(Result.Fail(null), null), 18 | CreateCase(Result.Fail("foo"), "foo"), 19 | }; 20 | 21 | [TestCaseSource(nameof(Cases))] 22 | public string? Process_Result(Result result) 23 | { 24 | return result.GetFaultOrDefault(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Success/TValue/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Success.TValue 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultFailedException))] 10 | [TestFixture(typeof(ResultFailedException))] 11 | internal class Standard_Exception_Should 12 | where TException : Exception 13 | { 14 | [Test] 15 | public void Throw_If_Failure() 16 | { 17 | const string expected = "bar"; 18 | var result = Result.Fail(expected); 19 | 20 | Action action = () => result.EnsureSuccess(); 21 | 22 | action.Should() 23 | .Throw() 24 | .WithMessage($"*{expected}*"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Results/Extensions/Extraction/Actions/Switch/SwitchResultPlainExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Kontur.Results 4 | { 5 | public static class SwitchResultPlainExtensions 6 | { 7 | public static Result Switch(this IResult result, Action onFailure, Action onSuccess) 8 | { 9 | return result.Switch(_ => onFailure(), onSuccess); 10 | } 11 | 12 | public static Result Switch(this IResult result, Action onFailure, Action onSuccess) 13 | { 14 | return result.Match( 15 | fault => 16 | { 17 | onFailure(fault); 18 | return result; 19 | }, 20 | () => 21 | { 22 | onSuccess(); 23 | return result; 24 | }) 25 | .Upcast(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Kontur.Tests.Results/Conversion/Combinations/Linq/Result/TValue/Where/WhereCaseGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Kontur.Tests.Results.Conversion.Combinations.Linq.Result.SelectCaseGenerators; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Conversion.Combinations.Linq.Result.TValue.Where 7 | { 8 | internal static class WhereCaseGenerator 9 | { 10 | internal static IEnumerable Create(int argumentsCount, int wherePosition) 11 | { 12 | return SelectCasesGenerator 13 | .Create(argumentsCount) 14 | .SelectMany(testCase => CreateCases(testCase, wherePosition)); 15 | } 16 | 17 | private static IEnumerable CreateCases(SelectCase testCase, int wherePosition) 18 | { 19 | return WhereCaseFactory.Create(testCase.Args, testCase.Result, wherePosition); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Ensure/Failure/TValue/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Ensure.Failure.TValue 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultSucceedException))] 10 | [TestFixture(typeof(ResultSucceedException))] 11 | internal class Standard_Exception_Should 12 | where TException : Exception 13 | { 14 | [Test] 15 | public void Throw_If_Success() 16 | { 17 | const string expected = "foo"; 18 | var result = Result.Succeed(expected); 19 | 20 | Action action = () => result.EnsureFailure(); 21 | 22 | action.Should() 23 | .Throw() 24 | .WithMessage($"*{expected}*"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Inheritance/Extraction/Get/OrDefault/Value/Class/NotNullable_Should.cs: -------------------------------------------------------------------------------- 1 | using Kontur.Results; 2 | using NUnit.Framework; 3 | 4 | namespace Kontur.Tests.Results.Inheritance.Extraction.Get.OrDefault.Value.Class 5 | { 6 | [TestFixture] 7 | internal class NotNullable_Should 8 | { 9 | private static TestCaseData CreateCase(StringFaultResult result, string? value) 10 | { 11 | return new(result) { ExpectedResult = value }; 12 | } 13 | 14 | private static readonly TestCaseData[] Cases = 15 | { 16 | CreateCase(StringFaultResult.Fail(new("bar")), null), 17 | CreateCase(StringFaultResult.Succeed("foo"), "foo"), 18 | }; 19 | 20 | [TestCaseSource(nameof(Cases))] 21 | public string? Process_Result(StringFaultResult result) 22 | { 23 | return result.GetValueOrDefault(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vostok.devtools/dotnetversionsuffix/dotnetversionsuffix.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | Latest 7 | 1.0.0 8 | Vostok team 9 | dotnetversionsuffix 10 | false 11 | embedded 12 | true 13 | true 14 | true 15 | true 16 | $(SolutionDir)\nupkg 17 | NETSDK1138 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /vostok.devtools/tcs-create-options/tcscreateoptions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | Latest 7 | 1.0.0 8 | Vostok team 9 | tcscreateoptions 10 | false 11 | embedded 12 | true 13 | true 14 | true 15 | true 16 | $(SolutionDir)\nupkg 17 | NETSDK1138 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrThrow/TValue/Value/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrThrow.TValue.Value 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultFailedException))] 10 | [TestFixture(typeof(ResultFailedException))] 11 | internal class Standard_Exception_Should 12 | where TException : Exception 13 | { 14 | [Test] 15 | public void Throw_If_Failure() 16 | { 17 | const string expected = "foo"; 18 | var result = Result.Fail(expected); 19 | 20 | Func action = () => result.GetValueOrThrow(); 21 | 22 | action.Should() 23 | .Throw() 24 | .WithMessage($"*{expected}*"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; 4-column space indentation 2 | [*] 3 | indent_style = space 4 | 5 | [*.{cs,tt}] 6 | indent_size = 4 7 | 8 | dotnet_diagnostic.CA1000.severity = none 9 | 10 | dotnet_diagnostic.CA1032.severity = none 11 | 12 | dotnet_diagnostic.CA1303.severity = none 13 | 14 | dotnet_diagnostic.CA1815.severity = none 15 | 16 | dotnet_diagnostic.CA2237.severity = none 17 | 18 | dotnet_diagnostic.SA0001.severity = none 19 | 20 | dotnet_diagnostic.SA1101.severity = none 21 | 22 | dotnet_diagnostic.SA1200.severity = none 23 | 24 | dotnet_diagnostic.SA1600.severity = none 25 | 26 | dotnet_diagnostic.SA1633.severity = none 27 | 28 | dotnet_diagnostic.S1128.severity = error 29 | 30 | dotnet_diagnostic.S2743.severity = none 31 | 32 | dotnet_diagnostic.S3925.severity = none 33 | 34 | 35 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 36 | indent_size = 2 37 | 38 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 39 | indent_size = 2 40 | -------------------------------------------------------------------------------- /Kontur.Tests.Results/Extraction/Get/OrThrow/TValue/Fault/Standard_Exception_Should.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using FluentAssertions; 3 | using Kontur.Results; 4 | using NUnit.Framework; 5 | 6 | namespace Kontur.Tests.Results.Extraction.Get.OrThrow.TValue.Fault 7 | { 8 | [TestFixture(typeof(InvalidOperationException))] 9 | [TestFixture(typeof(ResultSucceedException))] 10 | [TestFixture(typeof(ResultSucceedException))] 11 | internal class Standard_Exception_Should 12 | where TException : Exception 13 | { 14 | [Test] 15 | public void Throw_If_Success() 16 | { 17 | const string expected = "foo"; 18 | var result = Result.Succeed(expected); 19 | 20 | Func action = () => result.GetFaultOrThrow(); 21 | 22 | action.Should() 23 | .Throw() 24 | .WithMessage($"*{expected}*"); 25 | } 26 | } 27 | } 28 | --------------------------------------------------------------------------------