public async Task GetAvailableEmpty()
        {
            var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict);

            domainObjectStore.Setup(dos => dos.ReplayObject <ConfigStructureList>())
            .ReturnsAsync(() => Result.Success(new ConfigStructureList()))
            .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.Empty(result.Data);

            domainObjectStore.Verify();
            eventStore.Verify();
        }
        public async Task UpdateVariables()
        {
            var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict);

            domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigStructure>(), It.IsAny <string>()))
            .ReturnsAsync((ConfigStructure str, string id) =>
            {
                str.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 = 4710
                });
                return(Result.Success(str));
            })
            .Verifiable();

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

            eventStore.Setup(es => es.WriteEvents(It.IsAny <IList <DomainEvent> >()))
            .ReturnsAsync(4711)
            .Verifiable();

            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.UpdateVariables(new StructureIdentifier("Foo", 42), new Dictionary <string, string> {
                { "Bar", "Boo" }
            });

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

            domainObjectStore.Verify();
            eventStore.Verify();
        }
        public async Task GetKeysPaged()
        {
            var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict);

            domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigStructure>(), It.IsAny <string>()))
            .ReturnsAsync((ConfigStructure str, string id) =>
            {
                str.ApplyEvent(new ReplayedEvent
                {
                    DomainEvent = new StructureCreated(new StructureIdentifier("Foo", 42),
                                                       new Dictionary <string, string>
                    {
                        { "Bar", "BarValue" },
                        { "Baz", "BazValue" },
                        { "Foo", "FooValue" }
                    },
                                                       new Dictionary <string, string> {
                        { "Bar", "Baz" }
                    }),
                    UtcTime = DateTime.UtcNow,
                    Version = 4710
                });
                return(Result.Success(str));
            })
            .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.GetKeys(new StructureIdentifier("Foo", 42), QueryRange.Make(1, 1));

            Assert.False(result.IsError, "result.IsError");
            Assert.Single(result.Data);
            Assert.Equal(new KeyValuePair <string, string>("Baz", "BazValue"), result.Data.First());

            domainObjectStore.Verify();
            eventStore.Verify();
        }
        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();
        }