public bool AdvancedFunction([FromODataUri] IEnumerable <int> numbers,
                                     [FromODataUri] IEnumerable <ConventionGender> genders,
                                     [FromODataUri] ConventionAddress address, [FromODataUri] IEnumerable <ConventionAddress> addresses,
                                     [FromODataUri] ConventionCustomer customer, [FromODataUri] IEnumerable <ConventionCustomer> customers)
        {
            Assert.Equal(new[] { 1, 2, 3 }, numbers);
            Assert.Equal(new[] { ConventionGender.Male, ConventionGender.Female }, genders);

            IEnumerable <ConventionAddress> newAddress = addresses.Concat(new[] { address });

            Assert.Equal(2, newAddress.Count());
            foreach (ConventionAddress addr in newAddress)
            {
                Assert.Equal("Zi Xin Rd.", addr.Street);
                Assert.Equal("Shanghai", addr.City);
                Assert.Equal("2001100", addr.ZipCode);
            }

            IEnumerable <ConventionCustomer> newCustomers = customers.Concat(new[] { customer });

            Assert.Equal(2, newCustomers.Count());
            foreach (ConventionCustomer cust in newCustomers)
            {
                Assert.Equal(7, cust.ID);
                Assert.Equal("Tony", cust.Name);
                Assert.Null(cust.Address);
            }

            return(true);
        }
        public ITestActionResult UpdateAddress([FromBody] ODataUntypedActionParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var    id                = (int)parameters["ID"];
            var    address           = parameters["Address"] as EdmComplexObject;
            var    conventionAddress = new ConventionAddress();
            object temp              = null;

            if (address.TryGetPropertyValue("Street", out temp))
            {
                conventionAddress.Street = temp.ToString();
            }
            if (address.TryGetPropertyValue("City", out temp))
            {
                conventionAddress.City = temp.ToString();
            }
            if (address.TryGetPropertyValue("ZipCode", out temp))
            {
                conventionAddress.ZipCode = temp.ToString();
            }
            ConventionCustomer customer = _customers.Where(c => c.ID == id).FirstOrDefault();

            customer.Address = conventionAddress;
            return(Ok(_customers));
        }
        public async Task FunctionImportInFilter()
        {
            // Arrange
            const int          CustomerId     = 407;
            ConventionCustomer expectCustomer = (new ConventionCustomersController().GetConventionCustomerById(CustomerId)); // expect customer instance

            Assert.NotNull(expectCustomer);

            // Make sure the function import can be called successfully by following root.
            var requestFunction = this.BaseAddress + "/odata/GetConventionCustomerNameByIdImport(CustomerId=" + CustomerId + ")";

            using (var httpResponseMessage = await Client.GetAsync(requestFunction))
            {
                string responseString = await httpResponseMessage.Content.ReadAsStringAsync();

                Assert.Contains("Name 7", responseString);
            }

            var requestInFilter = this.BaseAddress + "/odata/ConventionCustomers?$filter=GetConventionCustomerNameByIdImport(CustomerId=" + CustomerId + ") eq 'Name 7'";

            using (var response = await Client.GetAsync(requestInFilter))
            {
                Assert.Equal((HttpStatusCode)400, response.StatusCode);

                var json = await response.Content.ReadAsObject <JObject>();

                var          errorMessage = json["error"]["message"].ToString();
                const string expect       = "The query specified in the URI is not valid. An unknown function with name 'GetConventionCustomerNameByIdImport' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed.";
                Assert.Equal(expect, errorMessage);
            }
        }
示例#4
0
        public async Task FunctionImportFollowedByQueryOption(string functionImport)
        {
            // Arrange
            const int          CustomerId     = 401;
            ConventionCustomer expectCustomer = (new ConventionCustomersController()).GetConventionCustomerById(CustomerId); // expect customer instance

            Assert.NotNull(expectCustomer);

            // Act
            var requestUri = String.Format("{0}/odata/{1}?$filter=ID eq {2}", this.BaseAddress, functionImport, CustomerId);
            var response   = await Client.GetAsync(requestUri);

            var responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.True(response.IsSuccessStatusCode);
            string expect = "\"Name\":\"" + expectCustomer.Name + "\"";

            Assert.Contains(expect, responseString);
            Assert.DoesNotContain("402", responseString);
        }
        public ConventionOrder GetConventionOrderByCustomerIdAndOrderName(int CustomerId, [FromODataUri] string OrderName)
        {
            ConventionCustomer customer = _customers.Where(c => c.ID == CustomerId).FirstOrDefault();

            return(customer.Orders.Where(o => o.OrderName == OrderName).FirstOrDefault());
        }