Skip to content

Write unit tests for factory methods #39

@monkey0506

Description

@monkey0506

Describe the issue

The factory methods (FromAction, FromFunc, and FromFunctionPointer) are implemented only via the source code that we are generating. If we fail to generate source code for any factory method that is actually used, then it will throw a NotImplementedException at runtime. This makes our source generation testable, because we can simply check whether the factory methods throw an exception when invoked.

Proposed solution

While the API is quite extensive, unit tests should be written for some iteration of every API method.

Because the interfaces are generic, it is inherently impossible to exhaustively test every possible type argument, but at minimum we should test two distinct types (that cannot be cast to each other) per type argument. If our source generation fails to cover a real use-case, this may produce an InvalidCastException or NotImplementedException.

Except for INativeAction and IUnmanagedAction (which take no type arguments), each other interface should provide tests for explicit type arguments (e.g., INativeAction<string>) and open type arguments (e.g., INativeAction<X> where X is an enclosing generic type or generic method's type parameter).

Factory methods which take the TMarshaller type parameter should be tested with at least two explicit marshallers and an open type argument.

The interface can be marked off here when tests have been written to satisfy all of the above conditions:

  • INativeAction
  • INativeAction<T>
  • INativeAction<T1, T2>
  • INativeAction<T1, T2, T3>
  • INativeAction<T1, T2, T3, T4>
  • INativeAction<T1, T2, T3, T4, T5>
  • INativeAction<T1, T2, T3, T4, T5, T6>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>
  • INativeAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>
  • INativeFunc<TResult>
  • INativeFunc<T, TResult>
  • INativeFunc<T1, T2, TResult>
  • INativeFunc<T1, T2, T3, TResult>
  • INativeFunc<T1, T2, T3, T4, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>
  • INativeFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>
  • IUnmanagedAction
  • IUnmanagedAction<T, U>
  • IUnmanagedAction<T1, T2, U1, U2>
  • IUnmanagedAction<T1, T2, T3, U1, U2, U3>
  • IUnmanagedAction<T1, T2, T3, T4, U1, U2, U3, U4>
  • IUnmanagedAction<T1, T2, T3, T4, T5, U1, U2, U3, U4, U5>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, U1, U2, U3, U4, U5, U6>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, U1, U2, U3, U4, U5, U6, U7>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, U1, U2, U3, U4, U5, U6, U7, U8>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, U1, U2, U3, U4, U5, U6, U7, U8, U9>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, U15>
  • IUnmanagedAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, U15, U16>
  • IUnmanagedFunc<TResult, UResult>
  • IUnmanagedFunc<T, TResult, U, UResult>
  • IUnmanagedFunc<T1, T2, TResult, U1, U2, UResult>
  • IUnmanagedFunc<T1, T2, T3, TResult, U1, U2, U3, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, TResult, U1, U2, U3, U4, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, TResult, U1, U2, U3, U4, U5, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, TResult, U1, U2, U3, U4, U5, U6, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, TResult, U1, U2, U3, U4, U5, U6, U7, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult, U1, U2, U3, U4, U5, U6, U7, U8, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, U15, UResult>
  • IUnmanagedFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, U15, U16, UResult>

Additional considerations

All interface methods and properties other than the factory methods are provided through real implementations. If testing those implementations is desired, that will be handled by a separate issue.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions