|
2 | 2 |
|
3 | 3 | public class BusinessExceptionTest |
4 | 4 | { |
| 5 | + [Fact] |
| 6 | + public void Constructor_SetNullBusinessErrorCollection() |
| 7 | + { |
| 8 | + // Arrange |
| 9 | + BusinessErrorCollection? businessErrors = null; |
| 10 | + |
| 11 | + // Act |
| 12 | + var businessEx = new BusinessException(businessErrors); |
| 13 | + |
| 14 | + // Assert |
| 15 | + Assert.Empty(businessEx.GetErrors()); |
| 16 | + Assert.Null(businessEx.InnerException); |
| 17 | + } |
| 18 | + |
| 19 | + [Fact] |
| 20 | + public void Constructor_SetBusinessErrorCollection() |
| 21 | + { |
| 22 | + // Arrange |
| 23 | + BusinessErrorCollection businessErrors = new BusinessErrorCollection(); |
| 24 | + businessErrors.AddOrMerge(new BusinessError("exceptionId1", new ErrorMessage("Error message 1."))); |
| 25 | + businessErrors.AddOrMerge(new BusinessError("exceptionId2", new ErrorMessage("Error message 2."))); |
| 26 | + |
| 27 | + // Act |
| 28 | + var businessEx = new BusinessException(businessErrors); |
| 29 | + |
| 30 | + // Assert |
| 31 | + Assert.Collection( |
| 32 | + businessEx.GetErrors(), |
| 33 | + error => |
| 34 | + { |
| 35 | + Assert.Equal("exceptionId1", error.ExceptionId); |
| 36 | + Assert.Equal("Error message 1.", error.ErrorMessage); |
| 37 | + }, |
| 38 | + error => |
| 39 | + { |
| 40 | + Assert.Equal("exceptionId2", error.ExceptionId); |
| 41 | + Assert.Equal("Error message 2.", error.ErrorMessage); |
| 42 | + }); |
| 43 | + Assert.Null(businessEx.InnerException); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void Constructor_SetBusinessErrorCollectionWithInnerException() |
| 48 | + { |
| 49 | + // Arrange |
| 50 | + Exception innerEx = new Exception(); |
| 51 | + BusinessErrorCollection businessErrors = new BusinessErrorCollection(); |
| 52 | + businessErrors.AddOrMerge(new BusinessError("exceptionId1", new ErrorMessage("Error message 1."))); |
| 53 | + businessErrors.AddOrMerge(new BusinessError("exceptionId2", new ErrorMessage("Error message 2."))); |
| 54 | + |
| 55 | + // Act |
| 56 | + var businessEx = new BusinessException(innerEx, businessErrors); |
| 57 | + |
| 58 | + // Assert |
| 59 | + Assert.Collection( |
| 60 | + businessEx.GetErrors(), |
| 61 | + error => |
| 62 | + { |
| 63 | + Assert.Equal("exceptionId1", error.ExceptionId); |
| 64 | + Assert.Equal("Error message 1.", error.ErrorMessage); |
| 65 | + }, |
| 66 | + error => |
| 67 | + { |
| 68 | + Assert.Equal("exceptionId2", error.ExceptionId); |
| 69 | + Assert.Equal("Error message 2.", error.ErrorMessage); |
| 70 | + }); |
| 71 | + Assert.Same(innerEx, businessEx.InnerException); |
| 72 | + } |
| 73 | + |
| 74 | + [Fact] |
| 75 | + public void Constructor_SetNullBusinessErrorCollectionWithInnerException() |
| 76 | + { |
| 77 | + // Arrange |
| 78 | + Exception innerEx = new Exception(); |
| 79 | + BusinessErrorCollection? businessErrors = null; |
| 80 | + |
| 81 | + // Act |
| 82 | + var businessEx = new BusinessException(innerEx, businessErrors); |
| 83 | + |
| 84 | + // Assert |
| 85 | + Assert.Empty(businessEx.GetErrors()); |
| 86 | + Assert.Same(innerEx, businessEx.InnerException); |
| 87 | + } |
| 88 | + |
5 | 89 | [Fact] |
6 | 90 | public void BusinessErrors_ReturnsAddedBusinessErrors() |
7 | 91 | { |
|
0 commit comments