80 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using Xunit;
 | |
| using Repositories;
 | |
| using Microsoft.EntityFrameworkCore;
 | |
| using Datamodels.Lookups;
 | |
| using System.Threading.Tasks;
 | |
| using System.Linq;
 | |
| using Datamodels.BusinessModels;
 | |
| using Microsoft.Extensions.Logging;
 | |
| using Microsoft.Extensions.Configuration;
 | |
| using Moq;
 | |
| 
 | |
| namespace fwrepo
 | |
| {
 | |
|     public class SimpleDbTests
 | |
|     {
 | |
| 
 | |
|         private readonly FwDbContext testdb = new FwDbContext();
 | |
|         private readonly FwMariaLookupRepo repo = new FwMariaLookupRepo(Mock.Of<ILogger<FwMariaLookupRepo>>(), Mock.Of<IConfiguration>());
 | |
| 
 | |
|         [Fact]
 | |
|         public void CreateSomeLookupData()
 | |
|         {
 | |
|             repo.DeleteAllCategories();
 | |
| 
 | |
|             var rand = new Random();
 | |
|             int catCount = rand.Next(10, 50);
 | |
|             for (int i = 0; i < catCount; i++)
 | |
|             {
 | |
|                 var category = new LookupCategory
 | |
|                 {
 | |
|                     CategoryName = $"{i} Category"
 | |
|                 };
 | |
|                 testdb.LookupCategories.Add(category);
 | |
|                 var valRnd = new Random();
 | |
|                 int valCount = valRnd.Next(10,50);
 | |
|                 for (int x = 0; x < valCount; x++)
 | |
|                 {
 | |
|                     testdb.LookupValues.Add(new LookupValue
 | |
|                     {
 | |
|                         Value = $"Category { i } - Value {x}",
 | |
|                         LookupCategory = category
 | |
|                     });
 | |
|                 }
 | |
|             }
 | |
|             int result = testdb.SaveChanges();
 | |
|             Assert.True(result > 0);
 | |
|         }
 | |
| 
 | |
|         [Fact]
 | |
|         public async Task GetAllLookupCategories()
 | |
|         {
 | |
|             var result = await repo.GetAllLookups();
 | |
|             Assert.NotEmpty(result.Data);
 | |
|             Assert.NotEmpty(result.Data.First().LookupValues);
 | |
|         }
 | |
| 
 | |
|         [Fact]
 | |
|         public async Task GetLookupCategoryById()
 | |
|         {
 | |
|             var result = await repo.GetLookupCategoryById(65);
 | |
|             Assert.NotNull(result.Data);
 | |
|         }
 | |
| 
 | |
|         [Fact]
 | |
|         public async Task GetLookupCategoryByName()
 | |
|         {
 | |
|             var result = await repo.GetLookupCategoryByName("Category");
 | |
|             Assert.NotEmpty(result.Data);
 | |
|         }
 | |
| 
 | |
|         [Fact]
 | |
|         public async Task GetActiveCategories()
 | |
|         {
 | |
|             var result = await repo.GetActiveLookupCategories();
 | |
|             Assert.NotEmpty(result.Data);
 | |
|         }
 | |
|     }
 | |
| }
 |