Beispiel #1
0
 public Map(ItemInfo itemInfo)
 {
     _id            = new Guid();
     _itemInfo      = itemInfo;
     _rentStatus    = RentStatus.AVAILABLE;
     _itemStatus    = ItemStatus.RENTABLE;
     _itemCondition = ItemCondition.OK;
 }
 public Book(ItemInfo itemInfo, string ISBN)
 {
     _id            = new Guid();
     _itemInfo      = itemInfo;
     _isbn          = ISBN;
     _rentStatus    = RentStatus.AVAILABLE;
     _itemStatus    = ItemStatus.RENTABLE;
     _itemCondition = ItemCondition.OK;
 }
        public StatusResponseDTO Execute(StatusRequestDTO request)
        {
            var status         = new RentStatus();
            var existingStatus = AiContext.RentStatus
                                 .Where(x => x.Name == request.Name)
                                 .Where(x => x.IsDeleted == 0)
                                 .FirstOrDefault();

            if (existingStatus != null)
            {
                throw new EntityExistsException("Rent status");
            }
            status.Name = request.Name;
            AiContext.RentStatus.Add(status);
            AiContext.SaveChanges();
            return(new StatusResponseDTO
            {
                Id = status.Id,
                Name = status.Name
            });
        }
Beispiel #4
0
 public void ReturnItem()
 {
     this.rentState  = RentStatus.Returned;
     this.returnDate = DateTime.Now;
 }
        public async Task ReturnAsyncShouldChangeRentedStatusToReturned(int productQuantity, bool isRented, RentStatus rentStatus, decimal penalty, ReturnedOnTime returnedOnTime, RentStatus expectedStatus, bool expextedIsRented, int expectedProductQuantity, decimal expectedPenalty)
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = rentStatus
            };

            dbContext.Rents.Add(rent);

            var productService  = new Mock <IProductsService>();
            var invoicesService = new Mock <IInvoicesService>();
            var userService     = new Mock <IUsersService>();

            var product = new Product {
                Name = "Canon M50", Quantity = productQuantity, IsRented = isRented
            };

            dbContext.Products.Add(product);

            var rentProduct = new RentProduct {
                Product = product, Quantity = 1
            };

            rent.Products.Add(rentProduct);
            await dbContext.SaveChangesAsync();

            var rentsService = new RentsService(dbContext, userService.Object, invoicesService.Object, productService.Object);

            await rentsService.ReturnAsync(rent.Id, penalty, returnedOnTime);

            Assert.Equal(expectedStatus, rent.RentStatus);
            Assert.Equal(expextedIsRented, product.IsRented);
            Assert.Equal(expectedProductQuantity, product.Quantity);
            Assert.Equal(expectedPenalty, rent.Penalty);
        }
        public async Task ShipAsyncShouldNotChangeStatusToShippedIfStatusIdDifferentThanPending(RentStatus rentStatus, RentStatus expected)
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = rentStatus
            };

            dbContext.Rents.Add(rent);
            await dbContext.SaveChangesAsync();

            var productService  = new Mock <IProductsService>();
            var invoicesService = new Mock <IInvoicesService>();
            var userService     = new Mock <IUsersService>();

            var rentsService = new RentsService(dbContext, userService.Object, invoicesService.Object, productService.Object);

            await rentsService.ShipAsync(rent.Id);

            Assert.Equal(expected, rent.RentStatus);
        }
Beispiel #7
0
 public void ReturnItem()
 {
     this.DateOfReturn = DateTime.Now;
     this.RentStatus = RentStatus.Returned;
 }
        private Guid AddItem(LibraryContext context, ItemCondition itemCondition = ItemCondition.OK, RentStatus rentStatus = RentStatus.AVAILABLE, ItemStatus itemStatus = ItemStatus.RENTABLE)
        {
            var item = ItemFactory.Get(new ItemInfo()
            {
                Author = "Test Author", Description = "A very good testing book", Title = "The best book"
            });

            item.ItemCondition = itemCondition;
            item.RentStatus    = rentStatus;
            item.ItemStatus    = itemStatus;
            context.Items.Add(item);
            context.SaveChanges();
            return(context.Items.Last().Id);
        }