Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames Add-CloudEvent*Data to Set-CloudEvent*Data #12

Merged
9 changes: 0 additions & 9 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,3 @@ Start-Tests -TestsType 'unit'

# 5. Run Integration Tests
Start-Tests -TestsType 'integration'

# 6. Prepare Module for Publishing
$dirItem = Get-Item $OutputDir
$catalogFilePath = Join-path $OutputDir ($dirItem.Name + ".cat")
if (Test-Path $catalogFilePath) {
# Delete previous catalog file
Remove-Item $catalogFilePath -Confirm:$false
}
New-FileCatalog -Path $OutputDir -CatalogFilePath $catalogFilePath | Out-Null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional suggestion: Maybe we can remove the whole step Prepare Module for Publishing although the condition for removing the previous catalog file will never be invoked with the removal of the NewFileCatalog call.

4 changes: 2 additions & 2 deletions src/CloudEventsPowerShell/CloudEvents.Sdk.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RootModule = 'CloudEvents.Sdk.psm1'

# Version number of this module.
ModuleVersion = '0.1.4'
ModuleVersion = '0.2.0'

# Supported PSEditions
CompatiblePSEditions = @('Core')
Expand Down Expand Up @@ -67,7 +67,7 @@ RequiredAssemblies = @('CloudNative.CloudEvents.dll')

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'New-CloudEvent', 'Add-CloudEventData', 'Add-CloudEventJsonData', 'Add-CloudEventXmlData', 'Read-CloudEventData', 'Read-CloudEventJsonData', 'Read-CloudEventXmlData', # CloudEvent Object Functions
'New-CloudEvent', 'Set-CloudEventData', 'Set-CloudEventJsonData', 'Set-CloudEventXmlData', 'Read-CloudEventData', 'Read-CloudEventJsonData', 'Read-CloudEventXmlData', # CloudEvent Object Functions
'ConvertTo-HttpMessage', 'ConvertFrom-HttpMessage' # Http Binding Functions
)

Expand Down
55 changes: 30 additions & 25 deletions src/CloudEventsPowerShell/CloudEvents.Sdk.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,30 @@ PROCESS {
}
}

#region Add Data Functions
function Add-CloudEventData {
#region Set Data Functions
function Set-CloudEventData {
<#
.SYNOPSIS
This function adds data to a cloud event.
This function sets data in a cloud event.

.DESCRIPTION
This function adds data to a cloud event object with the provided parameters.
This function sets data in a cloud event object with the provided parameters.

.PARAMETER CloudEvent
Specifies the cloud event object to add data to.
Specifies the cloud event object that receives the data.

.PARAMETER Data
Specifies the data object that is added to the cloud event 'data' attribute.
Specifies the data object for the cloud event 'data' attribute.

.PARAMETER DataContentType
Specifies the 'datacontenttype' attribute of the cloud event.


.EXAMPLE
$cloudEvent = New-CloudEvent -Type 'com.example.object.deleted.v2' -Source 'mailto:[email protected]' -Id '6e8bc430-9c3a-11d9-9669-0800200c9a66' -Time (Get-Date)
$cloudEvent | Add-CloudEventData -Data '<much wow="xml"/>' -DataContentType 'application/xml'
$cloudEvent | Set-CloudEventData -Data '<much wow="xml"/>' -DataContentType 'application/xml'

Adds xml data to the cloud event
Sets xml data to the cloud event
#>

[CmdletBinding()]
Expand Down Expand Up @@ -135,27 +135,32 @@ PROCESS {

}

function Add-CloudEventJsonData {
function Set-CloudEventJsonData {
<#
.SYNOPSIS
This function adds JSON format data to a cloud event.
This function sets JSON format data in a cloud event.

.DESCRIPTION
This function converts a PowerShell hashtable to JSON format data and adds it to a cloud event.
This function converts a PowerShell hashtable to JSON format data and sets it in a cloud event.

.PARAMETER CloudEvent
Specifies the cloud event object to add data to.
Specifies the cloud event object that receives the data.

.PARAMETER Data
Specifies the PowerShell hashtable object that is added as JSON to the cloud event 'data' attribute.
The 'datacontenttype' attribute is set to 'applicaiton/json'
Specifies the PowerShell hashtable object that is set as JSON on the cloud event 'data' attribute.
The 'datacontenttype' attribute is set to 'application/json'

.PARAMETER Depth
The maximum depth of the input hashtable specified on the `Data` parameter that will be converted to JSON.
This parameter is passed on the `-Depth` parameter of the `ConvertTo-Json` cmdlet.
The default value is 3


.EXAMPLE
$cloudEvent = New-CloudEvent -Type 'com.example.object.deleted.v2' -Source 'mailto:[email protected]' -Id '6e8bc430-9c3a-11d9-9669-0800200c9a66' -Time (Get-Date)
$cloudEvent | Add-CloudEventJsonData -Data @{ 'key1' = 'value1'; 'key2' = 'value2'; }
$cloudEvent | Set-CloudEventJsonData -Data @{ 'key1' = 'value1'; 'key2' = 'value2'; }

Adds JSON data to the cloud event
Sets JSON data to the cloud event
#>

[CmdletBinding()]
Expand Down Expand Up @@ -193,20 +198,20 @@ PROCESS {

}

function Add-CloudEventXmlData {
function Set-CloudEventXmlData {
<#
.SYNOPSIS
This function adds XML format data to a cloud event.
This function sets XML format data in a cloud event.

.DESCRIPTION
This function converts a PowerShell hashtable to XML format data and adds it to a cloud event.
This function converts a PowerShell hashtable to XML format data and sets it in a cloud event.

.PARAMETER CloudEvent
Specifies the cloud event object to add data to.
Specifies the cloud event object that receives the data.

.PARAMETER Data
Specifies the PowerShell hashtable object that is added as XML to the cloud event 'data' attribute.
The 'datacontenttype' attribute is set to 'applicaiton/xml'
Specifies the PowerShell hashtable object that is set as XML on the cloud event 'data' attribute.
The 'datacontenttype' attribute is set to 'application/xml'

.PARAMETER AttributesKeysInElementAttributes
Specifies how to format the XML. If specified and the input Data hashtable has pairs of 'Attributes', 'Value' keys
Expand All @@ -219,9 +224,9 @@ function Add-CloudEventXmlData {

.EXAMPLE
$cloudEvent = New-CloudEvent -Type 'com.example.object.deleted.v2' -Source 'mailto:[email protected]' -Id '6e8bc430-9c3a-11d9-9669-0800200c9a66' -Time (Get-Date)
$cloudEvent | Add-CloudEventXmlData -Data @{ 'key1' = 'value1'; 'key2' = 'value2'; } -AttributesKeysInElementAttributes $true
$cloudEvent | Set-CloudEventXmlData -Data @{ 'key1' = 'value1'; 'key2' = 'value2'; } -AttributesKeysInElementAttributes $true

Adds XML data to the cloud event
Sets XML data in the cloud event
#>

[CmdletBinding()]
Expand Down Expand Up @@ -256,7 +261,7 @@ PROCESS {
}

}
#endregion Add Data Functions
#endregion Set Data Functions

#region Read Data Functions
function Read-CloudEventData {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/HttpIntegration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Describe "Client-Server Integration Tests" {
-Source $script:ClientSource `
-Id 'integration-test-1' `
-Time (Get-Date) | `
Add-CloudEventJsonData -Data @{
Set-CloudEventJsonData -Data @{
'a1' = 'b'
'a2' = 'c'
'a3' = 'd'
Expand Down Expand Up @@ -106,7 +106,7 @@ Describe "Client-Server Integration Tests" {
-Source $script:ClientSource `
-Id 'integration-test-2' `
-Time (Get-Date) | `
Add-CloudEventXmlData -Data @{
Set-CloudEventXmlData -Data @{
'a1' = @{
'a2' = 'c'
'a3' = 'd'
Expand Down Expand Up @@ -157,7 +157,7 @@ Describe "Client-Server Integration Tests" {
-Source $script:ClientSource `
-Id 'integration-test-3' `
-Time (Get-Date) | `
Add-CloudEventJsonData -Data @{
Set-CloudEventJsonData -Data @{
'b1' = 'd'
'b2' = 'e'
'b3' = 'f'
Expand Down Expand Up @@ -205,7 +205,7 @@ Describe "Client-Server Integration Tests" {
-Source $script:ClientSource `
-Id 'integration-test-4' `
-Time (Get-Date) | `
Add-CloudEventXmlData -Data @{
Set-CloudEventXmlData -Data @{
'b1' = @{
'b2' = 'e'
'b3' = 'f'
Expand Down Expand Up @@ -256,7 +256,7 @@ Describe "Client-Server Integration Tests" {
-Source $script:ClientSource `
-Id 'integration-test-5' `
-Time (Get-Date) | `
Add-CloudEventData `
Set-CloudEventData `
-Data 'This is text data' `
-DataContentType 'application/text'

Expand Down
6 changes: 3 additions & 3 deletions test/integration/HttpServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ while ( -not $global:serverStopRequested ) {
$requestCloudEventJsonData = $requestCloudEvent | Read-CloudEventJsonData
$requestCloudEventXmlData = $requestCloudEvent | Read-CloudEventXmlData -ConvertMode 'SkipAttributes'
if ($requestCloudEventJsonData) {
$cloudEvent = $cloudEvent | Add-CloudEventJsonData `
$cloudEvent = $cloudEvent | Set-CloudEventJsonData `
-Data $requestCloudEventJsonData
} elseif ($requestCloudEventXmlData) {
$cloudEvent = $cloudEvent | Add-CloudEventXmlData `
$cloudEvent = $cloudEvent | Set-CloudEventXmlData `
-Data $requestCloudEventXmlData `
-AttributesKeysInElementAttributes $false
} else {
$requestCloudEventData = $requestCloudEvent | Read-CloudEventData
$cloudEvent = $cloudEvent | Add-CloudEventData `
$cloudEvent = $cloudEvent | Set-CloudEventData `
-Data $requestCloudEventData `
-DataContentType $requestCloudEvent.DataContentType
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/ConvertTo-HttpMessage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
-Time $expectedTime

$expectedData = @{ 'key1' = 'value2'; 'key3' = 'value4' }
$cloudEvent = Add-CloudEventJsonData `
$cloudEvent = Set-CloudEventJsonData `
-CloudEvent $cloudEvent `
-Data $expectedData

Expand Down Expand Up @@ -75,7 +75,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
-Source $expectedSource

$expectedData = '<much wow="xml"/>'
$cloudEvent = Add-CloudEventData `
$cloudEvent = Set-CloudEventData `
-CloudEvent $cloudEvent `
-Data $expectedData `
-DataContentType $expectedDataContentType
Expand Down Expand Up @@ -120,7 +120,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
-Time $expectedTime

$expectedData = @{ 'key1' = 'value2'; 'key3' = 'value4' }
$cloudEvent = Add-CloudEventJsonData `
$cloudEvent = Set-CloudEventJsonData `
-CloudEvent $cloudEvent `
-Data $expectedData

Expand Down Expand Up @@ -185,7 +185,7 @@ Describe "ConvertTo-HttpMessage Function Tests" {
-Source $expectedSource

$expectedData = '<much wow="xml"/>'
$cloudEvent = Add-CloudEventData `
$cloudEvent = Set-CloudEventData `
-CloudEvent $cloudEvent `
-Data $expectedData `
-DataContentType $expectedDataContentType
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Read-CloudEventData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Describe "Read-CloudEventData Function Tests" {
$expectedData = '<much wow="xml"/>'
$expectedDataContentType = 'text/xml'

$cloudEvent = $cloudEvent | Add-CloudEventData -Data $expectedData -DataContentType $expectedDataContentType
$cloudEvent = $cloudEvent | Set-CloudEventData -Data $expectedData -DataContentType $expectedDataContentType

# Act
$actual = $cloudEvent | Read-CloudEventData
Expand Down
6 changes: 3 additions & 3 deletions test/unit/Read-CloudEventJsonData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Describe "Read-CloudEventJsonData Function Tests" {

$expectedHtData = @{'a' = 'b'}

$cloudEvent = $cloudEvent | Add-CloudEventJsonData -Data $expectedHtData
$cloudEvent = $cloudEvent | Set-CloudEventJsonData -Data $expectedHtData -Depth 1

# Act
$actual = $cloudEvent | Read-CloudEventJsonData
Expand All @@ -32,7 +32,7 @@ Describe "Read-CloudEventJsonData Function Tests" {
-Type test `
-Source 'urn:test'

$cloudEvent = $cloudEvent | Add-CloudEventData -Data "test" -DataContentType 'application/text'
$cloudEvent = $cloudEvent | Set-CloudEventData -Data "test" -DataContentType 'application/text'
$pre

# Act
Expand All @@ -58,7 +58,7 @@ Describe "Read-CloudEventJsonData Function Tests" {
}
}

$cloudEvent = $cloudEvent | Add-CloudEventJsonData -Data $expectedHtData -Depth 4
$cloudEvent = $cloudEvent | Set-CloudEventJsonData -Data $expectedHtData -Depth 4

# Act
$actual = $cloudEvent | Read-CloudEventJsonData -Depth 4
Expand Down
6 changes: 3 additions & 3 deletions test/unit/Read-CloudEventXmlData.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Describe "Read-CloudEventXmlData Function Tests" {
$xmlData = "<a>b</a>"
$expectedHtData = @{'a' = 'b'}

$cloudEvent = $cloudEvent | Add-CloudEventData -Data $xmlData -DataContentType 'application/xml'
$cloudEvent = $cloudEvent | Set-CloudEventData -Data $xmlData -DataContentType 'application/xml'

# Act
$actual = $cloudEvent | Read-CloudEventXmlData -ConvertMode 'SkipAttributes'
Expand All @@ -33,7 +33,7 @@ Describe "Read-CloudEventXmlData Function Tests" {
-Type test `
-Source 'urn:test'

$cloudEvent = $cloudEvent | Add-CloudEventData -Data "test" -DataContentType 'application/text'
$cloudEvent = $cloudEvent | Set-CloudEventData -Data "test" -DataContentType 'application/text'
$pre

# Act
Expand All @@ -60,7 +60,7 @@ Describe "Read-CloudEventXmlData Function Tests" {
}
}

$cloudEvent = $cloudEvent | Add-CloudEventData -Data $xmlData -DataContentType 'application/xml'
$cloudEvent = $cloudEvent | Set-CloudEventData -Data $xmlData -DataContentType 'application/xml'

# Act
$actual = $cloudEvent | Read-CloudEventXmlData -ConvertMode 'SkipAttributes'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
# **************************************************************************

Describe "Add-CloudEventData Function Tests" {
Context "Adds Data" {
It 'Adds byte[] data' {
Describe "Set-CloudEventData Function Tests" {
Context "Sets Data" {
It 'Sets byte[] data' {
# Arrange
$cloudEvent = New-CloudEvent `
-Id ([Guid]::NewGuid()) `
Expand All @@ -18,7 +18,7 @@ Describe "Add-CloudEventData Function Tests" {

# Act
$actual = $cloudEvent | `
Add-CloudEventData `
Set-CloudEventData `
-Data $expectedData `
-DataContentType $expectedDataContentType

Expand All @@ -28,7 +28,7 @@ Describe "Add-CloudEventData Function Tests" {
$actual.Data | Should -Be $expectedData
}

It 'Adds xml text data' {
It 'Sets xml text data' {
# Arrange
$cloudEvent = New-CloudEvent `
-Id ([Guid]::NewGuid()) `
Expand All @@ -41,7 +41,7 @@ Describe "Add-CloudEventData Function Tests" {

# Act
$actual = $cloudEvent | `
Add-CloudEventData `
Set-CloudEventData `
-Data $expectedData `
-DataContentType $expectedDataContentType

Expand All @@ -64,7 +64,7 @@ Describe "Add-CloudEventData Function Tests" {
-Source 'urn:test'

# Act & Assert
{ Add-CloudEventData `
{ Set-CloudEventData `
-CloudEvent $cloudEvent `
-Data '1' `
-DataContentType $invalidContentType } | `
Expand All @@ -81,7 +81,7 @@ Describe "Add-CloudEventData Function Tests" {
-Source 'urn:test'

# Act & Assert
{ Add-CloudEventData `
{ Set-CloudEventData `
-CloudEvent $cloudEvent `
-Data '1' `
-DataContentType $invalidContentType } | `
Expand All @@ -98,7 +98,7 @@ Describe "Add-CloudEventData Function Tests" {
-Source 'urn:test'

# Act & Assert
{ Add-CloudEventData `
{ Set-CloudEventData `
-CloudEvent $cloudEvent `
-Data '1' `
-DataContentType $invalidContentType } | `
Expand Down
Loading