public void ExpenseService_Delete_Item_exists_Is_Removed()
        {
            var testDataWithID = baseTestData.Copy();

            testDataWithID.Id = 1;

            var mock = ServiceMocks.GetMockExpenseService(new List <Expense> {
                testDataWithID
            });

            var before = mock.LoadAll();

            Assert.IsTrue(before.Contains(testDataWithID));

            var actual = mock.LoadById(testDataWithID.Id);

            Assert.IsNotNull(actual);

            mock.Delete(testDataWithID.Id);

            var after = mock.LoadAll();

            Assert.IsFalse(after.Contains(testDataWithID));

            var itemAfter = mock.LoadById(testDataWithID.Id);

            Assert.IsNull(itemAfter);
        }
        public void ExpenseService_Save_Existing_Item_Is_Updated()
        {
            var testDataWithID = baseTestData.Copy();

            testDataWithID.Id = 1;

            var mock = ServiceMocks.GetMockExpenseService(new List <Expense> {
                testDataWithID
            });

            var before = mock.LoadAll();

            Assert.IsTrue(before.Contains(testDataWithID));

            testDataWithID.Comments = "some random things";

            mock.Save(testDataWithID);

            var after = mock.LoadAll();

            Assert.IsTrue(after.Contains(testDataWithID));

            var actual = mock.LoadById(testDataWithID.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(testDataWithID, actual);
        }
        public void ExpenseService_LoadOfMonth_Returns_All_Matching_Data()
        {
            var data = Enumerable.Range(1, 5)
                       .Select(i =>
            {
                var c    = baseTestData.Copy();
                c.Id     = i;
                c.Date   = new DateTime(2015, 3, 3);
                c.Amount = (decimal)Math.Pow(i, i);
                return(c);
            })
                       .ToList();
            var expected = new List <Expense>(data);

            data = data.Concat(Enumerable.Range(1, 5)
                               .Select(i =>
            {
                var c    = baseTestData.Copy();
                c.Id     = i;
                c.Date   = new DateTime(2012, 6, 3);
                c.Amount = (decimal)Math.Pow(i, i);
                return(c);
            }))
                   .ToList();

            var mock = ServiceMocks.GetMockExpenseService(data);

            var actual = mock.LoadOfMonth(new DateTime(2015, 3, 1));

            CollectionAssert.AreEquivalent(expected, actual.ToList());
        }
        public void ExpenseService_LoadById_Item_Does_Not_Exist_Returns_Null()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            var actual = mock.LoadById(1);

            Assert.IsNull(actual);
        }
Пример #5
0
        public void ExpenseService_Save_PaymentMethod_Null_Throw_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            mock.Save(new Expense {
                Category = new ExpenseCategory(), PaymentMethodId = 0
            });
        }
        public void ExpenseService_GetPaymentMethodTotalForMonth_No_Matching_Data_Returns_Zero()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            var total = mock.GetPaymentMethodTotalForMonth(DateTime.Today, "not here");

            Assert.AreEqual(0, total);
        }
        public void ExpenseService_GetMonthTotal_No_Matching_Data_Returns_Zero()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            var total = mock.GetMonthTotal(DateTime.Today);

            Assert.AreEqual(0, total);
        }
        public void ExpenseService_GetAllPaymentMethodTotals_No_Methods_Returns_Empty_Dictionary()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            var actual = mock.GetAllPaymentMethodTotals(DateTime.Today);

            CollectionAssert.AreEquivalent(new Dictionary <string, decimal>(), actual);
        }
Пример #9
0
        public void ExpenseService_Create_Category_Is_Null_Throws_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            mock.Create(new Expense {
                Method = new PaymentMethod(), CategoryId = 0
            });
        }
        public void ExpenseService_GetAll_No_Data_Returns_Empty_List()
        {
            var mock = ServiceMocks.GetMockExpenseService(new List <Expense>());

            var actual = mock.LoadAll();

            CollectionAssert.AreEquivalent(new List <Expense>(), actual.ToList());
        }
        public void ExpenseService_Create_PaymentMethod_Is_Null_Throws_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            mock.Create(new Expense {
                Category = new ExpenseCategory()
            });
        }
        public void ExpenseService_Save_Catgeory_Null_Throws_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            mock.Save(new Expense()
            {
                Method = new PaymentMethod()
            });
        }
        public void ExpenseService_GetAll_Returns_Data()
        {
            var data = Enumerable.Range(1, 5)
                       .Select(i => { var c = baseTestData.Copy(); c.Id = i; c.Amount = (decimal)Math.Pow(i, i); return(c); })
                       .ToList();
            var mock = ServiceMocks.GetMockExpenseService(data);

            var actual = mock.LoadAll();

            CollectionAssert.AreEquivalent(data, actual.ToList());
        }
        public void ExpenseService_LoadById_Item_Exists_Returns_It()
        {
            var mock = ServiceMocks.GetMockExpenseService(new List <Expense> {
                baseTestData
            });

            var actual = mock.LoadById(baseTestData.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(baseTestData, actual);
        }
        public void ExpenseService_GetMonthTotal_Returns_Full_Sum()
        {
            var data = Enumerable.Range(1, 5)
                       .Select(i =>
            {
                var c    = baseTestData.Copy();
                c.Id     = i;
                c.Date   = DateTime.Today;
                c.Amount = 1;
                return(c);
            })
                       .ToList();
            var mock = ServiceMocks.GetMockExpenseService(data);

            var total = mock.GetMonthTotal(DateTime.Today);

            Assert.AreEqual(5, total);
        }
        public void ExpenseService_LoadOfMonth_Only_Month_Matches_Returns_Empty_List()
        {
            var data = Enumerable.Range(1, 5)
                       .Select(i =>
            {
                var c    = baseTestData.Copy();
                c.Id     = i;
                c.Date   = new DateTime(2015, 1, 3);
                c.Amount = (decimal)Math.Pow(i, i);
                return(c);
            })
                       .ToList();
            var mock = ServiceMocks.GetMockExpenseService(data);

            var actual = mock.LoadOfMonth(new DateTime(2010, 1, 1));

            CollectionAssert.AreEquivalent(new List <Expense>(), actual.ToList());
        }
        public void ExpenseService_Create_Item_Is_Added()
        {
            var mock = ServiceMocks.GetMockExpenseService(new List <Expense>());

            var before = mock.LoadAll();

            Assert.IsFalse(before.Contains(baseTestData));

            mock.Create(baseTestData);

            var after = mock.LoadAll();

            Assert.IsTrue(after.Contains(baseTestData));

            var actual = mock.LoadById(baseTestData.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(baseTestData, actual);
        }
        public void ExpenseService_GetPaymentMethodTotalForMonth_Case_Insensitive_Returns_Full_Sum()
        {
            var data = Enumerable.Range(1, 5)
                       .Select(i =>
            {
                var c    = baseTestData.Copy();
                c.Id     = i;
                c.Date   = DateTime.Today;
                c.Method = new PaymentMethod(0, "this");
                c.Amount = 1;
                return(c);
            })
                       .ToList();
            var mock = ServiceMocks.GetMockExpenseService(data);

            var total = mock.GetPaymentMethodTotalForMonth(DateTime.Today, "THIS");

            Assert.AreEqual(5, total);
        }
        public void ExpenseService_GetAllPaymentMethodTotals_All_Methods_With_Correct_Sum()
        {
            var data = Enumerable.Range(1, 5)
                       .Select(i =>
            {
                var c    = baseTestData.Copy();
                c.Id     = i;
                c.Date   = DateTime.Today;
                c.Method = new PaymentMethod(0, i.ToString());
                c.Amount = 1;
                return(c);
            })
                       .ToList();
            var expected = Enumerable.Range(1, 5)
                           .ToDictionary(k => k.ToString(), v => (decimal)1);
            var mock = ServiceMocks.GetMockExpenseService(data);

            var actual = mock.GetAllPaymentMethodTotals(DateTime.Today);

            CollectionAssert.AreEquivalent(expected, actual);
        }
        public void ExpenseService_GetCategoryTotalForMonth_Null_Category_Throws_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            var total = mock.GetCategoryTotalForMonth(DateTime.Today, null);
        }
        public void ExpenseService_Delete_Item_Does_Not_Exist_Nothing_Happens()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            mock.Delete(12);
        }
        public void ExpenseService_Create_Item_Is_Null_Throws_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            mock.Create(null);
        }
        public void ExpenseService_GetPaymentMethodTotalForMonth_Whitespace_Category_Throws_Exception()
        {
            var mock = ServiceMocks.GetMockExpenseService();

            var total = mock.GetPaymentMethodTotalForMonth(DateTime.Today, "\t\t\t");
        }