UserService/UserService.Test/OrgUnitRepositoryTests.cs

61 lines
2.0 KiB
C#

using System;
using System.Threading.Tasks;
using NUnit.Framework;
using UserService.DatabaseLayer.Repositories;
using UserService.Infrastructure.DataModels;
namespace UserService.Test
{
public class OrgUnitRepositoryTests
{
private OrganizationUnitsRepository _repository;
[OneTimeSetUp]
public void SetUp()
{
_repository = new OrganizationUnitsRepository();
}
[Test]
[Order(2)]
public async Task Test1()
{
var entities = await _repository.GetAllAsync().ConfigureAwait(false);
Assert.AreEqual(entities.Count, 4);
}
[Test]
[Order(1)]
public async Task Test2()
{
var ou = new OrganizationUnit {CommonName = "Users", Description = "Users"};
var id = await _repository.AddAsync(ou).ConfigureAwait(false);
ou = new OrganizationUnit {CommonName = "USA", Description = "Users", ParentId = id};
id = await _repository.AddAsync(ou).ConfigureAwait(false);
ou = new OrganizationUnit { CommonName = "Arizona", Description = "Users", ParentId = id };
id = await _repository.AddAsync(ou).ConfigureAwait(false);
ou = new OrganizationUnit { CommonName = "Germany", Description = "Users", ParentId = id };
await _repository.AddAsync(ou).ConfigureAwait(false);
}
[Test]
[Order(3)]
public async Task Test3()
{
var entity = await _repository.GetAsync(x => x.CommonName == "Users").ConfigureAwait(false);
entity.Description = DateTime.Now.ToString("O");
await _repository.UpdateAsync(entity).ConfigureAwait(false);
}
[Test]
[Order(4)]
public async Task Test4()
{
var entity = await _repository.GetAllAsync().ConfigureAwait(false);
foreach (var organizationUnit in entity)
{
await _repository.DeleteAsync(organizationUnit).ConfigureAwait(false);
}
}
}
}