public void UpdateAsync_Any_ReplaceOneAsyncCalled() { string id = "AnyId"; var model = new AnyModel { AnyString = "AnyString" }; _repository.UpdateAsync(id, model); A.CallTo(() => _collection.ReplaceOneAsync(A <Expression <Func <AnyModel, bool> > > .Ignored, model)).MustHaveHappenedOnceExactly(); }
public void Create_Any_InsertOneCalled() { // Arrange var model = new AnyModel { AnyString = "AnyString" }; // Act _repository.Create(model); // Assert A.CallTo(() => _collection.InsertOne(model, null, default)).MustHaveHappenedOnceExactly(); }
public void Create_CreateForbidden_ReturnsForbidden() { // Arrange var readOnlyController = new AnyReadOnlyController(_repository, _logger); var model = new AnyModel(); // Act var result = readOnlyController.Create(model) as ObjectResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(403); A.CallTo(() => _repository.Create(model)).MustNotHaveHappened(); }
public ActionResult UploadAction(AnyModel model, List <HttpPostedFileBase> fileUpload) { // Your Code - / Save Model Details to DB // Handling Attachments - foreach (HttpPostedFileBase item in fileUpload) { if (item != null && Array.Exists(model.FilesToBeUploaded.Split(','), s => s.Equals(item.FileName))) { item.SaveAs(HttpContext.Server.MapPath("~/assets/") + item.FileName); // Console.WriteLine(item.filename); } } return(View("Index")); }
public void Update_UpdateForbidden_ReturnsForbidden() { // Arrange var readOnlyController = new AnyReadOnlyController(_repository, _logger); string id = ObjectId.GenerateNewId().ToString(); var model = new AnyModel(); // Act var result = readOnlyController.Update(id, model) as ObjectResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(403); A.CallTo(() => _repository.Update(id, model)).MustNotHaveHappened(); }
public ActionResult UploadAction(AnyModel model, List<HttpPostedFileBase> fileUpload) { // Your Code - / Save Model Details to DB // Handling Attachments - foreach (HttpPostedFileBase item in fileUpload) { if (item != null && Array.Exists(model.FilesToBeUploaded.Split(','), s => s.Equals(item.FileName))) { item.SaveAs(HttpContext.Server.MapPath("~/assets/") + item.FileName); // Console.WriteLine(item.filename); } } return View("Index"); }
public void Create_AnyModel_ModelCreated() { // Arrange var model = new AnyModel { Id = ObjectId.GenerateNewId().ToString(), AnyString = "AnyString" }; // Act var result = _controller.Create(model) as OkResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(200); A.CallTo(() => _repository.Create(model)).MustHaveHappenedOnceExactly(); }
public ActionResult UploadAction(AnyModel model, List <HttpPostedFileBase> fileUpload, short AlbumID) { string mes = ""; if (fileUpload.Count > 0) { List <string> l_path = new List <string>(); string prefix = DateTime.Now.ToString("ddMMyyyy_HHmmssfff", CultureInfo.InvariantCulture); int i = 0; //Datatable DataTable dt = new DataTable(); dt.Columns.Add("TenFile"); dt.Columns.Add("KieuAnh"); dt.Columns.Add("URL"); dt.Columns.Add("LoaiAnhID"); // Handling Attachments - foreach (HttpPostedFileBase item in fileUpload) { if (item != null && Array.Exists(model.FilesToBeUploaded.Split(','), s => s.Equals(item.FileName)) && CommonFunc.IsImage(item)) { i++; //Save or do your action - Each Attachment ( HttpPostedFileBase item ) var fileName = prefix + "_" + i.ToString() + Path.GetExtension(item.FileName); var path = Path.Combine(Server.MapPath("~/images/upload/album/" + AlbumID.ToString()), fileName); FileInfo file = new FileInfo(path); if (!file.Exists) { l_path.Add("/images/upload/album/" + AlbumID.ToString() + "/" + fileName); item.SaveAs(path); // Add row into datatable dt.Rows.Add(fileName, null, "/images/upload/album/" + AlbumID.ToString() + "/" + fileName, 2); } } } if (new Anh().Add(dt, AlbumID, "", "") <= 0) { deleteFiles(l_path); mes += "Upload không thành công!"; } else { mes += "Upload ảnh thành công!"; } } return(View("UploadAnh")); }
public async Task Update_AnyModel_ModelUpdated() { // Arrange string id = ObjectId.GenerateNewId().ToString(); var model = new AnyModel { Id = id, AnyString = "AnyString" }; // Act var result = await _controller.Update(id, model) as OkResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(200); A.CallTo(() => _repository.UpdateAsync(id, model)).MustHaveHappenedOnceExactly(); }
public void Read_AnyId_ReturnsModel() { // Arrange string id = ObjectId.GenerateNewId().ToString(); var expected = new AnyModel { Id = id, AnyString = "AnyString" }; A.CallTo(() => _repository.Find(id)).Returns(expected); // Act var result = _controller.Read(id).Result as OkObjectResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(200); var actual = result.Value as AnyModel; actual.Should().Be(expected); }