public void Controller_Returns_NotFound_For_Nonexisting_Currency() { // Arrange var currenciesController = new CurrenciesController(new StubCurrencyReferenceDataRepository()); // Act var response = currenciesController.Get("YYY") as NegotiatedContentResult<string>; // Assert // ReSharper disable once PossibleNullReferenceException Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("A currency with code 'YYY' was not found.", response.Content); }
public void Controller_Returns_All_Currencies() { // Arrange var currenciesController = new CurrenciesController(new StubCurrencyReferenceDataRepository()); // Act var response = currenciesController.Get() as OkNegotiatedContentResult<IEnumerable<Currency>>; // Assert if (response != null) { var currencies = response.Content; Assert.AreEqual(2, currencies.Count()); } }
public void Currency_Is_Updated() { // Arrange var currenciesController = new CurrenciesController(new StubCurrencyReferenceDataRepository()); // Act var currency = new Currency { CurrencyChar3Code = "GBP", CurrencyName = "British Pound", CurrencyNumberCode = 01, NumberOfDigits = 2 }; var response = currenciesController.Put("GBP", currency); // Assert // ReSharper disable once PossibleNullReferenceException Assert.IsInstanceOfType(response, typeof(OkResult)); }
public void Controller_Returns_Existing_Currency() { // Arrange var currenciesController = new CurrenciesController(new StubCurrencyReferenceDataRepository()); // Act var response = currenciesController.Get("GBP") as OkNegotiatedContentResult<Currency>; // Assert if (response != null) { var currency = response.Content; Assert.AreEqual("GBP", currency.CurrencyChar3Code); Assert.AreEqual(00, currency.CurrencyNumberCode); Assert.AreEqual("British Pound", currency.CurrencyName); Assert.AreEqual(2, currency.NumberOfDigits); } }
public void New_Currency_Is_Added() { // Arrange var currenciesController = new CurrenciesController(new StubCurrencyReferenceDataRepository()); // Act var currency = new Currency { CurrencyChar3Code = "ZMD", CurrencyName = "Zamundan Dollar", CurrencyNumberCode = 50, NumberOfDigits = 300 }; var response = currenciesController.Post(currency) as CreatedAtRouteNegotiatedContentResult<Currency>; // Assert // ReSharper disable once PossibleNullReferenceException Assert.IsNotNull(response); Assert.AreEqual("GetCurrencyByCode", response.RouteName); Assert.AreEqual(response.Content.CurrencyChar3Code, response.RouteValues["CurrencyCode"]); }