|
| 1 | +package mocking |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + abstractions "github.com/microsoft/kiota-abstractions-go" |
| 7 | + "github.com/microsoft/kiota-abstractions-go/serialization" |
| 8 | + "github.com/microsoft/kiota-abstractions-go/store" |
| 9 | + "github.com/stretchr/testify/mock" |
| 10 | +) |
| 11 | + |
| 12 | +type MockRequestAdapter struct { |
| 13 | + mock.Mock |
| 14 | +} |
| 15 | + |
| 16 | +func NewMockRequestAdapter() *MockRequestAdapter { |
| 17 | + return &MockRequestAdapter{ |
| 18 | + mock.Mock{}, |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +// Send executes the HTTP request specified by the given RequestInformation and returns the deserialized response model. |
| 23 | +func (rA *MockRequestAdapter) Send(context context.Context, requestInfo *abstractions.RequestInformation, constructor serialization.ParsableFactory, errorMappings abstractions.ErrorMappings) (serialization.Parsable, error) { |
| 24 | + args := rA.Called(context, requestInfo, constructor, errorMappings) |
| 25 | + return args.Get(0).(serialization.Parsable), args.Error(1) |
| 26 | +} |
| 27 | + |
| 28 | +// SendEnum executes the HTTP request specified by the given RequestInformation and returns the deserialized response model. |
| 29 | +func (rA *MockRequestAdapter) SendEnum(context context.Context, requestInfo *abstractions.RequestInformation, parser serialization.EnumFactory, errorMappings abstractions.ErrorMappings) (any, error) { |
| 30 | + args := rA.Called(context, requestInfo, parser, errorMappings) |
| 31 | + return args.Get(0), args.Error(1) |
| 32 | +} |
| 33 | + |
| 34 | +// SendCollection executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection. |
| 35 | +func (rA *MockRequestAdapter) SendCollection(context context.Context, requestInfo *abstractions.RequestInformation, constructor serialization.ParsableFactory, errorMappings abstractions.ErrorMappings) ([]serialization.Parsable, error) { |
| 36 | + args := rA.Called(context, requestInfo, constructor, errorMappings) |
| 37 | + return args.Get(0).([]serialization.Parsable), args.Error(1) |
| 38 | +} |
| 39 | + |
| 40 | +// SendEnumCollection executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection. |
| 41 | +func (rA *MockRequestAdapter) SendEnumCollection(context context.Context, requestInfo *abstractions.RequestInformation, parser serialization.EnumFactory, errorMappings abstractions.ErrorMappings) ([]any, error) { |
| 42 | + args := rA.Called(context, requestInfo, parser, errorMappings) |
| 43 | + return args.Get(0).([]any), args.Error(1) |
| 44 | +} |
| 45 | + |
| 46 | +// SendPrimitive executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model. |
| 47 | +func (rA *MockRequestAdapter) SendPrimitive(context context.Context, requestInfo *abstractions.RequestInformation, typeName string, errorMappings abstractions.ErrorMappings) (any, error) { |
| 48 | + args := rA.Called(context, requestInfo, typeName, errorMappings) |
| 49 | + return args.Get(0), args.Error(1) |
| 50 | +} |
| 51 | + |
| 52 | +// SendPrimitiveCollection executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection. |
| 53 | +func (rA *MockRequestAdapter) SendPrimitiveCollection(context context.Context, requestInfo *abstractions.RequestInformation, typeName string, errorMappings abstractions.ErrorMappings) ([]any, error) { |
| 54 | + args := rA.Called(context, requestInfo, typeName, errorMappings) |
| 55 | + return args.Get(0).([]any), args.Error(1) |
| 56 | +} |
| 57 | + |
| 58 | +// SendNoContent executes the HTTP request specified by the given RequestInformation with no return content. |
| 59 | +func (rA *MockRequestAdapter) SendNoContent(context context.Context, requestInfo *abstractions.RequestInformation, errorMappings abstractions.ErrorMappings) error { |
| 60 | + args := rA.Called(context, requestInfo, errorMappings) |
| 61 | + return args.Error(1) |
| 62 | +} |
| 63 | + |
| 64 | +// GetSerializationWriterFactory returns the serialization writer factory currently in use for the request adapter service. |
| 65 | +func (rA *MockRequestAdapter) GetSerializationWriterFactory() serialization.SerializationWriterFactory { |
| 66 | + args := rA.Called() |
| 67 | + return args.Get(0).(serialization.SerializationWriterFactory) |
| 68 | +} |
| 69 | + |
| 70 | +// EnableBackingStore enables the backing store proxies for the SerializationWriters and ParseNodes in use. |
| 71 | +func (rA *MockRequestAdapter) EnableBackingStore(factory store.BackingStoreFactory) { |
| 72 | + _ = rA.Called(factory) |
| 73 | +} |
| 74 | + |
| 75 | +// SetBaseUrl sets the base url for every request. |
| 76 | +func (rA *MockRequestAdapter) SetBaseUrl(baseUrl string) { //nolint:stylecheck |
| 77 | + _ = rA.Called(baseUrl) |
| 78 | +} |
| 79 | + |
| 80 | +// GetBaseUrl gets the base url for every request. |
| 81 | +func (rA *MockRequestAdapter) GetBaseUrl() string { //nolint:stylecheck |
| 82 | + args := rA.Called() |
| 83 | + return args.String(0) |
| 84 | +} |
| 85 | + |
| 86 | +// ConvertToNativeRequest converts the given RequestInformation into a native HTTP request. |
| 87 | +func (rA *MockRequestAdapter) ConvertToNativeRequest(context context.Context, requestInfo *abstractions.RequestInformation) (any, error) { |
| 88 | + args := rA.Called(context, requestInfo) |
| 89 | + return args.Get(0), args.Error(1) |
| 90 | +} |
0 commit comments