Exemplo n.º 1
0
        public async Task EditDescriptionAsync_SouldReturn_True_IfInputIsCorrect()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstRent = new RentAgreement {
                Id = 1, Description = "Some", ParkingSlotDescription = "None"
            };

            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService = new RentsService(mapper, db, null);

            var result = await rentService.EditDescriptionsAsync("Property Description", "Parking description", 1);

            var editedRent = await db.RentAgreements.FindAsync(1);

            result
            .Should()
            .BeTrue();
            editedRent
            .Should()
            .BeOfType <RentAgreement>()
            .And
            .Match <RentAgreement>(c =>
                                   c.ParkingSlotDescription == "Parking description" &&
                                   c.Description == "Property Description");
        }
        public async Task AddProductAsyncShouldAddProduct()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = RentStatus.Open
            };

            var userService = new Mock <IUsersService>();

            var productId      = 1;
            var productService = new Mock <IProductsService>();

            productService.Setup(p => p.GetProductByIdAsync(productId))
            .ReturnsAsync(new Product {
                Name = "Canon M50", PricePerDay = 100
            });

            var invoicesService = new Mock <IInvoicesService>();

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

            await rentsService.AddProductAsync(productId, rent);

            var rentProducts = dbContext.RentProducts.ToList();

            Assert.Single(rentProducts);
            Assert.Equal(rent.Id, rentProducts.First().RentId);
        }
Exemplo n.º 3
0
        public async Task Create_ShouldCreated()
        {
            var oldCount = Rents.Count;
            var rent     = new RentDto()
            {
                Id         = Random.Next(int.MaxValue),
                Count      = 5,
                IsActive   = true,
                Book       = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                Subscriber = Mapper.Map <SubscriberDto>(DefaultData.Subscribers.Maslov),
                Date       = DateTime.Now
            };
            await RentsService.Create(rent);

            Assert.That(Rents.Count, Is.EqualTo(oldCount + 1));
            var created = Rents.SingleOrDefault(x => x.Id == rent.Id);

            Assert.That(created, Is.Not.Null);
            Assert.That(created.Count, Is.EqualTo(rent.Count));
            Assert.That(created.IsActive, Is.EqualTo(rent.IsActive));
            Assert.That(created.Date, Is.EqualTo(created.Date));

            Assert.That(created.Subscriber.Fio, Is.EqualTo(rent.Subscriber.ToString()));
            Assert.That(created.Book.Id, Is.EqualTo(rent.Book.Id));
        }
Exemplo n.º 4
0
        public async Task UploadContractAsync_SouldReturn_True_IfEntityExistAndContentIsCorrect()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();


            var firstRent = new RentAgreement
            {
                Id                     = 1,
                Description            = "Some",
                ParkingSlotDescription = "None",
                MonthlyPrice           = 2000,
                StartDate              = new DateTime(2018, 3, 3),
                IsActual               = true
            };
            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService     = new RentsService(mapper, db, null);
            var contractContent = new byte[] { 121 };
            //Act
            var result = await rentService.UploadContractAsync(contractContent, 1);

            var uploadedRent = await db.RentAgreements.FindAsync(1);

            //Assert
            result
            .Should()
            .BeTrue();
            uploadedRent
            .Should()
            .Match <RentAgreement>(ra => ra.Contracts
                                   .Any(x => x.ScannedContract.Length == contractContent.Length));
        }
Exemplo n.º 5
0
        public async Task UploadContractAsync_SouldReturn_False_IfEntityD0NotExist()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstRent = new RentAgreement
            {
                Id                     = 1,
                Description            = "Some",
                ParkingSlotDescription = "None",
                MonthlyPrice           = 2000,
                StartDate              = new DateTime(2018, 3, 3),
                IsActual               = true
            };
            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService     = new RentsService(mapper, db, null);
            var contractContent = new byte[] { 121 };
            //Act
            var result = await rentService.UploadContractAsync(contractContent, 2);

            var uploadedRent = await db.RentAgreements.FindAsync(2);

            //Assert
            result
            .Should()
            .BeFalse();
            uploadedRent
            .Should()
            .BeNull();
        }
        public async Task AddProductAsyncWithInvalidProductShouldNotAddProduct()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = RentStatus.Open
            };

            var userService = new Mock <IUsersService>();

            var     productId      = 1;
            Product product        = null;
            var     productService = new Mock <IProductsService>();

            productService.Setup(p => p.GetProductByIdAsync(productId))
            .ReturnsAsync(product);

            var invoicesService = new Mock <IInvoicesService>();

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

            await rentsService.AddProductAsync(productId, rent);

            var rentProducts = dbContext.RentProducts.ToList();

            Assert.Empty(rentProducts);
        }
Exemplo n.º 7
0
        public async Task TerminateAsync_SouldReturn_False_IfEntityDoNotExist()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();


            var firstRent = new RentAgreement
            {
                Id                     = 1,
                Description            = "Some",
                ParkingSlotDescription = "None",
                MonthlyPrice           = 2000,
                StartDate              = new DateTime(2018, 3, 3),
                IsActual               = true
            };
            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService = new RentsService(mapper, db, null);

            var result = await rentService.TerminateAsync(2);

            var tereminatedRent = await db.RentAgreements.FindAsync(2);

            result
            .Should()
            .BeFalse();
            tereminatedRent
            .Should()
            .BeNull();
        }
        public async Task CreateOpenRentByUserIdAsyncShouldCreateOpenRent()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var user = new ApplicationUser {
                UserName = "******"
            };

            var userService = new Mock <IUsersService>();

            userService.Setup(u => u.GetUserByUsername(user.UserName))
            .Returns(user);

            var productsService = new Mock <IProductsService>();
            var invoicesService = new Mock <IInvoicesService>();

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

            await rentsService.CreateOpenRentByUserIdAsync(user.UserName);

            var openRent = dbContext.Rents.ToList();

            Assert.Single(openRent);
            Assert.Equal(RentStatus.Open, openRent.First().RentStatus);
        }
Exemplo n.º 9
0
        public async Task EditDescriptionAsync_SouldReturn_False_IfInputIsNotCorrect()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstRent = new RentAgreement {
                Id = 1, Description = "Some", ParkingSlotDescription = "None"
            };

            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService = new RentsService(mapper, db, null);

            var result = await rentService.EditDescriptionsAsync("Property Description", "Parking description", 2);

            var editedRent = await db.RentAgreements.FindAsync(2);

            result
            .Should()
            .BeFalse();
            editedRent
            .Should()
            .BeNull();
        }
Exemplo n.º 10
0
        public async Task SetRentDetailsAsyncShouldUpdateRent()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = RentStatus.Open
            };

            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);

            rent.ShippingAddress      = "Sofia, Mladost 4";
            rent.RecipientPhoneNumber = "0877777777";

            await rentsService.SetRentDetailsAsync(rent);

            Assert.Equal("Sofia, Mladost 4", rent.ShippingAddress);
            Assert.Equal("0877777777", rent.RecipientPhoneNumber);
        }
Exemplo n.º 11
0
        public async Task GetById_ShouldFindRent()
        {
            var rent = await RentsService.GetById(DefaultData.Rents.RentIvanov1.Id);

            Assert.That(rent, Is.Not.Null);
            Assert.That(rent.Id, Is.EqualTo(DefaultData.Rents.RentIvanov1.Id));
        }
Exemplo n.º 12
0
        public async Task DeleteProductAsyncShouldNotDeleteProductWithInvalidProductId()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = RentStatus.Open
            };

            dbContext.Rents.Add(rent);

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

            var products = new List <Product>
            {
                new Product {
                    Name = "Canon M50"
                },
                new Product {
                    Name = "Phanyom 4"
                },
                new Product {
                    Name = "Vanguard bag"
                },
                new Product {
                    Name = "Ikan SM"
                },
            };

            dbContext.Products.AddRange(products);

            var rentProducts = new List <RentProduct>
            {
                new RentProduct {
                    Product = products.First()
                },
                new RentProduct {
                    Product = products.Last()
                },
            };

            rent.Products = rentProducts;
            await dbContext.SaveChangesAsync();

            var rentsService    = new RentsService(dbContext, userService.Object, invoicesService.Object, productService.Object);
            var delereProductId = 1000;
            await rentsService.DeleteProductAsync(delereProductId, rent);

            var openRentProducts = dbContext.RentProducts.ToList();

            Assert.Equal(2, openRentProducts.Count());
        }
Exemplo n.º 13
0
        public async Task RentProductsByRentIdAsyncShouldReturnAllOrderProductsInTheOrder()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = RentStatus.Open
            };

            dbContext.Rents.Add(rent);

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

            var products = new List <Product>
            {
                new Product {
                    Name = "Canon M50"
                },
                new Product {
                    Name = "Phanyom 4"
                },
                new Product {
                    Name = "Vanguard bag"
                },
                new Product {
                    Name = "Ikan SM"
                },
            };

            dbContext.Products.AddRange(products);

            var rentProducts = new List <RentProduct>
            {
                new RentProduct {
                    Product = products.First(), Quantity = 1
                },
                new RentProduct {
                    Product = products.Last(), Quantity = 1
                },
            };

            rent.Products = rentProducts;
            await dbContext.SaveChangesAsync();

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

            var rentdProducts = await rentsService.RentProductsByRentIdAsync(rent.Id);

            Assert.Equal(2, rentdProducts.Count());
        }
Exemplo n.º 14
0
        public async Task GetAll_ShouldReturnValidCount()
        {
            var rents = await RentsService.GetAll(null);

            Assert.That(rents.Count(), Is.EqualTo(Rents.Count));
            foreach (var rent in Rents)
            {
                Assert.That(rent.Count, Is.Not.EqualTo(0));
                Assert.That(rent.Subscriber, Is.Not.Null);
                Assert.That(rent.Book, Is.Not.Null);
            }
        }
Exemplo n.º 15
0
        public async Task GetOpenRentAsyncShouldReturnOpenRentByUser()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var user1 = new ApplicationUser {
                UserName = "******"
            };
            var user2 = new ApplicationUser {
                UserName = "******"
            };

            dbContext.Add(user1);
            dbContext.Add(user2);

            var rents = new List <Rent>
            {
                new Rent {
                    RentStatus = RentStatus.Open, Customer = user1
                },
                new Rent {
                    RentStatus = RentStatus.Pending, Customer = user1
                },
                new Rent {
                    RentStatus = RentStatus.Rented, Customer = user1
                },
                new Rent {
                    RentStatus = RentStatus.Open, Customer = user2
                },
                new Rent {
                    RentStatus = RentStatus.Returned, Customer = user1
                },
            };

            dbContext.Rents.AddRange(rents);
            await dbContext.SaveChangesAsync();

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

            userService.Setup(r => r.GetUserByUsername(user1.UserName))
            .Returns(user1);

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

            var userRent = await rentsService.GetOpenRentAsync(user1.UserName);

            Assert.Equal(user1.UserName, userRent.Customer.UserName);
            Assert.Equal(RentStatus.Open, userRent.RentStatus);
        }
Exemplo n.º 16
0
        public async Task Update_Deactivate_SuccessfullyDeactivated()
        {
            var rent = Rents.First(x => x.IsActive);

            rent.IsActive = false;
            var dto = Mapper.Map <RentDto>(rent);
            await RentsService.Update(rent.Id, dto);

            var updatedRent = Rents.First(x => x.Id == rent.Id);

            Assert.That(updatedRent.IsActive, Is.False);
        }
Exemplo n.º 17
0
        public void Create_SubscriberNull_ShouldThrowRentNotHasBookOrSubscriberException()
        {
            var rent = new RentDto()
            {
                Id       = Random.Next(int.MaxValue),
                Count    = 55,
                IsActive = true,
                Book     = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                Date     = DateTime.Now
            };

            Assert.Throws <RentNotHasBookOrSubscriberException>(async() => await RentsService.Create(rent));
        }
Exemplo n.º 18
0
        public async Task GetDetailsAsync_SouldReturn_DetaildInformation_IfEntityExist()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();
            var client = new Client {
                Id = 1, Name = "Margaritka 89"
            };
            await db.Clients.AddAsync(client);

            var property = new Property {
                Id = 1, Area = 2000, Name = "Warehouse"
            };
            await db.Properties.AddAsync(property);

            var firstRent = new RentAgreement
            {
                Id                     = 1,
                Description            = "Some",
                ParkingSlotDescription = "None",
                MonthlyPrice           = 2000,
                StartDate              = new DateTime(2018, 3, 3),
                Client                 = client,
                PropertyRents          = new List <PropertyRent>()
                {
                    new PropertyRent {
                        Property = property
                    }
                }
            };
            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService = new RentsService(mapper, db, null);

            var result = await rentService.GetDetailsAsync(1);

            result
            .Should()
            .BeOfType <RentDetailsModel>()
            .And
            .Match <RentDetailsModel>(r =>
                                      r.Client == "Margaritka 89" &&
                                      r.Description == "Some" &&
                                      r.EndDate == null &&
                                      r.MonthlyPrice == 2000 &&
                                      r.ParkingSlotDescription == "None" &&
                                      r.Properties.Any(x => x.Area == 2000) &&
                                      r.StartDate == new DateTime(2018, 3, 3)
                                      );
        }
Exemplo n.º 19
0
        public void Create_CountMoreCountOfBooks_ShouldThrownRentCountMoreCountOfBookException()
        {
            var rent = new RentDto()
            {
                Id         = Random.Next(int.MaxValue),
                Count      = DefaultData.Books.ClrVia.Count + 1,
                IsActive   = true,
                Book       = Mapper.Map <BookDto>(DefaultData.Books.ClrVia),
                Subscriber = Mapper.Map <SubscriberDto>(DefaultData.Subscribers.Maslov),
                Date       = DateTime.Now
            };

            Assert.Throws <RentCountMoreCountOfBookException>(async() => await RentsService.Create(rent));
        }
Exemplo n.º 20
0
        public async Task AllAsync_SouldReturn_CollectionWithActualRentAgreements_FromDb()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstRent = new RentAgreement {
                Id = 1, MonthlyPrice = 800, IsActual = false, Client = new Client {
                    Id = 1, Name = "Asen"
                }
            };
            var secondRent = new RentAgreement {
                Id = 2, MonthlyPrice = 900, IsActual = true, Client = new Client {
                    Id = 2, Name = "Boris"
                }
            };
            var thirdRent = new RentAgreement {
                Id = 3, MonthlyPrice = 1900, IsActual = true, Client = new Client {
                    Id = 3, Name = "Ceco"
                }
            };
            var forthRent = new RentAgreement {
                Id = 4, MonthlyPrice = 2900, IsActual = true, Client = new Client {
                    Id = 4, Name = "Asen"
                }
            };
            await db.RentAgreements.AddRangeAsync(firstRent, secondRent, thirdRent, forthRent);

            await db.SaveChangesAsync();

            var rentService = new RentsService(mapper, db, null);

            var result = await rentService.AllAsync();

            result
            .Should()
            .NotBeEmpty()
            .And
            .BeOfType <List <RentListingViewModel> >()
            .And
            .HaveCount(3)
            .And
            .Match(c =>
                   c.ElementAt(0).Id == 4 &&
                   c.ElementAt(1).Id == 2);
        }
Exemplo n.º 21
0
        public async Task GetPendingRentsAsyncShouldReturnNothingIfNoPendingRentss()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rents = new List <Rent>
            {
                new Rent {
                    RentStatus = RentStatus.Open
                },
                new Rent {
                    RentStatus = RentStatus.Rented
                },
                new Rent {
                    RentStatus = RentStatus.Denied
                },
                new Rent {
                    RentStatus = RentStatus.Denied
                },
                new Rent {
                    RentStatus = RentStatus.Returned
                },
                new Rent {
                    RentStatus = RentStatus.Rented
                },
            };

            dbContext.Rents.AddRange(rents);
            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);

            var pendingRents = await rentsService.GetPendingRentsAsync();

            Assert.Empty(pendingRents);
        }
Exemplo n.º 22
0
        public async Task GetDetailsAsync_SouldReturn_Null_IfEntityDoNotExist()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();
            var client = new Client {
                Id = 1, Name = "Margaritka 89"
            };
            await db.Clients.AddAsync(client);

            var property = new Property {
                Id = 1, Area = 2000, Name = "Warehouse"
            };
            await db.Properties.AddAsync(property);

            var firstRent = new RentAgreement
            {
                Id                     = 1,
                Description            = "Some",
                ParkingSlotDescription = "None",
                MonthlyPrice           = 2000,
                StartDate              = new DateTime(2018, 3, 3),
                Client                 = client,
                PropertyRents          = new List <PropertyRent>()
                {
                    new PropertyRent {
                        Property = property
                    }
                }
            };
            await db.RentAgreements.AddAsync(firstRent);

            await db.SaveChangesAsync();

            var rentService = new RentsService(mapper, db, null);

            var result = await rentService.GetDetailsAsync(2);

            result
            .Should()
            .BeNull();
        }
Exemplo n.º 23
0
        public void Create_BookNotHasAvailableCount_ShouldThrownBookNotHasAvailableCountException()
        {
            var book     = Books.First();
            var reserved = Rents.Where(x => x.Book.Id == book.Id).Sum(x => x.Count);

            Rents.Add(new Rent(book, Subscribers.First(), book.Count - reserved)
            {
                Id   = Random.Next(int.MaxValue),
                Date = DateTime.Now,
            });

            var dto = new RentDto()
            {
                Subscriber = Mapper.Map <SubscriberDto>(Subscribers.First()),
                Book       = Mapper.Map <BookDto>(book),
                Count      = 1,
                Date       = DateTime.Now,
            };

            Assert.Throws <NotHasAvailableBooksCountException>(async() => await RentsService.Create(dto));
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        public async Task GetRentByIdAsyncShouldNotReturnRentWhichIsOpen()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var rent = new Rent {
                RentStatus = RentStatus.Open
            };

            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);

            var searchedRent = await rentsService.GetRentByIdAsync(rent.Id);

            Assert.Null(searchedRent);
        }
Exemplo n.º 27
0
        public async Task GetById_ShoulReturnNull()
        {
            var rent = await RentsService.GetById(int.MaxValue);

            Assert.That(rent, Is.Null);
        }
Exemplo n.º 28
0
        public async Task CreateAsync_SouldReturn_True_IfAllArguentsAreCorrect()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var thirdRent = new RentAgreement {
                Id = 3, MonthlyPrice = 1900, IsActual = true
            };
            var forthRent = new RentAgreement {
                Id = 4, MonthlyPrice = 2900, IsActual = true
            };
            await db.RentAgreements.AddRangeAsync(thirdRent, forthRent);

            var client = new Client {
                Id = 1, Name = "Ivan"
            };
            await db.Clients.AddAsync(client);

            var propertyOne = new Property {
                Id = 1, Area = 800, IsActual = true
            };
            var propertyTwo = new Property {
                Id = 2, Area = 600, IsActual = true
            };
            await db.Properties.AddRangeAsync(propertyTwo, propertyOne);

            await db.SaveChangesAsync();

            var createModel = new CreateRentModel
            {
                StartDate              = new DateTime(2018, 3, 3),
                ClientId               = 1,
                Description            = "No Desc",
                ParkingSlotDescription = "Some Desc",
                MonthlyPrice           = 2000,
                PropertiesIds          = new List <int>()
                {
                    1, 2
                },
                CarSlots           = 1,
                CarMonthPrice      = 1,
                BusSlots           = 2,
                BusMonthPrice      = 2,
                TruckSlots         = 3,
                TruckMonthPrice    = 3,
                BigTruckSlots      = 4,
                BigTruckMonthPrice = 4,
                CarCageSlots       = 5,
                CarCageMonthPrice  = 5,
                OtherSlots         = 6,
                OtherMonthPrice    = 6
            };
            var monthlyRentMock = new Mock <IMonthlyRentsService>();

            monthlyRentMock
            .Setup(mr => mr.CreateAsync(It.IsAny <int>(), It.IsAny <decimal>(), It.IsAny <DateTime>()))
            .ReturnsAsync(true);
            var rentService = new RentsService(mapper, db, monthlyRentMock.Object);
            //Act
            var result = await rentService.CreateAsync(createModel);

            var createdRent = await db.RentAgreements
                              .FirstOrDefaultAsync(x => x.Description == "No Desc");

            //Assert
            result
            .Should()
            .BeTrue();

            createdRent.Should().BeOfType <RentAgreement>().And
            .Match <RentAgreement>(r =>
                                   r.ClientId == 1 &&
                                   r.StartDate == new DateTime(2018, 3, 3) &&
                                   r.ParkingSlotDescription == "Some Desc" &&
                                   r.MonthlyPrice == 2000M &&
                                   r.PropertyRents.Any(x => x.Property.Id == 2) &&
                                   r.ParkingSlots.Any(x => x.Price == 1M ||
                                                      x.Price == 2M ||
                                                      x.Price == 3M ||
                                                      x.Price == 4M ||
                                                      x.Price == 5M ||
                                                      x.Price == 6M));
        }