Esempio n. 1
0
        public async Task NoteControllerPostDelete()
        {
            var data  = new NoteApiDataHandler();
            var model = NoteData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <NotesByRefId>())).Returns(model);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <Notes> >())).Returns(model);

            var controller = new NoteController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Delete(NoteData.FirstId, "0") as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().NotBeNull();

            var check = result.Value as NotableViewModel;

            check.Notes.Name.Should().Be(model.Name);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <NotesByRefId>()), Times.Once);
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <Notes> >()), Times.Once());
        }
        public void Delete()
        {
            // Act
            var badResponse = _controller.Delete(1, 4);

            // Assert
            Assert.IsType <OkObjectResult>(badResponse);
        }
        public void NoteController_DeleteNote_ShouldReturnCorrectInt()
        {
            _mockService.CallCount = 1;

            var result = _controller.Delete(1);

            Assert.AreEqual(0, _mockService.CallCount);
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Esempio n. 4
0
        public void DeleteNoteTest(string header, string description, int id)
        {
            Note note = new Note(header, description);

            NoteController noteController = new NoteController();

            noteController.Create(header, description);
            noteController.Delete(id);

            Assert.NotEqual(note, noteController.GetNote(id));
        }
        public void DeleteExistingNote()
        {
            Note note = notes[1];

            var controller = new NoteController(_edbContext);

            controller.Delete(note.NoteId);

            Note result = (from n in _edbContext.Note where n.NoteId == note.NoteId select n).FirstOrDefault();

            Assert.Null(result);
        }
Esempio n. 6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstNotes.SelectedIndex < 0)
            {
                MessageBox.Show("Not seç");
                return;
            }

            Guid noteID       = (Guid)lstNotes.SelectedValue;
            Note selectedNote = _noteController.GetNote(noteID);

            _noteController.Delete(selectedNote);
            FillList();
        }
        public void DeleteShouldReturnToIndex()
        {
            int noteId   = 1;
            var mockRepo = new Mock <INoteRepository>();

            mockRepo.Setup(repo => repo.DeletNote(noteId)).Returns(1);
            var noteController = new NoteController(mockRepo.Object);

            var actual = noteController.Delete(noteId);

            var actionResult = Assert.IsType <RedirectToActionResult>(actual);

            Assert.Null(actionResult.ControllerName);
            Assert.Equal("Index", actionResult.ActionName);
        }
Esempio n. 8
0
        public override void Run()
        {
            if (!(Owner is NoteController))
            {
                return;
            }

            NoteController controller = this.Owner as NoteController;
            bool           result     = controller.Delete();

            if (result)
            {
                ObjectSetChangedMessage message = new ObjectSetChangedMessage();
                message.ObjectName       = controller.ObjectName;
                message.ParentObjectName = controller.ParentObjectName;
                EventAggregationManager.SendMessage(message);
            }
        }
Esempio n. 9
0
        public async void Delete_Errors()
        {
            NoteControllerMockFacade mock = new NoteControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            NoteController controller = new NoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
Esempio n. 10
0
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0)
            {
                MessageBox.Show("Not seçiniz");
                return;
            }
            int  noteID   = (int)listBox1.SelectedValue;
            Note selected = _noteController.GetByID(noteID);
            bool result   = _noteController.Delete(selected);

            if (result)
            {
                MessageBox.Show("Not başarıyla silindi");
                FillNotes();
            }
            else
            {
                MessageBox.Show("Not Silinemedi.");
            }
        }
Esempio n. 11
0
        public async Task NoteControllerPostDeleteNotFound()
        {
            var data  = new NoteApiDataHandler();
            var model = NoteData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <NotesByRefId>())).Returns(null);

            var controller = new NoteController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Delete(NoteData.FirstId, "0") as NotFoundResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <NotFoundResult>();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <NotesByRefId>()), Times.Once);
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <Notes> >()), Times.Never());
        }
Esempio n. 12
0
        private void btnSil_Click(object sender, EventArgs e)
        {
            if (lstNotes.SelectedIndex < 0)
            {
                MessageBox.Show("Note seç");
                return;
            }

            int  noteID   = (int)lstNotes.SelectedValue;
            Note selected = _noteController.getById(noteID);
            bool result   = _noteController.Delete(selected);

            if (result)
            {
                MessageBox.Show("Not başarıyla silindi");
                FillNotes();
            }
            else
            {
                MessageBox.Show("Silinemedi !!!");
            }
        }
Esempio n. 13
0
        public void DeleteMethodDoesNothingIfParamIsIncorrect()
        {
            var testStore   = GetTestNotes();
            var userManager = TestUserManager <AppUser>();
            var repoMock    = new Mock <IRepository <Note> >();

            repoMock.Setup(x => x.DeleteAsync(It.IsAny <int?>())).Returns(async(int?id) =>
            {
                var noteToDelete = testStore.FirstOrDefault(x => x.Id == id);
                if (noteToDelete != null)
                {
                    testStore.Remove(noteToDelete);
                }
                return(noteToDelete);
            });
            repoMock.Setup(x => x.SaveAsync()).Callback(() => { });
            var repository     = repoMock.Object;
            var noteController = new NoteController(userManager, repository);

            var result = noteController.Delete(null);

            Assert.Equal(2, testStore.Count);
        }
Esempio n. 14
0
        public void DeleteMethodSuccessfullyDeleteNoteWithCorrectParam()
        {
            var testStore   = GetTestNotes();
            var userManager = TestUserManager <AppUser>();
            var repoMock    = new Mock <IRepository <Note> >();

            repoMock.Setup(x => x.DeleteAsync(It.IsAny <int?>())).Returns(async(int?id) =>
            {
                var noteToDelete = testStore.FirstOrDefault(x => x.Id == id);
                if (noteToDelete != null)
                {
                    testStore.Remove(noteToDelete);
                }
                return(noteToDelete);
            });
            repoMock.Setup(x => x.SaveAsync()).Callback(() => { });
            var repository     = repoMock.Object;
            var noteController = new NoteController(userManager, repository);

            var result = noteController.Delete(1);

            Assert.Single(testStore);
        }
Esempio n. 15
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstNotes.SelectedIndex < 0)
            {
                MessageBox.Show("Silmek istediğiniz notu seçiniz!");
                return;
            }

            Note deleteNote = _noteController.GetByID((int)lstNotes.SelectedValue);

            deleteNote.UserID = _currentUser.UserID;
            bool result = _noteController.Delete(deleteNote);

            if (result)
            {
                MessageBox.Show("Notunuz başarıyla silindi");
                FillNote();
            }
            else
            {
                MessageBox.Show("Notunuz silinirken bir hata oluştu");
            }
        }
        public void DeleteUnexistingNote()
        {
            Note note = new Note
            {
                NoteId = 11,
                Title  = "sadsad"
            };

            var controller = new NoteController(_edbContext);

            var exception = Assert.Throws <System.Web.Http.HttpResponseException>(() => controller.Delete(note.NoteId));

            Assert.Equal(exception.Response.StatusCode, HttpStatusCode.NotFound);
        }