예제 #1
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #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);
            }
예제 #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());
        }
예제 #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());
        }
예제 #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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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);
        }
예제 #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);
            }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }