Bundle: redb-route / tests/redb.Route.Tests.Firebase (tests.redb.Route.Tests.Firebase.txt), 31 files
Snapshot: development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt
====
Path: redb-route/tests/redb.Route.Tests.Firebase/ComponentSideTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/ComponentSideTests.cs
----
using redb.Route.Core;
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
/// The component declares the only side it has ([EndpointRole], Apache Camel's producerOnly / consumerOnly).
public sealed class ComponentSideTests
{
[Fact]
public void The_component_declares_its_only_side()
{
var fcm = typeof(FirebaseStorageComponent).Assembly.GetType("redb.Route.Firebase.FcmComponent", throwOnError: true)!;
EndpointSides.Declaration(fcm)!.Role.Should().Be(EndpointRole.Producer);
EndpointSides.Declaration(typeof(FirebaseStorageComponent)).Should().BeNull("fbstorage has both sides");
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Fcm/FcmComponentTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Fcm/FcmComponentTests.cs
----
using redb.Route.Abstractions;
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FcmComponentTests
{
[Fact]
public void Scheme_IsFcm()
{
var component = new FcmComponent();
component.Scheme.Should().Be("fcm");
}
[Fact]
public void CreateEndpoint_ValidToken_ReturnsEndpoint()
{
var component = new FcmComponent();
var uri = new EndpointUri("fcm", "send", "fcm://send",
new Dictionary
{
["credentialPath"] = "/sa.json",
["messageType"] = "Token",
["token"] = "tok"
});
var endpoint = component.CreateEndpoint(uri);
endpoint.Should().NotBeNull();
endpoint.Should().BeOfType();
}
[Fact]
public void CreateEndpoint_CreateConsumer_ThrowsNotSupported()
{
var component = new FcmComponent();
var uri = new EndpointUri("fcm", "send", "fcm://send",
new Dictionary
{
["credentialPath"] = "/sa.json",
["messageType"] = "Token",
["token"] = "tok"
});
var endpoint = component.CreateEndpoint(uri);
var act = () => endpoint.CreateConsumer(Substitute.For());
act.Should().Throw();
}
[Fact]
public void CreateEndpoint_CreateProducer_ReturnsFcmProducer()
{
var component = new FcmComponent();
var uri = new EndpointUri("fcm", "send", "fcm://send",
new Dictionary
{
["credentialPath"] = "/sa.json",
["messageType"] = "Token",
["token"] = "tok"
});
var endpoint = component.CreateEndpoint(uri);
var producer = endpoint.CreateProducer();
producer.Should().NotBeNull();
}
[Fact]
public void CreateEndpoint_NullUri_Throws()
{
var component = new FcmComponent();
var act = () => component.CreateEndpoint(null!);
act.Should().Throw();
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Fcm/FcmEndpointOptionsTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Fcm/FcmEndpointOptionsTests.cs
----
using redb.Route.Core;
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
[Collection("FirebaseEnvSensitive")]
public sealed class FcmEndpointOptionsTests
{
// ── BindFromUri ──
[Fact]
public void BindFromUri_MessageType_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["messageType"] = "Topic",
["topic"] = "news"
});
options.MessageType.Should().Be(FcmMessageType.Topic);
}
[Fact]
public void BindFromUri_Token_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["token"] = "device-123"
});
options.Token.Should().NotBeNull();
}
[Fact]
public void BindFromUri_CredentialPath_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary { ["credentialPath"] = "/path/to/sa.json", ["token"] = "t" });
options.CredentialPath.Should().Be("/path/to/sa.json");
}
[Fact]
public void BindFromUri_ProjectId_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary { ["projectId"] = "my-proj", ["credentialPath"] = "/sa.json", ["token"] = "t" });
options.ProjectId.Should().Be("my-proj");
}
[Fact]
public void BindFromUri_DataOnly_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary { ["credentialPath"] = "/sa.json", ["dataOnly"] = "true", ["token"] = "t" });
options.DataOnly.Should().BeTrue();
}
[Fact]
public void BindFromUri_DryRun_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary { ["credentialPath"] = "/sa.json", ["dryRun"] = "true", ["token"] = "t" });
options.DryRun.Should().BeTrue();
}
[Fact]
public void BindFromUri_AndroidTtlSeconds_Parsed()
{
var options = new FcmEndpointOptions();
options.BindFromUri(new Dictionary { ["credentialPath"] = "/sa.json", ["androidTtlSeconds"] = "3600", ["token"] = "t" });
options.AndroidTtlSeconds.Should().Be(3600);
}
// ── Validate ──
[Fact]
public void Validate_NoCredential_NoEnvVar_Throws()
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", null);
var options = new FcmEndpointOptions
{
MessageType = FcmMessageType.Token,
Token = DynamicValue.FromStatic("tok")
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*CredentialPath*");
}
[Fact]
public void Validate_WithCredentialPath_DoesNotThrowOnCredential()
{
var options = new FcmEndpointOptions
{
CredentialPath = "/sa.json",
MessageType = FcmMessageType.Token,
Token = DynamicValue.FromStatic("tok")
};
var act = () => options.Validate();
act.Should().NotThrow();
}
[Fact]
public void Validate_WithConnectionFactory_DoesNotThrowOnCredential()
{
var options = new FcmEndpointOptions
{
ConnectionFactory = "factory1",
MessageType = FcmMessageType.Token,
Token = DynamicValue.FromStatic("tok")
};
var act = () => options.Validate();
act.Should().NotThrow();
}
[Fact]
public void Validate_TokenType_NoToken_Throws()
{
var options = new FcmEndpointOptions
{
CredentialPath = "/sa.json",
MessageType = FcmMessageType.Token
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*Token*");
}
[Fact]
public void Validate_TopicType_NoTopic_Throws()
{
var options = new FcmEndpointOptions
{
CredentialPath = "/sa.json",
MessageType = FcmMessageType.Topic
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*Topic*");
}
[Fact]
public void Validate_ConditionType_NoCondition_Throws()
{
var options = new FcmEndpointOptions
{
CredentialPath = "/sa.json",
MessageType = FcmMessageType.Condition
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*Condition*");
}
[Theory]
[InlineData(-1)]
[InlineData(-100)]
public void Validate_NegativeAndroidTtl_Throws(int ttl)
{
var options = new FcmEndpointOptions
{
CredentialPath = "/sa.json",
MessageType = FcmMessageType.Token,
Token = DynamicValue.FromStatic("tok"),
AndroidTtlSeconds = ttl
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*AndroidTtlSeconds*");
}
[Theory]
[InlineData(0)]
[InlineData(3600)]
public void Validate_ValidAndroidTtl_DoesNotThrow(int ttl)
{
var options = new FcmEndpointOptions
{
CredentialPath = "/sa.json",
MessageType = FcmMessageType.Token,
Token = DynamicValue.FromStatic("tok"),
AndroidTtlSeconds = ttl
};
var act = () => options.Validate();
act.Should().NotThrow();
}
// ── Defaults ──
[Fact]
public void DefaultMessageType_IsToken()
{
new FcmEndpointOptions().MessageType.Should().Be(FcmMessageType.Token);
}
[Fact]
public void DefaultDataOnly_IsFalse()
{
new FcmEndpointOptions().DataOnly.Should().BeFalse();
}
[Fact]
public void DefaultDryRun_IsFalse()
{
new FcmEndpointOptions().DryRun.Should().BeFalse();
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Fcm/FcmHeadersTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Fcm/FcmHeadersTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FcmHeadersTests
{
[Fact]
public void Prefix_IsCorrect()
{
FcmHeaders.Prefix.Should().Be("redbFcm.");
}
[Theory]
[InlineData(nameof(FcmHeaders.MessageId), "redbFcm.MessageId")]
[InlineData(nameof(FcmHeaders.Token), "redbFcm.Token")]
[InlineData(nameof(FcmHeaders.Topic), "redbFcm.Topic")]
[InlineData(nameof(FcmHeaders.Condition), "redbFcm.Condition")]
public void Header_StartsWithPrefix(string fieldName, string expected)
{
var value = typeof(FcmHeaders).GetField(fieldName)?.GetValue(null) as string;
value.Should().NotBeNull();
value.Should().StartWith(FcmHeaders.Prefix);
value.Should().Be(expected);
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/FirebaseEnvSensitiveCollection.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/FirebaseEnvSensitiveCollection.cs
----
namespace redb.Route.Tests.Firebase;
///
/// xUnit collection used to serialize tests that mutate process-wide Firebase/Firestore
/// environment variables (FIRESTORE_EMULATOR_HOST, GOOGLE_APPLICATION_CREDENTIALS) and tests
/// that read them. Prevents race conditions between option/validation tests and the live
/// emulator integration suite.
///
[CollectionDefinition("FirebaseEnvSensitive", DisableParallelization = true)]
public sealed class FirebaseEnvSensitiveCollection { }
Path: redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreComponentTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreComponentTests.cs
----
using redb.Route.Abstractions;
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FirestoreComponentTests
{
private static EndpointUri MakeUri(string path = "orders", Dictionary? extra = null)
{
var parameters = new Dictionary { ["credentialPath"] = "/sa.json" };
if (extra is not null)
foreach (var (k, v) in extra)
parameters[k] = v;
return new EndpointUri("fstore", path, $"fstore://{path}", parameters);
}
[Fact]
public void Scheme_IsFirestore()
{
var component = new FirestoreComponent();
component.Scheme.Should().Be("fstore");
}
[Fact]
public void CreateEndpoint_ValidOptions_ReturnsEndpoint()
{
var component = new FirestoreComponent();
var endpoint = component.CreateEndpoint(MakeUri());
endpoint.Should().NotBeNull();
endpoint.Should().BeOfType();
}
[Fact]
public void CreateEndpoint_NullUri_Throws()
{
var component = new FirestoreComponent();
var act = () => component.CreateEndpoint(null!);
act.Should().Throw();
}
[Fact]
public void CreateEndpoint_CollectionPath_ParsedFromUri()
{
var component = new FirestoreComponent();
var endpoint = (FirestoreEndpoint)component.CreateEndpoint(
MakeUri("users/uid/orders"));
endpoint.CollectionPath.Should().Be("users/uid/orders");
}
[Fact]
public void CreateEndpoint_CreateProducer_ReturnsProducer()
{
var component = new FirestoreComponent();
var endpoint = component.CreateEndpoint(MakeUri());
var producer = endpoint.CreateProducer();
producer.Should().NotBeNull();
}
[Fact]
public void CreateEndpoint_CreateConsumer_ReturnsConsumer()
{
var component = new FirestoreComponent();
var endpoint = component.CreateEndpoint(MakeUri());
var consumer = endpoint.CreateConsumer(Substitute.For());
consumer.Should().NotBeNull();
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreEndpointOptionsTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreEndpointOptionsTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
[Collection("FirebaseEnvSensitive")]
public sealed class FirestoreEndpointOptionsTests
{
// ── BindFromUri ──
[Fact]
public void BindFromUri_Operation_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["operation"] = "Query"
});
options.Operation.Should().Be(FirestoreOperationType.Query);
}
[Fact]
public void BindFromUri_Where_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["where"] = "status==pending"
});
options.Where.Should().Be("status==pending");
}
[Fact]
public void BindFromUri_OrderBy_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["orderBy"] = "createdAt desc"
});
options.OrderBy.Should().Be("createdAt desc");
}
[Fact]
public void BindFromUri_Limit_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["limit"] = "50"
});
options.Limit.Should().Be(50);
}
[Fact]
public void BindFromUri_Merge_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["merge"] = "true"
});
options.Merge.Should().BeTrue();
}
[Fact]
public void BindFromUri_Realtime_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["realtime"] = "false"
});
options.Realtime.Should().BeFalse();
}
[Fact]
public void BindFromUri_Delay_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["delay"] = "10000"
});
options.Delay.Should().Be(10000);
}
[Fact]
public void BindFromUri_RawJson_Parsed()
{
var options = new FirestoreEndpointOptions();
options.BindFromUri(new Dictionary
{
["credentialPath"] = "/sa.json",
["rawJson"] = "true"
});
options.RawJson.Should().BeTrue();
}
// ── Validate ──
[Fact]
public void Validate_NoCredential_NoEnvVar_Throws()
{
var prevCreds = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS");
var prevEmu = Environment.GetEnvironmentVariable("FIRESTORE_EMULATOR_HOST");
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", null);
Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", null);
try
{
var options = new FirestoreEndpointOptions();
var act = () => options.Validate();
act.Should().Throw().WithMessage("*CredentialPath*");
}
finally
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", prevCreds);
Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", prevEmu);
}
}
[Fact]
public void Validate_WithCredentialPath_DoesNotThrow()
{
var options = new FirestoreEndpointOptions { CredentialPath = "/sa.json" };
var act = () => options.Validate();
act.Should().NotThrow();
}
[Fact]
public void Validate_WithConnectionFactory_DoesNotThrow()
{
var options = new FirestoreEndpointOptions { ConnectionFactory = "factory1" };
var act = () => options.Validate();
act.Should().NotThrow();
}
[Fact]
public void Validate_WithEmulatorHost_DoesNotThrow()
{
Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8080");
try
{
var options = new FirestoreEndpointOptions();
var act = () => options.Validate();
act.Should().NotThrow();
}
finally
{
Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", null);
}
}
[Theory]
[InlineData(0)]
[InlineData(50)]
[InlineData(99)]
public void Validate_DelayTooLow_Throws(int delay)
{
var options = new FirestoreEndpointOptions
{
CredentialPath = "/sa.json",
Delay = delay
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*Delay*");
}
[Theory]
[InlineData(100)]
[InlineData(5000)]
public void Validate_ValidDelay_DoesNotThrow(int delay)
{
var options = new FirestoreEndpointOptions
{
CredentialPath = "/sa.json",
Delay = delay
};
var act = () => options.Validate();
act.Should().NotThrow();
}
[Theory]
[InlineData(0)]
[InlineData(-1)]
public void Validate_InvalidLimit_Throws(int limit)
{
var options = new FirestoreEndpointOptions
{
CredentialPath = "/sa.json",
Limit = limit
};
var act = () => options.Validate();
act.Should().Throw().WithMessage("*Limit*");
}
[Fact]
public void Validate_NullLimit_DoesNotThrow()
{
var options = new FirestoreEndpointOptions
{
CredentialPath = "/sa.json",
Limit = null
};
var act = () => options.Validate();
act.Should().NotThrow();
}
// ── Defaults ──
[Fact]
public void DefaultOperation_IsSet()
{
new FirestoreEndpointOptions().Operation.Should().Be(FirestoreOperationType.Set);
}
[Fact]
public void DefaultRealtime_IsTrue()
{
new FirestoreEndpointOptions().Realtime.Should().BeTrue();
}
[Fact]
public void DefaultDelay_Is5000()
{
new FirestoreEndpointOptions().Delay.Should().Be(5000);
}
[Fact]
public void DefaultRawJson_IsFalse()
{
new FirestoreEndpointOptions().RawJson.Should().BeFalse();
}
[Fact]
public void DefaultMerge_IsFalse()
{
new FirestoreEndpointOptions().Merge.Should().BeFalse();
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreHeadersTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreHeadersTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FirestoreHeadersTests
{
[Fact]
public void Prefix_IsCorrect()
{
FirestoreHeaders.Prefix.Should().Be("redbFirestore.");
}
[Theory]
[InlineData(nameof(FirestoreHeaders.DocumentId), "redbFirestore.DocumentId")]
[InlineData(nameof(FirestoreHeaders.DocumentPath), "redbFirestore.DocumentPath")]
[InlineData(nameof(FirestoreHeaders.CollectionPath), "redbFirestore.CollectionPath")]
[InlineData(nameof(FirestoreHeaders.ChangeType), "redbFirestore.ChangeType")]
public void Header_StartsWithPrefix(string fieldName, string expected)
{
var value = typeof(FirestoreHeaders).GetField(fieldName)?.GetValue(null) as string;
value.Should().NotBeNull();
value.Should().StartWith(FirestoreHeaders.Prefix);
value.Should().Be(expected);
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreQueryHelperTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Firestore/FirestoreQueryHelperTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
///
/// The Where syntax: a string literal goes in single quotes
/// (status=='007' is strictly a string), array-contains is recognized only as a token
/// with spaces around it, and a field with "-contains" in its name no longer breaks.
///
public sealed class FirestoreQueryHelperTests
{
[Fact]
public void ParseCondition_QuotedValue_StaysString()
{
var (field, op, value) = FirestoreQueryHelper.ParseCondition("status=='007'");
field.Should().Be("status");
op.Should().Be("==");
FirestoreQueryHelper.ParseValue(value).Should().Be("007",
"a quoted literal is strictly a string, with no coercion to int");
}
[Fact]
public void ParseValue_Unquoted_KeepsTypeInference()
{
FirestoreQueryHelper.ParseValue("007").Should().Be(7);
FirestoreQueryHelper.ParseValue("true").Should().Be(true);
FirestoreQueryHelper.ParseValue("3.5").Should().Be(3.5);
FirestoreQueryHelper.ParseValue("plain").Should().Be("plain");
}
[Fact]
public void ParseCondition_FieldContainingArrayContains_NotTornApart()
{
var (field, op, value) = FirestoreQueryHelper.ParseCondition("my-array-contains-x==5");
field.Should().Be("my-array-contains-x",
"the substring 'array-contains' in a field name must not break the condition");
op.Should().Be("==");
value.Should().Be("5");
}
[Fact]
public void ParseCondition_ArrayContains_SpacedToken()
{
var (field, op, value) = FirestoreQueryHelper.ParseCondition("tags array-contains 'admin'");
field.Should().Be("tags");
op.Should().Be("array-contains");
FirestoreQueryHelper.ParseValue(value).Should().Be("admin");
}
[Theory]
[InlineData("age>=18", "age", ">=", "18")]
[InlineData("age<=18", "age", "<=", "18")]
[InlineData("age!=18", "age", "!=", "18")]
[InlineData("age>18", "age", ">", "18")]
[InlineData("age<18", "age", "<", "18")]
public void ParseCondition_ComparisonOperators_Unchanged(string condition, string field, string op, string value)
{
var parsed = FirestoreQueryHelper.ParseCondition(condition);
parsed.Should().Be((field, op, value));
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Fluent/FcmDslTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Fluent/FcmDslTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FcmDslTests
{
[Fact]
public void Token_GeneratesBasicUri()
{
string uri = Fcm.Token("device-token-123");
uri.Should().Contain("fcm://send?");
uri.Should().Contain("messageType=Token");
uri.Should().Contain("token=device-token-123");
}
[Fact]
public void Topic_GeneratesBasicUri()
{
string uri = Fcm.Topic("news");
uri.Should().Contain("messageType=Topic");
uri.Should().Contain("topic=news");
}
[Fact]
public void Condition_GeneratesBasicUri()
{
string uri = Fcm.Condition("'sports' in topics");
uri.Should().Contain("messageType=Condition");
uri.Should().Contain("condition=");
}
[Fact]
public void Builder_WithAllOptions_GeneratesFullUri()
{
string uri = Fcm.Token("tok")
.CredentialPath("/secrets/sa.json")
.ProjectId("my-project")
.Title("Hello")
.Body("World")
.ImageUrl("https://example.com/img.png")
.DataOnly()
.DryRun()
.AndroidPriority("high")
.AndroidTtlSeconds(3600)
.AndroidChannelId("channel1")
.ApnsPriority("10")
.ApnsCollapseId("group1")
.WebPushLink("https://example.com")
.ConnectionFactory("myFactory");
uri.Should().Contain("credentialPath=");
uri.Should().Contain("projectId=my-project");
uri.Should().Contain("title=Hello");
uri.Should().Contain("body=World");
uri.Should().Contain("imageUrl=");
uri.Should().Contain("dataOnly=True");
uri.Should().Contain("dryRun=True");
uri.Should().Contain("androidPriority=high");
uri.Should().Contain("androidTtlSeconds=3600");
uri.Should().Contain("androidChannelId=channel1");
uri.Should().Contain("apnsPriority=10");
uri.Should().Contain("apnsCollapseId=group1");
uri.Should().Contain("webPushLink=");
uri.Should().Contain("connectionFactory=myFactory");
}
[Fact]
public void Builder_ImplicitStringConversion()
{
FcmBuilder builder = Fcm.Token("tok");
string uri = builder;
uri.Should().StartWith("fcm://send?");
}
[Fact]
public void Builder_ToString_EqualsImplicit()
{
var builder = Fcm.Token("tok").Title("T");
builder.ToString().Should().Be((string)builder);
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Fluent/FirebaseStorageDslTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Fluent/FirebaseStorageDslTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FirebaseStorageDslTests
{
[Fact]
public void Bucket_GeneratesBasicUri()
{
string uri = FirebaseStorage.Bucket("my-app.appspot.com");
uri.Should().Be("fbstorage://my-app.appspot.com");
}
[Fact]
public void Bucket_WithPrefix_GeneratesUri()
{
string uri = FirebaseStorage.Bucket("my-app.appspot.com", "uploads/");
uri.Should().Be("fbstorage://my-app.appspot.com/uploads/");
}
[Fact]
public void Builder_ProducerOptions_GeneratesUri()
{
string uri = FirebaseStorage.Bucket("bucket")
.Operation(FirebaseStorageOperationType.Upload)
.ObjectName("data/report.csv")
.ContentType("text/csv")
.CacheControl("public, max-age=3600")
.StreamBody()
.CredentialPath("/secrets/sa.json")
.ProjectId("proj")
.ConnectionFactory("cf");
uri.Should().Contain("fbstorage://bucket?");
uri.Should().Contain("operation=Upload");
uri.Should().Contain("objectName=data");
uri.Should().Contain("contentType=");
uri.Should().Contain("cacheControl=");
uri.Should().Contain("streamBody=True");
uri.Should().Contain("credentialPath=");
uri.Should().Contain("projectId=proj");
uri.Should().Contain("connectionFactory=cf");
}
[Fact]
public void Builder_ConsumerOptions_GeneratesUri()
{
string uri = FirebaseStorage.Bucket("data")
.Prefix("incoming/")
.Include("*.csv")
.Exclude("*.tmp")
.Delay(10000)
.MaxMessagesPerPoll(20)
.DeleteAfterRead()
.Idempotent()
.IncludeBody();
uri.Should().Contain("prefix=incoming");
uri.Should().Contain("include=%2A.csv");
uri.Should().Contain("exclude=%2A.tmp");
uri.Should().Contain("delay=10000");
uri.Should().Contain("maxMessagesPerPoll=20");
uri.Should().Contain("deleteAfterRead=True");
uri.Should().Contain("idempotent=True");
uri.Should().Contain("includeBody=True");
}
[Fact]
public void Builder_MoveAfterRead_GeneratesUri()
{
string uri = FirebaseStorage.Bucket("source")
.MoveAfterRead("processed/");
uri.Should().Contain("moveAfterRead=processed");
}
[Fact]
public void Builder_ImplicitStringConversion()
{
FirebaseStorageBuilder builder = FirebaseStorage.Bucket("test");
string uri = builder;
uri.Should().Be("fbstorage://test");
}
[Fact]
public void Builder_ToString_EqualsImplicit()
{
var builder = FirebaseStorage.Bucket("test").Delay(5000);
builder.ToString().Should().Be((string)builder);
}
[Fact]
public void Builder_NoParams_NoQueryString()
{
string uri = FirebaseStorage.Bucket("data");
uri.Should().NotContain("?");
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Fluent/FirestoreDslTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Fluent/FirestoreDslTests.cs
----
using redb.Route.Firebase;
namespace redb.Route.Tests.Firebase;
public sealed class FirestoreDslTests
{
[Fact]
public void Collection_GeneratesBasicUri()
{
string uri = Firestore.Collection("users");
uri.Should().Be("fstore://users");
}
[Fact]
public void Collection_WithNestedPath()
{
string uri = Firestore.Collection("users/uid/orders");
uri.Should().Be("fstore://users/uid/orders");
}
[Fact]
public void Builder_WithAllOptions_GeneratesFullUri()
{
string uri = Firestore.Collection("orders")
.Operation(FirestoreOperationType.Query)
.DocumentId("doc-123")
.Where("status==pending")
.OrderBy("createdAt desc")
.Limit(50)
.Offset(10)
.Merge()
.Realtime()
.Delay(3000)
.RawJson()
.CredentialPath("/secrets/sa.json")
.ProjectId("proj")
.ConnectionFactory("cf");
uri.Should().Contain("fstore://orders?");
uri.Should().Contain("operation=Query");
uri.Should().Contain("documentId=doc-123");
uri.Should().Contain("where=");
uri.Should().Contain("orderBy=");
uri.Should().Contain("limit=50");
uri.Should().Contain("offset=10");
uri.Should().Contain("merge=True");
uri.Should().Contain("realtime=True");
uri.Should().Contain("delay=3000");
uri.Should().Contain("rawJson=True");
uri.Should().Contain("credentialPath=");
uri.Should().Contain("projectId=proj");
uri.Should().Contain("connectionFactory=cf");
}
[Fact]
public void Builder_ImplicitStringConversion()
{
FirestoreBuilder builder = Firestore.Collection("test");
string uri = builder;
uri.Should().Be("fstore://test");
}
[Fact]
public void Builder_ToString_EqualsImplicit()
{
var builder = Firestore.Collection("test").Limit(10);
builder.ToString().Should().Be((string)builder);
}
[Fact]
public void Builder_NoParams_NoQueryString()
{
string uri = Firestore.Collection("data");
uri.Should().NotContain("?");
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Integration/FcmProducerE2ETests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Integration/FcmProducerE2ETests.cs
----
using System.Text.Json;
using FirebaseAdmin;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Http;
using OpenTelemetry;
using OpenTelemetry.Trace;
using redb.Route.Core;
using redb.Route.Firebase;
using Xunit.Abstractions;
namespace redb.Route.Tests.Firebase.Integration;
///
/// FCM producer e2e against the fcm-echo container (:18200) — Google ships no FCM
/// emulator, so the mock records HTTP v1 messages:send calls. The FirebaseAdmin SDK
/// is pointed at the mock through with a static
/// access token, so the full production send path (FirebaseMessaging → HTTP v1 envelope)
/// is exercised — only the network target differs.
///
[Trait("Category", "Integration")]
[Collection("FirebaseEnvSensitive")]
public sealed class FcmProducerE2ETests : IAsyncLifetime
{
private const string EchoBase = "http://localhost:18200";
// Project id per test-class instance: three TFM assemblies hit ONE shared fcm-echo store
// in parallel, so isolation comes from filtering by project, never from clearing the store.
private readonly string ProjectId = $"demo-{Guid.NewGuid():N}";
private readonly ITestOutputHelper _output;
private readonly HttpClient _echo = new();
public FcmProducerE2ETests(ITestOutputHelper output) => _output = output;
private string? _prevGac;
public Task InitializeAsync()
{
// Validate() needs a credential source; the mock provider supplies the real app,
// so a dummy GOOGLE_APPLICATION_CREDENTIALS satisfies the option check honestly
// (a fake connectionFactory name would now fail loud).
_prevGac = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS");
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "unused-by-mock.json");
return Task.CompletedTask;
}
public Task DisposeAsync()
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", _prevGac);
_echo.Dispose();
return Task.CompletedTask;
}
[Fact]
public async Task Fcm_TokenSend_DeliversEnvelopeToFcmV1Endpoint()
{
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.Token("device-token-1").Title("Order update").Body("Shipped")
.ProjectId(ProjectId).Build());
await producer.Start();
var exchange = new Exchange(new Message("fallback body"));
await producer.Process(exchange);
await producer.Stop();
var messageId = exchange.In.GetHeader(FcmHeaders.MessageId);
messageId.Should().StartWith($"projects/{ProjectId}/messages/");
_output.WriteLine($"MessageId: {messageId}");
var recorded = await FetchRecordedAsync();
recorded.Should().HaveCount(1);
var msg = recorded[0].GetProperty("envelope").GetProperty("message");
msg.GetProperty("token").GetString().Should().Be("device-token-1");
msg.GetProperty("notification").GetProperty("title").GetString().Should().Be("Order update");
msg.GetProperty("notification").GetProperty("body").GetString().Should().Be("Shipped");
}
[Fact]
public async Task Fcm_TopicDataOnlyDryRun_SendsValidateOnlyWithDataPayload()
{
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.Topic("news").DataOnly().DryRun()
.ProjectId(ProjectId).Build());
await producer.Start();
var body = new Dictionary { ["orderId"] = "42", ["status"] = "shipped" };
var exchange = new Exchange(new Message(body));
exchange.In.Headers[FcmHeaders.DataPrefix + "source"] = "e2e";
await producer.Process(exchange);
await producer.Stop();
var recorded = await FetchRecordedAsync();
recorded.Should().HaveCount(1);
var envelope = recorded[0].GetProperty("envelope");
envelope.GetProperty("validate_only").GetBoolean().Should().BeTrue("DryRun must go out as validate_only");
var msg = envelope.GetProperty("message");
msg.GetProperty("topic").GetString().Should().Be("news");
msg.TryGetProperty("notification", out _).Should().BeFalse("DataOnly carries no notification");
var data = msg.GetProperty("data");
data.GetProperty("orderId").GetString().Should().Be("42");
data.GetProperty("status").GetString().Should().Be("shipped");
data.GetProperty("source").GetString().Should().Be("e2e");
}
[Fact]
public async Task Fcm_ImageUrlHeader_ReachesNotification()
{
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.Token("t1").Title("hello")
.ProjectId(ProjectId).Build());
await producer.Start();
var exchange = new Exchange(new Message("body"));
exchange.In.Headers[FcmHeaders.ImageUrl] = "https://img.example/1.png";
await producer.Process(exchange);
await producer.Stop();
var recorded = await FetchRecordedAsync();
recorded[0].GetProperty("envelope").GetProperty("message")
.GetProperty("notification").GetProperty("image").GetString()
.Should().Be("https://img.example/1.png",
"the FcmHeaders.ImageUrl header must be read, not be a dead constant");
}
[Fact]
public async Task Fcm_TopicSend_SpanCarriesDestination()
{
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.Topic("news").ProjectId(ProjectId).Build());
var activities = new List();
using var tracer = Sdk.CreateTracerProviderBuilder()
.AddSource(redb.Route.Telemetry.RouteActivitySource.SourceName)
.AddInMemoryExporter(activities)
.Build()!;
await producer.Start();
await producer.Process(new Exchange(new Message("body")));
await producer.Stop();
tracer.ForceFlush(1000);
activities.Should().NotBeEmpty();
activities[0].GetTagItem("messaging.destination.name").Should().Be("news",
"the FCM span must carry a destination (topic/condition; for a token the literal \"token\")");
}
[Fact]
public async Task Fcm_HeaderOverrides_WinOverOptions()
{
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.Token("option-token").Title("option-title")
.ProjectId(ProjectId).Build());
await producer.Start();
var exchange = new Exchange(new Message("body"));
exchange.In.Headers[FcmHeaders.Token] = "header-token";
exchange.In.Headers[FcmHeaders.Title] = "header-title";
await producer.Process(exchange);
await producer.Stop();
var recorded = await FetchRecordedAsync();
var msg = recorded[0].GetProperty("envelope").GetProperty("message");
msg.GetProperty("token").GetString().Should().Be("header-token");
msg.GetProperty("notification").GetProperty("title").GetString().Should().Be("header-title");
}
// ═══ Multicast ═══
[Fact]
public async Task Fcm_Multicast_SendsToEveryTokenAndReportsCounts()
{
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.Multicast().Title("bulk").ProjectId(ProjectId).Build());
await producer.Start();
var tokens = new List { "mt-1", "mt-2", "mt-3" };
var exchange = new Exchange(new Message(tokens));
await producer.Process(exchange);
await producer.Stop();
exchange.In.Headers[FcmHeaders.SuccessCount].Should().Be(3,
"multicast must return SuccessCount - the header has been declared since the first version");
exchange.In.Headers[FcmHeaders.FailureCount].Should().Be(0);
var recorded = await FetchRecordedAsync();
recorded.Should().HaveCount(3, "one HTTP v1 send per token");
recorded.Select(m => m.GetProperty("envelope").GetProperty("message")
.GetProperty("token").GetString())
.Should().BeEquivalentTo(tokens);
}
// ═══ Topic management ═══
// FirebaseAdmin 3.7 manages topics through FCM v1: one topicSubscriptions request per token.
[Fact]
public async Task Fcm_SubscribeToTopic_SendsOneSubscriptionPerToken()
{
var topic = $"news-{Guid.NewGuid():N}";
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.SubscribeToTopic(topic).ProjectId(ProjectId).Build());
await producer.Start();
var exchange = new Exchange(new Message(new List { "sub-1", "sub-2" }));
await producer.Process(exchange);
await producer.Stop();
exchange.In.Headers[FcmHeaders.SuccessCount].Should().Be(2);
exchange.In.Headers[FcmHeaders.FailureCount].Should().Be(0);
var ops = await FetchTopicOpsAsync(topic);
ops.Should().HaveCount(2, "one FCM v1 subscription request per token");
ops.Select(op => op.GetProperty("envelope").GetProperty("topicOp").GetString())
.Should().AllBe("add");
ops.Select(op => op.GetProperty("envelope").GetProperty("token").GetString())
.Should().BeEquivalentTo(["sub-1", "sub-2"]);
}
[Fact]
public async Task Fcm_UnsubscribeFromTopic_SendsOneRemovalPerToken()
{
var topic = $"news-{Guid.NewGuid():N}";
using var cred = new FcmEchoCredentialProvider(ProjectId);
var producer = CreateProducer(cred,
Fcm.UnsubscribeFromTopic(topic).ProjectId(ProjectId).Build());
await producer.Start();
var exchange = new Exchange(new Message(new List { "un-1" }));
await producer.Process(exchange);
await producer.Stop();
exchange.In.Headers[FcmHeaders.SuccessCount].Should().Be(1);
var ops = await FetchTopicOpsAsync(topic);
ops.Should().HaveCount(1);
ops[0].GetProperty("envelope").GetProperty("topicOp").GetString().Should().Be("remove");
ops[0].GetProperty("envelope").GetProperty("token").GetString().Should().Be("un-1");
}
// ── Helpers ──
private async Task> FetchTopicOpsAsync(string topic)
{
var json = await _echo.GetStringAsync($"{EchoBase}/messages");
return JsonSerializer.Deserialize>(json)!
.Where(m => m.GetProperty("project").GetString() == ProjectId
&& m.GetProperty("envelope").TryGetProperty("topic", out var t)
&& t.GetString() == topic)
.ToList();
}
private FcmProducer CreateProducer(IFirebaseCredentialProvider cred, string uri)
{
var component = new FcmComponent { CredentialProvider = cred };
var endpoint = (FcmEndpoint)component.CreateEndpoint(EndpointUriParser.Parse(uri));
return (FcmProducer)endpoint.CreateProducer();
}
private async Task> FetchRecordedAsync()
{
var json = await _echo.GetStringAsync($"{EchoBase}/messages");
return JsonSerializer.Deserialize>(json)!
.Where(m => m.GetProperty("project").GetString() == ProjectId)
.ToList();
}
///
/// Builds a real whose HTTP traffic is redirected to fcm-echo.
/// Static access token — no token endpoint round-trip; named app — no DEFAULT clash.
///
private sealed class FcmEchoCredentialProvider : IFirebaseCredentialProvider, IDisposable
{
private readonly FirebaseApp _app;
internal FcmEchoCredentialProvider(string projectId) =>
_app = FirebaseApp.Create(new AppOptions
{
Credential = GoogleCredential.FromAccessToken("fake-e2e-token"),
ProjectId = projectId,
HttpClientFactory = new RedirectingHttpClientFactory(new Uri(EchoBase)),
}, $"fcm-echo-{Guid.NewGuid():N}");
public FirebaseApp GetOrCreateApp(string? credentialPath = null, string? projectId = null) => _app;
public Google.Cloud.Firestore.FirestoreDb GetFirestoreDb(string? projectId = null, string? credentialPath = null, string? databaseId = null)
=> throw new NotSupportedException("FCM-only tests");
public Google.Cloud.Storage.V1.StorageClient GetStorageClient(string? credentialPath = null)
=> throw new NotSupportedException("FCM-only tests");
public void Dispose() => _app.Delete();
}
private sealed class RedirectingHttpClientFactory : HttpClientFactory
{
private readonly Uri _target;
internal RedirectingHttpClientFactory(Uri target) => _target = target;
protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args)
=> new RedirectHandler(_target, base.CreateHandler(args));
private sealed class RedirectHandler : DelegatingHandler
{
private readonly Uri _target;
internal RedirectHandler(Uri target, HttpMessageHandler inner) : base(inner) => _target = target;
protected override Task SendAsync(HttpRequestMessage request, CancellationToken ct)
{
var builder = new UriBuilder(request.RequestUri!)
{
Scheme = _target.Scheme,
Host = _target.Host,
Port = _target.Port,
};
request.RequestUri = builder.Uri;
return base.SendAsync(request, ct);
}
}
}
}
Path: redb-route/tests/redb.Route.Tests.Firebase/Integration/FirebaseIntegrationTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Firebase/Integration/FirebaseIntegrationTests.cs
----
using System.Collections.Concurrent;
using System.Text;
using System.Text.Json;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Firestore;
using Google.Cloud.Storage.V1;
using OpenTelemetry;
using OpenTelemetry.Trace;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Firebase;
using redb.Route.Telemetry;
using Xunit.Abstractions;
namespace redb.Route.Tests.Firebase.Integration;
///
/// Integration tests against Firebase emulators (docker-compose.tests.yml).
/// Firestore: localhost:8086 (FIRESTORE_EMULATOR_HOST)
/// GCS: localhost:4443 (fake-gcs-server)
///
/// Start with:
/// docker compose -f docker-compose.tests.yml up firebase-emulators fake-gcs -d
/// dotnet test --filter "Category=Integration"
///
[Trait("Category", "Integration")]
[Collection("FirebaseEnvSensitive")]
public sealed class FirebaseIntegrationTests : IAsyncLifetime
{
private const string ProjectId = "demo-redb";
private const string FirestoreHost = "localhost:8086";
private const string GcsEndpoint = "http://localhost:4443/storage/v1/";
// Bucket per TFM: the test assemblies of each target framework run in parallel against the same
// fake-gcs, and one assembly's cleanup must not delete another's freshly seeded objects.
private static readonly string TestBucket = $"integration-test-bucket-net{Environment.Version.Major}";
private readonly ITestOutputHelper _output;
private StorageClient? _rawGcs;
private FirestoreDb? _rawFirestore;
private FirebaseCredentialProvider? _prodProvider;
public FirebaseIntegrationTests(ITestOutputHelper output) => _output = output;
public async Task InitializeAsync()
{
// Emulator env vars BEFORE the production provider builds any client:
// the connector path under test detects the emulators through these.
Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", FirestoreHost);
Environment.SetEnvironmentVariable("STORAGE_EMULATOR_HOST", GcsEndpoint);
_prodProvider = new FirebaseCredentialProvider();
_rawFirestore = new FirestoreDbBuilder
{
ProjectId = ProjectId,
EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOnly,
}.Build();
// Create GCS client pointing at fake-gcs-server
_rawGcs = CreateFakeGcsClient();
// Create test bucket (ignore if exists)
try
{
await _rawGcs.CreateBucketAsync(ProjectId, TestBucket);
_output.WriteLine($"Created bucket: {TestBucket}");
}
catch (Google.GoogleApiException ex) when (ex.HttpStatusCode == System.Net.HttpStatusCode.Conflict)
{
_output.WriteLine($"Bucket already exists: {TestBucket}");
}
}
public async Task DisposeAsync()
{
_prodProvider?.Dispose();
// Cleanup GCS objects
if (_rawGcs is not null)
{
try
{
var objects = _rawGcs.ListObjects(TestBucket, "test-");
foreach (var obj in objects)
await _rawGcs.DeleteObjectAsync(TestBucket, obj.Name);
}
catch { /* best-effort cleanup */ }
}
}
// ── Firestore Component Helpers ──
private FirestoreComponent CreateFirestoreComponent()
{
// Production credential provider — the same path a real host runs.
var component = new FirestoreComponent { CredentialProvider = _prodProvider! };
return component;
}
private FirestoreEndpoint CreateFirestoreEndpoint(string collection, string? extraParams = null)
{
var qs = $"projectId={ProjectId}";
if (extraParams is not null) qs += $"&{extraParams}";
var uri = EndpointUriParser.Parse($"fstore://{collection}?{qs}");
var component = CreateFirestoreComponent();
return (FirestoreEndpoint)component.CreateEndpoint(uri);
}
// ── Storage Component Helpers ──
private FirebaseStorageComponent CreateStorageComponent()
{
// Production credential provider — the same path a real host runs.
var component = new FirebaseStorageComponent { CredentialProvider = _prodProvider! };
return component;
}
private FirebaseStorageEndpoint CreateStorageEndpoint(string bucket, string? extraParams = null)
{
var qs = extraParams ?? "";
var uri = EndpointUriParser.Parse(string.IsNullOrEmpty(qs)
? $"fbstorage://{bucket}"
: $"fbstorage://{bucket}?{qs}");
var component = CreateStorageComponent();
return (FirebaseStorageEndpoint)component.CreateEndpoint(uri);
}
// ═══════════════════════════════════════════════════════════════════
// FIRESTORE — CRUD
// ═══════════════════════════════════════════════════════════════════
[Fact]
public async Task Firestore_SetAndGet_Roundtrip()
{
var collection = $"test-{Guid.NewGuid():N}";
var docId = "doc1";
// Set
var epSet = CreateFirestoreEndpoint(collection, $"operation=Set&documentId={docId}");
var producer = (FirestoreProducer)epSet.CreateProducer();
await producer.Start();
var data = new Dictionary { ["name"] = "Alice", ["age"] = 30 };
var setExchange = new Exchange(new Message(data));
await producer.Process(setExchange);
await producer.Stop();
setExchange.In.Headers[FirestoreHeaders.DocumentId].Should().Be(docId);
_output.WriteLine($"Set doc: {setExchange.In.Headers[FirestoreHeaders.DocumentPath]}");
// Get
var epGet = CreateFirestoreEndpoint(collection, $"operation=Get&documentId={docId}");
var getProd = (FirestoreProducer)epGet.CreateProducer();
await getProd.Start();
var getExchange = new Exchange(new Message());
await getProd.Process(getExchange);
await getProd.Stop();
getExchange.Out.Should().NotBeNull();
var result = getExchange.Out!.Body as IDictionary;
result.Should().NotBeNull();
result!["name"].Should().Be("Alice");
((long)result["age"]!).Should().Be(30);
_output.WriteLine($"Got doc: name={result["name"]}, age={result["age"]}");
}
[Fact]
public async Task Firestore_SetFromJson_Roundtrip()
{
var collection = $"test-{Guid.NewGuid():N}";
var docId = "json-doc";
// Set from JSON string (exercises CRITICAL 3 fix — JsonElement conversion)
var epSet = CreateFirestoreEndpoint(collection, $"operation=Set&documentId={docId}");
var producer = (FirestoreProducer)epSet.CreateProducer();
await producer.Start();
var json = JsonSerializer.Serialize(new
{
name = "Bob",
tags = new[] { "admin", "user" },
address = new { city = "Moscow", zip = "101000" }
});
var setExchange = new Exchange(new Message(json));
await producer.Process(setExchange);
await producer.Stop();
// Get back
var epGet = CreateFirestoreEndpoint(collection, $"operation=Get&documentId={docId}");
var getProd = (FirestoreProducer)epGet.CreateProducer();
await getProd.Start();
var getExchange = new Exchange(new Message());
await getProd.Process(getExchange);
await getProd.Stop();
var result = getExchange.Out!.Body as IDictionary;
result.Should().NotBeNull();
result!["name"].Should().Be("Bob");
(result["tags"] as IEnumerable