예제 #1
0
        public void Should_validate_settings()
        {
            var defaultSettings = new MongoEventStoreSettings
            {
                EventsCollectionName = null,
                Database             = DatabaseName
            };

            Action action = () => new MongoEventStore(new MongoClient(), defaultSettings);

            action.ShouldThrowExactly <ArgumentNullException>();
        }
예제 #2
0
        public void Should_use_custom_settings()
        {
            var customSettings = new MongoEventStoreSettings
            {
                EventsCollectionName = "MyEvents",
                Database             = DatabaseName
            };

            using (var eventStore = new MongoEventStore(_mongoClient, customSettings))
            {
                eventStore.Settings.EventsCollectionName.Should().Be(customSettings.EventsCollectionName);
            }
        }
예제 #3
0
        public static async Task Main(string[] args)
        {
            var services = new ServiceCollection()
                           .AddLogging(lb => lb
                                       .SetMinimumLevel(LogLevel.Trace)
                                       .AddConsole()
                                       );

            await using var serviceProvider = services.BuildServiceProvider();

            var jsonSerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                },
                Converters =
                {
                    new StringEnumConverter()
                }
            };

            var jsonSerializer = JsonSerializer.CreateDefault(jsonSerializerSettings);
            var serializer     = new JsonEventSerializer(jsonSerializer);
            // var serializer = new Aggregail.System.Text.Json.JsonEventSerializer(new JsonSerializerOptions());

            // using var connection = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113");
            // await connection.ConnectAsync();
            // var eventStore = new EventStore(connection, serializer);

            var mongoClient = new MongoClient("mongodb://*****:*****@mongodb-primary:27017,mongodb-secondary:27018,mongodb-arbiter:27019/aggregail_demo?authSource=admin&replicaSet=rs0");
            // var mongoClient = new MongoClient("mongodb://*****:*****@mongodb:27017/aggregail_demo?authSource=admin&replicaSet=rs0");
            var mongoDatabase = mongoClient.GetDatabase("aggregail_demo");

            var mongoSettings = new MongoEventStoreSettings(mongoDatabase, "streams", serializer);

            mongoSettings.Logger          = serviceProvider.GetRequiredService <ILogger <MongoEventStore> >();
            mongoSettings.MetadataFactory = new UserMetadataFactory("nije");

            var mongoStore = new MongoEventStore(mongoSettings);

            await mongoStore.InitializeAsync();

            var sw = new Stopwatch();

            sw.Start();
            Console.WriteLine("Running Test Case...");

            var inMemoryStore = new InMemoryEventStore(new InMemoryEventStoreSettings(serializer));

            var robotStore = new Robot.Store(mongoStore);
            await RobotProgram.RunAsync(robotStore);

            // var tasks = Enumerable.Range(0, 500)
            //     .Select(_ => TestCase(mongoStore))
            //     .ToArray();
            //
            // await Task.WhenAll(tasks);
            sw.Stop();

            Console.WriteLine($"Test Case Complete in {sw.Elapsed}");
        }
예제 #4
0
        public void Should_validate_constructor_parameters(MongoClient mongoClient, MongoEventStoreSettings settings)
        {
            Action action = () => new MongoEventStore(mongoClient, settings);

            action.ShouldThrowExactly <ArgumentNullException>();
        }