Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions Google.GenAI.E2E.Tests/EmbedContent/EmbedContentTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Google.GenAI;
using Google.GenAI.Types;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestServerSdk;

[TestClass]
public class EmbedContentTest {
private static TestServerProcess? _server;
private Client vertexClient;
private Client geminiClient;
private string modelName;
public TestContext TestContext { get; set; }

[ClassInitialize]
public static void ClassInit(TestContext _) {
_server = TestServer.StartTestServer();
}

[ClassCleanup]
public static void ClassCleanup() {
TestServer.StopTestServer(_server);
}

[TestInitialize]
public void TestInit() {
// Test server specific setup.
if (_server == null) {
throw new InvalidOperationException("Test server is not initialized.");
}
var geminiClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1453"
};
var vertexClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1454"
};

// Common setup for both clients.
string project = System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");

Check warning on line 65 in Google.GenAI.E2E.Tests/EmbedContent/EmbedContentTest.cs

View workflow job for this annotation

GitHub Actions / unit-e2e-tests

Converting null literal or possible null value to non-nullable type.
string location =
System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_LOCATION") ?? "us-central1";
string apiKey = System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY");

Check warning on line 68 in Google.GenAI.E2E.Tests/EmbedContent/EmbedContentTest.cs

View workflow job for this annotation

GitHub Actions / unit-e2e-tests

Converting null literal or possible null value to non-nullable type.
vertexClient = new Client(project: project, location: location, vertexAI: true,
credential: TestServer.GetCredentialForTestMode(),
httpOptions: vertexClientHttpOptions);
geminiClient =
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions);

// Specific setup for this test class
modelName = "text-embedding-004";
}

[TestMethod]
public async Task EmbedContentSimpleTextVertexTest() {
var contents = new List<Content> {
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
};
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: modelName, contents: contents, config: null);

Assert.IsNotNull(vertexResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentSimpleTextGeminiTest() {
var contents = new List<Content> {
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
};
var geminiResponse = await geminiClient.Models.EmbedContentAsync(
model: modelName, contents: contents, config: null);

Assert.IsNotNull(geminiResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentSingleStringVertexTest() {
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: modelName, contents: "What is your name?", config: null);

Assert.IsNotNull(vertexResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentSingleStringGeminiTest() {
var geminiResponse = await geminiClient.Models.EmbedContentAsync(
model: modelName, contents: "What is your name?", config: null);

Assert.IsNotNull(geminiResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentMultiTextVertexTest() {
var contents = new List<Content> {
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } },
new Content { Parts = new List<Part> { new Part { Text = "I am a model." } } }
};
var config = new EmbedContentConfig { OutputDimensionality = 10, Title = "test_title",
TaskType = "RETRIEVAL_DOCUMENT" };
var vertexResponse =
await vertexClient.Models.EmbedContentAsync(model: modelName, contents: contents, config: config);

Assert.IsNotNull(vertexResponse.Embeddings);
Assert.AreEqual(2, vertexResponse.Embeddings.Count);
}

[TestMethod]
public async Task EmbedContentMultiTextGeminiTest() {
var contents = new List<Content> {
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } },
new Content { Parts = new List<Part> { new Part { Text = "I am a model." } } }
};
var config = new EmbedContentConfig { OutputDimensionality = 10, Title = "test_title",
TaskType = "RETRIEVAL_DOCUMENT" };
var geminiResponse =
await geminiClient.Models.EmbedContentAsync(model: modelName, contents: contents, config: config);

Assert.IsNotNull(geminiResponse.Embeddings);
Assert.AreEqual(2, geminiResponse.Embeddings.Count);
}
}
90 changes: 90 additions & 0 deletions Google.GenAI.E2E.Tests/Models/DeleteModelTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Google.GenAI;
using Google.GenAI.Types;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestServerSdk;

[TestClass]
public class DeleteModelTest {
private static TestServerProcess? _server;
private Client vertexClient;
private Client geminiClient;
public TestContext TestContext { get; set; }

[ClassInitialize]
public static void ClassInit(TestContext _) {
_server = TestServer.StartTestServer();
}

[ClassCleanup]
public static void ClassCleanup() {
TestServer.StopTestServer(_server);
}

[TestInitialize]
public void TestInit() {
// Test server specific setup.
if (_server == null) {
throw new InvalidOperationException("Test server is not initialized.");
}
var geminiClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1453"
};
var vertexClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1454"
};

// Common setup for both clients.
string project = System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");
string location =
System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_LOCATION") ?? "us-central1";
string apiKey = System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
vertexClient = new Client(project: project, location: location, vertexAI: true,
credential: TestServer.GetCredentialForTestMode(),
httpOptions: vertexClientHttpOptions);
geminiClient =
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions);
}

[TestMethod]
public async Task DeleteModelVertexTest() {
var vertexResponse =
await vertexClient.Models.DeleteAsync(model: "models/89657476663738368", config: null);

Assert.IsNotNull(vertexResponse);
}

[TestMethod]
public async Task DeleteModelGeminiTest() {
var geminiResponse =
await geminiClient.Models.DeleteAsync(model: "tunedModels/generate-num-1896", config: null);

Assert.IsNotNull(geminiResponse);
}
}
94 changes: 94 additions & 0 deletions Google.GenAI.E2E.Tests/Models/GetModelTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Google.GenAI;
using Google.GenAI.Types;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestServerSdk;

[TestClass]
public class GetModelTest {
private static TestServerProcess? _server;
private Client vertexClient;
private Client geminiClient;
private string modelName;
public TestContext TestContext { get; set; }

[ClassInitialize]
public static void ClassInit(TestContext _) {
_server = TestServer.StartTestServer();
}

[ClassCleanup]
public static void ClassCleanup() {
TestServer.StopTestServer(_server);
}

[TestInitialize]
public void TestInit() {
// Test server specific setup.
if (_server == null) {
throw new InvalidOperationException("Test server is not initialized.");
}
var geminiClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1453"
};
var vertexClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1454"
};

// Common setup for both clients.
string project = System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");
string location =
System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_LOCATION") ?? "us-central1";
string apiKey = System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
vertexClient = new Client(project: project, location: location, vertexAI: true,
credential: TestServer.GetCredentialForTestMode(),
httpOptions: vertexClientHttpOptions);
geminiClient =
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions);

// Specific setup for this test class
modelName = "gemini-2.5-flash";
}

[TestMethod]
public async Task GetModelTunedVertexTest() {
string tunedModel = "models/8611312396578848768";
var vertexResponse = await vertexClient.Models.GetAsync(model: tunedModel, config: null);

Assert.IsNotNull(vertexResponse);
}

[TestMethod]
public async Task GetModelTunedGeminiTest() {
string tunedModel = "tunedModels/generate-num-8498";
var geminiResponse = await geminiClient.Models.GetAsync(model: tunedModel, config: null);

Assert.IsNotNull(geminiResponse);
}
}
Loading
Loading