/// <summary> /// 创建新的地图纠错 /// </summary> /// <param name="correcting"></param> /// <returns></returns> public ActionResult CreateCorrecting(Correcting correcting) { ReturnObject2 ro = new ReturnObject2(); try { var newCorrecting = new Correcting(); newCorrecting.ErrorType = correcting.ErrorType; newCorrecting.ErrorDescription = correcting.ErrorDescription; newCorrecting.ContactInfo = correcting.ContactInfo; newCorrecting.CreateTime = DateTime.Now; newCorrecting.POI_ID = correcting.POI_ID; newCorrecting.X = correcting.X; newCorrecting.Y = correcting.Y; _efDbContext.Correcting.Add(newCorrecting); _efDbContext.SaveChanges(); } catch (Exception ex) { ro = new ReturnObject2(ex.Message); } return(Json(ro)); }
[Test] // 2 CheckAccount Positive corection public void Correcrint_CorrectsBalanceTo30ForNewCreatedBankAccountWithBankAccountId2IncontextWithBalance100And_NewBankAccountInContextHasBalance30Left_WhenCalled() { //Arrange BankAccount bankAccount = new BankAccount { CustomerId = 1, BankAccountTypeId = 2, Balance = 100 }; BankAccountType bankAccountType1 = new BankAccountType { BankAccountTypeId = 1, BankAccountTypeName = "Saving Account" }; BankAccountType bankAccountType2 = new BankAccountType { BankAccountTypeId = 2, BankAccountTypeName = "Check Account" }; context.BankAccountTypes.Add(bankAccountType1); context.BankAccountTypes.Add(bankAccountType2); context.BankAccounts.Add(bankAccount); context.SaveChanges(); Correcting correcting = new Correcting(context); decimal expected = 30; //Act correcting.Correct(30, bankAccount); context.SaveChanges(); decimal actual = context.BankAccounts.ToList().ElementAt(0).Balance; //Assert Assert.AreEqual(expected, actual); }
[Test] // 3 SavingAccount Negative corection public void Correcrint_ThrowsAnExceptionForNewCreatedBankAccountWithBankAccountId1IncontextWithBalance100_WhenCalledWithACorrectionAmountOfMinus30() { //Arrange BankAccount bankAccount = new BankAccount { CustomerId = 1, BankAccountTypeId = 1, Balance = 100 }; BankAccountType bankAccountType1 = new BankAccountType { BankAccountTypeId = 1, BankAccountTypeName = "Saving Account" }; context.BankAccountTypes.Add(bankAccountType1); context.BankAccounts.Add(bankAccount); context.SaveChanges(); Correcting correcting = new Correcting(context); //decimal expected = 30; //Act //correcting.Correct(-30, bankAccount); var ex = Assert.Throws <Exception>(() => correcting.Correct(-30, bankAccount)); //Assert Assert.That(ex.Message, Is.EqualTo("Overdraft not allowed")); }
public CorrectingService() { correcting = new Correcting(); }