public void GivenIHaveACompanyIWishToManage() { // Get the last company created, sorted by creation date IEnumerable <Company> items1 = new RestCall <List <Company> >(Method.GET, context.Get <string>("url"), context.Get <string>("companyResource")).Data(); Company latest = items1.Aggregate((i1, i2) => i1.id > i2.id ? i1 : i2); context["company"] = latest; Logger.Debug($"Managing Company: {latest.companyName} [id: {latest.id}]"); }
public void WhenUserAccessesProductsLabeledFresh() { var response = new RestCall <List <Product> >(Method.GET, context.Get <string>("url"), "/products") .Where("product_name like Fresh") .Execute(); response.IsSuccessful.Should().BeTrue(); context.Add("data", response.Data); }
public void WhenUserAccessesEmployee(string id) { var employee = new RestCall <Employee>(Method.GET, context.Get <string>("url"), "/employee/{id}") .AddUrlParameter("id", id) .Data(); context.Add("employee", employee); Logger.Debug($"Accessed employee {employee.name} [id: {employee.id}]"); }
public void ThenTheCompanyIsDisplayedInTheDatabaseAt(string resource) { var storedCompany = context.Get <Company>("company"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), resource) .AddUrlParameter("id", storedCompany.id.ToString()) .Data(); retrievedCompany.Should().BeEquivalentTo(storedCompany, $"Company {storedCompany} is not the same as {retrievedCompany}"); }
public void ThenTheChangeIsReflectedAt(string resource) { var storedCompany = context.Get <Company>("company"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), resource) .AddUrlParameter("id", storedCompany.id.ToString()) .Data(); storedCompany.netWorth.Should().Be(retrievedCompany.netWorth); }
public static List <ElasticSearchDataModel> GetDataModelWithIndiceName(string indice) { RestCall.GetIndiceTotalCount(_url, "/" + indice + "/_count"); indice = "/" + indice + "/_search"; var result = RestCall.GetIndiceData(_url, indice); return(result); }
public static RestCall <T> SelectProperties <T>(this RestCall <T> call) where T : new() { var properties = typeof(T).GetProperties() .Where(p => p.CanWrite && p.CanRead) .Select(p => p.Name).ToList(); call.Select(properties); return(call); }
public void PerformingCall_WithRestCallNull_ThrowsArgumentException() { // Arrange RestCall nullRestCall = null; // Act & Assert //// ReSharper disable once ExpressionIsAlwaysNull Assert.ThrowsAsync <ArgumentException>(() => _sut.SendAsync <string>(nullRestCall)); }
public void WhenTheUserReplacesCompanyEmployeesWithCompanyEmployees() { context.Get <Company>("resCompany").employees = context.Get <List <Employee> >("company2Employees"); context["resCompany"] = new RestCall <Company>(Method.PUT, (string)context["baseUrl"], "/{id}") .AddUrlParameter("id", context.Get <Company>("resCompany").id.ToString()) .AddPayload(context.Get <Company>("resCompany")) .Execute() .Data; }
public void WhenUserRetrievesEmployees(int numEmployees) { var employees = new RestCall <List <Employee> >(Method.GET, context.Get <string>("url"), "/employees") .Execute() .Data .Take(numEmployees); context.Add("employees", employees); Logger.Debug($"Retrieved {numEmployees} employees"); }
public void WhenUserSubmitsThisToTheEndpoint(string resource) { var company = context.Get <Company>("company"); var response = new RestCall <Company>(Method.POST, context.Get <string>("url"), resource) .AddUrlParameter("id", company.id.ToString()) .AddPayload(company) .Execute(); response.StatusCode.Should().Be(HttpStatusCode.Created); }
public void ThenTheCompanyIsNowDisplayedInTheDatabase() { var storedCompany = context.Get <Company>("company"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), context.Get <string>("companyResource") + "/{id}") .AddUrlParameter("id", storedCompany.id.ToString()) .Data(); retrievedCompany.companyName.Should().Be(storedCompany.companyName); Logger.Debug($"Company found: {retrievedCompany.companyName} [id: {retrievedCompany.id}]"); }
public HttpRequestMessage Create(RestCall restCall) { var httpRequestMessage = new HttpRequestMessage(MapHttpMethod(restCall.MethodType), restCall.AbsoluteUri); CheckAddBody(httpRequestMessage, restCall.Body); restCall.Headers.Entries.ForEach(header => httpRequestMessage.Headers.Add(header.Name, header.Value)); restCall.Security.ApplySecurity(httpRequestMessage); return(httpRequestMessage); }
public void ThenTheCompanyShouldHaveANewAddress(int id) { var storedCompany = context.Get <Company>("company"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), "/companies/{id}") .AddUrlParameter("id", id.ToString()) .Data(); (storedCompany.address.street == retrievedCompany.address.street && storedCompany.address.number == retrievedCompany.address.number && storedCompany.address.city == retrievedCompany.address.city) .Should().BeTrue(); }
public async Task CallingGetAllEndPointReturnsOkButFailAnyway() { // Arrange const string uri = "${server}/v1/Samples"; // Act var result = await RestCall.CallGetAsync <IEnumerable <GetItemList> >(uri); // Assert result.Status.Should().Be(HttpStatusCode.OK); }
public void WhenUserUpdatesEmployeeWithNewSalary(string id, string salary) { var employee = context.Get <Employee>("employee"); employee.salary = salary; _ = new RestCall <Employee>(Method.PUT, context.Get <string>("url"), "update/{id}") .AddUrlParameter("id", id) .AddPayload(employee) .Data(); Logger.Debug($"Updated employee {employee.name} [id: {employee.id}] with new salary {salary}"); }
public void WhenISubmitThisCompanyToTheCompanyDatabase() { var company = context.Get <Company>("company"); var response = new RestCall <Company>(Method.POST, context.Get <string>("url"), context.Get <string>("companyResource")) .AddUrlParameter("id", company.id.ToString()) .AddPayload(company) .Execute(); response.StatusCode.Should().Be(HttpStatusCode.Created); Logger.Debug($"Added Company: {company.companyName} [id: {company.id}]"); }
/// <summary> /// Intialize proxies from namespace and running assembly /// </summary> /// <param name="runningAssembly">Current running assembly</param> /// <param name="nameSpace">Namespace from running application</param> public void Init(Assembly runningAssembly, string nameSpace) { Logger.Info("Retrieving array of types from namespace: " + nameSpace); var types = Tools.GetTypesInNamespace(runningAssembly, nameSpace); Logger.Info(string.Format("Found {0} types inside namespace {1}", types.Count, nameSpace)); foreach (var type in types) { var restAttribute = type.GetCustomAttribute(typeof(REST)); if (restAttribute != null) { Logger.Info("Found REST class " + type.Name); var rest = (REST)restAttribute; this._proxies.Add(type.Name, new RestProxy(type, this._injectables)); var methods = type.GetMethods(); foreach (var method in methods) { foreach (var restType in this._restTypes) { var httpMethodAttribute = method.GetCustomAttribute(restType); if (httpMethodAttribute != null) { var restCall = new RestCall(type.Name, method.Name, (IHTTPMethod)httpMethodAttribute, rest); try { Logger.Info(string.Format( "Registering method {0} for {1} {2}{3}", method.Name, restCall.HttpMethod.Method, rest.Path, restCall.HttpMethod.Path )); this.AddEndpoint(restCall); } catch (DuplicateRestMethodException) { Logger.Error(string.Format( "DuplicateRestMethodException: There is already a {0} for {1}{2} registered.", restCall.HttpMethod.Method, rest.Path, restCall.HttpMethod.Path )); } } } } } } }
public async Task CallingBySingleEndpointReturnsOk() { // Arrange var uri = new Uri("http://localhost:36146/v1/Samples/1"); // Act var result = await RestCall.CallGetAsync <GetItem>(uri); // Assert result.Status.Should().Be(HttpStatusCode.OK); }
public async Task CallingOptionsReturnsOk() { // Arrange var uri = new Uri("http://localhost:36146/v1/Samples"); // Act var result = await RestCall.CallOptionsAsync(uri); // Assert result.Status.Should().Be(HttpStatusCode.OK); }
public void WhenUserSetsCompanyValueTo(int newValue) { var company = context.Get <Company>("company"); company.netWorth = newValue; //context["company"] = company; var response = new RestCall <Company>(Method.PUT, context.Get <string>("url"), "companies/{id}") .AddUrlParameter("id", company.id.ToString()) .AddPayload(company) .Execute(); }
public void ThenTheCompanyHasTheNewName() { var storedCompany = context.Get <Company>("company"); string oldName = context.Get <string>("companyOldName"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), context.Get <string>("companyResource") + "/{id}") .AddUrlParameter("id", storedCompany.id.ToString()) .Data(); retrievedCompany.companyName.Should().Be(storedCompany.companyName, "The new name '{retrievedCompany.companyName}' was expected to be '{storedCompany.companyName}'"); Logger.Info($"The company {retrievedCompany.id} now has the new name '{retrievedCompany.companyName}'"); }
public async Task CallingPutReturnsOk() { // Arrange var uri = new Uri("http://localhost:36146/v1/Samples/1"); var content = new PutItem(); // Act var result = await RestCall.CallPutAsync <GetItem, PutItem>(uri, content); // Assert result.Status.Should().Be(HttpStatusCode.OK); }
public void WhenUserPostsThisTo(string resource) { var product = context.Get <Product>("product"); context["resource"] = resource; var response = new RestCall <Product>(Method.POST, context.GetUrl(), resource) .AddPayload(product) .Execute(res => product.id = res.Data.id) .StatusCode.Should().Be(HttpStatusCode.Created); context["product"] = product; }
public void ThenTheCompanyNoLongerHasTheShareholder() { var storedCompany = context.Get <Company>("company"); var deletedShareholder = context.Get <Shareholder>("deletedShareholder"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), context.Get <string>("companyResource") + "/{id}") .AddUrlParameter("id", storedCompany.id.ToString()) .Data(); retrievedCompany.shareholders.Should().NotContain(deletedShareholder, $"The company {retrievedCompany.companyName} [{retrievedCompany.id}] should not have the shareholder {deletedShareholder.name} [{deletedShareholder.id}]"); Logger.Info($"The company {retrievedCompany.companyName} [{retrievedCompany.id}] no longer has the shareholder {deletedShareholder.name} [{deletedShareholder.id}]"); }
public Task Given_the_user_is_about_to_call_a_nonexisting_url() { _restCall = new RestCall( new Uri("https://googlewdwwfwef.com/"), Maybe.CreateNone <string>(), RestCallMethodType.Post, RestSecurity.CreateAnonymous(), new RestHeaders(new List <RestHeader>()), Maybe.CreateNone <RestCallBody>(), new QueryParameters(new List <QueryParameter>())); return(Task.CompletedTask); }
public void ThenTheEmployeeIsPresentInTheEmployeesList() { var storedEmployee = context.Get <Employee>("employee"); var retrievedEmployee = new RestCall <List <Employee> >(Method.GET, context.Get <string>("url"), "/employees") .AddHeader("Accept", "application/json") .Data() .Where(e => e.id == context.Get <Employee>("employee").id) .First(); Console.WriteLine($"Created employee: {storedEmployee.ToString()}"); Console.WriteLine($"Retrieved employee: {retrievedEmployee.ToString()}"); retrievedEmployee.Should().BeEquivalentTo(storedEmployee); }
public void ThenAllCompaniesInDatabaseNetworthWillBeGreaterThan(int minNetWorth) { context["companies"] = new RestCall <List <Company> >(Method.GET, (string)context["baseUrl"], "") .Execute() .Data; //((List<Company>)context["companies"]) // .All(company => company.netWorth > minNetWorth).Should().BeTrue(); context.Get <List <Company> >("companies") .All(company => company.netWorth > minNetWorth) .Should() .BeTrue(); }
public void ThenTheCompanyHasTheNewAddress() { var storedCompany = context.Get <Company>("company"); var retrievedCompany = new RestCall <Company>(Method.GET, context.Get <string>("url"), context.Get <string>("companyResource") + "/{id}") .AddUrlParameter("id", storedCompany.id.ToString()) .Data(); retrievedCompany.address.ToString().Should().Be(storedCompany.address.ToString()); Logger.Debug($"Check updated address. Expected " + $"'{storedCompany.address.number} {storedCompany.address.street}, " + $" {storedCompany.address.city}', got '{retrievedCompany.address.number} " + $"{retrievedCompany.address.street}, {retrievedCompany.address.city}'"); }
public void ThenTheSalaryIncreaseWillBeReflectedInTheDatabase() { var resCompanies = new RestCall <List <Company> >(Method.GET, (string)context["baseUrl"], "") .Execute() .Data; //using the companies in context from the first step foreach (var contextCompany in (List <Company>)context["companies"]) { var resCompany = resCompanies.Find(e => e.companyName.Equals(contextCompany.companyName)); contextCompany.employees.Should().BeEquivalentTo(resCompany.employees); } }