Beispiel #1
0
 public virtual void CheckOut(Holding holding, int patronId)
 {
     // TODO determine policy material, which in turn comes from from Isbn lookup on creation
     // Currently Holding creation in controller does not accept ISBN
     holding.CheckOut(TimeService.Now, patronId, new BookCheckoutPolicy());
     context.SaveChanges();
 }
Beispiel #2
0
        public static Holding SaveCheckedOutHoldingWithClassification(LibraryContext context, string classification)
        {
            var holding = new Holding {
                Classification = classification
            };

            holding.CheckOut(DateTime.Now, 1, CheckoutPolicies.BookCheckoutPolicy);
            context.Holdings.Add(holding);
            context.SaveChanges();
            return(holding);
        }
Beispiel #3
0
        public void CheckInAnswersZeroDaysLateWhenReturnedBeforeDueDate()
        {
            var holding = new Holding {
                Classification = "X", BranchId = 1, CopyNumber = 1
            };

            holding.CheckOut(DateTime.Now, PatronId, CheckoutPolicies.BookCheckoutPolicy);

            var date     = holding.DueDate.Value.AddDays(-1);
            int branchId = 2;

            holding.CheckIn(date, branchId);
            Assert.Equal(0, holding.DaysLate());
        }
Beispiel #4
0
        public void DaysLateCalculatedWhenReturnedAfterDueDate()
        {
            var holding = new Holding {
                Classification = "X", BranchId = 1, CopyNumber = 1
            };

            holding.CheckOut(DateTime.Now, PatronId, CheckoutPolicies.BookCheckoutPolicy);

            var date     = holding.DueDate.Value.AddDays(2);
            var branchId = 2;

            holding.CheckIn(date, branchId);
            Assert.Equal(2, holding.DaysLate());
        }
        public void CheckInAnswersZeroDaysLateWhenReturnedOnDueDate()
        {
            var holding = new Holding {
                Classification = "X", BranchId = 1, CopyNumber = 1
            };

            holding.CheckOut(DateTime.Now, PatronId, CheckoutPolicies.BookCheckoutPolicy);

            var dueDate = holding.DueDate.Value;
            int brId    = 2;

            holding.CheckIn(dueDate, brId);
            Assert.That(holding.DaysLate(), Is.EqualTo(0));
        }
        public void CheckIn()
        {
            var holding = new Holding {
                Classification = "X", BranchId = 1, CopyNumber = 1
            };

            // check out movie
            holding.CheckOut(DateTime.Now, PatronId, CheckoutPolicies.BookCheckoutPolicy);
            var       tomorrow    = DateTime.Now.AddDays(1);
            const int newBranchId = 2;

            holding.CheckIn(tomorrow, newBranchId);
            Assert.IsFalse(holding.IsCheckedOut);
            Assert.That(holding.HeldByPatronId, Is.EqualTo(Holding.NoPatron));
            Assert.That(holding.CheckOutTimestamp, Is.Null);
            Assert.That(holding.BranchId, Is.EqualTo(newBranchId));
            // day after now
            Assert.That(holding.LastCheckedIn, Is.EqualTo(tomorrow));
        }
        public void CheckIn()
        {
            var holding = new Holding("X", 1)
            {
                BranchId = 1
            };

            holding.CheckOut(DateTime.Now, PatronId, CheckoutPolicies.BookCheckoutPolicy);
            var       tomorrow    = DateTime.Now.AddDays(1);
            const int newBranchId = 2;

            holding.CheckIn(tomorrow, newBranchId);

            Assert.IsFalse(holding.IsCheckedOut);
            Assert.That(holding.HeldByPatronId, Is.EqualTo(Holding.NoPatron));
            Assert.That(holding.CheckOutTimestamp, Is.EqualTo(DateTime.MinValue));
            Assert.That(holding.BranchId, Is.EqualTo(newBranchId));
            Assert.That(holding.LastCheckedIn, Is.EqualTo(tomorrow));
        }
        public void Co()
        {
            var holding = new Holding("X", 1);

            Assert.IsFalse(holding.IsCheckedOut);
            var now = DateTime.Now;

            var policy = CheckoutPolicies.BookCheckoutPolicy;

            holding.CheckOut(now, PatronId, policy);

            Assert.IsTrue(holding.IsCheckedOut);

            Assert.AreSame(policy, holding.CheckoutPolicy);
            Assert.That(holding.HeldByPatronId, Is.EqualTo(PatronId));

            var dueDate = now.AddDays(policy.MaximumCheckoutDays());

            Assert.That(holding.DueDate, Is.EqualTo(dueDate));
        }
Beispiel #9
0
        public void Co()
        {
            var holding = new Holding {
                Classification = "", CopyNumber = 1, BranchId = 1
            };

            Assert.False(holding.IsCheckedOut);
            var now = DateTime.Now;

            var policy = CheckoutPolicies.BookCheckoutPolicy;

            holding.CheckOut(now, PatronId, policy);

            Assert.True(holding.IsCheckedOut);

            Assert.Equal(policy.Id, holding.CheckoutPolicy.Id);
            Assert.Equal(PatronId, holding.HeldByPatronId);

            var dueDate = now.AddDays(policy.MaximumCheckoutDays());

            Assert.Equal(dueDate, holding.DueDate);

            Assert.Equal(Branch.CheckedOutId, holding.BranchId);

            // checking in
            var       tomorrow    = DateTime.Now.AddDays(1);
            const int newBranchId = 2;

            holding.CheckIn(tomorrow, newBranchId);
            Assert.False(holding.IsCheckedOut);
            Assert.Equal(Holding.NoPatron, holding.HeldByPatronId);
            Assert.Null(holding.CheckOutTimestamp);
            Assert.Equal(newBranchId, holding.BranchId);
            // day after now
            Assert.Equal(tomorrow, holding.LastCheckedIn);
        }
        public void Co()
        {
            var holding = new Holding {
                Classification = "", CopyNumber = 1, BranchId = 1
            };

            Assert.IsFalse(holding.IsCheckedOut);
            var now = DateTime.Now;

            var policy = CheckoutPolicies.BookCheckoutPolicy;

            holding.CheckOut(now, PatronId, policy);

            Assert.IsTrue(holding.IsCheckedOut);

            Assert.AreSame(policy, holding.CheckoutPolicy);
            Assert.That(holding.HeldByPatronId, Is.EqualTo(PatronId));

            var dueDate = now.AddDays(policy.MaximumCheckoutDays());

            Assert.That(holding.DueDate, Is.EqualTo(dueDate));

            Assert.That(holding.BranchId, Is.EqualTo(Branch.CheckedOutId));
        }