5using Microsoft.EntityFrameworkCore;
7using Xunit.Abstractions;
32 ModuleLevelName =
"Stocks 1",
33 ModuleLevelRestriction =
"250M/100tr",
50 var res = await
service.GetAllModuleLevels();
69 var addedModuleLevel =
context.ModuleLevels.Add(moduleLevel);
70 await
context.SaveChangesAsync();
74 var res = await
service.GetAllModuleLevels();
78 Assert.Equal(moduleLevel.ModuleLevelName, res[0].ModuleLevelName);
94 var res = await
service.GetModuleLevelById(100);
112 await
context.SaveChangesAsync();
116 var res = await moduleService.GetModuleById(1);
137 var res = await
service.AddModuleLevel(moduleLevel);
139 Assert.Equal(moduleLevel.ModuleLevelName, res.ModuleLevelName);
140 Assert.NotNull(moduleLevel.Module);
158 await
service.AddModuleLevel(moduleLevel);
161 var ex = await Assert.ThrowsAsync<InvalidOperationException>(op);
177 ModuleLevelName =
"Stocks 1",
178 ModuleLevelRestriction =
"250M/100tr"
181 var op = async () => await
service.AddModuleLevel(moduleLevel);
183 await Assert.ThrowsAsync<DbUpdateException>(op);
ModuleLevelService class inserts and updates ModuleLevel in the Database
ModuleService class inserts and updates Module in the Database
ModuleLevelService Testing Environment
async void AddModuleLevel_DuplicateName()
passes if modulelevelname already exist, and it throws an InvalidOperationException
ModuleLevelServiceTest(ITestOutputHelper testOutputHelper)
readonly ITestOutputHelper _testOutputHelper
async void GetModuleLevelById_ModuleLevelNotExisting()
passes if modulelevel with id 100 does not exist
async void AddModuleLevel_MissingModuleRef()
passes if modulelevel is missing a reference to a module, and it throws a DbUpdateException
async void AddModuleLevel_Success()
passes if modulelevel is correctly inserted
ModuleLevel CreateModuleLevelObject()
Creates ModuleLevel
async void GetModuleById_ModuleExisting()
passes if modulelevel is inserted, and module is found by id
async void GetAllModuleLevels_IsEmpty()
passes if modulelevels-list is empty
async void GetAllModuleLevels_NotEmptyAndCorrectObject()
passes if modulelevel-list is not empty after insertion, and the modulelevelname equals the added mod...
static DataContext GetContext()
Creates a testcontext for testing
Reusable methods for inserting information into tests
static DataContext InsertProductAndModule(DataContext context)
Inserts Product and Module into the context Used for inserting product and module into the test envir...