public void Save_ValidCollateralJson_ShouldReturnIdOfNewCollateral() { Collateral validCollateral = new Land() { LoanId = 1001, CustomerId = 2001, InitialAssesDate = DateTime.Now.AddDays(-5), LastAssessDate = DateTime.Now.AddDays(5), AreaInSqFt = 1000, InitialPricePerSqFt = 1100, CurrentPricePerSqFt = 1200 }; JsonElement validCollateralJson = JsonDocument.Parse(JsonSerializer.Serialize(validCollateral)).RootElement; int newCollateralId = 1; collateralDeserializer.Setup(m => m.DeserializeByType(It.Is <JsonElement>(je => je.AsJson() == validCollateralJson.AsJson()), nameof(Collateral.Type))) .Returns(validCollateral); dao.Setup(m => m.Save(It.Is <Collateral>(c => c.AsJson() == validCollateral.AsJson()), It.IsAny <CollateralDb>())).Returns(newCollateralId); Assert.That(collateralManagement.Save(validCollateralJson) == newCollateralId); dao.Verify(m => m.Save(It.Is <Collateral>(c => c.AsJson() == validCollateral.AsJson()), It.Is <CollateralDb>(db => db != null))); }
public void Save_ValidCollateral_ShouldReturnIdOfNewCollateral() { Collateral collateral = new Land() { LoanId = 1001, CustomerId = 2001, InitialAssesDate = DateTime.Now.AddDays(-5), LastAssessDate = DateTime.Now.AddDays(5), AreaInSqFt = 1000, InitialPricePerSqFt = 1000, CurrentPricePerSqFt = 1000 }; int id = dao.Save(collateral, db); Assert.IsTrue(id > 0); Assert.AreEqual(collateral.AsJson(), db.Collaterals.SingleOrDefault(c => c.Id == id).AsJson()); }