public void ConvertText() { if (string.IsNullOrWhiteSpace(SomeText)) { return; } AddToHistory(ConverterService.Convert(SomeText)); SomeText = string.Empty; }
public void TestService() { ConverterService cs = new ConverterService(); cs.Login("lluis"); cs.SetCurrencyRate("EUR", 0.5); Assert.AreEqual(0.5, cs.GetCurrencyRate("EUR"), "#1"); double res = cs.Convert("EUR", "USD", 6); Assert.AreEqual((int)res, (int)12, "#2"); CurrencyInfo[] infos = cs.GetCurrencyInfo(); Assert.IsNotNull(infos, "infos"); foreach (CurrencyInfo info in infos) { double val = 0; Assert.IsNotNull(info.Name, "info.Name"); switch (info.Name) { case "USD": val = 1; break; case "EUR": val = 0.5; break; case "GBP": val = 0.611817; break; case "JPY": val = 118.271; break; case "CAD": val = 1.36338; break; case "AUD": val = 1.51485; break; case "CHF": val = 1.36915; break; case "RUR": val = 30.4300; break; case "CNY": val = 8.27740; break; case "ZAR": val = 7.62645; break; case "MXN": val = 10.5025; break; } Assert.AreEqual(val, info.Rate, "#3 " + info.Name); } cs.SetCurrencyRate("EUR", 0.9); }
public void ConvertInvalidCtoFTest() { // Arrange var cT = new CelsiusTemperature(0); var fT = new FahrenheitTemperature(0); var validatorMock = new Mock <IValidator>(); validatorMock.Setup(s => s.Validate(It.IsAny <ITemperature>(), out It.Ref <string> .IsAny)) .Returns(false); var converter = new ConverterService(validatorMock.Object); // Act // Assert Assert.Throws <Exception>(() => converter.Convert(cT, fT)); }
private dynamic ConvertFieldValue(dynamic value, FieldInfo field) { Type converter = null; if (field.GetCustomAttribute <GConverter>() != null) { converter = field.GetCustomAttribute <GConverter>().ConverterType; } if (field.FieldType.GetCustomAttribute <GConverter>() != null) { converter = field.FieldType.GetCustomAttribute <GConverter>().ConverterType; } return(_converterService.Convert(value, field.FieldType, converter)); }
public void ConvertValidCtoFTest(double cValue, double fValue) { // Arrange var cT = new CelsiusTemperature(cValue); var fT = new FahrenheitTemperature(0); var validatorMock = new Mock <IValidator>(); validatorMock.Setup(s => s.Validate(It.IsAny <CelsiusTemperature>(), out It.Ref <string> .IsAny)) .Returns(true); var converter = new ConverterService(validatorMock.Object); // Act converter.Convert(cT, fT); // Assert Assert.AreEqual(fValue, fT.Value); }
public void TestService () { ConverterService cs = new ConverterService (); cs.Login ("lluis"); cs.SetCurrencyRate ("EUR", 0.5); Assert.AreEqual (0.5, cs.GetCurrencyRate ("EUR"), "#1"); double res = cs.Convert ("EUR","USD",6); Assert.AreEqual ((int)res, (int)12, "#2"); CurrencyInfo[] infos = cs.GetCurrencyInfo (); Assert.IsNotNull (infos, "infos"); foreach (CurrencyInfo info in infos) { double val = 0; Assert.IsNotNull (info.Name, "info.Name"); switch (info.Name) { case "USD": val = 1; break; case "EUR": val = 0.5; break; case "GBP": val = 0.611817; break; case "JPY": val = 118.271; break; case "CAD": val = 1.36338; break; case "AUD": val = 1.51485; break; case "CHF": val = 1.36915; break; case "RUR": val = 30.4300; break; case "CNY": val = 8.27740; break; case "ZAR": val = 7.62645; break; case "MXN": val = 10.5025; break; } Assert.AreEqual (val, info.Rate, "#3 " + info.Name); } cs.SetCurrencyRate ("EUR", 0.9); }