public async Task GetSchemaAsNode() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); string id = serializer.Serialize("Schema", schema.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($id: ID!) { node(id: $id) { id ... on Schema { name description } } }") .SetVariableValue("id", id) .Create()); // assert result.MatchSnapshot(o => o.Assert(fo => Assert.Equal(id, fo.Field <string>("Data.node.id")))); }
public async Task UpdateSchema() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); string id = serializer.Serialize("Schema", schema.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"mutation($id: ID!) { updateSchema(input: { id: $id name: ""abc2"" description: ""def2"" clientMutationId: ""ghi"" }) { schema { id name description } clientMutationId } }") .SetVariableValue("id", id) .Create()); // assert result.MatchSnapshot(o => o.Assert(fo => Assert.NotNull(fo.Field <string>("Data.updateSchema.schema.id")))); }
public async Task GetSchemaById_Invalid_Id_Type() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); string id = serializer.Serialize("Foo", schema.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($id: ID!) { schemaById(id: $id) { id name description } }") .SetVariableValue("id", id) .Create()); // assert result.MatchSnapshot(); }
public async Task ExecutePublishDocumentServer_With_SchemaFile_Handler() { // arrange var handler = new PublishSchemaDocumentHandler( Storage, SchemaRepository, PublishSchemaEventSender); using var service = new PublishDocumentService( PublishDocumentMessageReceiver, new IPublishDocumentHandler[] { handler }); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); var message = new PublishDocumentMessage( "ghi", environment.Id, schema.Id, Array.Empty <Tag>()); IFileContainer fileContainer = await Storage.CreateContainerAsync("ghi"); using (Stream stream = await fileContainer.CreateFileAsync("schema.graphql")) { byte[] buffer = Encoding.UTF8.GetBytes(@" type Query { foo: String } "); await stream.WriteAsync(buffer, 0, buffer.Length); } await PublishDocumentMessageSender.SendAsync(message); // act await service.StartAsync(default);
public async Task GetSchemaVersionById() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var schemaVersion = new SchemaVersion( Guid.NewGuid(), schema.Id, "abc", "def", Array.Empty <Tag>(), DateTime.UnixEpoch); await SchemaRepository.AddSchemaVersionAsync(schemaVersion); string id = serializer.Serialize("SchemaVersion", schemaVersion.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($id: ID!) { schemaVersionById(id: $id) { id sourceText } }") .SetVariableValue("id", id) .Create()); // assert result.MatchSnapshot(o => o.Assert(fo => Assert.Equal(id, fo.Field <string>("Data.schemaVersionById.id")))); }
public async Task GetSchemaVersionsById_Invalid_Id_Type() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var schemaVersion = new SchemaVersion( Guid.NewGuid(), schema.Id, "abc", "def", Array.Empty <Tag>(), DateTime.UnixEpoch); await SchemaRepository.AddSchemaVersionAsync(schemaVersion); string id = serializer.Serialize("Foo", schemaVersion.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($ids: [ID!]!) { schemaVersionsById(ids: $ids) { id sourceText } }") .SetVariableValue("ids", new[] { id }) .Create()); // assert result.MatchSnapshot(); }
public async Task GetSchemasByNames_Empty_Names() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); string id = serializer.Serialize("Schema", schema.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($names: [String!]!) { schemasByName(names: $names) { id name description } }") .SetVariableValue("names", new string[0]) .Create()); // assert result.MatchSnapshot(); }
public async Task QuerySchema() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); string id = serializer.Serialize("Schema", schema.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($name: String!) { schemas(where: { name: $name }) { nodes { id name description } } }") .SetVariableValue("name", schema.Name) .Create()); // assert result.MatchSnapshot(o => o.Assert(fo => Assert.Equal(id, fo.Field <string>("Data.schemas.nodes[0].id")))); }
public async Task PublishSchema() { // arrange var serializer = new IdSerializer(); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"mutation( $schemaName: String! $environmentName: String! $sourceText: String! $version: String!) { publishSchema(input: { schemaName: $schemaName environmentName: $environmentName sourceText: $sourceText tags: [ { key: ""version"" value: $version } ] clientMutationId: ""ghi"" }) { sessionId clientMutationId } }") .SetVariableValue("schemaName", "abc") .SetVariableValue("environmentName", "abc") .SetVariableValue("sourceText", "type Query { a: String }") .SetVariableValue("version", "1.0.0") .Create()); // assert result.MatchSnapshot(o => o.Assert(fo => Assert.NotNull(fo.Field <string>("Data.publishSchema.sessionId")))); Assert.Collection(ReceivedMessages, t => { PublishDocumentMessage message = Assert.IsType <PublishDocumentMessage>(t); Assert.Equal(schema.Id, message.SchemaId); Assert.Equal(environment.Id, message.EnvironmentId); Assert.Equal(DocumentType.Schema, message.Type); Assert.Null(message.ClientId); Assert.NotNull(message.SessionId); Assert.Collection(message.Tags, t => { Assert.Equal("version", t.Key); Assert.Equal("1.0.0", t.Value); }); }); }
public async Task OnPublishSchema() { // arrange var serializer = new IdSerializer(); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); string sessionId = await SessionCreator.CreateSessionAsync(); await PublishSchemaEventSender.SendAsync( new PublishDocumentEvent( sessionId, new Issue("foo", "file.graphql", new Location(0, 0, 1, 1), IssueType.Information))); await PublishSchemaEventSender.SendAsync( PublishDocumentEvent.Completed(sessionId)); // act var responseStream = (IResponseStream)await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"subscription( $sessionId: String!) { onPublishSchema(sessionId: $sessionId) { sessionId isCompleted } }") .SetVariableValue("sessionId", sessionId) .Create()); // assert var results = new List <IReadOnlyQueryResult>(); await foreach (IReadOnlyQueryResult result in responseStream) { results.Add(result); } results.MatchSnapshot(matchOptions => matchOptions.Assert(fieldOption => Assert.Collection( fieldOption.Fields <string>("[*].Data.onPublishSchema.sessionId"), t => Assert.Equal(sessionId, t), t => Assert.Equal(sessionId, t)))); }
public async Task HandleMessage() { // arrange string sessionId = await SessionCreator.CreateSessionAsync(); var handler = new PublishNewSchemaDocumentHandler( Storage, SchemaRepository, PublishSchemaEventSender); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); var message = new PublishDocumentMessage( sessionId, environment.Id, schema.Id, "externalId", Array.Empty <DocumentInfo>(), Array.Empty <Tag>()); IFileContainer fileContainer = await Storage.CreateContainerAsync(sessionId); byte[] buffer = Encoding.UTF8.GetBytes(@" type Query { foo: String } "); await fileContainer.CreateFileAsync("schema.graphql", buffer, 0, buffer.Length); // act await handler.HandleAsync(message, default); // assert var list = new List <PublishDocumentEvent>(); using var cts = new CancellationTokenSource(5000); IAsyncEnumerable <PublishDocumentEvent> eventStream = await PublishSchemaEventReceiver.SubscribeAsync(sessionId, cts.Token); await foreach (PublishDocumentEvent eventMessage in eventStream.WithCancellation(cts.Token)) { list.Add(eventMessage); } list.MatchSnapshot(matchOption => matchOption.Assert(fieldOption => Assert.Equal(sessionId, fieldOption.Field <string>("[0].SessionId")))); }
public async Task PublishSchema() { // arrange var serializer = new IdSerializer(); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"mutation( $schemaName: String! $environmentName: String! $sourceText: String! $version: String!) { publishSchema(input: { schemaName: $schemaName environmentName: $environmentName sourceText: $sourceText tags: [ { key: ""version"" value: $version } ] clientMutationId: ""ghi"" }) { report { environment { name } schemaVersion { hash } } clientMutationId } }") .SetVariableValue("schemaName", "abc") .SetVariableValue("environmentName", "abc") .SetVariableValue("sourceText", "type Query { a: String }") .SetVariableValue("version", "1.0.0") .Create()); // assert result.MatchSnapshot(); }
public async Task HandleMessage() { // arrange var handler = new PublishSchemaDocumentHandler( Storage, SchemaRepository, PublishSchemaEventSender); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); var message = new PublishDocumentMessage( "ghi", environment.Id, schema.Id, Array.Empty <Tag>()); IFileContainer fileContainer = await Storage.CreateContainerAsync("ghi"); using (Stream stream = await fileContainer.CreateFileAsync("schema.graphql")) { byte[] buffer = Encoding.UTF8.GetBytes(@" type Query { foo: String } "); await stream.WriteAsync(buffer, 0, buffer.Length); } // act await handler.HandleAsync(message, default); // assert var list = new List <PublishSchemaEvent>(); using var cts = new CancellationTokenSource(5000); IAsyncEnumerable <PublishSchemaEvent> eventStream = await PublishSchemaEventReceiver.SubscribeAsync("ghi", cts.Token); await foreach (PublishSchemaEvent eventMessage in eventStream.WithCancellation(cts.Token)) { list.Add(eventMessage); } list.MatchSnapshot(); }
public async Task GetSchemaVersionAsNode() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var schemaVersion = new SchemaVersion( Guid.NewGuid(), schema.Id, "abc", DocumentHash.FromSourceText("def"), Array.Empty <Tag>(), DateTime.UnixEpoch); await SchemaRepository.AddSchemaVersionAsync(schemaVersion); string id = serializer.Serialize("SchemaVersion", schemaVersion.Id); IFileContainer container = await Storage.CreateContainerAsync( schemaVersion.Id.ToString("N", CultureInfo.InvariantCulture)); byte[] buffer = Encoding.UTF8.GetBytes("SourceTextAbc"); await container.CreateFileAsync("schema.graphql", buffer, 0, buffer.Length); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($id: ID!) { node(id: $id) { id ... on SchemaVersion { sourceText hash { hash } } } }") .SetVariableValue("id", id) .Create()); // assert result.MatchSnapshot(o => o.Assert(fo => Assert.Equal(id, fo.Field <string>("Data.node.id")))); }
public async Task OnPublishSchema() { // arrange var serializer = new IdSerializer(); var schema = new Schema("abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var environment = new Environment("abc", "def"); await EnvironmentRepository.AddEnvironmentAsync(environment); string sessionId = "abc"; await PublishSchemaEventSender.SendAsync( new PublishSchemaEvent(sessionId, new Issue("foo", IssueType.Information))); await PublishSchemaEventSender.SendAsync( PublishSchemaEvent.Completed(sessionId)); // act var responseStream = (IResponseStream)await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"subscription( $sessionId: String!) { onPublishSchema(sessionId: $sessionId) { sessionId isCompleted } }") .SetVariableValue("sessionId", sessionId) .Create()); // assert var results = new List <IReadOnlyQueryResult>(); await foreach (IReadOnlyQueryResult result in responseStream) { results.Add(result); } results.MatchSnapshot(); }
public async Task CreateClient() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); string schemaId = serializer.Serialize("Schema", schema.Id); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"mutation($schemaId: ID! $name: String! $description: String) { createClient(input: { schemaId: $schemaId name: $name description: $description }) { schema { name description } client { name description } } }") .SetVariableValue("schemaId", schemaId) .SetVariableValue("name", "client_abc") .SetVariableValue("description", "client_def") .Create()); // assert result.MatchSnapshot(); }
public async Task GetSchemaVersionsById_Invalid_Id_Type() { // arrange var serializer = new IdSerializer(); var schema = new Schema(Guid.NewGuid(), "abc", "def"); await SchemaRepository.AddSchemaAsync(schema); var schemaVersion = new SchemaVersion( Guid.NewGuid(), schema.Id, "abc", DocumentHash.FromSourceText("def"), Array.Empty <Tag>(), DateTime.UnixEpoch); await SchemaRepository.AddSchemaVersionAsync(schemaVersion); string id = serializer.Serialize("Foo", schemaVersion.Id); IFileContainer container = await Storage.CreateContainerAsync( schemaVersion.Id.ToString("N", CultureInfo.InvariantCulture)); byte[] buffer = Encoding.UTF8.GetBytes("SourceTextAbc"); await container.CreateFileAsync("schema.graphql", buffer, 0, buffer.Length); // act IExecutionResult result = await Executor.ExecuteAsync( QueryRequestBuilder.New() .SetQuery( @"query($ids: [ID!]!) { schemaVersionsById(ids: $ids) { id sourceText } }") .SetVariableValue("ids", new[] { id }) .Create()); // assert result.MatchSnapshot(); }