按照软件设计文档开始重构代码01
This commit is contained in:
@@ -10,50 +10,50 @@ 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;
|
||||
// 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 DbVariableTable FakeDbVariableTable()
|
||||
// {
|
||||
// var dbVarTable = new Faker<DbVariableTable>()
|
||||
// .RuleFor(d => d.Name, f => f.Commerce.ProductName())
|
||||
// .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
|
||||
// .Generate();
|
||||
// dbVarTable.ProtocolType = Core.Enums.ProtocolType.S7;
|
||||
// dbVarTable.IsActive=true;
|
||||
// return dbVarTable;
|
||||
// }
|
||||
|
||||
return dbDevice;
|
||||
}
|
||||
|
||||
public static DbVariableTable FakeDbVariableTable()
|
||||
{
|
||||
var dbVarTable = new Faker<DbVariableTable>()
|
||||
.RuleFor(d => d.Name, f => f.Commerce.ProductName())
|
||||
.RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
|
||||
.Generate();
|
||||
dbVarTable.ProtocolType = Core.Enums.ProtocolType.S7;
|
||||
dbVarTable.IsActive=true;
|
||||
return dbVarTable;
|
||||
}
|
||||
|
||||
public static DbVariable FakeDbVariable()
|
||||
{
|
||||
var dbVariable = new Faker<DbVariable>()
|
||||
.RuleFor(d => d.Name, f => f.Commerce.ProductName())
|
||||
.RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
|
||||
.RuleFor(d => d.S7Address, f => f.Internet.DomainWord())
|
||||
.RuleFor(d => d.DataValue, f => f.Commerce.Price())
|
||||
.Generate();
|
||||
dbVariable.ProtocolType = Core.Enums.ProtocolType.S7;
|
||||
dbVariable.IsActive = true;
|
||||
dbVariable.SignalType=Core.Enums.SignalType.RunSignal;
|
||||
dbVariable.UpdateTime=DateTime.Now;
|
||||
dbVariable.DataType = "String";
|
||||
return dbVariable;
|
||||
}
|
||||
// public static DbVariable FakeDbVariable()
|
||||
// {
|
||||
// var dbVariable = new Faker<DbVariable>()
|
||||
// .RuleFor(d => d.Name, f => f.Commerce.ProductName())
|
||||
// .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
|
||||
// .RuleFor(d => d.S7Address, f => f.Internet.DomainWord())
|
||||
// .RuleFor(d => d.DataValue, f => f.Commerce.Price())
|
||||
// .Generate();
|
||||
// dbVariable.ProtocolType = Core.Enums.ProtocolType.S7;
|
||||
// dbVariable.IsActive = true;
|
||||
// dbVariable.SignalType=Core.Enums.SignalType.RunSignal;
|
||||
// dbVariable.UpdateTime=DateTime.Now;
|
||||
// dbVariable.DataType = "String";
|
||||
// return dbVariable;
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DMS.Config;
|
||||
|
||||
namespace DMS.Infrastructure.UnitTests.Repository_Test
|
||||
{
|
||||
public class BaseRepositoryTests
|
||||
{
|
||||
|
||||
protected readonly SqlSugarDbContext _sqlSugarDbContext;
|
||||
|
||||
public BaseRepositoryTests()
|
||||
{
|
||||
// Load real connection settings
|
||||
var connectionSettings = new Config.AppSettings()
|
||||
{
|
||||
Database = new DatabaseSettings()
|
||||
{
|
||||
Database = "dms_test"
|
||||
}
|
||||
};
|
||||
_sqlSugarDbContext = new SqlSugarDbContext(connectionSettings);
|
||||
_sqlSugarDbContext.GetInstance().DbMaintenance.CreateDatabase();
|
||||
_sqlSugarDbContext.GetInstance().CodeFirst.InitTables<DbDevice>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using AutoMapper;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DMS.Infrastructure.UnitTests.Repository_Test
|
||||
{
|
||||
public class DeviceRepositoryTests:BaseRepositoryTests
|
||||
{
|
||||
private readonly DeviceRepository _deviceRepository;
|
||||
|
||||
public DeviceRepositoryTests() : base()
|
||||
{
|
||||
|
||||
_deviceRepository = new DeviceRepository(_sqlSugarDbContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllAsync_Test()
|
||||
{
|
||||
// Act
|
||||
var result = await _deviceRepository.GetAllAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateByIdAsync_Test()
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdAsync(33);
|
||||
device.Name = "<22>ŷ<EFBFBD>";
|
||||
// Act
|
||||
var result = await _deviceRepository.UpdateAsync(device);
|
||||
|
||||
// Assert
|
||||
//Assert.NotNull(result);
|
||||
Assert.Equal(result, 1);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_Test()
|
||||
{
|
||||
var device = await _deviceRepository.GetByIdAsync(33);
|
||||
// Act
|
||||
var result = await _deviceRepository.DeleteAsync(device);
|
||||
|
||||
// Assert
|
||||
//Assert.NotNull(result);
|
||||
Assert.Equal(result, 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddAsync_Test()
|
||||
{
|
||||
try
|
||||
{
|
||||
//await _sqlSugarDbContext.BeginTranAsync();
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var dbDevice = FakerHelper.FakeDbDevice();
|
||||
//await _sqlSugarDbContext.GetInstance().Insertable(dbDevice).ExecuteCommandAsync();
|
||||
|
||||
// Act
|
||||
var result = await _deviceRepository.AddAsync(dbDevice);
|
||||
}
|
||||
throw new Exception("ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3A1A3A1><EFBFBD>");
|
||||
//await _sqlSugarDbContext.CommitTranAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//await _sqlSugarDbContext.RollbackTranAsync();
|
||||
Console.WriteLine($"<22><><EFBFBD><EFBFBD><EFBFBD>豸ʱ<E8B1B8><CAB1><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>{e}");
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
//Assert.NotNull(result);
|
||||
//Assert.Contains(result, d => d.Name == testDevice.Name);
|
||||
|
||||
// Clean up after the test
|
||||
//await _sqlSugarDbContext.GetInstance().Deleteable<DbDevice>().ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Xunit;
|
||||
|
||||
namespace DMS.Infrastructure.UnitTests.Repository_Test
|
||||
{
|
||||
public class VariableTableRepositoryTests
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace DMS.Infrastructure.UnitTests.Services_Test;
|
||||
|
||||
public class DeviceServer_Test
|
||||
{
|
||||
public DeviceServer_Test()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task AddDeviceAsync_Test()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user