public void Update_SuccessfullyUpdatesCountry() { // Arrange var countries = new List <Country> { new Country { Name = "TestCountry1", Id = 1 }, new Country { Name = "TestCountry2", Id = 2 } }.AsQueryable(); var countrymockDbSet = new Mock <DbSet <Country> >(); countrymockDbSet.As <IQueryable <Country> >().Setup(m => m.Provider).Returns(countries.Provider); countrymockDbSet.As <IQueryable <Country> >().Setup(m => m.Expression).Returns(countries.Expression); countrymockDbSet.As <IQueryable <Country> >().Setup(m => m.ElementType).Returns(countries.ElementType); countrymockDbSet.As <IQueryable <Country> >().Setup(m => m.GetEnumerator()).Returns(countries.GetEnumerator()); var mockContext = new Mock <EazyCartContext>(); mockContext.Setup(c => c.Countries).Returns(countrymockDbSet.Object); var countryBusiness = new CountryBusiness(mockContext.Object); // Act countryBusiness.Update("UpdatedCountry", 1); // Assert mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public static object Update(SessionInfo sessioninfo, MA_COUNTRY record) { try { CountryBusiness _countryBusiness = new CountryBusiness(); record.LABEL = record.LABEL.ToUpper(); record.DESCRIPTION = record.DESCRIPTION.ToUpper(); var updateRecord = _countryBusiness.Update(sessioninfo, record); return(new { Result = "OK", Record = updateRecord }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }