forked from andlabs/ews
-
Notifications
You must be signed in to change notification settings - Fork 29
/
get_user_availability_test.go
169 lines (156 loc) · 5.88 KB
/
get_user_availability_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package ews
import (
"encoding/xml"
"github.com/stretchr/testify/assert"
"log"
"testing"
"time"
)
func Test_marshal_GetUserAvailabilityRequest(t *testing.T) {
mb := make([]MailboxData, 0)
mb = append(mb, MailboxData{
Email: Email{
Name: "",
Address: "someone@ExServer.example.com",
RoutingType: "SMTP",
},
AttendeeType: AttendeeTypeOrganizer,
ExcludeConflicts: false,
})
start, _ := time.Parse(time.RFC3339, "2006-02-06T00:00:00Z")
end, _ := time.Parse(time.RFC3339, "2006-02-25T23:59:59Z")
req := GetUserAvailabilityRequest{
TimeZone: TimeZone{
Bias: 480,
StandardTime: TimeZoneTime{
Bias: 0,
Time: "02:00:00",
DayOrder: 5,
Month: 10,
DayOfWeek: "Sunday",
},
DaylightTime: TimeZoneTime{
Bias: -60,
Time: "02:00:00",
DayOrder: 1,
Month: 4,
DayOfWeek: "Sunday",
},
},
MailboxDataArray: MailboxDataArray{MailboxData: mb},
FreeBusyViewOptions: FreeBusyViewOptions{
TimeWindow: TimeWindow{
StartTime: start,
EndTime: end,
},
MergedFreeBusyIntervalInMinutes: 60,
RequestedView: RequestedViewFreeBusyMerged,
},
}
xmlBytes, err := xml.MarshalIndent(req, "", " ")
if err != nil {
log.Fatal(err)
}
assert.Equal(t, `<m:GetUserAvailabilityRequest>
<t:TimeZone>
<t:Bias>480</t:Bias>
<t:StandardTime>
<t:Bias>0</t:Bias>
<t:Time>02:00:00</t:Time>
<t:DayOrder>5</t:DayOrder>
<t:Month>10</t:Month>
<t:DayOfWeek>Sunday</t:DayOfWeek>
</t:StandardTime>
<t:DaylightTime>
<t:Bias>-60</t:Bias>
<t:Time>02:00:00</t:Time>
<t:DayOrder>1</t:DayOrder>
<t:Month>4</t:Month>
<t:DayOfWeek>Sunday</t:DayOfWeek>
</t:DaylightTime>
</t:TimeZone>
<m:MailboxDataArray>
<t:MailboxData>
<t:Email>
<t:Name></t:Name>
<t:Address>someone@ExServer.example.com</t:Address>
<t:RoutingType>SMTP</t:RoutingType>
</t:Email>
<t:AttendeeType>Organizer</t:AttendeeType>
<t:ExcludeConflicts>false</t:ExcludeConflicts>
</t:MailboxData>
</m:MailboxDataArray>
<t:FreeBusyViewOptions>
<t:TimeWindow>
<t:StartTime>2006-02-06T00:00:00Z</t:StartTime>
<t:EndTime>2006-02-25T23:59:59Z</t:EndTime>
</t:TimeWindow>
<t:MergedFreeBusyIntervalInMinutes>60</t:MergedFreeBusyIntervalInMinutes>
<t:RequestedView>FreeBusyMerged</t:RequestedView>
</t:FreeBusyViewOptions>
</m:GetUserAvailabilityRequest>`, string(xmlBytes))
}
func Test_unmarshal_GetUserAvailabilityResponse(t *testing.T) {
soapResp := `
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="2495" MinorBuildNumber="21" Version="V2018_01_08"
xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<GetUserAvailabilityResponse
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FreeBusyResponseArray>
<FreeBusyResponse>
<ResponseMessage ResponseClass="Error">
<MessageText>Microsoft.Exchange.InfoWorker.Common.Availability.MailRecipientNotFoundException: Unable to resolve e-mail address someone@ExServer.example.com to an Active Directory object.
. Name of the server where exception originated: PR3PR01MB6473. LID: 57660</MessageText>
<ResponseCode>ErrorMailRecipientNotFound</ResponseCode>
<DescriptiveLinkKey>0</DescriptiveLinkKey>
<MessageXml>
<ExceptionType
xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">MailRecipientNotFoundException
</ExceptionType>
<ExceptionCode
xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">5009
</ExceptionCode>
<ExceptionServerName
xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">PR3PR01MB6473
</ExceptionServerName>
<ExceptionMessage
xmlns="http://schemas.microsoft.com/exchange/services/2006/errors">Unable to resolve e-mail address someone@ExServer.example.com to an Active Directory object. LID: 57660</ExceptionMessage>
</MessageXml>
</ResponseMessage>
<FreeBusyView>
<FreeBusyViewType
xmlns="http://schemas.microsoft.com/exchange/services/2006/types">None
</FreeBusyViewType>
</FreeBusyView>
</FreeBusyResponse>
</FreeBusyResponseArray>
</GetUserAvailabilityResponse>
</s:Body>
</s:Envelope>
`
var resp getUserAvailabilityResponseEnvelop
err := xml.Unmarshal([]byte(soapResp), &resp)
if err != nil {
log.Fatal(err)
}
assert.Equal(t,
ResponseClassError,
resp.Body.GetUserAvailabilityResponse.FreeBusyResponseArray.FreeBusyResponse[0].
ResponseMessage.ResponseClass,
)
assert.Equal(t,
`Unable to resolve e-mail address someone@ExServer.example.com to an Active Directory object. LID: 57660`,
resp.Body.GetUserAvailabilityResponse.FreeBusyResponseArray.FreeBusyResponse[0].
ResponseMessage.MessageXml.ExceptionMessage,
)
}