public async Task Group_MessageTypeIsLocation_ReturnsMessage()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Messages.Location);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.User, source.SourceType);
            Assert.AreEqual("U206d25c2ea6bd87c17655609a1c37cb8", source.User.Id);

            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.ReplyToken);

            Assert.IsNotNull(lineEvent.Message);
            Assert.AreEqual("325708", lineEvent.Message.Id);
            Assert.AreEqual(MessageType.Location, lineEvent.Message.MessageType);
            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.Message.ReplyToken);
            Assert.IsNull(lineEvent.Message.Text);
            Assert.IsNull(lineEvent.Message.Sticker);

            ILocation location = lineEvent.Message.Location;

            Assert.IsNotNull(location);
            Assert.AreEqual("〒150-0002 東京都渋谷区渋谷2丁目21−1", location.Address);
            Assert.AreEqual(35.65910807942215m, location.Latitude);
            Assert.AreEqual(139.70372892916203m, location.Longitude);
            Assert.AreEqual("my location", location.Title);
        }
        public async Task GetEvents_ValidRequest_ReturnsPostbackEvent()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Postback);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Postback, lineEvent.EventType);

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.User, source.SourceType);
            Assert.AreEqual("U206d25c2ea6bd87c17655609a1c37cb8", source.User.Id);

            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.ReplyToken);

            IPostback postback = lineEvent.Postback;

            Assert.IsNotNull(postback);
            Assert.AreEqual("action=buyItem&itemId=123123&color=red", postback.Data);
            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", postback.ReplyToken);
        }
        public async Task Group_MessageTypeIsImage_ReturnsMessage()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Messages.Image);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.User, source.SourceType);
            Assert.AreEqual("U206d25c2ea6bd87c17655609a1c37cb8", source.User.Id);

            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.ReplyToken);

            Assert.IsNotNull(lineEvent.Message);
            Assert.AreEqual("325708", lineEvent.Message.Id);
            Assert.IsNull(lineEvent.Message.Location);
            Assert.AreEqual(MessageType.Image, lineEvent.Message.MessageType);
            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.Message.ReplyToken);
            Assert.IsNull(lineEvent.Message.Sticker);
            Assert.IsNull(lineEvent.Message.Text);
        }
        public async Task GetEvents_ValidRequest_ReturnsBeaconEvent()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(BeaconEventJson);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Beacon, lineEvent.EventType);

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.User, source.SourceType);
            Assert.AreEqual("U206d25c2ea6bd87c17655609a1c37cb8", source.User.Id);

            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.ReplyToken);

            IBeacon beacon = lineEvent.Beacon;

            Assert.IsNotNull(beacon);
            Assert.AreEqual("d41d8cd98f", beacon.Hwid);
            Assert.AreEqual(BeaconType.Enter, beacon.BeaconType);
            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", beacon.ReplyToken);
        }
Beispiel #5
0
            public async Task ShouldHaveDestination()
            {
                var bot     = TestConfiguration.CreateBot();
                var request = new TestHttpRequest(JsonDocuments.Events.Webhook);

                var events = await bot.GetEvents(request);

                Assert.AreEqual("xxxxxxxxxx", events.Destination);
            }
Beispiel #6
0
        public async Task GetEvents_NoData_ReturnsEmptyEnumerable()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest();

            var events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(0, events.Count());
        }
Beispiel #7
0
        public async Task GetEvents_Whitespace_ReturnsEmptyEnumerable()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(WhitespaceJson);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(0, events.Count());
        }
Beispiel #8
0
            public async Task ShouldHaveDestinationWhenEventsNull()
            {
                var bot     = TestConfiguration.CreateBot();
                var request = new TestHttpRequest(JsonDocuments.Events.NoEvents);

                var events = await bot.GetEvents(request);

                Assert.IsNotNull(events.Events);
                Assert.AreEqual(0, events.Events.Count());
                Assert.AreEqual("xxxxxxxxxx", events.Destination);
            }
        public async Task GetEvents_InvalidRequest_ReplyTokenReturnsNull()
        {
            ILineBot bot = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Invalid);

            IEnumerable<ILineEvent> events = await bot.GetEvents(request);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.IsNull(lineEvent.ReplyToken);
        }
        public async Task GetEvents_InvalidRequest_BeaconIsNull()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(InvalidJson);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.IsNull(lineEvent.Beacon);
        }
        public async Task GetEvents_InvalidMessageType_MessageTypeIsUnknown()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Messages.Invalid);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.IsNotNull(lineEvent.Message);
            Assert.AreEqual(MessageType.Unknown, lineEvent.Message.MessageType);
        }
        public async Task GetEvents_RequestWithoutBeacon_BeaconIsNull()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(BeaconEventWithoutBeaconJson);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Beacon, lineEvent.EventType);
            Assert.IsNull(lineEvent.Beacon);
        }
        public async Task GetEvents_RequestWithoutPostback_PostbackIsNull()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.WithoutPostback);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Postback, lineEvent.EventType);
            Assert.IsNull(lineEvent.Postback);
        }
Beispiel #14
0
            public async Task ShouldLogRequest()
            {
                var logger  = new TestLogger();
                var bot     = TestConfiguration.CreateBot(logger);
                var request = new TestHttpRequest(JsonDocuments.Events.Webhook);

                await bot.GetEvents(request);

                var actual = Encoding.UTF8.GetString(logger.LogReceivedEventsEventsData);

                var bytes = await File.ReadAllBytesAsync(JsonDocuments.Events.Webhook);

                var expected = Encoding.UTF8.GetString(bytes).Substring(1); // Skip preamable.

                Assert.AreEqual(expected, actual);
            }
Beispiel #15
0
        public async Task GetEvents_ValidRequest_IsUnfollowEvent()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Unfollow);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Unfollow, lineEvent.EventType);

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.User, source.SourceType);
            Assert.AreEqual("U206d25c2ea6bd87c17655609a1c37cb8", source.User.Id);
        }
Beispiel #16
0
        public async Task GetEvents_ValidRequest_IsLeaveEvent()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(LeaveEventJson);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Leave, lineEvent.EventType);

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.Group, source.SourceType);
            Assert.AreEqual("cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", source.Group.Id);
        }
Beispiel #17
0
        public async Task GetEvents_ValidRequest_ReturnsFollowEvent()
        {
            ILineBot        bot     = TestConfiguration.CreateBot();
            TestHttpRequest request = new TestHttpRequest(JsonDocuments.Events.Join);

            IEnumerable <ILineEvent> events = await bot.GetEvents(request);

            Assert.IsNotNull(events);
            Assert.AreEqual(1, events.Count());

            ILineEvent lineEvent = events.First();

            Assert.AreEqual(LineEventType.Join, lineEvent.EventType);

            IEventSource source = lineEvent.Source;

            Assert.IsNotNull(source);
            Assert.AreEqual(EventSourceType.Group, source.SourceType);
            Assert.AreEqual("cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", source.Group.Id);

            Assert.AreEqual("nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", lineEvent.ReplyToken);
        }