Skip to content

Commit

Permalink
Merge pull request #12 from microsoft/feature/enum-send
Browse files Browse the repository at this point in the history
- adds support for enum and enum collection responses
  • Loading branch information
baywet authored May 27, 2022
2 parents a2c0718 + 2466d0d commit 2980d93
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.8.0] - 2022-05-26

### Added

- Adds support for enum and enum collections responses.

## [0.7.0] - 2022-05-18

### Changed
Expand Down
12 changes: 12 additions & 0 deletions authentication/anonymous_authentication_provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package authentication

import (
"testing"

assert "github.com/stretchr/testify/assert"
)

func TestAnonymousProviderHonoursInterface(t *testing.T) {
instance := &AnonymousAuthenticationProvider{}
assert.Implements(t, (*AuthenticationProvider)(nil), instance)
}
23 changes: 23 additions & 0 deletions authentication/base_bearer_token_authentication_provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package authentication

import (
u "net/url"
"testing"

assert "github.com/stretchr/testify/assert"
)

type MockAccessTokenProvider struct {
}

func (m *MockAccessTokenProvider) GetAuthorizationToken(url *u.URL, additionalAuthenticationContext map[string]interface{}) (string, error) {
return "", nil
}
func (m *MockAccessTokenProvider) GetAllowedHostsValidator() *AllowedHostsValidator {
return nil
}
func TestBaseBearerProviderHonoursInterface(t *testing.T) {
mockToken := &MockAccessTokenProvider{}
instance := NewBaseBearerTokenAuthenticationProvider(mockToken)
assert.Implements(t, (*AuthenticationProvider)(nil), instance)
}
4 changes: 4 additions & 0 deletions request_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ type ErrorMappings map[string]s.ParsableFactory
type RequestAdapter interface {
// SendAsync executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
SendAsync(requestInfo *RequestInformation, constructor s.ParsableFactory, responseHandler ResponseHandler, errorMappings ErrorMappings) (s.Parsable, error)
// SendEnumAsync executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
SendEnumAsync(requestInfo *RequestInformation, parser s.EnumFactory, responseHandler ResponseHandler, errorMappings ErrorMappings) (interface{}, error)
// SendCollectionAsync executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
SendCollectionAsync(requestInfo *RequestInformation, constructor s.ParsableFactory, responseHandler ResponseHandler, errorMappings ErrorMappings) ([]s.Parsable, error)
// SendEnumCollectionAsync executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
SendEnumCollectionAsync(requestInfo *RequestInformation, parser s.EnumFactory, responseHandler ResponseHandler, errorMappings ErrorMappings) ([]interface{}, error)
// SendPrimitiveAsync executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
SendPrimitiveAsync(requestInfo *RequestInformation, typeName string, responseHandler ResponseHandler, errorMappings ErrorMappings) (interface{}, error)
// SendPrimitiveCollectionAsync executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection.
Expand Down
3 changes: 3 additions & 0 deletions serialization/parsable.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ type Parsable interface {

// ParsableFactory is a factory for creating Parsable.
type ParsableFactory func(parseNode ParseNode) (Parsable, error)

// EnumFactory is a factory for creating Enum.
type EnumFactory func(string) (interface{}, error)
4 changes: 2 additions & 2 deletions serialization/parse_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ParseNode interface {
// GetCollectionOfPrimitiveValues returns the collection of primitive values from the node.
GetCollectionOfPrimitiveValues(targetType string) ([]interface{}, error)
// GetCollectionOfEnumValues returns the collection of Enum values from the node.
GetCollectionOfEnumValues(parser func(string) (interface{}, error)) ([]interface{}, error)
GetCollectionOfEnumValues(parser EnumFactory) ([]interface{}, error)
// GetObjectValue returns the Parsable value from the node.
GetObjectValue(ctor ParsableFactory) (Parsable, error)
// GetStringValue returns a String value from the nodes.
Expand Down Expand Up @@ -45,7 +45,7 @@ type ParseNode interface {
// GetUUIDValue returns a UUID value from the nodes.
GetUUIDValue() (*uuid.UUID, error)
// GetEnumValue returns a Enum value from the nodes.
GetEnumValue(parser func(string) (interface{}, error)) (interface{}, error)
GetEnumValue(parser EnumFactory) (interface{}, error)
// GetByteArrayValue returns a ByteArray value from the nodes.
GetByteArrayValue() ([]byte, error)
}
11 changes: 11 additions & 0 deletions serialization/parse_node_factory_registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package serialization

import (
"testing"

assert "github.com/stretchr/testify/assert"
)

func TestParseNodeFactoryRegistryHonoursInterface(t *testing.T) {
assert.Implements(t, (*ParseNodeFactory)(nil), DefaultParseNodeFactoryInstance)
}
38 changes: 23 additions & 15 deletions serialization/serialization_writer_factory_registry_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package serialization

import (
assert "github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/mock"
"time"

"github.com/google/uuid"

assert "github.com/stretchr/testify/assert"
)

type mockSerializer struct {
}

Expand Down Expand Up @@ -38,22 +42,22 @@ func (*mockSerializer) WriteByteArrayValue(key string, value []byte) error {
func (*mockSerializer) WriteTimeValue(key string, value *time.Time) error {
return nil
}
func (*mockSerializer) WriteISODurationValue(key string, value *serialization.ISODuration) error {
func (*mockSerializer) WriteISODurationValue(key string, value *ISODuration) error {
return nil
}
func (*mockSerializer) WriteDateOnlyValue(key string, value *serialization.DateOnly) error {
func (*mockSerializer) WriteDateOnlyValue(key string, value *DateOnly) error {
return nil
}
func (*mockSerializer) WriteTimeOnlyValue(key string, value *serialization.TimeOnly) error {
func (*mockSerializer) WriteTimeOnlyValue(key string, value *TimeOnly) error {
return nil
}
func (*mockSerializer) WriteUUIDValue(key string, value *uuid.UUID) error {
return nil
}
func (*mockSerializer) WriteObjectValue(key string, item serialization.Parsable) error {
func (*mockSerializer) WriteObjectValue(key string, item Parsable) error {
return nil
}
func (*mockSerializer) WriteCollectionOfObjectValues(key string, collection []serialization.Parsable) error {
func (*mockSerializer) WriteCollectionOfObjectValues(key string, collection []Parsable) error {
return nil
}
func (*mockSerializer) WriteCollectionOfStringValues(key string, collection []string) error {
Expand Down Expand Up @@ -83,13 +87,13 @@ func (*mockSerializer) WriteCollectionOfFloat64Values(key string, collection []f
func (*mockSerializer) WriteCollectionOfTimeValues(key string, collection []time.Time) error {
return nil
}
func (*mockSerializer) WriteCollectionOfISODurationValues(key string, collection []serialization.ISODuration) error {
func (*mockSerializer) WriteCollectionOfISODurationValues(key string, collection []ISODuration) error {
return nil
}
func (*mockSerializer) WriteCollectionOfDateOnlyValues(key string, collection []serialization.DateOnly) error {
func (*mockSerializer) WriteCollectionOfDateOnlyValues(key string, collection []DateOnly) error {
return nil
}
func (*mockSerializer) WriteCollectionOfTimeOnlyValues(key string, collection []serialization.TimeOnly) error {
func (*mockSerializer) WriteCollectionOfTimeOnlyValues(key string, collection []TimeOnly) error {
return nil
}
func (*mockSerializer) WriteCollectionOfUUIDValues(key string, collection []uuid.UUID) error {
Expand All @@ -111,13 +115,17 @@ type mockSerializerFactory struct {
func (*mockSerializerFactory) GetValidContentType() (string, error) {
return "application/json", nil
}
func (*mockSerializerFactory) GetSerializationWriter(contentType string) (serialization.SerializationWriter, error) {
func (*mockSerializerFactory) GetSerializationWriter(contentType string) (SerializationWriter, error) {
return &mockSerializer{}, nil
}

func TestItGetsVendorSpecificSerializationWriter(t *testing.T) {
registry := NewSerializationWriterFactoryRegistry()
registry.ContentTypeAssociatedFactories["application/json"] = &mockSerializerFactory{}
serializationWriter = registry.GetSerializationWriter("application/vnd+json")
assert.NotNil(t, serializationWriter)
DefaultSerializationWriterFactoryInstance.ContentTypeAssociatedFactories["application/json"] = &mockSerializerFactory{}
serializationWriter, err := DefaultSerializationWriterFactoryInstance.GetSerializationWriter("application/vnd+json")
assert.Nil(t, err)
assert.NotNil(t, serializationWriter)
}

func TestSerializationWriterFactoryRegistryHonoursInterface(t *testing.T) {
assert.Implements(t, (*SerializationWriterFactory)(nil), DefaultSerializationWriterFactoryInstance)
}

0 comments on commit 2980d93

Please sign in to comment.