private void TestSagaDefinition <TSagaType>(ModuleDefinition moduleToUse = null)
    {
        moduleToUse = moduleToUse ?? module;

        var dataType     = moduleToUse.GetTypeDefinition <TSagaType>();
        var instructions = InstructionAnalyzer.GetConfigureHowToFindSagaInstructions(dataType);

        var results = new SagaInspectionResults
        {
            HasUnmanagedCalls  = InstructionAnalyzer.CallsUnmanagedMethods(instructions),
            HasUnexpectedCalls = InstructionAnalyzer.CallsUnexpectedMethods(instructions),
            HasBranchingLogic  = InstructionAnalyzer.ContainsBranchingLogic(instructions)
        };

        try
        {
            SagaDefinitionReader.TryGetSagaDefinition(dataType, out results.SagaDefinition);
        }
        catch (Exception x)
        {
            results.Exception = x.Message;
        }

        Approver.Verify(results);
    }
예제 #2
0
    void TestSagaDefinition <TSagaType>(ModuleDefinition moduleToUse = null)
    {
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable IDE0054 //False positive
        moduleToUse = moduleToUse ?? module;
#pragma warning restore IDE0054 //False positive
#pragma warning restore IDE0079 // Remove unnecessary suppression

        var dataType     = moduleToUse.GetTypeDefinition <TSagaType>();
        var instructions = InstructionAnalyzer.GetConfigureHowToFindSagaInstructions(dataType);

        var results = new SagaInspectionResults
        {
            HasUnmanagedCalls  = InstructionAnalyzer.CallsUnmanagedMethods(instructions),
            HasUnexpectedCalls = InstructionAnalyzer.CallsUnexpectedMethods(instructions),
            HasBranchingLogic  = InstructionAnalyzer.ContainsBranchingLogic(instructions)
        };

        try
        {
            SagaDefinitionReader.TryGetSagaDefinition(dataType, out results.SagaDefinition);
        }
        catch (Exception x)
        {
            results.Exception = x.Message;
        }

        Approver.Verify(results);
    }
    static string GetCoreSagaCorrelationId(TypeDefinition type, TypeDefinition sagaDataType)
    {
        var instructions = InstructionAnalyzer.GetConfigureHowToFindSagaInstructions(type);

        if (InstructionAnalyzer.ContainsBranchingLogic(instructions))
        {
            throw new ErrorsException("Looping & branching statements are not allowed in a ConfigureHowToFindSaga method.");
        }

        if (InstructionAnalyzer.CallsUnmanagedMethods(instructions))
        {
            throw new ErrorsException("Calling unmanaged code is not allowed in a ConfigureHowToFindSaga method.");
        }

        if (InstructionAnalyzer.CallsUnexpectedMethods(instructions))
        {
            throw new ErrorsException("Unable to determine Saga correlation property because an unexpected method call was detected in the ConfigureHowToFindSaga method.");
        }

        var correlationId = InstructionAnalyzer.GetCorrelationId(instructions, sagaDataType.FullName);

        return(correlationId);
    }