示例#1
0
        public Task <MovieResult> fetchMoviesSameYear(StringIdMovie movie)
        {
            var orderBy = GetQueryValue("orderby", "Title");

            return(getMovie("Year", movie.Year, orderBy));
        }
示例#2
0
        public Task <MovieResult> fetchMoviesSameDuration(StringIdMovie movie)
        {
            var orderBy = GetQueryValue("orderby", "Title");

            return(getMovie("Duration", movie.Duration, orderBy));
        }
示例#3
0
        private static ZumoTest CreateTypedApiTest(Random seedGenerator, TypedTestType testType)
        {
            string testName = "Typed overload - " + testType;

            return(new ZumoTest(testName, async delegate(ZumoTest test)
            {
                var client = ZumoTestGlobals.Instance.Client;
                var apiName = MovieFinderApiName;
                var testResult = true;
                for (int i = 0; i < 10; i++)
                {
                    int seed = seedGenerator.Next();
                    test.AddLog("Test with seed = {0}", seed);
                    Random rndGen = new Random(seed);

                    StringIdMovie[] expectedResult = null;
                    AllStringIdMovies actualResult = null;
                    StringIdMovie inputTemplate = ZumoQueryTestData.AllStringIdMovies()[rndGen.Next(ZumoQueryTestData.AllStringIdMovies().Length)];
                    test.AddLog("Using movie '{0}' as template", inputTemplate.Title);
                    string apiUrl;
                    switch (testType)
                    {
                    case TypedTestType.GetByTitle:
                        apiUrl = apiName + "/title/" + inputTemplate.Title;
                        expectedResult = new StringIdMovie[] { inputTemplate };
                        actualResult = await client.InvokeApiAsync <AllStringIdMovies>(apiUrl, HttpMethod.Get, null);
                        break;

                    case TypedTestType.GetByDate:
                        var releaseDate = inputTemplate.ReleaseDate;
                        apiUrl = apiName + "/date/" + releaseDate.Year + "/" + releaseDate.Month + "/" + releaseDate.Day;
                        expectedResult = ZumoQueryTestData.AllStringIdMovies().Where(m => m.ReleaseDate == releaseDate).ToArray();
                        actualResult = await client.InvokeApiAsync <AllStringIdMovies>(apiUrl, HttpMethod.Get, null);
                        break;

                    case TypedTestType.PostByDuration:
                    case TypedTestType.PostByYear:
                        string orderBy = null;
                        switch (rndGen.Next(3))
                        {
                        case 0:
                            orderBy = null;
                            break;

                        case 1:
                            orderBy = "id";
                            break;

                        case 2:
                            orderBy = "Title";
                            break;
                        }

                        Dictionary <string, string> queryParams = orderBy == null ?
                                                                  null :
                                                                  new Dictionary <string, string> {
                            { "orderBy", orderBy }
                        };

                        Func <StringIdMovie, bool> predicate;
                        if (testType == TypedTestType.PostByYear)
                        {
                            predicate = m => m.Year == inputTemplate.Year;
                            apiUrl = apiName + "/moviesOnSameYear";
                        }
                        else
                        {
                            predicate = m => m.Duration == inputTemplate.Duration;
                            apiUrl = apiName + "/moviesWithSameDuration";
                        }

                        if (queryParams == null)
                        {
                            actualResult = await client.InvokeApiAsync <StringIdMovie, AllStringIdMovies>(apiUrl, inputTemplate);
                        }
                        else
                        {
                            actualResult = await client.InvokeApiAsync <StringIdMovie, AllStringIdMovies>(apiUrl, inputTemplate, HttpMethod.Post, queryParams);
                        }

                        expectedResult = ZumoQueryTestData.AllStringIdMovies().Where(predicate).ToArray();
                        if (orderBy == null || orderBy == "Title")
                        {
                            Array.Sort(expectedResult, (m1, m2) => m1.Title.CompareTo(m2.Title));
                        }

                        break;

                    default:
                        throw new ArgumentException("Invalid test type: " + testType);
                    }

                    test.AddLog("  - Sent request to {0}", apiUrl);
                    List <string> errors = new List <string>();
                    if (Util.CompareArrays(expectedResult, actualResult.Movies, errors))
                    {
                        test.AddLog("  - Result is expected");
                    }
                    else
                    {
                        foreach (var error in errors)
                        {
                            test.AddLog("  - {0}", error);
                        }

                        test.AddLog("Expected: {0}", string.Join(", ", expectedResult.Select(m => m.Title)));
                        test.AddLog("Actual: {0}", string.Join(", ", actualResult.Movies.Select(m => m.Title)));
                        testResult = false;
                        break;
                    }
                }

                return testResult;
            }, ZumoTestGlobals.RuntimeFeatureNames.STRING_ID_TABLES));
        }