You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
haoliang-net/tests/CncRepository.Tests/BrandRepositoryTests.cs

107 lines
2.9 KiB
C#

using System;
using System.Linq;
using CncModels.Entity;
using CncRepository.Impl;
using Xunit;
namespace CncRepository.Tests
{
/// <summary>
/// 品牌仓储测试
/// </summary>
[Collection("Database")]
public class BrandRepositoryTests : IDisposable
{
private readonly BrandRepository _repo;
public BrandRepositoryTests()
{
_repo = new BrandRepository(TestDb.ConnectionString);
TestDb.TruncateAll();
}
public void Dispose()
{
TestDb.TruncateAll();
}
[Fact]
public void GetAll_()
{
var result = _repo.GetAll();
Assert.NotNull(result);
Assert.True(result.Count >= 1);
Assert.Equal("FANUC", result[0].BrandName);
}
[Fact]
public void GetById_ID_()
{
var result = _repo.GetById(1);
Assert.NotNull(result);
Assert.Equal("FANUC", result.BrandName);
}
[Fact]
public void Create__ID()
{
var entity = new Brand
{
BrandName = "Siemens",
DeviceField = "device",
TagsPath = "tags",
IsEnabled = 1,
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now
};
var id = _repo.Create(entity);
Assert.True(id > 0);
Assert.Equal("Siemens", _repo.GetById(id).BrandName);
}
[Fact]
public void Update__true()
{
var entity = _repo.GetById(1);
entity.BrandName = "FANUC-修改";
entity.UpdatedAt = DateTime.Now;
var result = _repo.Update(entity);
Assert.True(result);
}
[Fact]
public void Delete_ID_true()
{
var id = _repo.Create(new Brand
{
BrandName = "待删除", DeviceField = "d", TagsPath = "t", IsEnabled = 1,
CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now
});
Assert.True(_repo.Delete(id));
}
[Fact]
public void ToggleEnabled_()
{
var before = _repo.GetById(1).IsEnabled;
_repo.ToggleEnabled(1);
var after = _repo.GetById(1).IsEnabled;
Assert.NotEqual(before, after);
}
[Fact]
public void GetFieldMappingCount_()
{
var count = _repo.GetFieldMappingCount(1);
Assert.True(count >= 0);
}
[Fact]
public void GetCollectAddressCount_()
{
var count = _repo.GetCollectAddressCount(1);
Assert.True(count >= 0);
}
}
}