Пример #1
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);
            }
        }
Пример #2
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);
        }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
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));
        }
Пример #7
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);
            }
        }