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 IActionResult 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();
                Assert.Equal("Street 11", conventionAddress.Street);
            }
            if (address.TryGetPropertyValue("City", out temp))
            {
                conventionAddress.City = temp.ToString();
            }
            if (address.TryGetPropertyValue("ZipCode", out temp))
            {
                conventionAddress.ZipCode = temp.ToString();
            }

            // In real scenario, we should update the original data, but for test, let's create a new Database
            var customers = InitCustomers();
            ConventionCustomer customer = customers.Where(c => c.ID == id).FirstOrDefault();

            customer.Address = conventionAddress;
            return(Ok(customers));
        }
Esempio n. 3
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("odata/{0}?$filter=ID eq {1}", functionImport, CustomerId);
            HttpClient client     = CreateClient();
            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());
        }