public static bool ModifyChargingBase(ChargingBaseEntity entity) { int result = 0; if (entity != null) { ChargeRepository mr = new ChargeRepository(); ChargingBaseInfo info = TranslateChargingBaseEntity(entity); if (entity.ChargeBaseID > 0) { result = mr.ModifyChargingBase(info); } else { info.CreateDate = DateTime.Now; result = mr.CreateNewChargingBase(info); } List <ChargingBaseInfo> miList = mr.GetAllChargingBaseInfo();//刷新缓存 Cache.Add("ChargingBaseALL", miList); } return(result > 0); }
public static bool ModifyChargingPile(ChargingPileEntity entity) { int result = 0; if (entity != null) { ChargeRepository mr = new ChargeRepository(); ChargingPileInfo info = TranslateChargingPileEntity(entity); if (entity.ID > 0) { result = mr.ModifyChargingPile(info); } else { info.CreateDate = DateTime.Now; result = mr.CreateNewChargingPile(info); if (result > 0) { ChargingBaseInfo cb = mr.GetChargingBaseById(info.ChargingBaseID); if (cb != null) { int num = cb.ChargeNum + 1; mr.ModifyPileNum(num, info.ChargingBaseID); } } } List <ChargingPileInfo> miList = mr.GetAllChargingPileInfo();//刷新缓存 Cache.Add("ChargingPileALL", miList); } return(result > 0); }
public static int RemoveChargingPiple(long id) { ChargeRepository mr = new ChargeRepository(); int r = mr.RemoveChargePile(id); List <ChargingPileInfo> miList = mr.GetAllChargingPileInfo();//刷新缓存 Cache.Add("ChargingPileALL", miList); return(r); }
/// <summary> /// 1、 不传 返回所有2、 充电桩ID CPid 3、 供应点信息ID ChargeBaseID /// </summary> /// <param name="ChargeBaseID">供应点信息ID</param> /// <returns></returns> public static List <ChargingBaseEntity> GetChargingPileInfo(string ChargeBaseID) { List <ChargingBaseEntity> listBase = new List <ChargingBaseEntity>(); List <ChargingBaseInfo> listBaseInfo = ChargeRepository.GetChargingBaseInfo("", ChargeBaseID); if (listBaseInfo != null && listBaseInfo.Count > 0) { listBase.Add(TransChargeBase(listBaseInfo[0], true)); } return(listBase); }
public static ChargingBaseEntity GetChargingBaseById(int id) { ChargingBaseEntity entity = new ChargingBaseEntity(); ChargingBaseInfo info = new ChargeRepository().GetChargingBaseById(id); if (info != null) { entity = TranslateChargingBaseInfo(info); } return(entity); }
public async Task StoreChargeAsync_WhenChargeIsSaved_ThenSuccessReturnedAsync() { // Arrange var message = GetValidChangeOfChargesMessage(); SeedDatabaseContext(); var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions)); // Act var result = await sut.StoreChargeAsync(message).ConfigureAwait(false); // Assert Assert.True(result.Success); }
public static List <ChargingBaseEntity> GetChargingBaseInfoByRule(string name, int status) { List <ChargingBaseEntity> list = new List <ChargingBaseEntity>(); List <ChargingBaseInfo> info = new ChargeRepository().GetChargingBaseInfoRule(name, status); if (info != null) { foreach (ChargingBaseInfo item in info) { list.Add(TranslateChargingBaseInfo(item)); } } return(list); }
public static List <ChargingPileEntity> GetChargingPileListByBaseID(int baseID) { List <ChargingPileEntity> all = new List <ChargingPileEntity>(); ChargeRepository mr = new ChargeRepository(); List <ChargingPileInfo> miList = mr.GetChargingPileListByBaseID(baseID); if (!miList.IsEmpty()) { foreach (ChargingPileInfo mInfo in miList) { ChargingPileEntity chargingPileEntity = TranslateChargingPileInfo(mInfo); all.Add(chargingPileEntity); } } return(all); }
public async Task StoreChargeAsync_WhenPointsIsNull_ThenExceptionThrownAsync() { // Arrange var message = GetValidChangeOfChargesMessage(); #pragma warning disable CS8602 // Dereference of a possibly null reference. message.Period.Points = null; #pragma warning restore CS8602 // Dereference of a possibly null reference. SeedDatabaseContext(); var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions)); // Act var exception = await Record.ExceptionAsync(async() => await sut.StoreChargeAsync(message).ConfigureAwait(false)); // Assert Assert.IsType <ArgumentException>(exception); Assert.Contains($"{nameof(message.Period.Points)} can't be null", exception.Message); }
public static List <ChargingBaseEntity> GetAllChargingBaseEntity() { List <ChargingBaseEntity> all = new List <ChargingBaseEntity>(); ChargeRepository mr = new ChargeRepository(); List <ChargingBaseInfo> miList = Cache.Get <List <ChargingBaseInfo> >("ChargingBaseALL"); if (miList.IsEmpty()) { miList = mr.GetAllChargingBaseInfo(); Cache.Add("ChargingBaseALL", miList); } if (!miList.IsEmpty()) { foreach (ChargingBaseInfo mInfo in miList) { ChargingBaseEntity chargingBaseEntity = TranslateChargingBaseInfo(mInfo); all.Add(chargingBaseEntity); } } return(all); }
public async Task StoreChargeAsync_WhenValuesInMessageUsedForDbContextLookupsAreInvalid_ThenExceptionThrownAsync(string chargeType, string resolutionType, string vatPayerType, string chargeOwner, string exceptionMessage) { // Arrange var message = GetValidChangeOfChargesMessage(); message.Type = chargeType; message.ChargeTypeOwnerMRid = chargeOwner; #pragma warning disable CS8602 // Dereference of a possibly null reference. message.MktActivityRecord.ChargeType.VATPayer = vatPayerType; message.Period.Resolution = resolutionType; #pragma warning restore CS8602 // Dereference of a possibly null reference. SeedDatabaseContext(); var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions)); // Act var exception = await Record.ExceptionAsync(async() => await sut.StoreChargeAsync(message).ConfigureAwait(false)); // Assert Assert.IsType <ArgumentException>(exception); Assert.Contains(exceptionMessage, exception.Message); }
public async Task StoreChargeAsync_WhenValueNotFoundInDbContext_ThenFailureStatusReturnedAsync(string chargeType, string resolutionType, string vatPayerType, string chargeOwner, string failureReason) { // Arrange var message = GetValidChangeOfChargesMessage(); message.Type = chargeType; message.ChargeTypeOwnerMRid = chargeOwner; #pragma warning disable CS8602 // Dereference of a possibly null reference. message.MktActivityRecord.ChargeType.VATPayer = vatPayerType; message.Period.Resolution = resolutionType; #pragma warning restore CS8602 // Dereference of a possibly null reference. SeedDatabaseContext(); var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions)); // Act var result = await sut.StoreChargeAsync(message).ConfigureAwait(false); // Assert Assert.False(result.Success); Assert.Equal(failureReason, result.Reason); }
public async Task StoreChargeAsync_WhenValuesInMessageAreInvalid_ThenExceptionThrownAsync(string chargeTypeMRid, string correlationId, string lastUpdatedBy, string shortDescription, string longDescription, string argumentThatFails) { // Arrange var message = GetValidChangeOfChargesMessage(); message.ChargeTypeMRid = chargeTypeMRid; message.CorrelationId = correlationId; message.LastUpdatedBy = lastUpdatedBy; #pragma warning disable CS8602 // Dereference of a possibly null reference. message.MktActivityRecord.ChargeType.Name = shortDescription; message.MktActivityRecord.ChargeType.Description = longDescription; #pragma warning restore CS8602 // Dereference of a possibly null reference. SeedDatabaseContext(); var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions)); // Act var exception = await Record.ExceptionAsync(async() => await sut.StoreChargeAsync(message).ConfigureAwait(false)); // Assert Assert.IsType <ArgumentException>(exception); Assert.Contains($"{argumentThatFails} must have value", exception.Message); }