Exemple #1
0
        public async Task GetPerson_ThrowsException()
        {
            PersonRepositoryMock.Setup(x => x.GetById(It.IsAny <int>()))
            .Throws(new InvalidOperationException());

            var result = await PersonServiceClient.GetPerson("1");
        }
Exemple #2
0
        public async Task GetPerson_ReturnsCorrectResult()
        {
            PersonRepositoryMock.Setup(x => x.GetById(It.IsAny <int>()))
            .Returns(_person);

            var response = await PersonServiceClient.GetPerson("1");

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual("Mocked LN1", response.Result.LastName);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            PersonServiceClient client=new PersonServiceClient();
            Person nullPerson = client.GetPerson(0);
            Person person = client.GetPerson(1);

            Console.WriteLine(nullPerson == null ? "Person object is null" : nullPerson.Name);

            Console.WriteLine(person.Name);

            try
            {
                Console.WriteLine(nullPerson.Name);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception"+exception.Message);
            }

            Console.ReadLine();
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            PersonServiceClient client    = new PersonServiceClient();
            PersonDTO           personDto = client.GetPerson(textBox1.Text);

            if (personDto != null)
            {
                button1.Text = personDto.Firstname;
            }
            else
            {
                button1.Text = "not found";
            }
            button1.Enabled = true;
        }
        public Person GetPerson(string NIN)
        {
            PersonServiceClient client = new PersonServiceClient();

            client.ClientCredentials.UserName.UserName = "******";
            client.ClientCredentials.UserName.Password = "******";

            LookupParameters lookupParameter = new LookupParameters();

            lookupParameter.NIN = NIN;

            var person = client.GetPerson(lookupParameter);

            client.Close();

            return(person);
        }
        public HttpResponseMessage Get(String id)
        {
            //Connect to person service
            PersonServiceClient client = new PersonServiceClient();

            client.ClientCredentials.UserName.UserName = "******";
            client.ClientCredentials.UserName.Password = "******";

            //Add id to lookupparameters and fetch data
            LookupParameters lookupParameters = new LookupParameters();

            lookupParameters.NIN = id;
            Person xml = client.GetPerson(lookupParameters);

            client.Close();

            //serialize Person data to string
            var stringwriter = new System.IO.StringWriter();
            var serializer   = new XmlSerializer(xml.GetType());

            serializer.Serialize(stringwriter, xml);

            //convert from xml to json
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(stringwriter.ToString());

            var json = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented, false);

            //return json
            var res = Request.CreateResponse(HttpStatusCode.OK);

            res.Content = new StringContent(json, Encoding.UTF8, "application/json");

            return(res);
        }
 public Person GetPerson(string lastName)
 {
     return(proxy.GetPerson(lastName));
 }
 public Person GetItem(string key)
 {
     return(proxy.GetPerson(key));
 }