Ejemplo n.º 1
0
        public async Task CreateWarehouseShouldCreateNewWarehouse()
        {
            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly);
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var service = new WarehouseService(context);

            var warehouse = new WarehouseViewModel
            {
                Address = new AddressViewModel
                {
                    City          = "Test",
                    StreetAddress = "Test",
                    Zip           = "test",
                    Country       = "Test",
                },
                Name       = "Test",
                IsSellable = true,
            };

            await service.CreateWarehouseAsync(warehouse);

            var warehouseCount = context.Warehouses.Count();
            var expectedCount  = 1;

            Assert.Equal(expectedCount, warehouseCount);
        }
        public async Task UpdateWarehouseCityWhenValidID(string warehouseName, int cityID, int countryID, int addressID, bool toSave)
        {
            //Arrange
            var UpdateWarehouseCityWhenValidID = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = Utils.GetOptions(UpdateWarehouseCityWhenValidID);

            Utils.SeedDatabase(options);

            using (var arrangeContext = new StoreSystemDbContext(options))
            {
                arrangeContext.Countries.Add(new Country()
                {
                    CountryID = countryID
                });
                arrangeContext.Cities.Add(new City()
                {
                    CityID = cityID
                });
                arrangeContext.Addresses.Add(new Address()
                {
                    AddressID = addressID
                });
                await arrangeContext.SaveChangesAsync();
            }

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

                //Act
                var actualWarehouse = await sut.CreateWarehouseAsync(warehouseName, countryID, cityID, addressID, toSave);

                Assert.AreNotEqual(null, actualWarehouse);
                Assert.AreEqual(warehouseName, actualWarehouse.Name);
                Assert.AreEqual(countryID, actualWarehouse.CountryID);
                Assert.AreEqual(cityID, actualWarehouse.CityID);
                Assert.AreEqual(addressID, actualWarehouse.AddressID);

                var updatedWarehouse = await sut.UpdateWarehouseAsync(actualWarehouse.WarehouseID, warehouseName, countryID, 1, addressID, toSave);

                //Assert
                Assert.AreEqual(addressID, updatedWarehouse.AddressID);
                Assert.AreEqual(countryID, updatedWarehouse.CountryID);
                Assert.AreEqual(1, updatedWarehouse.CityID);
                Assert.AreEqual(warehouseName, updatedWarehouse.Name);
            }
        }
        public async Task DeleteWarehouseWhenInvalidID(string warehouseName, int cityID, int countryID, int addressID, bool toSave)
        {
            //Arrange
            var FindWarehouseWhenValidWarehouseIdIsPassed = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = Utils.GetOptions(FindWarehouseWhenValidWarehouseIdIsPassed);

            Utils.SeedDatabase(options);

            using (var arrangeContext = new StoreSystemDbContext(options))
            {
                arrangeContext.Countries.Add(new Country()
                {
                    CountryID = countryID
                });
                arrangeContext.Cities.Add(new City()
                {
                    CityID = cityID
                });
                arrangeContext.Addresses.Add(new Address()
                {
                    AddressID = addressID
                });
                await arrangeContext.SaveChangesAsync();
            }

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

                //Act
                var actualWarehouse = await sut.CreateWarehouseAsync(warehouseName, countryID, cityID, addressID, toSave);

                //Assert
                Assert.AreNotEqual(null, actualWarehouse);
                Assert.AreEqual(warehouseName, actualWarehouse.Name);
                Assert.AreEqual(countryID, actualWarehouse.CountryID);
                Assert.AreEqual(cityID, actualWarehouse.CityID);
                Assert.AreEqual(addressID, actualWarehouse.AddressID);

                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.DeleteWarehouseAsync(actualWarehouse.WarehouseID + 100));
            }
        }
        public async Task UpdateWarehouseWithWhiteSpaceNameWhenInvalidID(string warehouseName, int cityID, int countryID, int addressID, bool toSave)
        {
            //Arrange
            var UpdateWarehouseWithWhiteSpaceNameWhenInvalidID = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = Utils.GetOptions(UpdateWarehouseWithWhiteSpaceNameWhenInvalidID);

            Utils.SeedDatabase(options);

            using (var arrangeContext = new StoreSystemDbContext(options))
            {
                arrangeContext.Countries.Add(new Country()
                {
                    CountryID = countryID
                });
                arrangeContext.Cities.Add(new City()
                {
                    CityID = cityID
                });
                arrangeContext.Addresses.Add(new Address()
                {
                    AddressID = addressID
                });
                await arrangeContext.SaveChangesAsync();
            }

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

                //Act
                var actualWarehouse = await sut.CreateWarehouseAsync(warehouseName, countryID, cityID, addressID, toSave);

                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.UpdateWarehouseAsync(-actualWarehouse.WarehouseID, "                ", countryID, cityID, addressID, toSave));
            }
        }
Ejemplo n.º 5
0
        public async Task ThrowsArgumentExceptionWhenWarehouseNameIsWhiteSpaseAndAddressIDIsInvalid(string warehouseName, int cityID, int countryID, int addressID, bool toSave)
        {
            //Arrange
            var ThrowsArgumentExceptionWhenWarehouseNameIsWhiteSpaseAndAddressIDIsInvalid = System.Reflection.MethodBase.GetCurrentMethod().Name;

            var options = Utils.GetOptions(ThrowsArgumentExceptionWhenWarehouseNameIsWhiteSpaseAndAddressIDIsInvalid);

            Utils.SeedDatabase(options);

            using (var arrangeContext = new StoreSystemDbContext(options))
            {
                //arrangeContext.Warehouses.Add(new Warehouse() { Name = warehouseName });
                arrangeContext.Countries.Add(new Country()
                {
                    CountryID = countryID
                });
                arrangeContext.Cities.Add(new City()
                {
                    CityID = cityID
                });
                //arrangeContext.Addresses.Add(new Address() { AddressID = addressID });
                await arrangeContext.SaveChangesAsync();
            }

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

                //Act & Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await sut.CreateWarehouseAsync(warehouseName, countryID, cityID, addressID, toSave));
            }
        }