Пример #1
0
        public async Task ReadModelFeed()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("http://localost:5000/api/DomainEvents/?lastVersion=0")
            .Respond("application/json", "[{ \"domainEventType\": \"UNKNOWN_TYPE\",\"entityStreamVersion\": 12, \"overallVersion\": \"1\", \"domainEvent\": {\"EntityId\" : \"5a8b63c8-0f7f-4de7-a9e5-b6b377aa2180\"}}, { \"domainEventType\": \"TestEv\",\"entityStreamVersion\": 12, \"overallVersion\": \"2\", \"domainEvent\": {\"EntityId\" : \"5a8b63c8-0f7f-4de7-a9e5-b6b377aa2180\" }}]");

            var domainOverallEventClient = new HttpClient(mockHttp);

            domainOverallEventClient.BaseAddress = new Uri("http://localost:5000/api/DomainEvents/");

            var factoryMock = new Mock <IDomainEventClientFactory>();

            factoryMock.Setup(m => m.GetClient <ReadModelEventHandler <TestReadModel> >()).ReturnsAsync(domainOverallEventClient);
            var domainEventFactory = new DomainEventFactory(_eventTypeRegistration);
            var readModelFeed      = new EventFeed <ReadModelEventHandler <TestReadModel> >(
                domainEventFactory,
                factoryMock.Object, new MicrowaveLogger <EventFeed <ReadModelEventHandler <TestReadModel> > >());
            var domainEvents = await readModelFeed.GetEventsAsync();

            var domainEventWrappers = domainEvents.ToList();

            Assert.AreEqual(1, domainEventWrappers.Count);
            Assert.AreEqual(new Guid("5a8b63c8-0f7f-4de7-a9e5-b6b377aa2180").ToString(), domainEventWrappers[0].DomainEvent
                            .EntityId);
        }
Пример #2
0
        public async Task ReadModelFeed_Unauthorized()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("http://localost:5000/api/DomainEvents/?timeStamp=0001-01-01T00:00:00.0000000+00:00")
            .Respond(HttpStatusCode.Unauthorized);
            var domainOverallEventClient = new HttpClient(mockHttp);

            domainOverallEventClient.BaseAddress = new Uri("http://localost:5000/api/DomainEvents/");

            var factoryMock = new Mock <IDomainEventClientFactory>();

            factoryMock.Setup(m => m.GetClient <ReadModelEventHandler <TestReadModel> >()).ReturnsAsync(domainOverallEventClient);

            var domainEventFactory = new DomainEventFactory(_eventTypeRegistration);
            var readModelFeed      = new EventFeed <ReadModelEventHandler <TestReadModel> >(domainEventFactory, factoryMock
                                                                                            .Object, new MicrowaveLogger <EventFeed <ReadModelEventHandler <TestReadModel> > >());
            var domainEvents = await readModelFeed.GetEventsAsync();

            var domainEventWrappers = domainEvents.ToList();

            Assert.AreEqual(0, domainEventWrappers.Count);
        }
Пример #3
0
        public async Task ReadModelFeed_Exception()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("http://localost:5000/api/DomainEvents/?lastVersion=0")
            .Throw(new HttpRequestException());
            var domainOverallEventClient = new HttpClient(mockHttp);

            domainOverallEventClient.BaseAddress = new Uri("http://localost:5000/api/DomainEvents/");

            var factoryMock = new Mock <IDomainEventClientFactory>();

            factoryMock.Setup(m => m.GetClient <ReadModelEventHandler <TestReadModel> >()).ReturnsAsync(domainOverallEventClient);

            var domainEventFactory = new DomainEventFactory(_eventTypeRegistration);
            var readModelFeed      = new EventFeed <ReadModelEventHandler <TestReadModel> >(domainEventFactory, factoryMock
                                                                                            .Object, new MicrowaveLogger <EventFeed <ReadModelEventHandler <TestReadModel> > >());
            var domainEvents = await readModelFeed.GetEventsAsync();

            var domainEventWrappers = domainEvents.ToList();

            Assert.AreEqual(0, domainEventWrappers.Count);
        }