public void Get_Returns() { // Act var result = _controller.Get().Result; // Assert Assert.True(result.Value.Count() == 2); }
public async void CurrenciesController_Get_ReturnsObjectResult_WhenRequestIsOK() { var controllereee = controller; var result = await controller.Get(); var resultObjectResult = result as ObjectResult; var resultObject = resultObjectResult.Value as IEnumerable <Currency>; Assert.IsType <ObjectResult>(result); }
public void ObterListaDeMoedas() { CurrencyLayerService = new CurrencyLayerService(mockConfiguration); var controller = new CurrenciesController(CurrencyLayerService); var result = controller.Get(); var res = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, res.StatusCode); var currenciesResponse = Assert.IsType <ResulteResponse>(res.Value); Assert.NotEmpty(currenciesResponse.currencies); }
public void ConverterParaReal() { CurrencyLayerService = new CurrencyLayerService(mockConfiguration); decimal quote = CurrencyLayerService.GetListQuotes().quotes.FirstOrDefault(x => x.Key == $"USDBRL").Value; var controller = new CurrenciesController(CurrencyLayerService); var result = controller.Get("USD", quote); var res = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, res.StatusCode); var currenciesResponse = Assert.IsType <ConvertResponse>(res.Value); Assert.Equal(1, currenciesResponse.result); }
public void Update_Normally_ShouldWork() { Currency createdCurrency, updatedCurrency; using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) { createdCurrency = controller.CreateCurrency(TestDataProvider.CreateNewCurrency()); controller.Update(new CurrencyUpdate { Id = createdCurrency.Id, Code = "USD" }); updatedCurrency = controller.Get(createdCurrency.Id); } Assert.AreEqual("USD", updatedCurrency.Code); }
public void Get_Normally_ShouldReturn_CurrencyWithId() { Currency createdCurrency, queriedCurrency; using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) { createdCurrency = controller.CreateCurrency(TestDataProvider.CreateNewCurrency()); queriedCurrency = controller.Get(createdCurrency.Id); } Assert.IsTrue( queriedCurrency.IsEqualTo(createdCurrency), "The two currencies should be equal. " + $"Expected: {createdCurrency.Stringify()}, actual: {queriedCurrency.Stringify()}."); }
public void Delete_Normally_ShouldWork() { Currency createdCurrency, queriedCurrency; IEnumerable <Currency> listedCurrencies; using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) { createdCurrency = controller.CreateCurrency(TestDataProvider.CreateNewCurrency()); queriedCurrency = controller.Get(createdCurrency.Id); controller.Delete(createdCurrency.Id); listedCurrencies = controller.List(); } Assert.AreEqual(createdCurrency.Id, queriedCurrency.Id, "Unexpected ID."); Assert.AreEqual(false, listedCurrencies.Any(), "There should be no partners returned."); }
public async Task TestCase1() { var context = this.fixture.GetCurrentDataContext(); CurrenciesController control = new CurrenciesController(context); // Step 1. Read all var rsts = control.Get(); var rstscnt = await rsts.CountAsync(); var cnt1 = DataSetupUtility.Currencies.Count; Assert.Equal(cnt1, rstscnt); // Step 2. Read currency with select var httpContext = new DefaultHttpContext(); // or mock a `HttpContext` httpContext.Request.Path = "/api/Currencies"; httpContext.Request.QueryString = new QueryString("?$select=Name"); httpContext.Request.Method = "GET"; var routeData = new RouteData(); routeData.Values.Add("odataPath", "Currencies"); routeData.Values.Add("action", "GET"); //Controller needs a controller context var controllerContext = new ControllerContext() { RouteData = routeData, HttpContext = httpContext, }; // Assign context to controller control = new CurrenciesController(context) { ControllerContext = controllerContext, }; rsts = control.Get(); Assert.NotNull(rsts); await context.DisposeAsync(); }
public void Get_WhenRecordDoesNotExist_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) controller.Get(0); }