-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerTests.cs
More file actions
147 lines (110 loc) · 5.05 KB
/
Copy pathCustomerTests.cs
File metadata and controls
147 lines (110 loc) · 5.05 KB
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
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace MBDEVproAPI.Tests
{
public class CustomerTests
{
#region Variables and Constructors
private ICustomerService _customerService;
#endregion
public CustomerTests(ICustomerService customerService) {
_customerService = customerService;
}
//using MBDEVproAPI.DataModel.Entities;
private static readonly List<Customer> _customerListEntity = new()
{ new Customer { CustomerID = 1, BusinessID = 52466, Company = "cheeseburger", FirstName = "Jeff", LastName = "Smith", Email = "Jeff@Smith.com", Address = "123 Test St" }
};
//using MBDEVproAPI.Common.Models;
private static readonly List<CustomerModel> _customerListModel = new()
{ new CustomerModel { CustomerID = 1, BusinessID = 52466, Company = "cheeseburger", FirstName = "Jeff", LastName = "Smith", Email = "Jeff@Smith.com", Address = "123 Test St" }
};
#region commented out code
//public int CustomerID { get; set; }
//public int BusinessID { get; set; }
//public string? Company { get; set; }
//public string FirstName { get; set; } = String.Empty;
//public string LastName { get; set; } = String.Empty;
//public string Email { get; set; } = String.Empty;
//public string? Title { get; set; }
//public string? BPhone { get; set; }
//public string? HPhone { get; set; }
//public string? MPhone { get; set; }
//public string? Fax { get; set; }
//public string Address { get; set; } = String.Empty;
//public string City { get; set; } = String.Empty;
//public string State { get; set; } = String.Empty;
//public string ZIPCode { get; set; } = String.Empty;
//public string Country { get; set; } = String.Empty;
//public string? WebPage { get; set; }
//public string? Notes { get; set; }
//public string? Photo { get; set; }
//public string? Map { get; set; }
//public CustomerTests()
//{
// var mock = new Mock<ICustomerService>();
// mock.Setup(s => s.GetCustomerAsync(It.IsAny<int>()))
// .ReturnsAsync((int id) => _customerListEntity.FirstOrDefault(c => c.CustomerID == id) ?? new Customer());
// mock.Setup(s => s.GetAllCustomersVMAsync(It.IsAny<int>()))
// .ReturnsAsync((int businessId) => new CustomerViewModel { CustomerList = _customerListEntity.Select(x => Mapper.MapObject(x, new CustomerModel())).ToList() });
// _customerService = mock.Object;
//}
//public class CustomerTests
//{
// private ICustomerService _customerService;
// public CustomerTests()
// {
// _customerService = new TestCustomerService();
// }
// private static readonly List<Customer> _customerListEntity = new()
// {
// new Customer { CustomerID = 1, BusinessID = 52466, Company = "cheeseburger", FirstName = "Jeff", LastName = "Smith", Email = "Jeff@Smith.com", Address = "123 Test St" }
// };
// // Simple test-only implementation
// private class TestCustomerService : ICustomerService
// {
// public Task<Customer> GetCustomerAsync(int CustomerID)
// {
// var c = _customerListEntity.FirstOrDefault(x => x.CustomerID == CustomerID);
// return Task.FromResult(c ?? new Customer());
// }
// public Task<CustomerViewModel> GetAllCustomersVMAsync(int BusinessID)
// {
// var vm = new CustomerViewModel { CustomerList = _customerListEntity.Select(x => Mapper.MapObject(x, new CustomerModel())).ToList() };
// return Task.FromResult(vm);
// }
// // Implement other members of ICustomerService as no-op or throw NotImplementedException
// // ...
// }
// // tests follow...
//}
#endregion
#region Tests
[Fact]
public async Task GetCustomerAsync()
{
var customer = await _customerService.GetCustomerAsync(3);
Assert.NotNull(customer);
}
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
[InlineData(5)]
public async Task GetCustomerAsyncID(int id)
{
var customer = await _customerService.GetCustomerAsync(id);
Assert.NotNull(customer);
}
[Theory]
[InlineData(52466)]
public async Task GetAllCustomersVMAsyncTest(int id)
{
var customers = await _customerService.GetAllCustomersVMAsync(id);
Assert.NotNull(customers);
}
#endregion
}
}