临时提交2

This commit is contained in:
2025-07-21 18:49:49 +08:00
parent 29a2d44319
commit 525c681b6c
57 changed files with 628 additions and 558 deletions

View File

@@ -10,23 +10,23 @@ namespace DMS.Infrastructure.UnitTests
{
public static class FakerHelper
{
// public static DbDevice FakeDbDevice()
// {
// // var dbDevice = new Faker<DbDevice>()
// // .RuleFor(d => d.Name, f => f.Commerce.ProductName())
// // .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
// // .RuleFor(d => d.Ip, f => f.Internet.Ip())
// // .Generate();
// // dbDevice.Prot = 102;
// // dbDevice.ProtocolType = Core.Enums.ProtocolType.S7;
// // dbDevice.Slot = 1;
// // dbDevice.Rack = 0;
// // dbDevice.CpuType = S7.Net.CpuType.S71200;
// // dbDevice.DeviceType = Core.Enums.DeviceType.SiemensPLC;
//
//
// return dbDevice;
// }
public static DbDevice FakeDbDevice()
{
var dbDevice = new Faker<DbDevice>()
.RuleFor(d => d.Name, f => f.Commerce.ProductName())
.RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
.RuleFor(d => d.IpAddress, f => f.Internet.Ip())
.RuleFor(d => d.OpcUaServerUrl, f => f.Internet.Url())
.Generate();
dbDevice.Port = 102;
dbDevice.Protocol = ProtocolType.S7;
dbDevice.Slot = 1;
dbDevice.Rack = 0;
dbDevice.CpuType = "S7-1200";
dbDevice.DeviceType = Core.Enums.DeviceType.SiemensPLC;
return dbDevice;
}
// public static DbVariableTable FakeDbVariableTable()
// {

View File

@@ -0,0 +1,48 @@
using DMS.Config;
using DMS.Infrastructure.Data;
using DMS.Infrastructure.Entities;
using DMS.Infrastructure.Repositories;
namespace DMS.Infrastructure.UnitTests.Repositories_Test;
public class DeviceRepository_Test
{
private readonly DeviceRepository _deviceRepository;
public DeviceRepository_Test()
{
AppSettings appSettings = new AppSettings();
appSettings.Database.Database = "dms_test";
var dbContext = new SqlSugarDbContext(appSettings);
dbContext.GetInstance()
.DbMaintenance.CreateDatabase();
dbContext.GetInstance()
.CodeFirst.InitTables<DbDevice>();
// dbContext.GetInstance()
// .DbMaintenance.CreateIndex("Devices", new[] { "name" }, true);
_deviceRepository = new DeviceRepository(dbContext);
}
[Fact]
public async Task AddAsync_Test()
{
var dbDevice = FakerHelper.FakeDbDevice();
var resDevice = await _deviceRepository.AddAsync(dbDevice);
var res = await _deviceRepository.GetByIdAsync(resDevice.Id);
Assert.NotNull(res);
}
[Fact]
public async Task UpdateAsync_Test()
{
var dbDevice = FakerHelper.FakeDbDevice();
var resDevice = await _deviceRepository.AddAsync(dbDevice);
var res2 = await _deviceRepository.GetByIdAsync(resDevice.Id);
res2.Name = "HaHa";
var res = await _deviceRepository.UpdateAsync(res2);
Assert.Equal(res, 1);
}
}