Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
1d344f1e
Commit
1d344f1e
authored
9 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
Add test coverage for Metadata class
parent
8fe3f640
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/csharp/Grpc.Core.Tests/MetadataTest.cs
+113
-0
113 additions, 0 deletions
src/csharp/Grpc.Core.Tests/MetadataTest.cs
with
113 additions
and
0 deletions
src/csharp/Grpc.Core.Tests/MetadataTest.cs
+
113
−
0
View file @
1d344f1e
...
@@ -127,5 +127,118 @@ namespace Grpc.Core.Tests
...
@@ -127,5 +127,118 @@ namespace Grpc.Core.Tests
Assert
.
Throws
(
typeof
(
InvalidOperationException
),
()
=>
{
var
v
=
entry
.
Value
;
});
Assert
.
Throws
(
typeof
(
InvalidOperationException
),
()
=>
{
var
v
=
entry
.
Value
;
});
CollectionAssert
.
AreEqual
(
bytes
,
entry
.
ValueBytes
);
CollectionAssert
.
AreEqual
(
bytes
,
entry
.
ValueBytes
);
}
}
[
Test
]
public
void
IndexOf
()
{
var
metadata
=
CreateMetadata
();
Assert
.
AreEqual
(
0
,
metadata
.
IndexOf
(
metadata
[
0
]));
Assert
.
AreEqual
(
1
,
metadata
.
IndexOf
(
metadata
[
1
]));
}
[
Test
]
public
void
Insert
()
{
var
metadata
=
CreateMetadata
();
metadata
.
Insert
(
0
,
new
Metadata
.
Entry
(
"new-key"
,
"new-value"
));
Assert
.
AreEqual
(
3
,
metadata
.
Count
);
Assert
.
AreEqual
(
"new-key"
,
metadata
[
0
].
Key
);
Assert
.
AreEqual
(
"abc"
,
metadata
[
1
].
Key
);
}
[
Test
]
public
void
RemoveAt
()
{
var
metadata
=
CreateMetadata
();
metadata
.
RemoveAt
(
0
);
Assert
.
AreEqual
(
1
,
metadata
.
Count
);
Assert
.
AreEqual
(
"xyz"
,
metadata
[
0
].
Key
);
}
[
Test
]
public
void
Remove
()
{
var
metadata
=
CreateMetadata
();
metadata
.
Remove
(
metadata
[
0
]);
Assert
.
AreEqual
(
1
,
metadata
.
Count
);
Assert
.
AreEqual
(
"xyz"
,
metadata
[
0
].
Key
);
}
[
Test
]
public
void
Indexer_Set
()
{
var
metadata
=
CreateMetadata
();
var
entry
=
new
Metadata
.
Entry
(
"new-key"
,
"new-value"
);
metadata
[
1
]
=
entry
;
Assert
.
AreEqual
(
entry
,
metadata
[
1
]);
}
[
Test
]
public
void
Clear
()
{
var
metadata
=
CreateMetadata
();
metadata
.
Clear
();
Assert
.
AreEqual
(
0
,
metadata
.
Count
);
}
[
Test
]
public
void
Contains
()
{
var
metadata
=
CreateMetadata
();
Assert
.
IsTrue
(
metadata
.
Contains
(
metadata
[
0
]));
Assert
.
IsFalse
(
metadata
.
Contains
(
new
Metadata
.
Entry
(
"new-key"
,
"new-value"
)));
}
[
Test
]
public
void
CopyTo
()
{
var
metadata
=
CreateMetadata
();
var
array
=
new
Metadata
.
Entry
[
metadata
.
Count
+
1
];
metadata
.
CopyTo
(
array
,
1
);
Assert
.
AreEqual
(
default
(
Metadata
.
Entry
),
array
[
0
]);
Assert
.
AreEqual
(
metadata
[
0
],
array
[
1
]);
}
[
Test
]
public
void
IEnumerableGetEnumerator
()
{
var
metadata
=
CreateMetadata
();
var
enumerator
=
(
metadata
as
System
.
Collections
.
IEnumerable
).
GetEnumerator
();
int
i
=
0
;
while
(
enumerator
.
MoveNext
())
{
Assert
.
AreEqual
(
metadata
[
i
],
enumerator
.
Current
);
i
++;
}
}
[
Test
]
public
void
FreezeMakesReadOnly
()
{
var
entry
=
new
Metadata
.
Entry
(
"new-key"
,
"new-value"
);
var
metadata
=
CreateMetadata
().
Freeze
();
Assert
.
IsTrue
(
metadata
.
IsReadOnly
);
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
Insert
(
0
,
entry
));
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
RemoveAt
(
0
));
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
[
0
]
=
entry
);
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
Add
(
entry
));
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
Add
(
"new-key"
,
"new-value"
));
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
Add
(
"new-key-bin"
,
new
byte
[]
{
0xaa
}));
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
Clear
());
Assert
.
Throws
<
InvalidOperationException
>(()
=>
metadata
.
Remove
(
metadata
[
0
]));
}
private
Metadata
CreateMetadata
()
{
return
new
Metadata
{
{
"abc"
,
"abc-value"
},
{
"xyz"
,
"xyz-value"
},
};
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment