Example #1
0
        public async Task QueryEntitySetClientTestWithSelect()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.Format.UseJson();

                var accounts = client.Accounts.Where(a => a.Id <= 2).Select(a => new TypedProxy.Account() { Id = a.Id, Name = a.Name });
                List<TypedProxy.Account> accountList = accounts.ToList();

                Assert.Equal(2, accountList.Count);
                Assert.Equal(1, accountList[0].Id);

                Assert.Null(accountList[0].OwnerAlias);
                Assert.Equal(0, accountList[0].ShipAddresses.Count);
            }
        }
Example #2
0
        public async Task QueryEntityClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.Format.UseJson();

                var account = client.Accounts.Where(a => a.Id == 1).Single();

                Assert.Equal(1, account.Id);
                Assert.Equal("US", account.Address.Country);
                Assert.Equal(10, account.AccountInfo.Age);

                Assert.Equal(WebStack.QA.Test.OData.OpenType.Typed.Client.Gender.Male, account.AccountInfo.Gender);

                Assert.Equal("Value 1", account.Tags.Tag1);
                Assert.Equal("Value 2", account.Tags.Tag2);

                Assert.Equal(TypedProxy.Gender.Female, account.OwnerGender);
                Assert.Equal("jinfutan", account.OwnerAlias);
                Assert.Equal(true, account.IsValid);
                Assert.Equal(2, account.ShipAddresses.Count);
            }
        }
Example #3
0
        // PUT ~/Employees(1)/Namespace.Manager
        public async Task ReplaceDerivedEntityType()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/convention/");
            var client = new TypedProxy.Container(serviceUrl);
            client.MergeOption = MergeOption.OverwriteChanges;
            client.Format.UseJson();

            var employees = client.Employees.OfType<TypedProxy.Manager>().ToList();
            var manager = employees.Where(m => m.Id == 2).Single();

            manager.Level = 3;
            manager.Gender = TypedProxy.Gender.Male;
            manager.PhoneNumbers = new List<string>() { "8621-9999-8888", "2345", "4567" };
            client.UpdateObject(manager);
            client.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);

            var managers = client.Employees.OfType<TypedProxy.Manager>().ToList();
            var updatedManager = managers.Where(m => m.Id == 2).Single();

            expectedValueOfNullableInt = 3;
            actualValueOfNullableInt = updatedManager.Level;
            Assert.True(expectedValueOfNullableInt == actualValueOfNullableInt,
                string.Format("Manager Level is in-correct, expected: {0}, actual: {1}", expectedValueOfNullableInt, actualValueOfNullableInt));
            TypedProxy.Gender? gender = manager.Gender;
            Assert.Equal(TypedProxy.Gender.Male, gender);

            actualValueOfInt = manager.PhoneNumbers.Count();
            expectedValueOfInt = 3;
            Assert.True(expectedValueOfInt == actualValueOfInt,
                string.Format("Manager PhoneNumbers count is in-correct, expected: {0}, actual: {1}", expectedValueOfInt, actualValueOfInt));
        }
Example #4
0
        // PATCH ~/Employees(1)/Namespace.Manager
        public async Task UpdateDerivedEntityType()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/AttributeRouting/");
            var client = new TypedProxy.Container(serviceUrl);
            client.MergeOption = MergeOption.OverwriteChanges;
            client.Format.UseJson();

            var manager = client.Employees.OfType<TypedProxy.Manager>().Where(m => m.Id == 2).Single();
            manager.Gender = null;
            manager.PhoneNumbers = new List<string>() { "8621-9999-8888", "2345", "4567", "5678" };
            client.UpdateObject(manager);
            client.SaveChanges();

            var updatedManager = client.Employees.OfType<TypedProxy.Manager>().Where(m => m.Id == 2).Single();

            expectedValueOfNullableInt = 1;
            actualValueOfNullableInt = updatedManager.Level;
            Assert.True(expectedValueOfNullableInt == actualValueOfNullableInt,
                string.Format("The manager's Level should not be changed, expected: {0}, actual: {1}", expectedValueOfNullableInt, actualValueOfNullableInt));
            TypedProxy.Gender? gender = manager.Gender;
            Assert.True(manager.Gender == null,
                string.Format("The manager's gender is updated to null, but actually it is {0})", manager.Gender));

            actualValueOfInt = manager.PhoneNumbers.Count();
            expectedValueOfInt = 4;
            Assert.True(expectedValueOfInt == actualValueOfInt,
                string.Format("Manager PhoneNumbers count is in-correct, expected: {0}, actual: {1}", expectedValueOfInt, actualValueOfInt));
        }
Example #5
0
        public async Task PutEntityWithOpenComplexTypeClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);

                client.MergeOption = Microsoft.OData.Client.MergeOption.OverwriteChanges;
                client.Format.UseJson();

                var account = client.Accounts.Where(a => a.Id == 1).Single();
                Assert.NotNull(account);

                account.AccountInfo.NickName = "NewNickName";
                account.AccountInfo.Age = 11;

                account.AccountInfo.Gender = WebStack.QA.Test.OData.OpenType.Typed.Client.Gender.Male;

                account.AccountInfo.Subs = new Collection<string>() { "1", "2", "3" };

                account.Address.Country = "United States";
                account.Tags.Tag1 = "New Value";

                account.OwnerAlias = "saxu";
                account.ShipAddresses = new List<TypedProxy.Address>();
                account.OwnerGender = TypedProxy.Gender.Male;
                account.Emails = new List<string>() { "*****@*****.**", "*****@*****.**" };
                account.LuckyNumbers = new List<int>() { 4 };

                client.UpdateObject(account);
                client.SaveChanges(Microsoft.OData.Client.SaveChangesOptions.ReplaceOnUpdate);

                var updatedAccount = client.Accounts.Where(a => a.Id == 1).Single();
                Assert.NotNull(updatedAccount);

                var updatedAccountInfo = updatedAccount.AccountInfo;
                Assert.NotNull(updatedAccountInfo);
                Assert.Equal("NewNickName", updatedAccountInfo.NickName);
                Assert.Equal(11, updatedAccountInfo.Age);
                Assert.Equal(3, updatedAccountInfo.Subs.Count);

                // Defect 2371564 odata.type is missed in client payload for dynamic enum type
                //Assert.Equal(WebStack.QA.Test.OData.OpenType.Typed.Client.Gender.Male, updatedAccountInfo.Gender);

                var updatedAddress = updatedAccount.Address;
                Assert.NotNull(updatedAddress);
                Assert.Equal("United States", updatedAddress.Country);

                Assert.Equal("New Value", updatedAccount.Tags.Tag1);

                Assert.Equal("saxu", updatedAccount.OwnerAlias);
                Assert.Equal(0, updatedAccount.ShipAddresses.Count);
                Assert.Equal(1, updatedAccount.LuckyNumbers.Count);
                Assert.Equal(2, updatedAccount.Emails.Count);
                Assert.NotNull(updatedAccount.Emails.SingleOrDefault(e => e == "*****@*****.**"));
                // Defect 2371564 odata.type is missed in client payload for dynamic enum type
                //Assert.Equal(WebStack.QA.Test.OData.OpenType.Typed.Client.Gender.Male, updatedAccountInfo.Gender);
                //Assert.Equal(TypedProxy.Gender.Male, updatedAccount.OwnerGender);
            }
        }
Example #6
0
        public async Task GetAddressFunctionClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.MergeOption = MergeOption.OverwriteChanges;

                client.Format.UseJson();

                var address = client.Accounts.Where(a => a.Id == 1).Single().GetAddressFunction().GetValue();

                Assert.Equal("Redmond", address.City);
                Assert.Equal("US", address.Country);
            }
        }
Example #7
0
        public async Task QueryDerivedEntityType()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/convention/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            var employees = client.Employees.OfType<TypedProxy.Manager>().ToList();

            int expectedInt = 1;
            int actualInt = employees.Count();

            Assert.True(expectedInt == actualInt,
                string.Format("Manager count is in-correct, expected: {0}, actual: {1}", expectedInt, actualInt));

            TypedProxy.Manager manager = employees.Single(e => e.Id == 2);
            expectedValueOfNullableInt = 1;
            actualValueOfNullableInt = manager.Level;
            Assert.True(expectedValueOfNullableInt == actualValueOfNullableInt,
                string.Format("Manager Level is in-correct, expected: {0}, actual: {1}", expectedValueOfNullableInt, actualValueOfNullableInt));
            TypedProxy.Gender? gender = manager.Gender;
            Assert.Equal(TypedProxy.Gender.Male, gender);
            expectedValueOfInt = 2;
            actualValueOfInt = manager.PhoneNumbers.Count();
            Assert.True(expectedValueOfInt == actualValueOfInt,
                string.Format("Manager count is in-correct, expected: {0}, actual: {1}", expectedValueOfInt, actualValueOfInt));
        }
Example #8
0
        public async Task QueryOpenComplexTypePropertyTagsClientTest()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/AttributeRouting/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            var tags = client.Accounts.Where(a => a.Id == 1).Select(a => a.Tags).Single();

            Assert.Equal("Value 1", tags.Tag1);
            Assert.Equal("Value 2", tags.Tag2);
        }
Example #9
0
        public async Task UpdateAddressActionClientTest()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/AttributeRouting/"));
            var client = new TypedProxy.Container(serviceUrl);
            client.MergeOption = MergeOption.OverwriteChanges;

            TypedProxy.Address address = new TypedProxy.Address()
            {
                City = "New City",
                Street = "New Street",
                Country = "New Country"
            };
            client.UpdateAddressAction(address, 1).GetValue();

            var account = client.Accounts.Where(a => a.Id == 1).Single();
            Assert.Equal("New City", account.Address.City);
            Assert.Equal("New Country", account.Address.Country);
        }
Example #10
0
        public async Task QueryBaseEntityType()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/AttributeRouting/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            var employees = client.Employees.ToList();

            int expectedInt = 2;
            int actualInt = employees.Count();

            Assert.True(expectedInt == actualInt,
                string.Format("Employee count is in-correct, expected: {0}, actual: {1}", expectedInt, actualInt));
        }
Example #11
0
        public async Task AddShipAddressActionClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.MergeOption = MergeOption.OverwriteChanges;

                client.Format.UseJson();

                TypedProxy.Address shipAddress = new TypedProxy.Address()
                {
                    City = "Hang zhou",
                    Street = "Anything",
                };
                int shipAddressCount = client.Accounts.Where(a => a.Id == 1).Single().AddShipAddress(shipAddress).GetValue();

                Assert.Equal(3, shipAddressCount);
                shipAddressCount = client.Accounts.Where(a => a.Id == 1).Single().AddShipAddress(shipAddress).GetValue();

                Assert.Equal(4, shipAddressCount);
            }
        }
Example #12
0
        public async Task IncreaseAgeActionClientTest2()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.MergeOption = MergeOption.OverwriteChanges;

                client.Format.UseJson();

                client.Accounts.Where(a => a.Id == 1).Single().IncreaseAgeAction().GetValue();

                var account = client.Accounts.Where(a => a.Id == 1).Single();
                Assert.Equal(11, account.AccountInfo.Age);
            }
        }
Example #13
0
        public async Task GetShipAddressesFunctionClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.MergeOption = MergeOption.OverwriteChanges;

                client.Format.UseJson();

                IEnumerable<TypedProxy.Address> addresses = client.Accounts.Where(a => a.Id == 1).Single().GetShipAddresses();

                Assert.Equal(2, addresses.Count());
            }
        }
Example #14
0
        public async Task QueryDerivedEntityClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);
                client.Format.UseJson();

                var premiumAcconts = client.Accounts.OfType<TypedProxy.PremiumAccount>().ToList();
                var premiumAccount = premiumAcconts.Single(pa => pa.Id == 1);
                Assert.Equal(1, premiumAccount.Id);
                Assert.Equal("US", premiumAccount.Address.Country);
                Assert.Equal(10, premiumAccount.AccountInfo.Age);

                Assert.Equal(WebStack.QA.Test.OData.OpenType.Typed.Client.Gender.Male, premiumAccount.AccountInfo.Gender);

                Assert.Equal("Value 1", premiumAccount.Tags.Tag1);
                Assert.Equal("Value 2", premiumAccount.Tags.Tag2);

                Assert.Equal(TypedProxy.Gender.Female, premiumAccount.OwnerGender);
                Assert.Equal("jinfutan", premiumAccount.OwnerAlias);
                Assert.Equal(true, premiumAccount.IsValid);
                Assert.Equal(2, premiumAccount.ShipAddresses.Count);
                Assert.Equal(new DateTimeOffset(new DateTime(2014, 5, 22), TimeSpan.FromHours(8)), premiumAccount.Since);
            }
        }
Example #15
0
        public async Task ExpandOpenEntityType()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/AttributeRouting/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            var employees = client.Employees.Expand("Account").ToList();

            expectedValueOfInt = 2;
            actualValueOfInt = employees.Count();

            Assert.True(expectedValueOfInt == actualValueOfInt,
                string.Format("Employee count is in-correct, expected: {0}, actual: {1}", expectedValueOfInt, actualValueOfInt));

            TypedProxy.Account account = employees.Single(e => e.Id == 1).Account;
            Assert.Equal(TypedProxy.Gender.Female, account.OwnerGender);
            Assert.Equal("jinfutan", account.OwnerAlias);
            Assert.Equal(true, account.IsValid);
            Assert.Equal(2, account.ShipAddresses.Count);
        }
Example #16
0
        public async Task QueryOpenComplexTypePropertyAccountInfoClientTest()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/convention/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            var accountInfo = client.Accounts.Where(a => a.Id == 1).Select(a => a.AccountInfo).Single();

            Assert.Equal("NickName1", accountInfo.NickName);
            Assert.Equal(10, accountInfo.Age);
        }
Example #17
0
        public async Task InsertBaseEntity()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/AttributeRouting/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();
            string newName = "Name10";
            TypedProxy.Employee newEmployee = new TypedProxy.Employee() { Id = 0, Name = newName };
            client.AddToEmployees(newEmployee);
            client.SaveChanges();

            var insertedEmplyee = client.Employees.Where(e => e.Id >= 3).Single();
            expectedValueOfString = newName;
            actualValueOfString = insertedEmplyee.Name;

            Assert.True(expectedValueOfString == actualValueOfString,
               string.Format("Employee count is in-correct, expected: {0}, actual: {1}", expectedValueOfString, actualValueOfString));
        }
Example #18
0
        public async Task QueryNonDynamicPropertyClientTest()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/AttributeRouting/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            var city = client.Accounts.Where(a => a.Id == 1).Select(a => a.Address.City).Single();

            Assert.Equal("Redmond", city);
        }
Example #19
0
        public async Task InsertDerivedEntityType()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/convention/");
            var client = new TypedProxy.Container(serviceUrl);
            client.Format.UseJson();

            TypedProxy.Manager manager = new TypedProxy.Manager { Id = 0, Heads = 1 };
            manager.Level = 2;
            manager.Gender = TypedProxy.Gender.Male;
            manager.PhoneNumbers = new List<string>() { "8621-9999-8888" };
            client.AddToEmployees(manager);
            client.SaveChanges();

            var employees = client.Employees.OfType<TypedProxy.Manager>().ToList();
            var insertedManager = employees.Where(m => m.Id == 3).Single();

            expectedValueOfNullableInt = 2;
            actualValueOfNullableInt = insertedManager.Level;
            Assert.True(expectedValueOfNullableInt == actualValueOfNullableInt,
                string.Format("Manager Level is in-correct, expected: {0}, actual: {1}", expectedValueOfNullableInt, actualValueOfNullableInt));
            TypedProxy.Gender? gender = manager.Gender;
            Assert.Equal(TypedProxy.Gender.Male, gender);
            expectedValueOfInt = 1;
            actualValueOfInt = manager.PhoneNumbers.Count();
            Assert.True(expectedValueOfInt == actualValueOfInt,
                string.Format("Manager PhoneNumbers count is in-correct, expected: {0}, actual: {1}", expectedValueOfInt, actualValueOfInt));
        }
Example #20
0
        public async Task InsertDerivedEntityWithOpenComplexTypePropertyClientTest()
        {
            await ResetDatasource();

            Uri serviceUrl = new Uri(this.BaseAddress + "/convention/");
            var client = new TypedProxy.Container(serviceUrl);

            client.Format.UseJson();

            TypedProxy.PremiumAccount newAccount = new TypedProxy.PremiumAccount()
            {
                Id = 4,
                Name = "Name4",
                AccountInfo = new TypedProxy.AccountInfo
                {
                    NickName = "NickName4",
                    Age = 40,
                    Gender = TypedProxy.Gender.Female,
                },
                Address = new TypedProxy.Address
                {
                    City = "Paris",
                    Street = "1 Microsoft Way",
                    Country = "France",
                },
                Tags = new TypedProxy.Tags
                {
                    Tag1 = "value 1",
                    Tag2 = "value 2"
                },
                OwnerAlias = "saxu",
                ShipAddresses = new List<TypedProxy.Address>()
                {
                    new  TypedProxy.Address
                    {
                        City = "Jinan",
                        Street = "Danling Street"
                    },
                    new  TypedProxy.Address
                    {
                        City="Nanjing",
                        Street="Zixing",
                    },
                
                },
                OwnerGender = TypedProxy.Gender.Male,
                Emails = new List<string>() { "*****@*****.**", "*****@*****.**" },
                LuckyNumbers = new List<int>() { 1, 2, 3 },
                Since = new DateTimeOffset(2014, 05, 23, 0, 0, 0, TimeSpan.FromHours(8)),
            };
            client.AddToAccounts(newAccount);
            client.SaveChanges();

            TypedProxy.PremiumAccount insertedAccount = client.Accounts.Where(a => a.Id == 4).Single() as TypedProxy.PremiumAccount;
            Assert.NotNull(insertedAccount);
            Assert.Equal("NickName4", insertedAccount.AccountInfo.NickName);
            Assert.Equal(40, insertedAccount.AccountInfo.Age);

            // Defect 2371564 odata.type is missed in client payload for dynamic enum type
            //Assert.Equal(WebStack.QA.Test.OData.OpenType.Typed.TypedProxy.Gender.Female, insertedAccount.AccountInfo.Gender);

            Assert.Equal("value 1", insertedAccount.Tags.Tag1);
            Assert.Equal("value 2", insertedAccount.Tags.Tag2);
            Assert.Equal("saxu", insertedAccount.OwnerAlias);
            Assert.Equal(2, insertedAccount.ShipAddresses.Count);
            Assert.Equal(2, insertedAccount.Emails.Count);
            Assert.Equal(TypedProxy.Gender.Male, insertedAccount.OwnerGender);
            Assert.Equal(new DateTimeOffset(2014, 05, 23, 0, 0, 0, TimeSpan.FromHours(8)), insertedAccount.Since);
        }
Example #21
0
        public async Task DeleteEntityWithOpenComplexTypePropertyClientTest()
        {
            foreach (string routing in Routings)
            {
                await ResetDatasource();

                Uri serviceUrl = new Uri(string.Format(this.BaseAddress + "/{0}/", routing));
                var client = new TypedProxy.Container(serviceUrl);

                var accountToDelete = client.Accounts.Where(a => a.Id == 1).Single();
                client.DeleteObject(accountToDelete);
                client.SaveChanges();

                var accounts = client.Accounts.ToList();
                Assert.Equal(2, accounts.Count);

                var queryDeletedAccount = accounts.Where(a => a.Id == 1).ToList();
                Assert.Equal(0, queryDeletedAccount.Count);
            }
        }