Initial
This commit is contained in:
		
							
								
								
									
										79
									
								
								Tests/Repo/fwrepo/SimpleDbTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								Tests/Repo/fwrepo/SimpleDbTests.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| 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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										22
									
								
								Tests/Repo/fwrepo/fwrepo.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Tests/Repo/fwrepo/fwrepo.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>netcoreapp3.1</TargetFramework> | ||||
|  | ||||
|     <IsPackable>false</IsPackable> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||||
|     <PackageReference Include="Moq" Version="4.16.1" /> | ||||
|     <PackageReference Include="xunit" Version="2.4.0" /> | ||||
|     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||||
|     <PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\..\..\Repositories\Repositories.csproj" /> | ||||
|     <ProjectReference Include="..\..\..\Datamodels\Datamodels.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
		Reference in New Issue
	
	Block a user