|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Threading.Tasks;
|
3 | 4 | using Confluent.SchemaRegistry;
|
4 | 5 |
|
@@ -44,4 +45,58 @@ public async Task ResolveAsync_ValidProtobufObject_ReturnsProtoFields()
|
44 | 45 | // Assert
|
45 | 46 | protoFields.Should().NotBeNull();
|
46 | 47 | }
|
| 48 | + |
| 49 | + [TestMethod] |
| 50 | + public async Task ResolveAsync_SchemaWithPackageOnly_ReturnsTypeNameWithPackageNamespace() |
| 51 | + { |
| 52 | + // Arrange |
| 53 | + // below schema-string is base64 encoded protobuf schema of 'syntax = \"proto3\";\npackage kafkaflow.test;\n\nmessage Person {\n string name = 1;\n}\n' |
| 54 | + var schemaString = "CgdkZWZhdWx0Eg5rYWZrYWZsb3cudGVzdCIUCgZQZXJzb24SCgoEbmFtZRgBKAliBnByb3RvMw=="; |
| 55 | + var schemaId = 420; |
| 56 | + |
| 57 | + _schemaRegistryClient.Setup(client => client.GetSchemaAsync(schemaId, "serialized")) |
| 58 | + .ReturnsAsync(new RegisteredSchema("test", 1, schemaId, schemaString, SchemaType.Protobuf, new List<SchemaReference>())); |
| 59 | + |
| 60 | + // Act |
| 61 | + var actual = await _schemaRegistryTypeResolver.ResolveAsync(schemaId); |
| 62 | + |
| 63 | + // Assert |
| 64 | + actual.Should().Be("kafkaflow.test.Person"); |
| 65 | + } |
| 66 | + |
| 67 | + [TestMethod] |
| 68 | + public async Task ResolveAsync_SchemaWithCsharpNamespace_ReturnsTypeNameWithCsharpNamespace() |
| 69 | + { |
| 70 | + // Arrange |
| 71 | + // below schema-string is base64 encoded protobuf schema of 'syntax = \"proto3\";\npackage kafkaflow.test;\n\nmessage Person {\n string name = 1;\n}\n' |
| 72 | + var schemaString = "CgdkZWZhdWx0Eg5rYWZrYWZsb3cudGVzdCIUCgZQZXJzb24SCgoEbmFtZRgBKAlCEaoCDkthZmthRmxvdy5UZXN0YgZwcm90bzM="; |
| 73 | + var schemaId = 420; |
| 74 | + |
| 75 | + _schemaRegistryClient.Setup(client => client.GetSchemaAsync(schemaId, "serialized")) |
| 76 | + .ReturnsAsync(new RegisteredSchema("test", 1, schemaId, schemaString, SchemaType.Protobuf, new List<SchemaReference>())); |
| 77 | + |
| 78 | + // Act |
| 79 | + var actual = await _schemaRegistryTypeResolver.ResolveAsync(schemaId); |
| 80 | + |
| 81 | + // Assert |
| 82 | + Assert.AreEqual("KafkaFlow.Test.Person", actual); |
| 83 | + } |
| 84 | + |
| 85 | + [TestMethod] |
| 86 | + public async Task ResolveAsync_SchemaWithoutPackageOrNamespace_ReturnsTypeNameWithoutNamespace() |
| 87 | + { |
| 88 | + // Arrange |
| 89 | + // below schema-string is base64 encoded protobuf schema of 'syntax = \"proto3\";\n\nmessage Person {\n string name = 1;\n}\n' |
| 90 | + var schemaString = "CgdkZWZhdWx0IhQKBlBlcnNvbhIKCgRuYW1lGAEoCWIGcHJvdG8z"; |
| 91 | + var schemaId = 420; |
| 92 | + |
| 93 | + _schemaRegistryClient.Setup(client => client.GetSchemaAsync(schemaId, "serialized")) |
| 94 | + .ReturnsAsync(new RegisteredSchema("test", 1, schemaId, schemaString, SchemaType.Protobuf, new List<SchemaReference>())); |
| 95 | + |
| 96 | + // Act |
| 97 | + var actual = await _schemaRegistryTypeResolver.ResolveAsync(schemaId); |
| 98 | + |
| 99 | + // Assert |
| 100 | + Assert.AreEqual("Person", actual); |
| 101 | + } |
47 | 102 | }
|
0 commit comments