You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							96 lines
						
					
					
						
							3.4 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							96 lines
						
					
					
						
							3.4 KiB
						
					
					
				
								using Shentun.Pacs.CardRegisters;
							 | 
						|
								using Shentun.Pacs.Enums;
							 | 
						|
								using Shentun.Pacs.IncludeDetails;
							 | 
						|
								using Shentun.Pacs.Models;
							 | 
						|
								using Shentun.Pacs.Patients;
							 | 
						|
								using System;
							 | 
						|
								using System.Collections.Generic;
							 | 
						|
								using System.Linq;
							 | 
						|
								using System.Text;
							 | 
						|
								using System.Threading.Tasks;
							 | 
						|
								using Volo.Abp.Domain.Repositories;
							 | 
						|
								using Volo.Abp.Uow;
							 | 
						|
								using Xunit;
							 | 
						|
								using Xunit.Abstractions;
							 | 
						|
								
							 | 
						|
								namespace Shentun.Pacs
							 | 
						|
								{
							 | 
						|
								    public class PatientManagerTest : PeisDomainTestBase
							 | 
						|
								    {
							 | 
						|
								        private readonly IRepository<Patient, Guid> _repository;
							 | 
						|
								        private readonly PatientManager _manager;
							 | 
						|
								        private readonly ITestOutputHelper _output;
							 | 
						|
								        private readonly IUnitOfWorkManager _unitOfWorkManager;
							 | 
						|
								        public PatientManagerTest(ITestOutputHelper output)
							 | 
						|
								        {
							 | 
						|
								            _output = output;
							 | 
						|
								            _repository = GetRequiredService<IRepository<Patient, Guid>>();
							 | 
						|
								            _manager = GetRequiredService<PatientManager>();
							 | 
						|
								
							 | 
						|
								            _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        [Fact]
							 | 
						|
								        public async Task CreateAsync()
							 | 
						|
								        {
							 | 
						|
								            using(var unitOfWork = _unitOfWorkManager.Begin())
							 | 
						|
								            {
							 | 
						|
								                var patient = new Patient()
							 | 
						|
								                {
							 | 
						|
								                    MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
							 | 
						|
								                    DisplayName = "Test",
							 | 
						|
								                    SexId = SexFlag.UnKnown,
							 | 
						|
								                    MaritalStatusId = MaritalStatusFlag.UnKnown,
							 | 
						|
								                    IdNo = "43062419790909931X"
							 | 
						|
								                };
							 | 
						|
								                var newPatient = await _manager.CreateAsync(patient);
							 | 
						|
								                await _repository.InsertAsync(newPatient);
							 | 
						|
								                await unitOfWork.CompleteAsync();
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								        /// <summary>
							 | 
						|
								        /// 测试事务回滚
							 | 
						|
								        /// </summary>
							 | 
						|
								        /// <returns></returns>
							 | 
						|
								        /// <exception cref="Exception"></exception>
							 | 
						|
								        [Fact]
							 | 
						|
								        public async Task CreateFaildAsync()
							 | 
						|
								        {
							 | 
						|
								            using (var unitOfWork = _unitOfWorkManager.Begin())
							 | 
						|
								            {
							 | 
						|
								                var patient = new Patient()
							 | 
						|
								                {
							 | 
						|
								                    MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
							 | 
						|
								                    DisplayName = "Test",
							 | 
						|
								                    SexId = SexFlag.UnKnown,
							 | 
						|
								                    MaritalStatusId = MaritalStatusFlag.UnKnown,
							 | 
						|
								                    IdNo = "43062419790909920X"
							 | 
						|
								                };
							 | 
						|
								                var newPatient = await _manager.CreateAsync(patient);
							 | 
						|
								                throw new Exception("中断");
							 | 
						|
								                await _repository.InsertAsync(newPatient);
							 | 
						|
								                await unitOfWork.CompleteAsync();
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        [Fact]
							 | 
						|
								        public async Task UpdateAsync()
							 | 
						|
								        {
							 | 
						|
								            using (var unitOfWork = _unitOfWorkManager.Begin())
							 | 
						|
								            {
							 | 
						|
								                var sourcePatient = new Patient()
							 | 
						|
								                {
							 | 
						|
								                    MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
							 | 
						|
								                    DisplayName = "Test2",
							 | 
						|
								                    SexId = SexFlag.Female,
							 | 
						|
								                    MaritalStatusId = MaritalStatusFlag.Married,
							 | 
						|
								                    IdNo = "43062419790909920X"
							 | 
						|
								                };
							 | 
						|
								                var targetPatient = await _repository.GetAsync(new Guid("3a119be6-d9aa-2e13-a764-0b363c60169d"));
							 | 
						|
								                await _manager.UpdateAsync(sourcePatient,targetPatient);
							 | 
						|
								                await _repository.UpdateAsync(targetPatient);
							 | 
						|
								                await unitOfWork.CompleteAsync();
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								}
							 |