Ejemplo n.º 1
0
        public async Task EditSupplierAsync(SupplierAdminEditViewModel inputModel)
        {
            var supplier = await this.dbContext.Suppliers
                           .FirstOrDefaultAsync(a => a.Id == inputModel.Id);

            if (supplier == null)
            {
                throw new ArgumentNullException(string.Format(ServicesConstants.InvalidSupplierId, inputModel.Id));
            }

            supplier.IsDeleted = inputModel.IsDeleted;

            supplier.DeletedOn = inputModel.DeletedOn;

            supplier.CreatedOn = inputModel.CreatedOn;

            supplier.ModifiedOn = inputModel.ModifiedOn;

            supplier.Name = inputModel.Name;

            supplier.PriceToHome = inputModel.PriceToHome;

            supplier.PriceToOffice = inputModel.PriceToOffice;

            supplier.LogoUrl = inputModel.LogoUrl;

            supplier.IsDefault = inputModel.IsDefault;

            this.dbContext.Update(supplier);

            await this.dbContext.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task EditSupplierAsyncShouldThrowExceptionIfSupplierIsNull()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var suppliersService = new SuppliersService(dbContext, mapper);

            var supplierModel = new SupplierAdminEditViewModel
            {
                Name          = SupplierName,
                PriceToHome   = SupplierPriceToHome,
                PriceToOffice = SupplierPriceToOffice,
            };

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await suppliersService.EditSupplierAsync(supplierModel));

            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task <IActionResult> Edit(SupplierAdminEditViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.suppliersService.EditSupplierAsync(inputModel);

            return(this.RedirectToAction("All"));
        }
Ejemplo n.º 4
0
        public async Task EditSupplierAsyncShouldEditSupplierSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var suppliersService = new SuppliersService(dbContext, mapper);

            var supplier = new Supplier
            {
                Id            = SupplierId,
                Name          = SupplierName,
                PriceToHome   = SupplierPriceToHome,
                PriceToOffice = SupplierPriceToOffice,
            };

            await dbContext.Suppliers.AddAsync(supplier);

            await dbContext.SaveChangesAsync();

            var supplierModel = new SupplierAdminEditViewModel
            {
                Id            = supplier.Id,
                Name          = SupplierEditName,
                PriceToHome   = SupplierPriceToHome,
                PriceToOffice = SupplierPriceToOffice,
            };

            await suppliersService.EditSupplierAsync(supplierModel);

            var actual = await dbContext.Suppliers.FirstOrDefaultAsync(s => s.Name == supplier.Name);

            Assert.Equal(supplierModel.Name, actual.Name);
        }