Ejemplo n.º 1
0
        public void AddItem_WithValidLogEntry_CallsRep()
        {
            // Arrange
            _moneyRepo.Setup(r => r.SaveItem(It.IsAny<int>(), It.IsAny<MoneyFlow>()));
            var service = new MoneyService(_moneyRepo.Object);
            var item = new LogEntry { Description = "description", Value = 1, Category = "Category", Subcategory = "Subcategory"};

            // Act
            service.AddItem(1, item);

            // Assert
            _moneyRepo.Verify(r => r.SaveItem(It.IsAny<int>(), It.IsAny<MoneyFlow>()), Times.Once());
        }
Ejemplo n.º 2
0
        public void GetFlowsByMonth_WithValidData_ReturnsCorrectExpenses()
        {
            // Arrange
            var service = new MoneyService(_moneyRepo.Object);
            _moneyRepo.Setup(m => m.GetFlows(It.IsAny<int>())).Returns(new List<MoneyFlow>
            {
                new MoneyFlow { Date = DateTime.Parse("01/05/2012"), Debit = 1},
                new MoneyFlow { Date = DateTime.Parse("01/07/2012"), Debit = 1},
            }.AsQueryable());

            // Act
            var result = service.GetFlowsByMonth(1);

            // Assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Date.Month, Is.EqualTo(5));
            Assert.That(result[0].Expenses, Is.EqualTo(1));

            Assert.That(result[1].Date.Month, Is.EqualTo(7));
            Assert.That(result[1].Expenses, Is.EqualTo(1));
        }
Ejemplo n.º 3
0
        public void Can_Group_By()
        {
            // Arrange
            var service = new MoneyService(_moneyRepo.Object);
            var list = new List<MoneyFlow> {
                new MoneyFlow { Date = DateTime.Now, Category = "Food", Subcategory = "Groceries", Debit = .50m},
                new MoneyFlow { Date = DateTime.Now, Category = "Food",  Subcategory = "Groceries", Debit = 1m },
                new MoneyFlow { Date = DateTime.Now, Category = "Health",  Subcategory = "Drugs", Debit = .75m },

            };

            // Act
            var result = service.Collapse(list);

            // Assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Category, Is.EqualTo("Food"));
            Assert.That(result[0].SubCategory, Is.EqualTo("Groceries"));
            Assert.That(result[0].Pounds, Is.EqualTo(-1.5m));

            Assert.That(result[1].Category, Is.EqualTo("Health"));
            Assert.That(result[1].SubCategory, Is.EqualTo("Drugs"));
            Assert.That(result[1].Pounds, Is.EqualTo(-0.75m));
        }
Ejemplo n.º 4
0
        public void GetMoneyLogs_WithValidRepo_ShouldReturnItemsAtBeginningAndEndOfMonth()
        {
            // Arrange
            _moneyRepo.Setup(r => r.SaveItem(It.IsAny<int>(), It.IsAny<MoneyFlow>()));
            var service = new MoneyService(_moneyRepo.Object);
            _moneyRepo.Setup(m => m.GetFlows(It.IsAny<int>())).Returns(new List<MoneyFlow>
            {
                new MoneyFlow { Date = DateTime.Parse("01/04/2012"), Id = 1 },
                new MoneyFlow { Date = DateTime.Parse("30/04/2012"), Id = 2},
            }.AsQueryable());
            // Act

            var result = service.GetMoneyLogs(1, DateTime.Parse("07/04/2012"));

            // Assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Id, Is.EqualTo(1));
            Assert.That(result[1].Id, Is.EqualTo(2));
        }