예제 #1
0
        public void DictionaryTest_OnePersonInvolved()
        {
            //Arrange

            //var exp = expMaker.CreateExpense(1, "Adam", 12.60m, new List<string>() { "Igor" });
            var exp = ExpenseMaker.CreateExpense(1, "Adam", 12.60m, new List <string>()
            {
                "Igor"
            });
            var mockRepository = new Mock <IExpenseRepository>();

            mockRepository.Setup(x => x.GetAllExpenses(1)).Returns(new List <Expense>()
            {
                exp
            });

            ICalculationMethod calculationMethod = new CalculationMethod();
            Calculation        calculation       = new Calculation(mockRepository.Object, tableRepository, calculationMethod, optymizer);

            calculation.TableNumber = 1;
            //Act
            var dict         = calculationMethod.CalculateMembersExpenses(calculation);
            var expecteddict = new Dictionary <string, decimal>()
            {
                { "Igor_Adam", 6.30m }
            };


            //Assert
            Assert.IsNotNull(dict);
            Assert.AreEqual(expecteddict.Count, dict.Count);
            Assert.Contains("Igor_Adam", dict.Keys);
            Assert.Contains(6.30m, dict.Values);
        }
예제 #2
0
        public void EditExpense(ExpenseEdit exp)
        {
            Expense expense = GetExpenseById(exp.ExpenseId);
            Expense newExp  = ExpenseMaker.CreateExpense(exp.TableNumber, exp.Name, exp.Amount, exp.MembersInvolved, exp.Comment);

            if (expense != null)
            {
                expense.Name = newExp.Name;
                expense.NumberOfMembersInvolved = newExp.NumberOfMembersInvolved;
                expense.NamesOfMembersInvolved  = newExp.NamesOfMembersInvolved;
                expense.Amount  = newExp.Amount;
                expense.Comment = newExp.Comment;

                appDbContext.SaveChanges();
            }
        }
예제 #3
0
        public void ExpenseMaker_MakeMembers_MembersInvolvedIsNull_Test()
        {
            //Arrange

            string        Name            = "Adam";
            List <string> MembersInvolved = new List <string>()
            {
            };

            //Act
            string Members = ExpenseMaker.MakeMembers(Name, MembersInvolved);

            //Assert
            Assert.IsNotNull(Members);
            Assert.AreEqual("", Members);
            Assert.AreEqual(string.Empty, Members);
        }
예제 #4
0
        public void ExpenseMaker_MakeMembers_TheSameNameInMembersInvolved_Test()
        {
            //Arrange

            string        Name            = "Adam";
            List <string> MembersInvolved = new List <string>()
            {
                "Adam", "Igor", "Tomek"
            };


            //Act
            string Members = ExpenseMaker.MakeMembers(Name, MembersInvolved);

            //Assert
            Assert.IsNotNull(Members);
            Assert.AreEqual("Igor,Tomek", Members);
        }
예제 #5
0
        public IActionResult Add(ExpenseMapper em)
        {
            if (ModelState.IsValid)
            {
                if (em.MembersInvolved.Count() == 1 && em.MembersInvolved.Contains(em.Name))
                {
                    ModelState.AddModelError("MembersInvolved", $"Choose different member than {em.Name}");
                    ViewBag.TableNumber = em.TableNumber;
                    return(View());
                }

                Expense expense = ExpenseMaker.CreateExpense(em.TableNumber, em.Name, em.Amount, em.MembersInvolved, em.Comment);
                expenseRepository.AddNewExpense(expense);
                return(RedirectToAction("Success", new { id = em.TableNumber }));
            }
            ViewBag.TableNumber = em.TableNumber;
            return(View(em));
        }
예제 #6
0
        public void Setup()
        {
            tableRepository = new MockTableRepository();

            expenseRepository = new MockExpenseRepository();

            optymizer = new Optimizer();

            expectedDict1 = new Dictionary <string, decimal>()
            {
                { "Igor_Adam", 4.20m }, { "Heniek_Adam", 4.20m },
                { "Adam_Igor", 2.05m }, { "Heniek_Igor", 2.05m },
                { "Adam_Heniek", 8.10m }, { "Igor_Heniek", 8.10m }
            };

            testRepo = new List <Expense>();
            testRepo.Add(ExpenseMaker.CreateExpense(1, "Adam", 4.0m, new List <string>()
            {
                "Tomek", "Igor", "Heniek"
            }));
            //testRepo.Add(ExpenseMaker.CreateExpense(1, "Adam", 4.0m, "Tomek,Igor,Heniek"));
            testRepo.Add(ExpenseMaker.CreateExpense(1, "Tomek", 8.0m, new List <string>()
            {
                "Adam", "Igor", "Heniek"
            }));
            //testRepo.Add(ExpenseMaker.CreateExpense(1, "Tomek", 8.0m, "Adam,Igor,Heniek"));
            testRepo.Add(ExpenseMaker.CreateExpense(1, "Igor", 2.0m, new List <string>()
            {
                "Adam"
            }));
            //testRepo.Add(ExpenseMaker.CreateExpense(1, "Igor", 2.0m, "Adam"));
            testRepo.Add(ExpenseMaker.CreateExpense(1, "Heniek", 4.0m, new List <string>()
            {
                "Adam", "Tomek", "Igor"
            }));
            //testRepo.Add(ExpenseMaker.CreateExpense(1, "Heniek", 4.0m, "Adam,Tomek,Igor"));
        }
예제 #7
0
        public void ExpenseMaker_CreateExpenseTest()
        {
            //Arrange
            byte          TableNumber     = 1;
            string        Name            = "Adam";
            decimal       Amount          = 24.99m;
            List <string> MembersInvolved = new List <string>()
            {
                "Igor", "Tomek"
            };
            string members = "Igor,Tomek";


            //Act
            Expense expense = ExpenseMaker.CreateExpense(TableNumber, Name, Amount, MembersInvolved);

            //Assert
            Assert.IsNotNull(expense);
            Assert.AreEqual(Name, expense.Name);
            Assert.AreEqual(Amount, expense.Amount);
            Assert.AreEqual("No comment added.", expense.Comment);
            Assert.AreEqual(members, expense.NamesOfMembersInvolved);
            Assert.AreEqual(2, expense.NumberOfMembersInvolved);
        }