public async Task CreateNewEnvironment() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>())) .ReturnsAsync((ConfigEnvironment str, string id) => 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 EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.Create(new EnvironmentIdentifier("Foo", "Bar"), false); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task GetAvailableEmpty() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject <ConfigEnvironmentList>(It.IsAny <long>())) .ReturnsAsync(() => Result.Success(new ConfigEnvironmentList())) .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 EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.GetAvailable(QueryRange.All); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); Assert.Empty(result.Data); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task GetKeysWithoutRoot() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>())) .ReturnsAsync((ConfigEnvironment str, string id) => { str.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar")), UtcTime = DateTime.UtcNow, Version = 4710 }); str.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentKeysImported(new EnvironmentIdentifier("Foo", "Bar"), new[] { ConfigKeyAction.Set("Foo", "FooValue"), ConfigKeyAction.Set("Foo/Bar", "BarValue"), ConfigKeyAction.Set("Foo/Bar/Baz", "BazValue") }), UtcTime = DateTime.UtcNow, Version = 4711 }); 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 EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.GetKeys(new EnvironmentKeyQueryParameters { Environment = new EnvironmentIdentifier("Foo", "Bar"), Filter = "Foo/", RemoveRoot = "Foo", Range = QueryRange.All }); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); Assert.NotEmpty(result.Data); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task DeleteKeys() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>())) .ReturnsAsync((ConfigEnvironment str, string id) => { str.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar")), UtcTime = DateTime.UtcNow, Version = 4710 }); str.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentKeysImported(new EnvironmentIdentifier("Foo", "Bar"), new[] { ConfigKeyAction.Set("Foo", "FooValue"), ConfigKeyAction.Set("Bar", "BarValue"), ConfigKeyAction.Set("Baz", "BazValue") }), UtcTime = DateTime.UtcNow, Version = 4711 }); 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); eventStore.Setup(es => es.WriteEvents(It.IsAny <IList <DomainEvent> >())) .ReturnsAsync(4712) .Verifiable("events not written to stream"); var store = new EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.DeleteKeys(new EnvironmentIdentifier("Foo", "Bar"), new[] { "Bar", "Baz" }); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); domainObjectStore.Verify(); eventStore.Verify(); }
public async Task GetAvailablePaged() { var domainObjectStore = new Mock <IDomainObjectStore>(MockBehavior.Strict); domainObjectStore.Setup(dos => dos.ReplayObject <ConfigEnvironmentList>(It.IsAny <long>())) .ReturnsAsync((long v) => { var list = new ConfigEnvironmentList(); list.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Foo")), UtcTime = DateTime.UtcNow, Version = 4710 }); list.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar")), UtcTime = DateTime.UtcNow, Version = 4711 }); list.ApplyEvent(new ReplayedEvent { DomainEvent = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Baz")), UtcTime = DateTime.UtcNow, Version = 4712 }); 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 EnvironmentProjectionStore(eventStore.Object, domainObjectStore.Object, _logger, new ICommandValidator[0]); var result = await store.GetAvailable(QueryRange.Make(1, 1)); Assert.Empty(result.Message); Assert.False(result.IsError, "result.IsError"); Assert.Single(result.Data); domainObjectStore.Verify(); eventStore.Verify(); }