public async Task <AllStringIdMovies> PostMovie(AllStringIdMovies item)
        {
            var table = this.context.Movies;

            if (table.Count() == 0)
            {
                table.AddRange(item.Movies);
                await this.context.SaveChangesAsync();
            }
            return(item);
        }
Exemplo n.º 2
0
        internal static ZumoTest CreatePopulateStringIdTableTest()
        {
            return(new ZumoTest("Populate [string id] movies table, if necessary", new TestExecution(async delegate(ZumoTest test)
            {
                var client = ZumoTestGlobals.Instance.Client;
                var table = client.GetTable <AllStringIdMovies>();
                AllStringIdMovies allMovies = new AllStringIdMovies
                {
                    Movies = new StringIdMovie[ZumoQueryTestData.AllStringIdMovies().Length]
                };
                for (int i = 0; i < allMovies.Movies.Length; i++)
                {
                    allMovies.Movies[i] = new StringIdMovie(string.Format("Movie {0:000}", i), ZumoQueryTestData.AllMovies[i]);
                }
                await table.InsertAsync(allMovies);

                for (int i = 0; i < 20; i++)
                {
                    var counter = await table.Take(0).IncludeTotalCount().ToListAsync();
                    var totalCount = ((ITotalCountProvider)counter).TotalCount;
                    if (totalCount == allMovies.Movies.Length)
                    {
                        test.AddLog("Result of populating [string id] table: {0}", allMovies.Status);
                        return true;
                    }
                    else
                    {
                        test.AddLog("Already inserted {0} items, waiting for insertion to complete", totalCount);
                        await Util.TaskDelay(5000);
                    }
                }

                test.AddLog("Result of populating [string id] table: Time out. Not populate enough data.");
                return false;
            }), ZumoTestGlobals.RuntimeFeatureNames.STRING_ID_TABLES));
        }
Exemplo n.º 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));
        }