using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using PersonalFinance; using System.Collections.Generic; namespace PersonalFinanceTest { [TestClass] public class PaymentTest { [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException), "Price cannot be negative.")] public void Payment_NegativePrice() { Payment test = new Payment(new User()) { Price = -1 }; } [TestMethod] [ExpectedException(typeof(ArgumentNullException), "User cannot be null.")] public void Payment_NullUser() { Payment test = new Payment(null); } [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException), "Value is defined enum from PaymentGroup!")] public void Payment_CurrencyIsNotEnum() { Payment test = new Payment(new User()) { Currency = (PaymentCurrency)10 }; } [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException), "Value is defined enum from PaymentGroup!")] public void Payment_GroupIsNotEnum() { Payment test = new Payment(new User()) { Group = (PaymentGroup)10 }; } [TestMethod] public void Payment_FindExistTag() { Payment test = new Payment(new User()) { Tags = new System.Collections.Generic.List(new string[] { "test", "phone", "tomato" }) }; bool found = test.ExistTag("test"); Assert.IsTrue(found, "Value is not found in tags!"); found = test.ExistTag("TEST"); Assert.IsTrue(found, "Value is not found in tags!"); found = test.ExistTag("blabla"); Assert.IsFalse(found, "Value is found in tags!"); } [TestMethod] public void MultiplePayments_FindExistTag() { List tests = new List(new Payment[] { new Payment(new User()) { Tags = new List(new string[] { "test", "phone", "tomato" }) }, new Payment(new User()) { Tags = new List(new string[] { "test", "car", "tomato" }) }, new Payment(new User()) { Tags = new List(new string[] { "test", "phone", "car" }) } }); List foundCar = new List(); List foundTest = new List(); List foundBlabla = new List(); foreach (Payment test in tests) { if (test.ExistTag("car")) { foundCar.Add(test); } if (test.ExistTag("test")) { foundTest.Add(test); } if (test.ExistTag("blabla")) { foundBlabla.Add(test); } } Assert.IsTrue(foundCar.Count == 2, "Founded more or less payments!"); Assert.IsTrue(foundTest.Count == 3, "Founded more or less payments!"); Assert.IsTrue(foundBlabla.Count == 0, "Founded more or less payments!"); } [TestMethod] public void MultiplePayments_FoundGroup() { List tests = new List(new Payment[] { new Payment(new User()){ Group = PaymentGroup.Personal }, new Payment(new User()){ Group = PaymentGroup.Personal }, new Payment(new User()){ Group = PaymentGroup.Family }, new Payment(new User()){ Group = PaymentGroup.Personal }, new Payment(new User()){ Group = PaymentGroup.Family }, new Payment(new User()){ Group = PaymentGroup.Personal } }); List foundPersonal = new List(); List foundPrivate = new List(); foreach (Payment test in tests) { if (test.Group == PaymentGroup.Personal) { foundPersonal.Add(test); } if (test.Group == PaymentGroup.Private) { foundPrivate.Add(test); } } Assert.IsTrue(foundPersonal.Count == 4, "Founded more or less payments!"); Assert.IsTrue(foundPrivate.Count == 0, "Founded more or less payments!"); } } }