示例#1
0
        public void DynamicTest()
        {
            var d = Json.Parse <IDictionary <string, object> >("{\"apples\":1, \"pears\":2, \"bananas\":3}");

            Assert.AreEquivalent(d.Keys, new string[] { "apples", "pears", "bananas" });
            Assert.AreEquivalent(d.Values, new object[] { 1UL, 2UL, 3UL });
        }
示例#2
0
        public async Task ReadAsync_RoundTripsBytes_Generic()
        {
            const string tableName = "BytesType";

            ResetDatabase(tableName);

            var store = new MobileServiceSQLiteStore(TestDbName);

            store.DefineTable <BytesType>();

            var hijack = new TestHttpHandler();
            IMobileServiceClient service = await CreateClient(hijack, store);

            IMobileServiceSyncTable <BytesType> table = service.GetSyncTable <BytesType>();

            byte[] theData = { 0, 128, 255 };

            BytesType inserted = new BytesType {
                Data = theData
            };

            await table.InsertAsync(inserted);

            Assert.AreEquivalent(inserted.Data, theData);

            BytesType rehydrated = await table.LookupAsync(inserted.Id);

            Assert.AreEquivalent(rehydrated.Data, theData);
        }
示例#3
0
        public async Task ReadAsync_RoundTripsBytes()
        {
            const string tableName = "bytes_test_table";

            ResetDatabase(tableName);

            var store = new MobileServiceSQLiteStore(TestDbName);

            store.DefineTable(tableName, new JObject {
                { "id", String.Empty },
                { "data", new byte[0] }
            });

            var hijack = new TestHttpHandler();
            IMobileServiceClient service = await CreateClient(hijack, store);

            IMobileServiceSyncTable table = service.GetSyncTable(tableName);

            byte[] theData = { 0, 128, 255 };

            JObject inserted = await table.InsertAsync(new JObject { { "data", theData } });

            Assert.AreEquivalent(theData, inserted["data"].Value <byte[]>());

            JObject rehydrated = await table.LookupAsync(inserted["id"].Value <string>());

            Assert.AreEquivalent(theData, rehydrated["data"].Value <byte[]>());
        }
        public void Test()
        {
            #if CSharp8
            Span <int> span;
            //new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8}
            int[] array = Enumerable.Range(0, 9).ToArray();

            span = array[Range.Create(4, new Index(2, true))];
            Assert.AreEquivalent(new int[] { 4, 5, 6 }, span);

            span = array[4..^ 2]; // Range.Create(4, new Index(2, true))
        public void TestGenericList()
        {
            var l = new List <int>()
            {
                10, 20, 30
            };

            var json = Json.Format(l);

            var l2 = Json.Parse <IList <int> >(json);

            Assert.IsInstanceOf(typeof(List <int>), l2);

            Assert.AreEquivalent(l, l2);
        }
        public void TestGenericDictionary()
        {
            var l = new Dictionary <string, int>()
            {
                { "A", 10 },
                { "B", 20 },
                { "C", 30 }
            };

            var json = Json.Format(l);

            var l2 = Json.Parse <IDictionary <string, int> >(json);

            Assert.IsInstanceOf(typeof(Dictionary <string, int>), l2);

            Assert.AreEquivalent(l, l2);
        }
示例#7
0
        /// <summary>
        /// Verify GetFields values for a given type.
        /// </summary>
        /// <typeparam name="T">The type to check.</typeparam>
        /// <param name="inherited">
        /// Whether to include inherited fields.
        /// </param>
        /// <param name="publicOnly">
        /// Whether to include anything other than public fields.
        /// </param>
        /// <param name="expectedProperties">
        /// List of expected fields.
        /// </param>
        private static void VerifyFields <T>(bool inherited, bool publicOnly, params string[] expectedFields)
        {
            List <string> actual =
                typeof(T)
                .GetFields(inherited, publicOnly)
                .Select(p => p.Name)
                .OrderBy(n => n)
                .ToList();
            List <string> expected = expectedFields.OrderBy(n => n).ToList();

            Assert.AreEquivalent(
                expected,
                actual,
                string.Format(
                    "Expected->Actual: {0}",
                    string.Join(", ",
                                Enumerable.Zip(expected, actual, (e, a) => e + "->" + a))));
        }
示例#8
0
        public void GetBaseTypesAndSelf()
        {
            Assert.AreEquivalent(
                typeof(object).GetBaseTypesAndSelf().ToList(),
                new List <TypeInfo> {
                typeof(object).GetTypeInfo()
            });

            Assert.AreEquivalent(
                typeof(TestClassA).GetBaseTypesAndSelf().ToList(),
                new List <TypeInfo> {
                typeof(object).GetTypeInfo(),
                typeof(TestClassA).GetTypeInfo()
            });

            Assert.AreEquivalent(
                typeof(TestClassB).GetBaseTypesAndSelf().ToList(),
                new List <TypeInfo> {
                typeof(object).GetTypeInfo(),
                typeof(TestClassA).GetTypeInfo(),
                typeof(TestClassB).GetTypeInfo()
            });
        }
示例#9
0
        private async Task CreateTypedApiTest(Random seedGenerator, TypedTestType testType)
        {
            Log("### Typed overload - {0}", testType);

            var client  = GetClient();
            var apiName = MovieFinderApiName;

            for (int i = 0; i < 10; i++)
            {
                int seed = seedGenerator.Next();
                Log("Test with seed = {0}", seed);
                Random rndGen = new Random(seed);

                Movie[]   expectedResult = null;
                AllMovies actualResult   = null;
                Movie     inputTemplate;

                // TODO: BUG #2132434: .NET runtime should allow URI's that end with a dot
                while (true)
                {
                    inputTemplate = QueryTestData.TestMovies()[rndGen.Next(QueryTestData.TestMovies().Length)];
                    if (testType == TypedTestType.GetByTitle && inputTemplate.Title.EndsWith("."))
                    {
                        // The .NET backend barfs and returns 404 if the URI ends with a dot, so let's get another movie
                        continue;
                    }

                    if (testType == TypedTestType.GetByTitle && inputTemplate.Title.EndsWith("?"))
                    {
                        // The .NET & Node backend do not return anything if the URI ends with a '?' so let's get another movie
                        continue;
                    }
                    break;
                }

                Log("Using movie '{0}' as template", inputTemplate.Title);
                string apiUrl;
                switch (testType)
                {
                case TypedTestType.GetByTitle:
                    apiUrl         = apiName + "/title/" + inputTemplate.Title;
                    expectedResult = new Movie[] { inputTemplate };
                    actualResult   = await client.InvokeApiAsync <AllMovies>(apiUrl, HttpMethod.Get, null);

                    break;

                case TypedTestType.GetByDate:
                    var releaseDate = inputTemplate.ReleaseDate;
                    apiUrl         = apiName + "/date/" + releaseDate.Year + "/" + releaseDate.Month + "/" + releaseDate.Day;
                    expectedResult = QueryTestData.TestMovies().Where(m => m.ReleaseDate == releaseDate).ToArray();
                    actualResult   = await client.InvokeApiAsync <AllMovies>(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 <Movie, 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 <Movie, AllMovies>(apiUrl, inputTemplate);
                    }
                    else
                    {
                        actualResult = await client.InvokeApiAsync <Movie, AllMovies>(apiUrl, inputTemplate, HttpMethod.Post, queryParams);
                    }

                    expectedResult = QueryTestData.TestMovies().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);
                }

                Log("  - Sent request to {0}", apiUrl);
                List <string> errors = new List <string>();
                Assert.AreEquivalent(expectedResult, actualResult.Movies);
            }
        }