-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountryUnitTesting.cs
161 lines (134 loc) · 5.64 KB
/
CountryUnitTesting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//using adotoaspcorewebapi.Controllers;
//using adotoaspcorewebapi.Data;
//using adotoaspcorewebapi.Models;
//using Microsoft.AspNetCore.Http.HttpResults;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.Extensions.Hosting;
//using Moq;
//using System.Diagnostics.Metrics;
//using System.Net;
//namespace crudapitesting
//{
// public class CountryUnitTesting
// {
// private readonly Mock<ICountryDataAccess> _mockRepo;
// private readonly CountryController _controller;
// public CountryUnitTesting()
// {
// _mockRepo = new Mock<ICountryDataAccess>();
// _controller = new CountryController(_mockRepo.Object);
// }
// [Fact]
// public void Task_GetAllCountry_ReturnsAllCountries()
// {
// // Arrange
// var mockCountries = new List<CountryMaster>()
// {
// new CountryMaster() { CountryId = 1, CountryName = "Country A" },
// new CountryMaster() { CountryId = 2, CountryName = "Country B" }
// };
// _mockRepo.Setup(repo => repo.GetAllCountry()).Returns(mockCountries);
// // Act
// var result = _controller.GetAllCountry();
// // Assert
// var actionResult = Assert.IsType<OkObjectResult>(result);
// var model = Assert.IsAssignableFrom<ResponceModel<IEnumerable<CountryMaster>>>(actionResult.Value);
// Assert.Equal(2, model.Data.Count());
// }
// [Fact]
// public void Task_GetAllCountry_ReturnsBadRequestResult()
// {
// //Arrange
// var mockCountries = new List<CountryMaster>()
// {
// new CountryMaster() { CountryId = 1, CountryName = "Country A" },
// new CountryMaster() { CountryId = 2, CountryName = "Country B" }
// };
// _mockRepo.Setup(repo => repo.GetAllCountry()).Returns(mockCountries);
// //Act
// var data = _controller.GetAllCountry();
// data = null;
// if (data != null)
// //Assert
// Assert.IsType<BadRequestResult>(data);
// }
// [Fact]
// public void Task_GetAllCountryByID_ReturnsAllCountries()
// {
// // Arrange
// var mockCountries = new CountryMaster() { CountryId = 1, CountryName = "Country A" };
// _mockRepo.Setup(repo => repo.GetCountryById(1)).Returns(mockCountries);
// // Act
// var result = _controller.GetCountryById(1);
// // Assert
// var actionResult = Assert.IsType<OkObjectResult>(result);
// var model = Assert.IsAssignableFrom<ResponceModel<CountryMaster>>(actionResult.Value);
// Assert.Equal(mockCountries.CountryId, model.Data.CountryId);
// Assert.Equal(mockCountries.CountryName, model.Data.CountryName);
// }
// [Fact]
// public void Task_GetAllCountryByID_ReturnsBadRequestResult()
// {
// //Arrange
// var mockCountries = new CountryMaster() { CountryId = 1, CountryName = "Country A" };
// _mockRepo.Setup(repo => repo.GetCountryById(1)).Returns(mockCountries);
// //Act
// var data = _controller.GetCountryById(1);
// data = null;
// //Assert
// if (data != null)
// Assert.IsType<BadRequestResult>(data);
// }
// [Fact]
// public void Task_GetAllCountryByID_ReturnsNotFound()
// {
// //Arrange
// _mockRepo.Setup(repo => repo.GetCountryById(4)).Returns((CountryMaster)null);
// //Act
// var data = _controller.GetCountryById(4);
// //Assert
// Assert.IsType<OkObjectResult>(data);
// var okResult = data as OkObjectResult;
// Assert.NotNull(okResult);
// var response = okResult.Value as ResponceModel<CountryMaster>;
// Assert.NotNull(response);
// Assert.Equal((int)HttpStatusCode.NotFound, response.Status);
// }
// [Fact]
// public async void Task_AddInvalideCountryData_ReturnBadRequest()
// {
// //Arrange
// var countrymaster = new CountryMaster() { CountryId = 1, CountryName = "Country A" };
// //Act
// var data = _controller.AddCountry(countrymaster);
// //Assert
// Assert.IsType<BadRequestResult>(data);
// }
// [Fact]
// public void Task_AddCountryData_ReturnOkResult()
// {
// //Arrange
// var countrymaster = new CountryMaster() { CountryId = 1, CountryName = "Country A" };
// //Act
// var data = _controller.AddCountry(countrymaster);
// //Assert
// var actionResult = Assert.IsType<OkObjectResult>(data);
// Assert.NotNull(actionResult);
// // Optionally, you can further assert the content of the OkObjectResult
// var response = actionResult.Value as ResponceModel<string>;
// Assert.NotNull(response);
// Assert.Equal((int)HttpStatusCode.OK, response.Status);
// Assert.Equal("Data Added", response.Data);
// }
// [Fact]
// public void Task_AddValidData_MatchResult()
// {
// //Arrange
// var countrymaster = new CountryMaster() { CountryId = 1, CountryName = "Country A" };
// //Act
// var data = _controller.AddCountry(countrymaster);
// //Assert
// Assert.IsType<ConflictResult>(data);
// }
// }
//}