Example #1
0
            public async Task WillFindMatches(string filename)
            {
                IIqdbClient  api = GetIqdbClient();
                SearchResult result;

                using (var fs = new FileStream(filename, FileMode.Open))
                {
                    result = await api.SearchFile(fs);
                }

                Assert.NotNull(result);
                Assert.True(result.IsFound);

                Assert.NotNull(result.Matches);
                Assert.True(result.Matches.Count(match => match.MatchType == MatchType.Other) > 0);
                Assert.True(result.Matches.Count(match => match.MatchType == MatchType.Additional) > 1);
                Assert.True(result.Matches.Count(match => match.MatchType == MatchType.Best) == 1);

                AssertSearchStats(result);

                Assert.NotNull(result.YourImage);
                Assert.False(String.IsNullOrWhiteSpace(result.YourImage.Name));
                Assert.False(String.IsNullOrWhiteSpace(result.YourImage.PreviewUrl));

                foreach (var match in result.Matches)
                {
                    Assert.True(match.Similarity > 0);
                    Assert.NotEqual(default(Resolution), match.Resolution);

                    Assert.False(String.IsNullOrWhiteSpace(match.PreviewUrl));
                    Assert.False(String.IsNullOrWhiteSpace(match.Url));
                }
            }
Example #2
0
            public async Task WillThrowExceptions()
            {
                IIqdbClient api = GetIqdbClient();

                using (var fs = new FileStream("Resources/favicon.ico", FileMode.Open))
                {
                    await Assert.ThrowsAsync <InvalidFileFormatException>(() =>
                                                                          api.SearchFile(fs));
                }

                await Assert.ThrowsAsync <ArgumentNullException>(() => api.SearchFile(null));

                using (var fs = new FileStream("Resources/large.jpg", FileMode.Open))
                {
                    await Assert.ThrowsAsync <ImageTooLargeException>(() =>
                                                                      api.SearchFile(fs));
                }
            }
Example #3
0
 public IIqdbClient GetIqdbClient() => _api ?? (_api = new IqdbClient());