public async void Add_Loan_DAMAGED()
        {
            var memberSsn = 112233446;

            using (var context = GetContextWithData())
                using (var controller = new LoansController(context))
                {
                    var     itemId  = AddItem(context, ItemCondition.DAMAGED);
                    LoanAPI loanAPI = new LoanAPI()
                    {
                        ItemId = itemId, MemberSsn = memberSsn
                    };
                    var result = await controller.PostLoan(loanAPI);

                    var loans = await controller.GetLoans();

                    var loan = loans.Last();

                    output.WriteLine(loan.Item.RentStatus.ToString());
                    output.WriteLine(loan.Member.Ssn.ToString());

                    Assert.IsType <CreatedAtActionResult>(result);
                    Assert.True(loan is Loan);
                    Assert.Equal(RentStatus.UNAVAILABLE, loan.Item.RentStatus);
                }
        }
        public async void Add_Unavailable_Loan()
        {
            var memberSsn  = 112233446;
            var memberSsn2 = 556677889;

            using (var context = GetContextWithData())
                using (var controller = new LoansController(context))
                {
                    var itemId  = context.Items.FirstOrDefault().Id;
                    var loanAPI = new LoanAPI()
                    {
                        ItemId = itemId, MemberSsn = memberSsn
                    };
                    var result = await controller.PostLoan(loanAPI);


                    var loanAPI2 = new LoanAPI()
                    {
                        ItemId = itemId, MemberSsn = memberSsn2
                    };
                    var result2 = await controller.PostLoan(loanAPI2);

                    var loans = await controller.GetLoans();

                    var loanz = loans.Where(l => l.Item.Id == itemId && l.IsReturned == false);

                    Assert.True(loanz.Count() == 1);
                }
        }
        public async void Get_All_Loans()
        {
            using (var context = GetContextWithData())
                using (var controller = new LoansController(context))
                {
                    var result = await controller.GetLoans();

                    output.WriteLine(result.AsEnumerable().FirstOrDefault().StartDate.ToLongDateString());
                    Assert.True(result.Count() != 0);
                }
        }
Beispiel #4
0
        public void GetLoansTest()
        {
            var controller = new LoansController(_entityMock.Object);
            var result     = controller.GetLoans();

            var objectResult = Assert.IsType <OkObjectResult>(result);
            var model        = Assert.IsAssignableFrom <IEnumerable <LoanDTO> >(objectResult.Value);

            var loanToDelete = _loanDTOs.Where(l => l.LastDay < DateTime.Now).FirstOrDefault(); //egyet töröl a controller is

            _loanDTOs.Remove(loanToDelete);

            Assert.Equal(_loanDTOs.Count(), model.Count());
        }
        public async void Update_ItemStatus(ItemStatus status, ItemCondition condition)
        {
            var memberSsn = 112233446;

            using (var context = GetContextWithData())
                using (var controller = new LoansController(context))
                {
                    var     itemId  = context.Items.FirstOrDefault().Id;
                    LoanAPI loanAPI = new LoanAPI()
                    {
                        ItemId = itemId, MemberSsn = memberSsn
                    };
                    await controller.PostLoan(loanAPI);

                    await controller.ReturnLoan(loanAPI, (int)condition);

                    var loans = await controller.GetLoans();

                    var loan = loans.Where(l => l.Item.Id == itemId && l.Member.Ssn == memberSsn).FirstOrDefault();

                    Assert.Equal(status, loan.Item.ItemStatus);
                }
        }
        public async void Return_Loan(ItemCondition condition)
        {
            var memberSsn = 112233445;

            using (var context = GetContextWithData())
                using (var controller = new LoansController(context))
                {
                    var     itemId  = context.Items.FirstOrDefault().Id;
                    LoanAPI loanAPI = new LoanAPI()
                    {
                        ItemId = itemId, MemberSsn = memberSsn
                    };
                    await controller.PostLoan(loanAPI);

                    await controller.ReturnLoan(loanAPI, (int)condition);

                    var loans = await controller.GetLoans();

                    var loanz = loans.Where(l => l.Item.Id == itemId && l.Member.Ssn == memberSsn && l.IsReturned == false);

                    output.WriteLine(loanz.Count().ToString());
                    Assert.True(loanz.Count() == 0);
                }
        }