|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using FluentAssertions; |
| 5 | +using Microsoft.Extensions.DependencyInjection; |
| 6 | +using Typesense; |
| 7 | +using Typesense.Setup; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Squadron |
| 11 | +{ |
| 12 | + public class TypesenseResourceTests : IClassFixture<TypesenseResource> |
| 13 | + { |
| 14 | + private readonly TypesenseResource _typesenseResource; |
| 15 | + |
| 16 | + public TypesenseResourceTests(TypesenseResource typesenseResource) |
| 17 | + { |
| 18 | + _typesenseResource = typesenseResource; |
| 19 | + } |
| 20 | + |
| 21 | + [Fact] |
| 22 | + public void CreateAndGetDocument_NoError() |
| 23 | + { |
| 24 | + var provider = new ServiceCollection() |
| 25 | + .AddTypesenseClient(config => |
| 26 | + { |
| 27 | + config.ApiKey = _typesenseResource.ApiKey; |
| 28 | + config.Nodes = new List<Node> { new Node("localhost", _typesenseResource.Port.ToString(), "http") }; |
| 29 | + }, enableHttpCompression: false) |
| 30 | + .BuildServiceProvider(); |
| 31 | + |
| 32 | + ITypesenseClient client = provider.GetRequiredService<ITypesenseClient>(); |
| 33 | + |
| 34 | + //Act |
| 35 | + Action action = () => |
| 36 | + { |
| 37 | + var schema = new Schema("users", |
| 38 | + new[] { new Field("id", FieldType.String), |
| 39 | + new Field("name", FieldType.String) }); |
| 40 | + |
| 41 | + client.CreateCollection(schema); |
| 42 | + client.CreateDocument("users", new User{ Id = "1", Name = "John Doe" }); |
| 43 | + |
| 44 | + Task<User> _ = client.RetrieveDocument<User>("users", "1"); |
| 45 | + }; |
| 46 | + |
| 47 | + //Assert |
| 48 | + action.Should().NotThrow(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + internal class User |
| 53 | + { |
| 54 | + public string Id { get; set; } |
| 55 | + |
| 56 | + public string Name { get; set; } |
| 57 | + } |
| 58 | +} |
0 commit comments