Esempio n. 1
0
        public async Task should_call_expected_url_and_return_expected_groups()
        {
            // given
            const string slackKey = "I-is-another-key";

            var expectedResponse = new GroupsResponse
            {
                Groups = new[]
                {
                    new Group {
                        IsGroup = true, Name = "name1"
                    },
                    new Group {
                        IsOpen = true, Name = "name2"
                    }
                }
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _channelClient.GetGroups(slackKey);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.GROUPS_LIST_PATH))
            .WithQueryParamValue("token", slackKey)
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse.Groups);
        }
Esempio n. 2
0
        public async Task should_call_expected_url_with_given_slack_key()
        {
            // given
            const string slackKey = "something-that-looks-like-a-slack-key";
            const string channel  = "channel-name";
            const string text     = "some-text-for-you";

            var expectedResponse = new StandardResponse();

            _httpTest.RespondWithJson(expectedResponse);

            // when
            await _chatClient.PostMessage(slackKey, channel, text, null);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)));
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("channel", channel)
            .WithQueryParamValue("text", text)
            .WithQueryParamValue("as_user", "true")
            .WithoutQueryParam("attachments")
            .Times(1);
        }
Esempio n. 3
0
        public async Task should_call_expected_url_and_return_expected_channels()
        {
            // given
            const string slackKey = "I-is-da-key-yeah";

            var expectedResponse = new ChannelsResponse
            {
                Channels = new[]
                {
                    new Channel {
                        IsChannel = true, Name = "name1"
                    },
                    new Channel {
                        IsArchived = true, Name = "name2"
                    },
                }
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _channelClient.GetChannels(slackKey);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.CHANNELS_LIST_PATH))
            .WithQueryParamValue("token", slackKey)
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse.Channels);
        }
Esempio n. 4
0
        public async Task should_call_expected_url_with_given_slack_key()
        {
            // given
            const string slackKey = "something-that-looks-like-a-slack-key";
            const string channel  = "channel-name";
            const string text     = "some-text-for-you";

            var expectedResponse = new DefaultStandardResponse();

            _httpTest.RespondWithJson(expectedResponse);

            // when
            await _chatClient.PostMessage(slackKey, channel, text, null);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)));
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH))
            .WithRequestUrlEncoded(new
            {
                token      = slackKey,
                channel    = channel,
                text       = text,
                as_user    = "******",
                link_names = "true"
            })
            .Times(1);
        }
Esempio n. 5
0
        public async Task should_join_direct_message_channel()
        {
            // given
            const string slackKey = "I-is-another-key";
            const string userId   = "blahdy-blah";

            var expectedResponse = new JoinChannelResponse
            {
                Channel = new Channel
                {
                    Id        = "some-channel",
                    IsChannel = true
                }
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _channelClient.JoinDirectMessageChannel(slackKey, userId);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.JOIN_DM_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("user", userId)
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse.Channel);
        }
Esempio n. 6
0
        public async Task should_call_expected_url_with_given_slack_key()
        {
            // given
            const string slackKey = "I-is-da-key-yeah";

            var expectedResponse = new HandshakeResponse
            {
                Ok           = true,
                WebSocketUrl = "some-url"
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _handshakeClient.FirmShake(slackKey);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)));
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlHandshakeClient.HANDSHAKE_PATH))
            .WithQueryParamValue("token", slackKey)
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse);
        }
Esempio n. 7
0
        public async Task should_create_channel()
        {
            // given
            const string slackKey    = "I-is-another-key";
            const string channelName = "my-channel";

            var expectedResponse = new ChannelResponse()
            {
                Channel = new Channel
                {
                    Id        = "some-channel",
                    IsChannel = true
                }
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _channelClient.CreateChannel(slackKey, channelName);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.CHANNEL_CREATE_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("name", channelName)
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse.Channel);
        }
Esempio n. 8
0
        public async Task should_set_channel_topic()
        {
            // given
            const string slackKey     = "I-is-another-key";
            const string channelName  = "my-channel";
            const string channelTopic = "my topic";

            var expectedResponse = new TopicResponse()
            {
                Topic = channelTopic
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _channelClient.SetTopic(slackKey, channelName, channelTopic);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.CHANNEL_SET_TOPIC_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("channel", channelName)
            .WithQueryParamValue("topic", channelTopic)
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse.Topic);
        }
Esempio n. 9
0
        public async Task should_call_expected_url_and_return_expected_users()
        {
            // given
            const string slackKey = "I-is-another-key";

            var expectedResponse = new UsersResponse
            {
                Members = new[]
                {
                    new User {
                        Id = "some-id-thing", IsBot = true
                    },
                    new User {
                        Name = "some-id-thing", Deleted = true
                    },
                }
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            var result = await _channelClient.GetUsers(slackKey);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.USERS_LIST_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("presence", "1")
            .Times(1);

            result.ToExpectedObject().ShouldEqual(expectedResponse.Members);
        }
Esempio n. 10
0
        public void moq_will_not_match_on_a_strongly_typed_partial_object_that_differs()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 1, Name = "Test"
            });

            Assert.Throws <MockException>(() => mock.Verify(s => s.DoStuff(Looks.Like(() => new TestObject {
                ID = 2
            }))));
        }
Esempio n. 11
0
        public void moq_will_match_on_an_equivalent_object()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 1, Name = "Test"
            });

            Assert.DoesNotThrow(() => mock.Verify(s => s.DoStuff(Looks.Like(new TestObject {
                ID = 1, Name = "Test"
            }))));
        }
Esempio n. 12
0
        public void moq_will_not_match_on_a_nonequivalent_object()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 3, Name = "Name"
            });

            Assert.Throws <MockException>(() => mock.Verify(s => s.DoStuff(Looks.Like(new TestObject {
                ID = 1, Name = "Not Name"
            }))));
        }
Esempio n. 13
0
        public void then_it_will_not_match_on_a_strongly_typed_partial_object_with_a_partial_matcher_that_should_not_match()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 1, Name = "Test"
            });

            Assert.Throws <MockException>(() => mock.Verify(s => s.DoStuff(Looks.Like(() => new TestObject {
                ID = Some.ValueOf <int>(x => x == 2)
            }))));
        }
Esempio n. 14
0
        public void moq_will_match_on_a_strongly_typed_partial_object()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 1, Name = "Test"
            });

            Assert.DoesNotThrow(() => mock.Verify(s => s.DoStuff(Looks.Like(() => new TestObject {
                ID = 1, Name = "Test"
            }))));
        }
Esempio n. 15
0
        public void then_it_will_match_on_a_strongly_typed_partial_object_with_a_matching_expression()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 1, Name = "Test"
            });

            Assert.DoesNotThrow(() => mock.Verify(s => s.DoStuff(Looks.Like(() => new TestObject {
                ID = Some.ValueOf <int>(x => x == 1)
            }))));
        }
Esempio n. 16
0
 public void then_it_publishes_an_event()
 {
     GetMockFor <IPublisher>()
     .Verify(p => p.Publish(Looks.Like(new InvoiceSubmittedEvent
     {
         BillingName    = _invoice.BillingName,
         BillingAddress = _invoice.BillingAddress,
         BillingCity    = _invoice.BillingCity,
         BillingZip     = _invoice.BillingZip,
         Amount         = _invoice.Amount,
         Description    = _invoice.Description
     })));
 }
Esempio n. 17
0
            public void then_it_verifies_correctly_if_the_object_matches_the_specified_properties()
            {
                var myCar = new TrainCar {
                    Name = "Simple Car", MaxPassengers = 100, YearBuilt = 2014
                };

                GetMockFor <ITrainYard>().Object
                .StoreCar(myCar);

                GetMockFor <ITrainYard>()
                .Verify(x => x.StoreCar(Looks.Like(() => new TrainCar {
                    YearBuilt = 2014
                })));
            }
Esempio n. 18
0
            public void then_it_verifies_correctly_if_the_matcher_is_satisfied()
            {
                GetMockFor <ITrainYard>().Object
                .RetrieveLuggage(new LuggageTicket
                {
                    IssuedTo = "Jane Doe",
                    Issued   = DateTime.Now,
                });

                GetMockFor <ITrainYard>()
                .Verify(x => x.RetrieveLuggage(Looks.Like(() => new LuggageTicket
                {
                    IssuedTo = "Jane Doe",
                    Issued   = Some.ValueOf <DateTime>(d => DateTime.Now.Subtract(d) < TimeSpan.FromSeconds(1))
                })));
            }
Esempio n. 19
0
        public async Task should_call_expected_url_with_given_slack_key()
        {
            // given
            const string slackKey = "something-that-looks-like-a-slack-key";
            const string channel  = "channel-name";
            const string filePath = @"C:\test-file-name.exe";

            var expectedResponse = new StandardResponse();

            _httpTest.RespondWithJson(expectedResponse);

            // when
            await _fileClient.PostFile(slackKey, channel, filePath);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)));
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlFileClient.FILE_UPLOAD_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("channels", channel)
            .WithVerb(HttpMethod.Post)
            .WithContentType("multipart/form-data")
            .Times(1);
        }
Esempio n. 20
0
        public async Task should_archive_channel()
        {
            // given
            const string slackKey    = "I-is-another-key";
            const string channelName = "my-channel";

            var expectedResponse = new DefaultStandardResponse()
            {
                Ok = true
            };

            _httpTest.RespondWithJson(expectedResponse);

            // when
            await _channelClient.ArchiveChannel(slackKey, channelName);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)), Times.Once);
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChannelClient.CHANNEL_ARCHIVE_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("channel", channelName)
            .Times(1);
        }
Esempio n. 21
0
        public void then_it_will_not_match_on_a_strongly_typed_partial_object_with_a_partial_matcher_that_should_not_match()
        {
            var mock = GetMockFor <ITestService>();

            mock.Object.DoStuff(new TestObject {
                ID = 1, Name = "Test"
            });

            //TODO: The error message here sucks.  Something in Moq's internals is blowing up when the expression doesn't match.
            Assert.Throws <InvalidOperationException>(() => mock.Verify(s => s.DoStuff(Looks.Like(() => new TestObject {
                ID = Some.ValueOf <int>(x => x == 2)
            }))));
        }