コード例 #1
0
        public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
        {
            // Arrange
            Mock <IDbSet <Publisher> > mockSetPublishers;
            var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
            var repository  = new PublishersRepository(mockContext.Object);
            var publishers  = repository.Get(1);

            // Act
            repository.Remove(publishers);
            // Assert
            mockSetPublishers.Verify(x => x.Remove((Publisher)publishers), Times.Once);
        }
 public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
 {
     // Arrange
     Mock<IDbSet<Publisher>> mockSetPublishers;
     var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
     var repository = new PublishersRepository(mockContext.Object);
     var publishers = repository.Get(1);
     // Act
     repository.Remove(publishers);
     // Assert
     mockSetPublishers.Verify(x => x.Remove((Publisher)publishers), Times.Once);
 }
コード例 #3
0
        /* Remove */

        private void Remove(object sender, EventArgs e)
        {
            if (!CheckForSelectedItem())
            {
                return;
            }

            var removeConfirmation = MessageBox.Show($@"Are you sure you want to remove this entity?", @"Remove",
                                                     MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (removeConfirmation != DialogResult.Yes)
            {
                return;
            }

            switch (_option)
            {
            case 1:
                var removeDoubleConfirmationAuthor = MessageBox.Show($@"Removing this author will also remove all of his books and loans related to them!", @"Remove",
                                                                     MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if (removeDoubleConfirmationAuthor != DialogResult.OK)
                {
                    return;
                }
                _authorsRepository.Remove(entitiesListBox.SelectedItem as Author);
                break;

            case 2:
                var removeDoubleConfirmationPublisher = MessageBox.Show($@"Removing this publisher will also remove all of his books and loans related to them!", @"Remove",
                                                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if (removeDoubleConfirmationPublisher != DialogResult.OK)
                {
                    return;
                }
                _publishersRepository.Remove(entitiesListBox.SelectedItem as Publisher);
                break;

            case 3:
                var removeDoubleConfirmationStudent = MessageBox.Show($@"Removing this student will also remove all related loans!", @"Remove",
                                                                      MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if (removeDoubleConfirmationStudent != DialogResult.OK)
                {
                    return;
                }
                _studentsRepository.Remove(entitiesListBox.SelectedItem as Student);
                break;

            case 4:
                var removeDoubleConfirmationBook = MessageBox.Show($@"Removing this book will also remove all related loans!", @"Remove",
                                                                   MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if (removeDoubleConfirmationBook != DialogResult.OK)
                {
                    return;
                }
                _booksRepository.Remove(entitiesListBox.SelectedItem as Book);
                break;

            case 5:
                _loansRepository.Remove(entitiesListBox.SelectedItem as Loan);
                break;

            default:
                CommonErrorMessage();
                break;
            }

            RefreshList();
        }