public async Task CreatePart_WithCorrectData_ShouldSuccessfullyCreatePart()
        {
            string errorMessagePrefix = "PartService CreatePart() method does not work properly.";

            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _partService = new PartService(context);

            PartServiceModel part = new PartServiceModel()
            {
                Id           = "P3",
                Name         = "Break Pad For Trailer",
                Price        = 140.15M,
                UsedCount    = 0,
                Stock        = 5,
                AcquiredFrom = new PartsProviderServiceModel()
                {
                    Name = "Brembo"
                }
            };

            bool actualResult = await _partService.Create(part);

            Assert.True(actualResult, errorMessagePrefix);
        }
Example #2
0
        public async Task <bool> EditPart(PartServiceModel partServiceModel)
        {
            var part = partServiceModel.To <Part>();

            part.AcquiredFrom = await GetPartProviderByName(partServiceModel.AcquiredFrom.Name);

            _context.Parts.Update(part);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Example #3
0
        public async Task <bool> Create(PartServiceModel partServiceModel)
        {
            if (_context.Parts.Any(v => v.Name == partServiceModel.Name))
            {
                return(false);
            }

            Part part = AutoMapper.Mapper.Map <Part>(partServiceModel);

            part.AcquiredFrom = await GetPartProviderByName(partServiceModel.AcquiredFrom.Name);

            _context.Parts.Add(part);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
        public async Task <IActionResult> Create(PartCreateBindingModel partCreateBindingModel)
        {
            if (ModelState.IsValid)
            {
                PartServiceModel partServiceModel = AutoMapper.Mapper.Map <PartServiceModel>(partCreateBindingModel);
                var result = await _partService.Create(partServiceModel);

                if (result)
                {
                    return(this.RedirectToAction("All"));
                }

                this.ViewData["error"] = ControllerConstants.PartErrorMessage;
                return(this.View(partCreateBindingModel));
            }
            this.ViewData["error"] = ControllerConstants.InputErrorMessage;
            return(this.View(partCreateBindingModel));
        }
        public async Task GetPartByName_WithExistentName_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "PartService GetPartByName() method does not work properly.";

            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _partService = new PartService(context);

            PartServiceModel expectedData = context.Parts.SingleOrDefault(x => x.Name == "Blot 10.5x2").To <PartServiceModel>();
            PartServiceModel actualData   = await _partService.GetPartByName("Blot 10.5x2");

            Assert.True(expectedData.Name == actualData.Name, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly.");
            Assert.True(expectedData.UsedCount == actualData.UsedCount, errorMessagePrefix + " " + "UsedCount is not returned properly.");
            Assert.True(expectedData.Stock == actualData.Stock, errorMessagePrefix + " " + "Stock is not returned properly.");
            Assert.True(expectedData.AcquiredFrom.Name == actualData.AcquiredFrom.Name, errorMessagePrefix + " " + "AquiredFrom is not returned properly.");
        }