Skip to content

Commit 8eb7867

Browse files
Kai SongKai Song
authored andcommitted
Add UTs
1 parent d0fc33f commit 8eb7867

File tree

3 files changed

+206
-0
lines changed

3 files changed

+206
-0
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@
524524
23FB5C452255A11D002BF1EB /* MSIDClaimsRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 23FB5C24225517AA002BF1EB /* MSIDClaimsRequest.m */; };
525525
23FB5C462255A135002BF1EB /* MSIDIndividualClaimRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 23FB5C29225517AA002BF1EB /* MSIDIndividualClaimRequest.m */; };
526526
23FB5C472255A13A002BF1EB /* MSIDIndividualClaimRequestAdditionalInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 23FB5C27225517AA002BF1EB /* MSIDIndividualClaimRequestAdditionalInfo.m */; };
527+
2A0278912D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A0278902D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m */; };
528+
2A0278922D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A0278902D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m */; };
529+
2A0278A32D6E3787005655B4 /* MSIDLastRequestTelemetry+Tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A0278A22D6E3787005655B4 /* MSIDLastRequestTelemetry+Tests.h */; };
527530
580E25402719FD10003D1795 /* MSIDPrtHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 580E253E2719FD10003D1795 /* MSIDPrtHeader.h */; };
528531
580E25412719FD10003D1795 /* MSIDPrtHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 580E253F2719FD10003D1795 /* MSIDPrtHeader.m */; };
529532
580E25422719FD10003D1795 /* MSIDPrtHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 580E253F2719FD10003D1795 /* MSIDPrtHeader.m */; };
@@ -2392,6 +2395,8 @@
23922395
23FB5C2E22551866002BF1EB /* MSIDClaimsRequest+ClientCapabilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MSIDClaimsRequest+ClientCapabilities.m"; sourceTree = "<group>"; };
23932396
23FB5C32225585E6002BF1EB /* MSIDClaimsRequestMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDClaimsRequestMock.h; sourceTree = "<group>"; };
23942397
23FB5C33225585E6002BF1EB /* MSIDClaimsRequestMock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDClaimsRequestMock.m; sourceTree = "<group>"; };
2398+
2A0278902D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDAADTokenRequestServerTelemetryTests.m; sourceTree = "<group>"; };
2399+
2A0278A22D6E3787005655B4 /* MSIDLastRequestTelemetry+Tests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MSIDLastRequestTelemetry+Tests.h"; sourceTree = "<group>"; };
23952400
51E364572863C0F300A97F82 /* MSIDTelemetryConditionalCompile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSIDTelemetryConditionalCompile.h; sourceTree = "<group>"; };
23962401
580E253E2719FD10003D1795 /* MSIDPrtHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDPrtHeader.h; sourceTree = "<group>"; };
23972402
580E253F2719FD10003D1795 /* MSIDPrtHeader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDPrtHeader.m; sourceTree = "<group>"; };
@@ -3712,6 +3717,7 @@
37123717
B431B5322AF1C3AA0020CD3D /* MSIDSSOExtensionPasskeyAssertionRequestMock.m */,
37133718
B431B5352AF1C3BD0020CD3D /* MSIDSSOExtensionPasskeyCredentialRequestMock.h */,
37143719
B431B5362AF1C3C60020CD3D /* MSIDSSOExtensionPasskeyCredentialRequestMock.m */,
3720+
2A0278A22D6E3787005655B4 /* MSIDLastRequestTelemetry+Tests.h */,
37153721
);
37163722
path = mocks;
37173723
sourceTree = "<group>";
@@ -5717,6 +5723,7 @@
57175723
2347D6652D5415EB00372D20 /* MSIDSwitchBrowserResumeResponseTest.swift */,
57185724
2347D6682D5453A400372D20 /* MSIDSwitchBrowserOperationTest.swift */,
57195725
237034432D56AA7F00D6A70B /* MSIDSwitchBrowserResumeOperationTest.swift */,
5726+
2A0278902D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m */,
57205727
);
57215728
path = tests;
57225729
sourceTree = "<group>";
@@ -6261,6 +6268,7 @@
62616268
B217861823A57ED800839CE8 /* MSIDAuthorizationControllerMock.h in Headers */,
62626269
B2E4A07B24DDE5D7007CE642 /* NSUUID+MSIDTestUtil.h in Headers */,
62636270
B217862923A5839300839CE8 /* MSIDSSOExtensionSignoutRequestMock.h in Headers */,
6271+
2A0278A32D6E3787005655B4 /* MSIDLastRequestTelemetry+Tests.h in Headers */,
62646272
969CCB5622A9EB0300A55515 /* MSIDTestCacheDataSource.h in Headers */,
62656273
B28AC66421A0BB9D00A1FC4A /* MSIDTestBrokerResponseHelper.h in Headers */,
62666274
B23ECF031FF30BB90015FC1D /* MSIDTestIdentifiers.h in Headers */,
@@ -6822,6 +6830,7 @@
68226830
23AE9D9D213A06EF00B285F3 /* MSIDAadAuthorityCacheTests.m in Sources */,
68236831
58EB18382729BB8B00F4DD73 /* MSIDSSOExtensionGetSsoCookiesRequestTests.m in Sources */,
68246832
B2BE926F21A2668600F5AB8C /* MSIDBrokerInteractiveControllerIntegrationTests.m in Sources */,
6833+
2A0278912D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m in Sources */,
68256834
23AE9DAC21409A3800B285F3 /* MSIDWebMSAuthResponseTests.m in Sources */,
68266835
23985AB72391F8D100942308 /* MSIDBrokerOperationInteractiveTokenRequestTests.m in Sources */,
68276836
968871E920AD0397009D6FC3 /* MSIDWebAADAuthResponseTests.m in Sources */,
@@ -7584,6 +7593,7 @@
75847593
B26A0B972072B9CB006BD95A /* MSIDAADV1Oauth2FactoryTests.m in Sources */,
75857594
B208854C29ADC0FD00A50B88 /* MSIDPkeyAuthHelperTests.m in Sources */,
75867595
5837A7DD28F4977C007B3F4E /* MSIDLegacyTokenCacheKey+UTest.m in Sources */,
7596+
2A0278922D6E3216005655B4 /* MSIDAADTokenRequestServerTelemetryTests.m in Sources */,
75877597
B2DD5BA2204761660084313F /* MSIDLegacySingleResourceTokenTests.m in Sources */,
75887598
239DF9C020E04BC9002D428B /* MSIDAADAuthorityTests.m in Sources */,
75897599
D6D9A4BF1FBE712900EFA430 /* MSIDStringExtensionsTests.m in Sources */,
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
26+
#import <XCTest/XCTest.h>
27+
#import "MSIDLastRequestTelemetry+Tests.h"
28+
#import "MSIDAADTokenRequestServerTelemetry.h"
29+
#import "MSIDTestSwizzle.h"
30+
#import "MSIDTestContext.h"
31+
32+
@interface MSIDAADTokenRequestServerTelemetryTests : XCTestCase
33+
34+
@property (nonatomic) MSIDTestContext *context;
35+
36+
@end
37+
38+
@implementation MSIDAADTokenRequestServerTelemetryTests
39+
40+
- (void)setUp {
41+
// Put setup code here. This method is called before the invocation of each test method in the class.
42+
[MSIDTestSwizzle reset];
43+
__auto_type context = [MSIDTestContext new];
44+
context.correlationId = [[NSUUID alloc] initWithUUIDString:@"00000000-0000-0000-0000-000000000001"];
45+
self.context = context;
46+
}
47+
48+
- (void)tearDown {
49+
// Put teardown code here. This method is called after the invocation of each test method in the class.
50+
[MSIDTestSwizzle reset];
51+
}
52+
53+
- (void)test_whenNoError_passIn_handleErrorWithContext_shouldResetTelemetry
54+
{
55+
MSIDAADTokenRequestServerTelemetry *telemetry = [MSIDAADTokenRequestServerTelemetry new];
56+
MSIDLastRequestTelemetry *telemetryObject = [MSIDLastRequestTelemetry sharedInstance];
57+
[telemetry setValue:telemetryObject forKey:@"lastRequestTelemetry"];
58+
59+
XCTestExpectation *expectation = [self expectationWithDescription:@"resetTelemetry triggerred"];
60+
[MSIDTestSwizzle instanceMethod:@selector(resetTelemetry)
61+
class:[MSIDLastRequestTelemetry class]
62+
block:(id)^(void)
63+
{
64+
[expectation fulfill];
65+
66+
}];
67+
68+
[MSIDTestSwizzle instanceMethod:@selector(addErrorInfo:)
69+
class:[MSIDLastRequestTelemetry class]
70+
block:(id)^(void)
71+
{
72+
XCTFail(@"addErrorInfo should not be triggerred");
73+
}];
74+
75+
[telemetry handleError:nil context:self.context];
76+
77+
[self waitForExpectationsWithTimeout:1 handler:nil];
78+
}
79+
80+
- (void)test_whenError_passIn_handleErrorWithContext_shouldAddErrorInfo
81+
{
82+
MSIDAADTokenRequestServerTelemetry *telemetry = [MSIDAADTokenRequestServerTelemetry new];
83+
MSIDLastRequestTelemetry *telemetryObject = [MSIDLastRequestTelemetry sharedInstance];
84+
[telemetry setValue:telemetryObject forKey:@"lastRequestTelemetry"];
85+
86+
XCTestExpectation *expectation = [self expectationWithDescription:@"addErrorInfo triggerred"];
87+
[MSIDTestSwizzle instanceMethod:@selector(resetTelemetry)
88+
class:[MSIDLastRequestTelemetry class]
89+
block:(id)^(void)
90+
{
91+
XCTFail(@"resetTelemetry should not be triggerred");
92+
}];
93+
94+
[MSIDTestSwizzle instanceMethod:@selector(addErrorInfo:)
95+
class:[MSIDLastRequestTelemetry class]
96+
block:(id)^(void)
97+
{
98+
[expectation fulfill];
99+
}];
100+
101+
[telemetry handleError:[NSError new] context:self.context];
102+
103+
[self waitForExpectationsWithTimeout:1 handler:nil];
104+
}
105+
106+
- (void)test_whenNoError_passIn_handleErrorWithMessageAndContext_shouldAddErrorInfo
107+
{
108+
MSIDAADTokenRequestServerTelemetry *telemetry = [MSIDAADTokenRequestServerTelemetry new];
109+
MSIDLastRequestTelemetry *telemetryObject = [MSIDLastRequestTelemetry sharedInstance];
110+
[telemetry setValue:telemetryObject forKey:@"lastRequestTelemetry"];
111+
112+
XCTestExpectation *expectation = [self expectationWithDescription:@"resetTelemetry triggerred"];
113+
[MSIDTestSwizzle instanceMethod:@selector(resetTelemetry)
114+
class:[MSIDLastRequestTelemetry class]
115+
block:(id)^(void)
116+
{
117+
XCTFail(@"resetTelemetry should not be triggerred");
118+
}];
119+
120+
[MSIDTestSwizzle instanceMethod:@selector(addErrorInfo:)
121+
class:[MSIDLastRequestTelemetry class]
122+
block:(id)^(void)
123+
{
124+
[expectation fulfill];
125+
}];
126+
127+
[telemetry handleError:nil errorString:@"error string" context:self.context];
128+
129+
[self waitForExpectationsWithTimeout:1 handler:nil];
130+
}
131+
132+
- (void)test_whenError_passIn_handleErrorWithMessageAndContext_shouldAddErrorInfo
133+
{
134+
MSIDAADTokenRequestServerTelemetry *telemetry = [MSIDAADTokenRequestServerTelemetry new];
135+
MSIDLastRequestTelemetry *telemetryObject = [MSIDLastRequestTelemetry sharedInstance];
136+
[telemetry setValue:telemetryObject forKey:@"lastRequestTelemetry"];
137+
138+
XCTestExpectation *expectation = [self expectationWithDescription:@"resetTelemetry triggerred"];
139+
[MSIDTestSwizzle instanceMethod:@selector(resetTelemetry)
140+
class:[MSIDLastRequestTelemetry class]
141+
block:(id)^(void)
142+
{
143+
XCTFail(@"resetTelemetry should not be triggerred");
144+
}];
145+
146+
[MSIDTestSwizzle instanceMethod:@selector(addErrorInfo:)
147+
class:[MSIDLastRequestTelemetry class]
148+
block:(id)^(void)
149+
{
150+
[expectation fulfill];
151+
}];
152+
153+
[telemetry handleError:[NSError new] errorString:@"error string" context:self.context];
154+
155+
[self waitForExpectationsWithTimeout:1 handler:nil];
156+
}
157+
158+
@end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
26+
#import "MSIDLastRequestTelemetry.h"
27+
28+
NS_ASSUME_NONNULL_BEGIN
29+
30+
@interface MSIDLastRequestTelemetry ()
31+
32+
- (void)resetTelemetry;
33+
34+
- (void)addErrorInfo:(MSIDRequestTelemetryErrorInfo *)errorInfo;
35+
36+
@end
37+
38+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)