libgit2 / libgit2/libgit2sharp
Diff class not mockable
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 3.5k
- Fork
- 925
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
The Diff class is not very mockable due to its dependency on a private Repository field that is only set from an internal constructor. I encountered this when attempting to mock a repository and its related object graph and then invoking Commands.Stage with that mocked repository. It resulted in a null ref because the Diff.repo field wasn't set.
Commands.Stage ends up calling the internal Diff.Compare method:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Commands/Stage.cs#L77
Compare ends up passing the Diff.repo field to WorkdirToIndex:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Diff.cs#L472
Which then blows up because repo is null:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Diff.cs#L506
The repo field is null because it only gets set by an internal constructor:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Diff.cs#L90
This prevents a good mocking solution because the internal constructor can't be called without reflection.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với LibGit2Sharp/Diff.cs, đặc biệt là constructor nội bộ, Compare và WorkdirToIndex, sau đó lần theo lời gọi từ LibGit2Sharp/Commands/Stage.cs. Tái hiện kịch bản Commands.Stage với repository giả lập được mô tả trong issue. Được xem là hoàn tất khi đường dẫn này không còn phụ thuộc vào reflection để tạo một Diff có thể sử dụng và không thất bại vì repository của nó là null.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp
- Lĩnh vực
- devtools
- Loại issue
- Tái cấu trúc
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100