public async Task SingleInsertAndFind_TestAsync()
        {
            var streamEvent = FakeInstanceUtils.GenerateRandomStreamEvent();

            await mongo.InsertEventAsync(new WebSocketStream(streamEvent, "tests"));

            var events = await mongo.FindEventsByFiltersAsync(Builders <WebSocketStream> .Filter.Eq(x => x.StreamEvent.Payload.Id, streamEvent.Payload.Id));

            Assert.Single(events);
            var singleEvent = events.First();

            Assert.IsType <WebSocketStream>(singleEvent);
            Assert.IsType <StreamEvent>(singleEvent.StreamEvent);
            Assert.IsType <Payload>(singleEvent.StreamEvent.Payload);

            Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
            Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

            Assert.Equal(streamEvent.Event, singleEvent.StreamEvent.Event);
            Assert.Null(singleEvent.StreamEvent.JoinRef);
            Assert.Null(singleEvent.StreamEvent.Ref);
            Assert.Equal(streamEvent.Topic, singleEvent.StreamEvent.Topic);

            Assert.Equal(streamEvent.Payload.Timestamp, singleEvent.StreamEvent.Payload.Timestamp);
            Assert.Equal(streamEvent.Payload.MachineId, singleEvent.StreamEvent.Payload.MachineId);
            Assert.Equal(streamEvent.Payload.Status, singleEvent.StreamEvent.Payload.Status);
        }
        public async Task MultipleInsertAndFindByMachineId_TestAsync()
        {
            string machineId = Guid.NewGuid().ToString();

            for (int i = 0; i < 10; i++)
            {
                await mongo.InsertEventAsync(new WebSocketStream(
                                                 FakeInstanceUtils.GenerateRandomStreamEvent(machineId: machineId), "tests"
                                                 ));
            }


            var events = await mongo.FindEventsByFiltersAsync(
                Builders <WebSocketStream> .Filter.Eq(x => x.StreamEvent.Payload.MachineId, machineId),
                Builders <WebSocketStream> .Sort.Descending(x => x.StreamEvent.Payload.Timestamp),
                50
                );

            Assert.Equal(10, events.Count);
            foreach (var singleEvent in events)
            {
                Assert.IsType <WebSocketStream>(singleEvent);
                Assert.IsType <StreamEvent>(singleEvent.StreamEvent);
                Assert.IsType <Payload>(singleEvent.StreamEvent.Payload);

                Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
                Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

                Assert.Equal(machineId, singleEvent.StreamEvent.Payload.MachineId);
            }
        }
Ejemplo n.º 3
0
        public async Task GetEventsByFiltersWithMachineId_TestAsync()
        {
            var(id, machine_id, timestamp, status) = await FakeInstanceUtils.SeedDataAsync(mongo);

            IDictionary <string, string> filters = new Dictionary <string, string>
            {
                { "machine_id", machine_id },
                { "limit", "50" }
            };

            var events = await getData.GetEventsByFiltersAsync(filters);

            Assert.InRange(events.Count(), 0, 50);
            foreach (var singleEvent in events)
            {
                Assert.IsAssignableFrom <IWebSocketStream>(singleEvent);
                Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
                Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

                Assert.Null(singleEvent.StreamEvent.JoinRef);
                Assert.Null(singleEvent.StreamEvent.Ref);

                Assert.Equal(singleEvent.StreamEvent.Payload.MachineId, machine_id);
            }
        }
Ejemplo n.º 4
0
        public async Task GetLastEvents_TestAsync()
        {
            var(id, machine_id, timestamp, status) = await FakeInstanceUtils.SeedDataAsync(mongo);

            var lastEvents = await getData.GetLastEventsAsync(20);

            Assert.Equal(20, lastEvents.Count());

            foreach (var singleEvent in lastEvents)
            {
                Assert.IsAssignableFrom <IWebSocketStream>(singleEvent);
                Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
                Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

                Assert.Null(singleEvent.StreamEvent.JoinRef);
                Assert.Null(singleEvent.StreamEvent.Ref);
            }
        }
Ejemplo n.º 5
0
        public async Task GetEventsByFiltersWithEmpty_TestAsync()
        {
            var(id, machine_id, timestamp, status) = await FakeInstanceUtils.SeedDataAsync(mongo);

            IDictionary <string, string> filters = new Dictionary <string, string>();

            var events = await getData.GetEventsByFiltersAsync(filters);

            Assert.Equal(31, events.Count());
            foreach (var singleEvent in events)
            {
                Assert.IsAssignableFrom <IWebSocketStream>(singleEvent);
                Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
                Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

                Assert.Null(singleEvent.StreamEvent.JoinRef);
                Assert.Null(singleEvent.StreamEvent.Ref);
            }
        }
Ejemplo n.º 6
0
        public async Task GetEventById_TestAsync()
        {
            string id          = Guid.NewGuid().ToString();
            var    streamEvent = FakeInstanceUtils.GenerateRandomStreamEvent(id: id);

            await mongo.InsertEventAsync(new WebSocketStream(streamEvent, "test"));

            var singleEvent = await getData.GetEventByIdAsync(id);

            Assert.IsAssignableFrom <IWebSocketStream>(singleEvent);
            Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
            Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

            Assert.Equal(streamEvent.Event, singleEvent.StreamEvent.Event);
            Assert.Null(singleEvent.StreamEvent.JoinRef);
            Assert.Null(singleEvent.StreamEvent.Ref);
            Assert.Equal(streamEvent.Topic, singleEvent.StreamEvent.Topic);

            Assert.Equal(streamEvent.Payload.Timestamp, singleEvent.StreamEvent.Payload.Timestamp);
            Assert.Equal(streamEvent.Payload.MachineId, singleEvent.StreamEvent.Payload.MachineId);
            Assert.Equal(streamEvent.Payload.Status, singleEvent.StreamEvent.Payload.Status);
        }
Ejemplo n.º 7
0
        public async Task GetEventsByFiltersWithFromTo_TestAsync()
        {
            var(id, machine_id, timestamp, status) = await FakeInstanceUtils.SeedDataAsync(mongo);

            IDictionary <string, string> filters = new Dictionary <string, string>
            {
                { "from", timestamp.AddMinutes(-1).ToString("yyyy-MM-ddTHH:mm:ss.fffffffK") },
                { "to", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffK") },
                { "limit", "20" }
            };

            var events = await getData.GetEventsByFiltersAsync(filters);

            Assert.InRange(events.Count(), 10, 20);
            foreach (var singleEvent in events)
            {
                Assert.IsAssignableFrom <IWebSocketStream>(singleEvent);
                Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
                Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

                Assert.Null(singleEvent.StreamEvent.JoinRef);
                Assert.Null(singleEvent.StreamEvent.Ref);
            }
        }
Ejemplo n.º 8
0
        public async Task GetEventsByFiltersWithStatus_TestAsync()
        {
            var(id, machine_id, timestamp, status) = await FakeInstanceUtils.SeedDataAsync(mongo);

            IDictionary <string, string> filters = new Dictionary <string, string>
            {
                { "status", $"{status},finished" },
                { "limit", "50" }
            };

            var events = await getData.GetEventsByFiltersAsync(filters);

            foreach (var singleEvent in events)
            {
                Assert.IsAssignableFrom <IWebSocketStream>(singleEvent);
                Assert.IsAssignableFrom <IStreamEvent>(singleEvent.StreamEvent);
                Assert.IsAssignableFrom <IPayload>(singleEvent.StreamEvent.Payload);

                Assert.Null(singleEvent.StreamEvent.JoinRef);
                Assert.Null(singleEvent.StreamEvent.Ref);

                Assert.Contains(singleEvent.StreamEvent.Payload.Status, new string[] { status, "finished" });
            }
        }
        public async Task ValidStore_TestAsync()
        {
            await storeData.StoreEventAsync(FakeInstanceUtils.GenerateRandomStreamEvent(), "tests");

            Assert.True(true);
        }