Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Api/Captor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {It} from "./It";

export interface Captor<T> {
readonly value?: T
readonly allValues: T[]

capture(): T
}

export class ArgumentCaptor<T> implements Captor<T> {
static argumentCaptor<Q>() : Captor<Q> {
return new ArgumentCaptor<Q>();
}
private constructor() {
}

private capturedValues: T[] = [];

get value(): T {
if (this.capturedValues.length > 0) {
return this.capturedValues[0]
}
return undefined
}

get allValues(): T[] {
return this.capturedValues
}

capture(): T {
return It.is((arg) => {
this.capturedValues.push(arg);
return true
})
}
}

3 changes: 2 additions & 1 deletion src/Api/_all.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from "./IUsing";
export * from "./IVerifies";
export * from "./MockBehavior";
export * from "./ExpectedCallType";
export * from "./Times";
export * from "./Times";
export * from "./Captor";
3 changes: 2 additions & 1 deletion src/typemoq.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ export { MockApi as Mock } from "./Api/MockApi";
export { IMock } from "./Api/IMock";
export { It } from "./Api/It";
export { Times } from "./Api/Times";
export { Captor, ArgumentCaptor } from "./Api/Captor"
export { ExpectedCallType } from "./Api/ExpectedCallType";
export { GlobalMockApi as GlobalMock } from "./Api/GlobalMockApi";
export { IGlobalMock } from "./Api/IGlobalMock";
export { GlobalScopeApi as GlobalScope } from "./Api/GlobalScopeApi";
export { MockException } from "./Error/MockException";
export { MockException } from "./Error/MockException";
Loading