public void CalculateCacheSizeFilled()
        {
            var item = new ConfigStructureList();

            item.ApplyEvent(new ReplayedEvent
            {
                DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42),
                                                   new Dictionary <string, string>(),
                                                   new Dictionary <string, string>()),
                UtcTime = DateTime.UtcNow,
                Version = 4711
            });

            Assert.InRange(item.CalculateCacheSize(), 0, long.MaxValue);
        }
        public async Task GetAvailable()
        {
            var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict);

            domainObjectStore.Setup(dos => dos.ReplayObject <ConfigStructureList>())
            .ReturnsAsync(() =>
            {
                var list = new ConfigStructureList();
                list.ApplyEvent(new ReplayedEvent
                {
                    DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42),
                                                       new Dictionary <string, string> {
                        { "Foo", "Bar" }
                    },
                                                       new Dictionary <string, string> {
                        { "Bar", "Baz" }
                    }),
                    UtcTime = DateTime.UtcNow,
                    Version = 4711
                });
                return(Result.Success(list));
            })
            .Verifiable();

            var eventStore = new Mock <IEventStore>(MockBehavior.Strict);

            eventStore.Setup(es => es.ReplayEventsAsStream(
                                 It.IsAny <Func <(StoredEvent StoredEvent, DomainEventMetadata Metadata), bool> >(),
                                 It.IsAny <Func <(StoredEvent StoredEvent, DomainEvent DomainEvent), bool> >(),
                                 It.IsAny <int>(),
                                 It.IsAny <StreamDirection>(),
                                 It.IsAny <long>()))
            .Returns(Task.CompletedTask);

            var store = new StructureProjectionStore(_logger,
                                                     domainObjectStore.Object,
                                                     eventStore.Object,
                                                     new ICommandValidator[0]);

            var result = await store.GetAvailable(QueryRange.All);

            Assert.False(result.IsError, "result.IsError");
            Assert.NotEmpty(result.Data);

            domainObjectStore.Verify();
            eventStore.Verify();
        }
        public void ReplayHandlesStructureCreated()
        {
            var item = new ConfigStructureList();

            Assert.Empty(item.Identifiers);

            item.ApplyEvent(new ReplayedEvent
            {
                DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42),
                                                   new Dictionary <string, string>(),
                                                   new Dictionary <string, string>()),
                UtcTime = DateTime.UtcNow,
                Version = 4711
            });

            Assert.NotEmpty(item.Identifiers);
        }
        public void CreateValidSnapshot()
        {
            var item = new ConfigStructureList();

            item.ApplyEvent(new ReplayedEvent
            {
                DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42),
                                                   new Dictionary <string, string>(),
                                                   new Dictionary <string, string>()),
                UtcTime = DateTime.UtcNow,
                Version = 4711
            });

            var snapshot = item.CreateSnapshot();

            Assert.Equal(item.CurrentVersion, snapshot.Version);
            Assert.Equal(item.MetaVersion, snapshot.MetaVersion);
            Assert.False(string.IsNullOrWhiteSpace(snapshot.Identifier));
            Assert.False(string.IsNullOrWhiteSpace(snapshot.JsonData));
            Assert.False(string.IsNullOrWhiteSpace(snapshot.DataType));
        }
        public void SnapshotAppliesAllProperties()
        {
            var snapshotSource = new ConfigStructureList();

            snapshotSource.ApplyEvent(new ReplayedEvent
            {
                DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42),
                                                   new Dictionary <string, string>(),
                                                   new Dictionary <string, string>()),
                UtcTime = DateTime.UtcNow,
                Version = 4711
            });
            var snapshot = snapshotSource.CreateSnapshot();

            var target = new ConfigStructureList();

            target.ApplySnapshot(snapshot);

            Assert.Equal(snapshotSource.Identifiers, target.Identifiers);
            Assert.Equal(snapshotSource.CurrentVersion, target.CurrentVersion);
            Assert.Equal(snapshotSource.MetaVersion, target.MetaVersion);
        }
        public void CreateNew()
        {
            var item = new ConfigStructureList();

            Assert.Empty(item.Identifiers);
        }