![]() | |
CodeExamination Class |
Namespace: WeroSoft.Diagnostics.CodeExamination
public sealed class CodeExamination : ICodeExamination
The code examination is a library part which is intended to be used by developers during testing their code, but also on runtime for components which are mission critical and correctly must be implemented from the point of view of the framework and its products like Triton and Heron.
Code examination is not a replacement for the compiler. It has been introduced for checks of code which can not be made by the compiler, or where the compiler can be set to ignore rules. Code checks have been introduced to allow writing checking rules for any purpose, and to be examined to any code independent whether its code of the framework, code of projects or customers.
Principle of work
The principle of usage of code examination is easy. Follow the steps below for performing one or multiple code
examination on types of your choice.
Registration of types.
The registration of a type for the code examination can be performed in three different ways.
The following sample shows how a simple complete work cycle like it can be used in a unit test.
// Arrange the code examination and register the test type for testing. ICodeExamination examination = new CodeExamination(); examination.Register(typeof(StandardConstructorPositiveExaminee)); // Act the examination. CheckResult result = examination.Execute(); // Assert the result. Assert.AreEqual(CheckIssueLevel.Success, result.IssueLevel, "The issue level is not as expected.");
The following sample shows how a bulk test can be written. This sample loads the whole weroSoft Core Library and examine their rules. The result is created using all three possible representations. Where the CheckResult can directly be used for programmatic checks, the two text representations or used for tracing information in files (see below the code).
// Arrange the code examination and register the assembly which // contains the types to be examined. Note that a random // type is used for getting the needed assembly information. CodeExamination examination = new CodeExamination(); examination.Register(typeof(CheckResult).Assembly); // Act the examination and the all possible result representations. CheckResult result = examination.Execute(); string singleLineResult = examination.GetOverallExaminationResult(CodeExaminationResultTextFormat.LinePerIssue, true); string multiLineResult = examination.GetOverallExaminationResult(CodeExaminationResultTextFormat.FormatIssue); // Assert the content. Assert.AreEqual(CheckIssueLevel.Success, result.IssueLevel, "The code examination of the weroSoft Core library is not as expected"); // Add more asserts here ...
Success CEX_0001 WeroSoft.Diagnostics.CodeExamination.CodeExaminationRule The type 'CodeExaminationRule' was skipped by code examination due to registered exclude.Ensure that excluding this type is justified. Success CEX_0001 WeroSoft.Diagnostics.CodeExamination.CodeExaminationRule The type 'CodeExaminationRule' was skipped by code examination due to registered exclude.Ensure that excluding this type is justified. Success CEX_0000 WeroSoft.CertificateException The type 'CertificateException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.ImplementationException The type 'ImplementationException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.DataSearchException The type 'DataSearchException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.RecursionException The type 'RecursionException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.TypeManagerException The type 'TypeManagerException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.ConfigurationException The type 'ConfigurationException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.SecurityException The type 'SecurityException' was successfully examined by the rule 'Standard constructor rule'. No more action required. Success CEX_0000 WeroSoft.TypeFactoringException The type 'TypeFactoringException' was successfully examined by the rule 'Standard constructor rule'. No more action required. /// ...
Code Examination Report 22.12.2021 22:44:47 Count of report items: 46 Successful : 46 Error : 0 Warning : 0 Information : 0 Not checked : 0 Type: WeroSoft.AssertArgumentException Result: CEX_0000 Success Message: The type 'AssertArgumentException' was successfully examined by the rule 'Standard constructor rule'. Suggested action : No more action required. CustomData: Type: WeroSoft.BaseException Result: CEX_0000 Success Message: The type 'BaseException' was successfully examined by the rule 'Standard constructor rule'. Suggested action : No more action required. CustomData: Type: WeroSoft.CertificateException Result: CEX_0000 Success Message: The type 'CertificateException' was successfully examined by the rule 'Standard constructor rule'. Suggested action : No more action required. CustomData: Type: WeroSoft.Client.ClientLogicException Result: CEX_0000 Success Message: The type 'ClientLogicException' was successfully examined by the rule 'Standard constructor rule'. Suggested action : No more action required. CustomData: ...
The CodeExamination type exposes the following members.
Name | Description | |
---|---|---|
![]() | CodeExamination |
Initializes a new instance of the code examination.
|
Name | Description | |
---|---|---|
![]() ![]() | CheckTypeMatchTarget |
Checks whether the given type match the given target.
|
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Execute |
Executes the code examination for the registered types.
|
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetLastExaminationResult |
Gets the results of the last execution of code examination.
|
![]() | GetLastExaminationResult(Boolean) |
Gets the results of the last execution of code examination.
|
![]() | GetLastExaminationResult(CodeExaminationResultTextFormat) |
Gets the results of the last execution of code examination.
|
![]() | GetLastExaminationResult(CodeExaminationResultTextFormat, Boolean) |
Gets the results of the last execution of code examination.
|
![]() | GetOverallExaminationResult |
Gets the result of all executions since the code examination was initialized.
|
![]() | GetOverallExaminationResult(Boolean) |
Gets the result of all executions since the code examination was initialized.
|
![]() | GetOverallExaminationResult(CodeExaminationResultTextFormat) |
Gets the result of all executions since the code examination was initialized.
|
![]() | GetOverallExaminationResult(CodeExaminationResultTextFormat, Boolean) |
Gets the result of all executions since the code examination was initialized.
|
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | Register(Assembly) |
Registers the exported types provided by the defined assembly for code examination.
|
![]() | Register(Type) |
Registers a single type for code examination.
|
![]() | Register(Assembly, CodeExaminationTarget) |
Registers the exported types provided by the defined assembly for code examination.
|
![]() | Register(Type, Boolean) |
Registers a single type for code examination or exclude it from code examination.
|
![]() | Register(Type, ICodeExaminiationRule) |
Registers a single type for code examination together with an explicit defined rule.
|
![]() | RegisterAssignables | |
![]() | RegisterDecorated | |
![]() | Reset |
Resets the code examination.
|
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
![]() | Clone(CloneWorkingMode, IEnumerableType) | Overloaded.
Clones an object by serialization.
(Defined by RuntimeExtensions.) |
![]() | CloneT(CloneWorkingMode, IEnumerableType) | Overloaded.
Clones an object by serialization.
(Defined by RuntimeExtensions.) |
![]() | Convert | (Defined by DataConverterExtensions.) |
![]() | CreateTraceDataEntry(StringBuilder, SourceLevels, TraceableKind, String) | Overloaded.
Creates a data entry into a string builder according to the giving parameters.
(Defined by TraceExtensions.) |
![]() | CreateTraceDataEntry(SourceLevels, TraceableKind, String, String, Int32) | Overloaded.
Creates a trace entry for a data element.
(Defined by TraceExtensions.) |
![]() | CreateTraceDataEntry(StringBuilder, SourceLevels, TraceableKind, String, String, Int32) | Overloaded.
Creates a trace entry into a string builder.
(Defined by TraceExtensions.) |
![]() | DynamicCast |
Dynamically casts a reference to another type.
(Defined by TypeManagerHelper.) |
![]() | ExtractSystemParametersFromTrigger |
Extracts the system parameters from a collection of trigger parameter and transform them to a dictionary using string keys and string values.
(Defined by TriggerExtensions.) |
![]() | GetFieldValue(String) | Overloaded.
Gets the data object held by a defined field of a particular type.
(Defined by UnitTest.) |
![]() | GetFieldValueT(String) | Overloaded.
Gets the data object held by a defined field of a particular type.
(Defined by UnitTest.) |
![]() | GetPropertyValue(String) | Overloaded.
Gets the data object held by a defined property of a particular type.
(Defined by UnitTest.) |
![]() | GetPropertyValueT(String) | Overloaded.
Gets the data object held by a defined property of a particular type.
(Defined by UnitTest.) |
![]() | Inject(Type, Object) | Overloaded.
Injects all fields or properties which are marked with the defined attribute type name.
(Defined by DataInjection.) |
![]() | Inject(Type, Object, Boolean) | Overloaded.
Injects all fields or properties which are marked with the defined attribute type name.
(Defined by DataInjection.) |
![]() | InjectField |
Injects a value to a property within a data object.
(Defined by DataInjection.) |
![]() | InjectProperty(String, Object) | Overloaded.
Injects a value to a property within a data object.
(Defined by DataInjection.) |
![]() | InjectProperty(String, Type, Object) | Overloaded.
Injects a value to a property within a data object.
(Defined by DataInjection.) |
![]() | Invoke(String, Object) | Overloaded.
Invokes a method on an object by reflection.
(Defined by UnitTest.) |
![]() | InvokeTResult(String, Object) | Overloaded.
Invokes a method on an object by reflection.
(Defined by UnitTest.) |
![]() | SetFieldValue |
Sets the data object on a defined field of a particular type.
(Defined by UnitTest.) |
![]() | SetPropertyValue |
Sets the data object on a defined property of a particular type.
(Defined by UnitTest.) |
![]() | SetReadOnlyFieldValue |
Sets the data object on a defined field of a particular type.
(Defined by UnitTest.) |
![]() | TryInjectProperty |
Tries to Inject a value to a property within a data object.
(Defined by DataInjection.) |