Ejemplo n.º 1
0
        private static ZumoTestGroup CreateGroupWithAllTests(List <ZumoTestGroup> testGroups, bool unattendedOnly)
        {
            ZumoTestGroup result = new ZumoTestGroup(unattendedOnly ? AllTestsUnattendedGroupName : AllTestsGroupName);

            foreach (var group in testGroups)
            {
                result.AddTest(ZumoTestCommon.CreateSeparator("Start of group: " + group.Name));
                foreach (var test in group.AllTests)
                {
                    if (test.CanRunUnattended || !unattendedOnly)
                    {
                        result.AddTest(test);
                    }
                }

                result.AddTest(ZumoTestCommon.CreateSeparator("------------------"));
            }

            return(result);
        }
Ejemplo n.º 2
0
        internal static ZumoTestGroup CreateTests()
        {
            ZumoTestGroup result = new ZumoTestGroup("Query tests");

            result.AddTest(new ZumoTest("Populate table, if necessary", new TestExecution(async delegate(ZumoTest test)
            {
                var client          = ZumoTestGlobals.Instance.Client;
                var table           = client.GetTable <AllMovies>();
                AllMovies allMovies = new AllMovies
                {
                    Movies = ZumoQueryTestData.AllMovies
                };
                await table.InsertAsync(allMovies);
                test.AddLog("Result of populating table: {0}", allMovies.Status);
                return(true);
            })));

            // Numeric fields
            result.AddTest(CreateQueryTest("GreaterThan and LessThan - Movies from the 90s", m => m.Year > 1989 && m.Year < 2000));
            result.AddTest(CreateQueryTest("GreaterEqual and LessEqual - Movies from the 90s", m => m.Year >= 1990 && m.Year <= 1999));
            result.AddTest(CreateQueryTest("Compound statement - OR of ANDs - Movies from the 30s and 50s",
                                           m => ((m.Year >= 1930) && (m.Year < 1940)) || ((m.Year >= 1950) && (m.Year < 1960))));
            result.AddTest(CreateQueryTest("Division, equal and different - Movies from the year 2000 with rating other than R",
                                           m => ((m.Year / 1000.0) == 2) && (m.MPAARating != "R")));
            result.AddTest(CreateQueryTest("Addition, subtraction, relational, AND - Movies from the 1980s which last less than 2 hours",
                                           m => ((m.Year - 1900) >= 80) && (m.Year + 10 < 2000) && (m.Duration < 120)));

            // String functions
            result.AddTest(CreateQueryTest("String: StartsWith - Movies which starts with 'The'",
                                           m => m.Title.StartsWith("The"), 100));
            result.AddTest(CreateQueryTest("String: StartsWith, case insensitive - Movies which start with 'the'",
                                           m => m.Title.ToLower().StartsWith("the"), 100));
            result.AddTest(CreateQueryTest("String: EndsWith, case insensitive - Movies which end with 'r'",
                                           m => m.Title.ToLower().EndsWith("r")));
            result.AddTest(CreateQueryTest("String: Contains - Movies which contain the word 'one', case insensitive",
                                           m => m.Title.ToUpper().Contains("ONE")));
            result.AddTest(CreateQueryTest("String: Length - Movies with small names",
                                           m => m.Title.Length < 10, 200));
            result.AddTest(CreateQueryTest("String: Substring (1 parameter), length - Movies which end with 'r'",
                                           m => m.Title.Substring(m.Title.Length - 1) == "r"));
            result.AddTest(CreateQueryTest("String: Substring (2 parameters), length - Movies which end with 'r'",
                                           m => m.Title.Substring(m.Title.Length - 1, 1) == "r"));
            result.AddTest(CreateQueryTest("String: Replace - Movies ending with either 'Part 2' or 'Part II'",
                                           m => m.Title.Replace("II", "2").EndsWith("Part 2")));
            result.AddTest(CreateQueryTest("String: Concat - Movies rated 'PG' or 'PG-13' from the 2000s",
                                           m => m.Year >= 2000 && string.Concat(m.MPAARating, "-13").StartsWith("PG-13")));

            // String fields
            result.AddTest(CreateQueryTest("String equals - Movies since 1980 with rating PG-13",
                                           m => m.Year >= 1980 && m.MPAARating == "PG-13", 100));
            result.AddTest(CreateQueryTest("String field, comparison to null - Movies since 1980 without a MPAA rating",
                                           m => m.Year >= 1980 && m.MPAARating == null));
            result.AddTest(CreateQueryTest("String field, comparison (not equal) to null - Movies before 1970 with a MPAA rating",
                                           m => m.Year < 1970 && m.MPAARating != null));

            // Numeric functions
            result.AddTest(CreateQueryTest("Floor - Movies which last more than 3 hours",
                                           m => Math.Floor(m.Duration / 60.0) >= 3));
            result.AddTest(CreateQueryTest("Ceiling - Best picture winners which last at most 2 hours",
                                           m => m.BestPictureWinner == true && Math.Ceiling(m.Duration / 60.0) == 2));
            result.AddTest(CreateQueryTest("Round - Best picture winners which last more than 2.5 hours",
                                           m => m.BestPictureWinner == true && Math.Round(m.Duration / 60.0) > 2));

            // Date fields
            result.AddTest(CreateQueryTest("Date: Greater than, less than - Movies with release date in the 70s",
                                           m => m.ReleaseDate > new DateTime(1969, 12, 31, 0, 0, 0, DateTimeKind.Utc) &&
                                           m.ReleaseDate < new DateTime(1971, 1, 1, 0, 0, 0, DateTimeKind.Utc)));
            result.AddTest(CreateQueryTest("Date: Greater than, less than - Movies with release date in the 80s",
                                           m => m.ReleaseDate >= new DateTime(1980, 1, 1, 0, 0, 0, DateTimeKind.Utc) &&
                                           m.ReleaseDate < new DateTime(1989, 12, 31, 23, 59, 59, DateTimeKind.Utc)));
            result.AddTest(CreateQueryTest("Date: Equal - Movies released on 1994-10-14 (Shawshank Redemption / Pulp Fiction)",
                                           m => m.ReleaseDate == new DateTime(1994, 10, 14, 0, 0, 0, DateTimeKind.Utc)));

            // Date functions
            result.AddTest(CreateQueryTest("Date (month): Movies released in November",
                                           m => m.ReleaseDate.Month == 11));
            result.AddTest(CreateQueryTest("Date (day): Movies released in the first day of the month",
                                           m => m.ReleaseDate.Day == 1));
            result.AddTest(CreateQueryTest("Date (year): Movies whose year is different than its release year",
                                           m => m.ReleaseDate.Year != m.Year, 100));

            // Bool fields
            result.AddTest(CreateQueryTest("Bool: equal to true - Best picture winners before 1950",
                                           m => m.Year < 1950 && m.BestPictureWinner == true));
            result.AddTest(CreateQueryTest("Bool: equal to false - Best picture winners after 2000",
                                           m => m.Year >= 2000 && !(m.BestPictureWinner == false)));
            result.AddTest(CreateQueryTest("Bool: not equal to false - Best picture winners after 2000",
                                           m => m.BestPictureWinner != false && m.Year >= 2000));

            // Top and skip
            result.AddTest(CreateQueryTest("Get all using large $top - 500", null, 500));
            result.AddTest(CreateQueryTest("Skip all using large skip - 500", null, null, 500));
            result.AddTest(CreateQueryTest("Skip, take, includeTotalCount - movies 11-20, ordered by title",
                                           null, 10, 10, new[] { new OrderByClause("Title", true) }, null, true));
            result.AddTest(CreateQueryTest("Skip, take, filter includeTotalCount - movies 11-20 which won a best picture award, ordered by year",
                                           m => m.BestPictureWinner == true, 10, 10, new[] { new OrderByClause("Year", false) }, null, true));

            // Order by
            result.AddTest(CreateQueryTest("Order by date and string - 50 movies, ordered by release date, then title",
                                           null, 50, null, new[] { new OrderByClause("ReleaseDate", false), new OrderByClause("Title", true) }));
            result.AddTest(CreateQueryTest("Order by number - 30 shortest movies since 1970",
                                           m => m.Year >= 1970, 30, null, new[] { new OrderByClause("Duration", true), new OrderByClause("Title", true) }, null, true));

            // Select
            result.AddTest(CreateQueryTest("Select one field - Only title of movies from 2008",
                                           m => m.Year == 2008, null, null, null, m => m.Title));
            result.AddTest(CreateQueryTest("Select multiple fields - Nicely formatted list of movies from the 2000's",
                                           m => m.Year >= 2000, 200, null, new[] { new OrderByClause("ReleaseDate", false), new OrderByClause("Title", true) },
                                           m => string.Format("{0} {1} - {2} minutes", m.Title.PadRight(30), m.BestPictureWinner ? "(best picture)" : "", m.Duration)));

            // Negative tests
            result.AddTest(CreateQueryTest <MobileServiceInvalidOperationException>("(Neg) Very large top value", m => m.Year > 2000, 1001));
            result.AddTest(CreateQueryTest <NotSupportedException>("(Neg) Unsupported predicate: unsupported arithmetic",
                                                                   m => Math.Sqrt(m.Year) > 43));

            // Invalid lookup
            for (int i = -1; i <= 0; i++)
            {
                int id = i;
                result.AddTest(new ZumoTest("(Neg) Invalid id for lookup: " + i, async delegate(ZumoTest test)
                {
                    var table = ZumoTestGlobals.Instance.Client.GetTable <Movie>();
                    try
                    {
                        var item = await table.LookupAsync(id);
                        test.AddLog("Error, LookupAsync for id = {0} should have failed, but succeeded: {1}", id, item);
                        return(false);
                    }
                    catch (MobileServiceInvalidOperationException ex)
                    {
                        test.AddLog("Caught expected exception - {0}: {1}", ex.GetType().FullName, ex.Message);
                        return(true);
                    }
                }));
            }

            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("The next test will show a dialog with certain movies. Please validate that movie titles and release years are shown correctly in the list."));
            result.AddTest(new ZumoTest("ToCollectionView - displaying movies on a ListBox", async delegate(ZumoTest test)
            {
                var client = ZumoTestGlobals.Instance.Client;
                var table  = client.GetTable <Movie>();
                var query  = from m in table
                             where m.Year > 1980
                             orderby m.ReleaseDate descending
                             select new
                {
                    Date  = m.ReleaseDate.ToUniversalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
                    Title = m.Title
                };
                var newPage = new MoviesDisplayPage();
                newPage.SetMoviesSource(query.ToCollectionView());
                await newPage.Display();
                return(true);
            }));
            result.AddTest(ZumoTestCommon.CreateYesNoTest("Were the movies displayed correctly?", true));

            return(result);
        }
Ejemplo n.º 3
0
        public static ZumoTestGroup CreateTests()
        {
            ZumoTestGroup result = new ZumoTestGroup("Login tests");

            result.AddTest(CreateLogoutTest());
            result.AddTest(CreateCRUDTest(TablePublicPermission, null, TablePermission.Public, false));
            result.AddTest(CreateCRUDTest(TableApplicationPermission, null, TablePermission.Application, false));
            result.AddTest(CreateCRUDTest(TableUserPermission, null, TablePermission.User, false));
            result.AddTest(CreateCRUDTest(TableAdminPermission, null, TablePermission.Admin, false));

            int indexOfTestsWithAuthentication = result.AllTests.Count();

            Dictionary <MobileServiceAuthenticationProvider, bool> providersWithRecycledTokenSupport;

            providersWithRecycledTokenSupport = new Dictionary <MobileServiceAuthenticationProvider, bool>
            {
                { MobileServiceAuthenticationProvider.Facebook, true },
                { MobileServiceAuthenticationProvider.Google, false },   // Known bug - Drop login via Google token until Google client flow is reintroduced
                { MobileServiceAuthenticationProvider.MicrosoftAccount, false },
                { MobileServiceAuthenticationProvider.Twitter, false },
                { MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, false }
            };

#if !WINDOWS_PHONE
            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("In the next few tests you will be prompted for username / password five times."));
#endif

            foreach (MobileServiceAuthenticationProvider provider in Util.EnumGetValues(typeof(MobileServiceAuthenticationProvider)))
            {
                result.AddTest(CreateLogoutTest());
#if !WINDOWS_PHONE
                result.AddTest(CreateLoginTest(provider, false));
#else
                result.AddTest(CreateLoginTest(provider));
#endif
                result.AddTest(CreateCRUDTest(TableApplicationPermission, provider.ToString(), TablePermission.Application, true));
                result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, true));
                result.AddTest(CreateCRUDTest(TableAdminPermission, provider.ToString(), TablePermission.Admin, true));

                bool supportsTokenRecycling;
                if (providersWithRecycledTokenSupport.TryGetValue(provider, out supportsTokenRecycling) && supportsTokenRecycling)
                {
                    result.AddTest(CreateLogoutTest());
                    result.AddTest(CreateClientSideLoginTest(provider));
                    result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, userIsAuthenticated: true, usingSingleSignOnOrToken: true));
                }
            }

#if !WINDOWS_PHONE
            result.AddTest(ZumoTestCommon.CreateYesNoTest("Were you prompted for username / password five times?", true));
#endif

            result.AddTest(CreateLogoutTest());

#if WINDOWS_PHONE && !WP75
            result.AddTest(ZumoTestCommon.CreateInputTest("Enter Live App Client ID", testPropertyBag, ClientIdKeyName));
#endif

#if !WP75
            result.AddTest(CreateLiveSDKLoginTest());
            result.AddTest(CreateCRUDTest(TableUserPermission, MicrosoftViaLiveSDK, TablePermission.User, true));
#endif

#if !WINDOWS_PHONE
            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("We'll log in again; you may or may not be asked for password in the next few moments."));
            foreach (MobileServiceAuthenticationProvider provider in Enum.GetValues(typeof(MobileServiceAuthenticationProvider)))
            {
                if (provider == MobileServiceAuthenticationProvider.MicrosoftAccount)
                {
                    // Known issue - SSO with MS account will not work if Live SDK is also used
                    continue;
                }

                result.AddTest(CreateLogoutTest());
                result.AddTest(CreateLoginTest(provider, true));
                result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, userIsAuthenticated: true, usingSingleSignOnOrToken: true));
            }

            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("Now we'll continue running the tests, but you *should not be prompted for the username or password anymore*."));
            foreach (MobileServiceAuthenticationProvider provider in Enum.GetValues(typeof(MobileServiceAuthenticationProvider)))
            {
                if (provider == MobileServiceAuthenticationProvider.MicrosoftAccount)
                {
                    // Known issue - SSO with MS account will not work if Live SDK is also used
                    continue;
                }

                result.AddTest(CreateLogoutTest());
                result.AddTest(CreateLoginTest(provider, true));
                result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, userIsAuthenticated: true, usingSingleSignOnOrToken: true));
            }

            result.AddTest(ZumoTestCommon.CreateYesNoTest("Were you prompted for the username in any of the providers?", false));
#endif

            foreach (var test in result.AllTests.Skip(indexOfTestsWithAuthentication))
            {
                test.CanRunUnattended = false;
            }

            // Clean-up any logged in user
            result.AddTest(CreateLogoutTest());

            return(result);
        }
        public static ZumoTestGroup CreateTests()
        {
            ZumoTestGroup result = new ZumoTestGroup("Login tests");

            result.AddTest(CreateLogoutTest());
            result.AddTest(CreateCRUDTest(TablePublicPermission, null, TablePermission.Public, false));
            result.AddTest(CreateCRUDTest(TableApplicationPermission, null, TablePermission.Application, false));
            result.AddTest(CreateCRUDTest(TableUserPermission, null, TablePermission.User, false));
            result.AddTest(CreateCRUDTest(TableAdminPermission, null, TablePermission.Admin, false));

            Dictionary <MobileServiceAuthenticationProvider, bool> providersWithRecycledTokenSupport;

            providersWithRecycledTokenSupport = new Dictionary <MobileServiceAuthenticationProvider, bool>
            {
                { MobileServiceAuthenticationProvider.Facebook, true },
                { MobileServiceAuthenticationProvider.Google, true },
                { MobileServiceAuthenticationProvider.MicrosoftAccount, false },
                { MobileServiceAuthenticationProvider.Twitter, false },
            };

#if !WINDOWS_PHONE
            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("In the next few tests you will be prompted for username / password four times."));
#endif

            foreach (MobileServiceAuthenticationProvider provider in Util.EnumGetValues(typeof(MobileServiceAuthenticationProvider)))
            {
                result.AddTest(CreateLogoutTest());
#if !WINDOWS_PHONE
                result.AddTest(CreateLoginTest(provider, false));
#else
                result.AddTest(CreateLoginTest(provider));
#endif
                result.AddTest(CreateCRUDTest(TableApplicationPermission, provider.ToString(), TablePermission.Application, true));
                result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, true));
                result.AddTest(CreateCRUDTest(TableAdminPermission, provider.ToString(), TablePermission.Admin, true));

                bool supportsTokenRecycling;
                if (providersWithRecycledTokenSupport.TryGetValue(provider, out supportsTokenRecycling) && supportsTokenRecycling)
                {
                    result.AddTest(CreateLogoutTest());
                    result.AddTest(CreateClientSideLoginTest(provider));
                    result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, true));
                }
            }

#if !WINDOWS_PHONE
            result.AddTest(ZumoTestCommon.CreateYesNoTest("Were you prompted for username / password four times?", true));
#endif

            result.AddTest(CreateLogoutTest());

#if WINDOWS_PHONE && !WP75
            result.AddTest(ZumoTestCommon.CreateInputTest("Enter Live App Client ID", testPropertyBag, ClientIdKeyName));
#endif

#if !WP75
            result.AddTest(CreateLiveSDKLoginTest());
            result.AddTest(CreateCRUDTest(TableUserPermission, "Microsoft via Live SDK", TablePermission.User, true));
#endif

#if !WINDOWS_PHONE
            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("We'll log in again; you may or may not be asked for password in the next few moments."));
            foreach (MobileServiceAuthenticationProvider provider in Enum.GetValues(typeof(MobileServiceAuthenticationProvider)))
            {
                if (provider == MobileServiceAuthenticationProvider.MicrosoftAccount)
                {
                    // Known issue - SSO with MS account will not work if Live SDK is also used
                    continue;
                }

                result.AddTest(CreateLogoutTest());
                result.AddTest(CreateLoginTest(provider, true));
                result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, true));
            }

            result.AddTest(ZumoTestCommon.CreateTestWithSingleAlert("Now we'll continue running the tests, but you *should not be prompted for the username or password anymore*."));
            foreach (MobileServiceAuthenticationProvider provider in Enum.GetValues(typeof(MobileServiceAuthenticationProvider)))
            {
                if (provider == MobileServiceAuthenticationProvider.MicrosoftAccount)
                {
                    // Known issue - SSO with MS account will not work if Live SDK is also used
                    continue;
                }

                result.AddTest(CreateLogoutTest());
                result.AddTest(CreateLoginTest(provider, true));
                result.AddTest(CreateCRUDTest(TableUserPermission, provider.ToString(), TablePermission.User, true));
            }

            result.AddTest(ZumoTestCommon.CreateYesNoTest("Were you prompted for the username in any of the providers?", false));
#endif

            return(result);
        }