Exemplo n.º 1
0
        public IHttpActionResult PostStorage(StorageViewModel storage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            try
            {
                _storageRepository.Add(storage.ToModel());
            }
            catch (DbUpdateException)
            {
                if (StorageExist(storage.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = storage.Id }, storage));
        }
Exemplo n.º 2
0
        public void Add_CorrectPayload_AddItemToStorage()
        {
            // arrange
            var logger     = Substitute.For <ILogger <StorageRepository> >();
            var repository = new StorageRepository(logger);

            var storage = new Storage()
            {
                Id        = "testId1",
                Materials = new List <Material>()
                {
                    new Material()
                    {
                        Id       = "materialId1",
                        Name     = "materialName1",
                        Quantity = 12
                    }
                }
            };

            // act
            var actual = repository.Add(storage);

            // assert
            Assert.AreEqual(1, actual);
        }
Exemplo n.º 3
0
        public void Add_Null_LogInfo()
        {
            // arrange
            var logger     = Substitute.For <ILogger <StorageRepository> >();
            var repository = new StorageRepository(logger);

            // act
            var actual = repository.Add(null);

            // assert
            Assert.AreEqual(0, actual);
            logger.Received().Log(
                LogLevel.Information,
                Arg.Any <EventId>(),
                Arg.Is <object>(o => o.ToString() == "StorageRepository: Provided input model is null."),
                null,
                Arg.Any <Func <object, Exception, string> >());
        }
Exemplo n.º 4
0
 public ActionResult AddStorage(Storage storage, HttpPostedFileBase resim)
 {
     storage.ImagePath = ImageUploader.UploadImage("~/Pictures", resim);
     sRep.Add(storage);
     return(RedirectToAction("StorageList"));
 }