Next Post >>
<< Previous Post



Posted by Michael Horvath under Technology  Test Automation  .Net Web API  on Sep 02 2022

You may have already downloaded our nuget package and want some additional assistance in getting started using HSS_API_Store_SDK. Below you will find a unit test code snippet that demonstrates calls to the methods provided in our nuget package. Be sure to scroll through the entire post there is more after the following code.

 
using HSS_API_Store_SDK;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Configuration;
using System.Threading.Tasks;
using static HSS_API_Store_SDK.apiResponsePasswords;
using static HSS_API_Store_SDK.apiResponseFoods;
using static HSS_API_Store_SDK.apiResponsePeople;

namespace HSS_API_Store_SDK_UnitTests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public async Task TestMethod1()
        {
            var apiResponse = await Passwords.GetPasswordsAsync(ConfigurationManager.AppSettings.Get("HSS_API_Store_EmailAddress"), 
                ConfigurationManager.AppSettings.Get("HSS_API_Store_PasswordsKey"), 10, 20, 8, "", true, RequiredSymbols.Digits);

            Assert.IsNotNull(apiResponse);
            Assert.IsNotNull(apiResponse.passwordValues);
            Assert.AreEqual(ResponseEnumPasswords.Success, apiResponse.responseStatus);
            Assert.AreEqual(9, apiResponse.passwordValues.GetUpperBound(0));

            foreach(var password in apiResponse.passwordValues)
            {
                Console.WriteLine(password);
            }
        }

        [TestMethod]
        public async Task TestMethod2()
        {
            var apiResponse = await Passwords.GetPasswordsAsync(ConfigurationManager.AppSettings.Get("HSS_API_Store_EmailAddress"), 
                ConfigurationManager.AppSettings.Get("HSS_API_Store_PasswordsKey"), PasswordCharacterSelection: RequiredSymbols.Digits);

            Assert.IsNotNull(apiResponse);
            Assert.IsNotNull(apiResponse.passwordValues);
            Assert.AreEqual(ResponseEnumPasswords.Success, apiResponse.responseStatus);
            Assert.AreEqual(0, apiResponse.passwordValues.GetUpperBound(0));

            foreach (var password in apiResponse.passwordValues)
            {
                Console.WriteLine(password);
            }
        }

        [TestMethod]
        public async Task TestMethod3()
        {
            var apiResponse = await Foods.GetFoodsAsync(ConfigurationManager.AppSettings.Get("HSS_API_Store_EmailAddress"), 
                ConfigurationManager.AppSettings.Get("HSS_API_Store_FoodsKey"));

            Assert.IsNotNull(apiResponse);
            Assert.IsNotNull(apiResponse.foodsList);
            Assert.AreEqual(ResponseEnumFoods.Success, apiResponse.responseStatus);
            Assert.AreEqual(0, apiResponse.foodsList.ToArray().GetUpperBound(0));

            foreach (var food in apiResponse.foodsList)
            {
                Console.WriteLine(food.foodInformation.Name);
            }
        }

        [TestMethod]
        public async Task TestMethod4()
        {
            var apiResponse = await Foods.GetFoodsAsync(ConfigurationManager.AppSettings.Get("HSS_API_Store_EmailAddress"),
                ConfigurationManager.AppSettings.Get("HSS_API_Store_FoodsKey"), 20, "goat's milk");

            Assert.IsNotNull(apiResponse);
            Assert.IsNotNull(apiResponse.foodsList);
            Assert.AreEqual(ResponseEnumFoods.Success, apiResponse.responseStatus);
            Assert.AreEqual(19, apiResponse.foodsList.ToArray().GetUpperBound(0));

            foreach (var food in apiResponse.foodsList)
            {
                Console.WriteLine(food.foodInformation.BrandName + " " + food.foodInformation.Name + " " + food.foodInformation.HouseholdServing);
                Console.WriteLine(food.foodInformation.Ingredients);
                Console.WriteLine(" ");
            }
        }

        [TestMethod]
        public async Task TestMethod5()
        {
            var apiResponse = await People.GetPeopleAsync(ConfigurationManager.AppSettings.Get("HSS_API_Store_EmailAddress"), 
                ConfigurationManager.AppSettings.Get("HSS_API_Store_PeopleKey"), 5, StateSelection: StateIDEnum.AR);

            Assert.IsNotNull(apiResponse);
            Assert.IsNotNull(apiResponse.peopleList);
            Assert.AreEqual(ResponseEnumPeople.Success, apiResponse.responseStatus);
            Assert.AreEqual(4, apiResponse.peopleList.ToArray().GetUpperBound(0));

            foreach (var person in apiResponse.peopleList)
            {
                Console.WriteLine(person.Prefix + " " + person.FirstName + " " + person.LastName);
                Console.WriteLine(person.AddressLine1);
                if (person.AddressLine2 != null && person.AddressLine2 != "")
                    Console.WriteLine(person.AddressLine2);
                Console.WriteLine(person.City + ", " + person.StateID + " " + person.ZipCode);
                Console.WriteLine(person.PhoneNumber.FormatPhoneNumber());
                Console.WriteLine(" ");
            }
        }
    }
}



You will need to setup an app.config file in your project if you want to build this unit test code to define the AppSettings used in the code. Below is a sample app.config with placeholders in curly braces for your email and API keys. You can change these to the values you received when you requested API keys from our API Store.



  
    
    
    
    
  
  
    
      
        
        
      
    
  



Thank you for downloading our SDK and for reading our post!

Tagged --no tags--
share the love!



comments

there are no comments for this post. be the first to post one!


post your comment

name (*) - required
email address (*) - required
site address
your comment (*) - required

(*) - required


Next Post >>
<< Previous Post