2using System.Threading.Tasks;
26 var res = await customerService.GetAllCustomers();
42 var res = await Task.Run(() => customersService.GetAllCustomers());
58 var res = await Assert.ThrowsAsync<InvalidOperationException>(() => customerService.AddCustomer(
new Customer()
60 OrganizationNumber =
"111 111 111",
61 CustomerName =
"Customer1",
62 CustomerSince = DateTime.Now
64 Assert.Equal($
"OrgNr or CustomerName already Exist", res.Message);
76 var res = await Task.Run(() => customerService.AddCustomer(
new Customer()
78 OrganizationNumber =
"111 111 111",
79 CustomerName =
"Customer1",
80 CustomerSince = DateTime.Now,
101 var name = await Assert.ThrowsAsync<InvalidOperationException>(() => customerService.UpdateCustomer(
new Customer()
103 OrganizationNumber =
"111 111 111",
104 CustomerName =
"Customer1",
105 CustomerSince = DateTime.Now
108 var number = await Assert.ThrowsAsync<InvalidOperationException>(() => customerService.UpdateCustomer(
new Customer()
110 OrganizationNumber =
"111 111 111",
111 CustomerName =
"Customer123",
112 CustomerSince = DateTime.Now
115 Assert.Equal($
"Kunde med navn 'Customer1' finnes allerede.", name.Message);
116 Assert.Equal($
"Kunde med org.nr. '111 111 111' finnes allerede.", number.Message);
129 var res = customerService.UpdateCustomer(
new Customer()
131 OrganizationNumber =
"999 999 999",
132 CustomerName =
"999999",
133 CustomerSince = DateTime.Now
139 Assert.True(res.IsFaulted);
152 var customer = customerService.GetCustomerById(1);
153 customer.Result.CustomerName =
"CustomerUpdated";
154 var res = await Task.Run(() => customerService.UpdateCustomer(customer.Result));
157 Assert.Equal(customer.Result.CustomerName, res.CustomerName);
172 var res = async () => await customerService.DeactivateCustomer(2);
174 await Assert.ThrowsAsync<NullReferenceException>(res);
188 var res = await Task.Run(() => customerService.DeactivateCustomer(1));
190 Assert.True(res.IsActive ==
false);
206 var res = async () => await customerService.ActivateCustomer(2);
208 await Assert.ThrowsAsync<NullReferenceException>(res);
222 var res = await Task.Run(() => customerService.ActivateCustomer(1));
224 Assert.True(res.IsActive ==
true);
238 var firstEntry = await Task.Run(() => customerService.GetRegionSeq(region:
context.Customers.Find(1).Region));
239 var secondEntry = await Task.Run(() => customerService.GetRegionSeq(region:
context.Customers.Find(2).Region));
240 Assert.Equal(1, firstEntry);
241 Assert.Equal(2, secondEntry);
254 var res = await Task.Run(() => customerService.AddCustomer(
new Customer()
256 CustomerName =
"Ikke brukt",
257 OrganizationNumber =
"000 000 000",
258 CustomerSince = DateTime.Now,
266 Assert.Equal(3, res.RegionSeq);
CustomerService class inserts and updates Customer in the Database
CustomerService Testing Environment
async Task CustomerService_GetRegionSeq()
passes if region reference is found on customers in customerlist
async void DeactivateCustomer_CustomerDoesNotExist()
passes if trying to deactivate a customer that does not exist, and it throws NullReferenceException
async Task AddCustomer_CustomerDoesNotExist()
passes if customer does not exist and is correctly added
async Task AddCustomer_CustomerNameAlreadyExist()
passes if customername already exist in customer-list and it throws InvalidOperationException
async Task ActivateCustomer_CustomerExist()
passes if trying to activate a customer that exist
async Task UpdateCustomer_CustomerNameAndOrganizationNumberExist()
passes if customername and organizationname already exist in customer-list, and it throws InvalidOper...
async void UpdateCustomer_CustomerDoesNotExistReturnsNull()
passes if trying to update a customer that does not exist in customerlist
async Task UpdateCustomer_CustomerDoesExistReturnsEntity()
passes if customer exist in customerlist, and is correctly updated
async Task DeactivateCustomer_CustomerExist()
passes if trying to deactivate customer that does exist
async void ActivateCustomer_CustomerDoesNotExist()
passes if trying to activate a customer that does not exist, and it throws NullReferenceException
async void GetAllCustomers_ListIsEmpty()
passes if customerlist is empty
async Task GetAllCustomers_AddedElementExist()
passes if customer-list is not empty after adding a customer
async Task CustomerServiceCreatesNewRegion_GetRegionSeq()
passes if trying to add customer with new region gets a new regionseq
static DataContext GetContext()
Creates a testcontext for testing
Reusable methods for inserting information into tests
static DataContext InsertCustomers(DataContext context)
Insert two Customers into DataContext
static DataContext InsertCustomerWithRegionData(DataContext context)
Inserts two Customer combined with region data into the DataContext
static DataContext InsertCustomer(DataContext context)
Inserting customer into DB (only non nullable field defined)