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)); }
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); }
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> >()); }
public ActionResult AddStorage(Storage storage, HttpPostedFileBase resim) { storage.ImagePath = ImageUploader.UploadImage("~/Pictures", resim); sRep.Add(storage); return(RedirectToAction("StorageList")); }