Esempio n. 1
0
        public async Task AddPurchaseWhenPurchaseIDAndWarehouseIDExist(int validWarehouseID, int validPurchaseID)
        {
            //Arrange
            var AddPurchaseWhenPurchaseIDAndWarehouseIDExist = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = Utils.GetOptions(AddPurchaseWhenPurchaseIDAndWarehouseIDExist);

            Utils.SeedDatabase(options);

            using (var arrangeContext = new StoreSystemDbContext(options))
            {
                arrangeContext.Warehouses.Add(new Warehouse()
                {
                    WarehouseID = validWarehouseID
                });
                arrangeContext.Purchases.Add(new Purchase()
                {
                    PurchaseID = validPurchaseID
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var context = new StoreSystemDbContext(options))
            {
                var sut = new WarehouseService(context);

                //Act
                var isAdded = await sut.AddPurchaseToWarehouseAsync(validWarehouseID, validPurchaseID);

                var addedPurchase = context.Warehouses.Find(validWarehouseID).Purchases
                                    .Where(x => x.PurchaseID == validPurchaseID)
                                    .FirstOrDefault();

                //Assert
                Assert.AreEqual(true, isAdded);
                Assert.AreEqual(validPurchaseID, addedPurchase.PurchaseID);
            }
        }
Esempio n. 2
0
        public async Task ThrowsArgumentExceptionWhenWarehouseIDDoesNotExist(int validWarehouseID, int validPurchaseID)
        {
            //Arrange
            var ThrowsArgumentExceptionWhenWarehouseIDDoesNotExist = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = Utils.GetOptions(ThrowsArgumentExceptionWhenWarehouseIDDoesNotExist);

            Utils.SeedDatabase(options);

            using (var arrangeContext = new StoreSystemDbContext(options))
            {
                arrangeContext.Purchases.Add(new Purchase()
                {
                    PurchaseID = validPurchaseID
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var context = new StoreSystemDbContext(options))
            {
                var sut = new WarehouseService(context);

                //Act & Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.AddPurchaseToWarehouseAsync(validWarehouseID, validPurchaseID));
            }
        }