Example #1
0
        public void PersonInstantiation()
        {
            var options = new PersonOptions();

            SetPersonOptions(options);
            var person = new Person("-1", "-1", options);

            AssertPerson(person, options);
            AssertPerson(person, person.GetOptions());
        }
Example #2
0
        static int PersonAction(PersonOptions opt)
        {
            ParserResult <object> parserResult = CommandLineParser.ParseArguments <PersonLSOptions, PersonAddOptions>(opt.Options);

            parserResult
            .WithParsed <PersonLSOptions>(opt => DisplayPersons(opt))
            .WithParsed <PersonAddOptions>(opt => AddPerson(opt))
            .WithNotParsed(err => DisplayHelp(parserResult, "person"));

            return(0);
        }
        public void PersonOptions_should_be_registered_as_option_with_correct_values()
        {
            var personOptionsConfigurer = ServiceProvider.GetService <IConfigureOptions <PersonOptions> >();
            var personOptions           = new PersonOptions();

            personOptionsConfigurer.Configure(personOptions);

            personOptions.FullName.ShouldBe("Bitchiko Tchelidze");
            personOptions.Age.ShouldBe(22);
            personOptions.AddressOptions.ShouldNotBeNull();
            personOptions.AddressOptions.City.ShouldBe("Tbilisi");
            personOptions.AddressOptions.Country.ShouldBe("Georgia");
        }
Example #4
0
 static void AssertPerson(Person person, PersonOptions options)
 {
     AssertContainer(person, options);
     Assert.AreEqual(person.Language, options.Language);
 }
Example #5
0
 static void SetPersonOptions(PersonOptions options)
 {
     SetContainerOptions(options);
     options.Language = "41";
 }
Example #6
0
        /// <summary>
        /// Updates an existing contact from the sevDesk API.
        /// </summary>
        /// <param name="id">The ID of the contact.</param>
        /// <param name="options">The options that contain the information about the contact.</param>
        /// <exception cref="InvalidOperationException">If the API could not be reached or the token is not valid, an <see cref="InvalidOperationException" /> is thrown.</exception>
        /// <returns>Returns the updated contact.</returns>
        public async Task <Contact> UpdateContactAsync(string id, ContactOptions options)
        {
            try
            {
                // Initializes the key value pairs
                List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >();
                if (!string.IsNullOrWhiteSpace(options.CustomerNumber))
                {
                    values.Add(new KeyValuePair <string, string>("customerNumber", options.CustomerNumber));
                }
                if (!string.IsNullOrWhiteSpace(options.Description))
                {
                    values.Add(new KeyValuePair <string, string>("description", options.Description));
                }
                if (!string.IsNullOrWhiteSpace(options.CategoryId))
                {
                    values.Add(new KeyValuePair <string, string>("category[id]", options.CategoryId));
                    values.Add(new KeyValuePair <string, string>("category[objectName]", "Category"));
                }

                // Adds the specific properties of a person
                PersonOptions personOptions = options as PersonOptions;
                if (personOptions != null)
                {
                    if (!string.IsNullOrWhiteSpace(personOptions.FirstName))
                    {
                        values.Add(new KeyValuePair <string, string>("surename", personOptions.FirstName));
                    }
                    if (!string.IsNullOrWhiteSpace(personOptions.LastName))
                    {
                        values.Add(new KeyValuePair <string, string>("familyname", personOptions.LastName));
                    }
                    if (!string.IsNullOrWhiteSpace(personOptions.AcademicTitle))
                    {
                        values.Add(new KeyValuePair <string, string>("academicTitle", personOptions.AcademicTitle));
                    }
                    if (!string.IsNullOrWhiteSpace(personOptions.Position))
                    {
                        values.Add(new KeyValuePair <string, string>("titel", personOptions.Position));
                    }
                    if (personOptions.Birthday != null)
                    {
                        values.Add(new KeyValuePair <string, string>("birthday", personOptions.Birthday?.ToString("yyyy-MM-ddT00:00:00")));
                    }
                    values.Add(new KeyValuePair <string, string>("gender", personOptions.Gender == Gender.Male ? "m" : "w"));
                    if (!string.IsNullOrWhiteSpace(personOptions.OrganizationId))
                    {
                        values.Add(new KeyValuePair <string, string>("parent[id]", personOptions.OrganizationId));
                        values.Add(new KeyValuePair <string, string>("parent[objectName]", "Contact"));
                    }
                }

                // Adds the specific properties of an organization
                OrganizationOptions organizationOptions = options as OrganizationOptions;
                if (organizationOptions != null)
                {
                    if (!string.IsNullOrWhiteSpace(organizationOptions.Name))
                    {
                        values.Add(new KeyValuePair <string, string>("name", organizationOptions.Name));
                    }
                }

                // Sends an HTTP request to endpoint
                HttpResponseMessage response = await httpClient.PutAsync($"{this.apiUri}/Contact/{id}?token={this.Token}", new FormUrlEncodedContent(values));

                // Returns the updated contact
                return(this.GetContact(JsonConvert.DeserializeObject <Result <Models.Contacts.Contact> >(await response.Content.ReadAsStringAsync()).objects));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }