using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using PersonalFinance; using System.Collections.Generic; namespace PersonalFinanceTest { [TestClass] public class PaymentServiceTest { [TestMethod] public void PaymentService_GetAllPayments() { EntityContextInit contextInit = new EntityContextInit(); EntityContext context = new EntityContext(); List paymentList = contextInit.GetInitPaymentList(contextInit.GetInitUserList()); context.Payments = MoqContext.GetQueryableMockDbSet(paymentList.ToArray()); var service = new PaymentService(context); var payments = service.GetAllPayments(); Assert.AreEqual(5, payments.Count, "Count of all payments isn't right!"); } [TestMethod] public void PaymentService_FindPayments() { EntityContextInit contextInit = new EntityContextInit(); EntityContext context = new EntityContext(); List paymentList = contextInit.GetInitPaymentList(contextInit.GetInitUserList()); context.Payments = MoqContext.GetQueryableMockDbSet(paymentList.ToArray()); var service = new PaymentService(context); var payments = service.GetAllPayments(); var a = payments.FindAll(q => q.Currency.Equals(PaymentCurrency.CZK)); Assert.AreEqual(3, a.Count, "Count of payments with currency equals MALE isn't right!"); var b = payments.FindAll(q => q.Group.Equals(PaymentGroup.Family)); Assert.AreEqual(2, b.Count, "Count of payments with group equals MALE isn't right!"); var c = payments.FindAll(q => q.Paid.Equals(false)); Assert.AreEqual(1, c.Count, "Count of payments with paid equals FASLE isn't right!"); var d = payments.FindAll(q => q.Price < 100); Assert.AreEqual(1, d.Count, "Count of payments with price lowwer then 100 isn't right!"); } [TestMethod] public void PaymentService_UpdatePayment() { EntityContextInit contextInit = new EntityContextInit(); EntityContext context = new EntityContext(); List paymentList = contextInit.GetInitPaymentList(contextInit.GetInitUserList()); context.Payments = MoqContext.GetQueryableMockDbSet(paymentList.ToArray()); var service = new PaymentService(context); var payments = service.GetAllPayments(); payments[0].Price = 99; service.UpdatePayment(payments[0]); var a = payments.FindAll(q => q.Price < 100); Assert.AreEqual(2, a.Count, "Count of payments with price lowwer then 100 isn't right!"); } [TestMethod] [ExpectedException(typeof(IndexOutOfRangeException), "Payment with ID was found!")] public void PaymentService_DeĺeteNonexistingPayment() { EntityContextInit contextInit = new EntityContextInit(); EntityContext context = new EntityContext(); List paymentList = contextInit.GetInitPaymentList(contextInit.GetInitUserList()); context.Payments = MoqContext.GetQueryableMockDbSet(paymentList.ToArray()); var service = new PaymentService(context); service.DeletePayment(99); } } }