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
15 changes: 9 additions & 6 deletions src/CloudEventsPowerShell/CloudEvents.Sdk.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,16 @@ function Set-CloudEventData {

PROCESS {

# https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#datacontenttype
$contentType = New-Object `
-TypeName 'System.Net.Mime.ContentType' `
-ArgumentList ($DataContentType)

$cloudEvent.Data = $Data
$cloudEvent.DataContentType = $dataContentType

if ($PSBoundParameters.ContainsKey('DataContentType')) {
# https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#datacontenttype
$contentType = New-Object `
-TypeName 'System.Net.Mime.ContentType' `
-ArgumentList ($DataContentType)

$cloudEvent.DataContentType = $contentType
}

if ($PSBoundParameters.ContainsKey('DataSchema')) {
$cloudEvent.DataSchema = $DataSchema
Expand Down
10 changes: 10 additions & 0 deletions test/unit/Set-CloudEventData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ Describe "Set-CloudEventData Function Tests" {
# Assert
$actual | Should -Not -Be $null
$actual.DataContentType.ToString() | Should -Be $expectedDataContentType
$actual.DataContentType | Should -BeOfType ([System.Net.Mime.ContentType])
$actual.Data | Should -Be $expectedData
$actual.DataSchema | Should -BeNullOrEmpty
}

It 'Sets data when DataContentType is omitted' {
$cloudEvent = New-CloudEvent -Id 'test-id' -Type test -Source 'urn:test'

$actual = $cloudEvent | Set-CloudEventData -Data 'test'

$actual.Data | Should -Be 'test'
$actual.DataContentType | Should -BeNullOrEmpty
}

It 'Sets xml text data' {
# Arrange
$cloudEvent = New-CloudEvent `
Expand Down
Loading