public void Can_Insert_Entity() { // Arrange var entity = new WarehouseResponse { Id = 2, Name = "Warehouse 2" }; // Act Service.Add(entity); // Assert Repository.Verify(x => x.Insert(It.IsAny <Warehouse>()), Times.Once); var entities = Service.Get(); Assert.Equal(2, entities.Count()); }
public void Can_Update_Entity() { // Arrange var entity = new WarehouseResponse { Id = 1, Name = "New Name" }; // Act Service.Update(entity); // Assert Repository.Verify(x => x.Update(It.IsAny <Warehouse>()), Times.Once); var entityResult = Service.GetById(1); Assert.Equal("New Name", entityResult.Name); }
public void Update(WarehouseResponse entry) { _service.Update(_mapper.Map <WarehouseResponse, Warehouse>(entry)); }
public void Add(WarehouseResponse entry) { _service.Add(_mapper.Map <WarehouseResponse, Warehouse>(entry)); }
private void ValidateRequest(string origin, string destiny, ShipsToRequestModel entity, out WarehouseResponse originWarehouse, out WarehouseResponse destinyWarehouse) { if (entity == null) { throw new HttpRequestException(_errorHandler.GetErrorMessage(ErrorMessagesEnum.EntityNull)); } if (!ModelState.IsValid) { throw new HttpRequestException(string.Format(_errorHandler.GetErrorMessage(ErrorMessagesEnum.ModelValidation), ModelState.Values.First().Errors.First().ErrorMessage)); } originWarehouse = GetWarehouseByName(origin); destinyWarehouse = GetWarehouseByName(destiny); }
public WarehouseResponse Warehouse(IUnitOfWork uow, WarehouseRequest request) { request.CheckNotNull(); var response = new WarehouseResponse(); response.ErrorList = new List <string>(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); var user = (UserDefinition)Authorization.UserDefinition; int tn = user.TenantId; List <MyRow> Items = new List <MyRow>(); SqlDataAdapter adapter = new SqlDataAdapter(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Store"].ToString())) { conn.Open(); using (SqlCommand cmd = new SqlCommand("usp_MakeStore", conn)) { try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("Tenant", SqlDbType.Int).Value = tn; //conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException sqlException) { response.ErrorList.Add("Exception: " + sqlException.Message); } } adapter = DAL.StoreAdapter(conn, tn); adapter.Fill(dt); adapter.DeleteCommand.ExecuteNonQuery(); foreach (DataRow row in dt.Rows) { MyRow obj = row.ToObject <MyRow>(); Items.Add(obj); } Average(Items); dt = DAL.ConvertTo(Items); adapter.Update(dt); adapter.Dispose(); using (SqlCommand cmd = new SqlCommand("usp_PriceUpdate", conn)) { try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("Tenant", SqlDbType.Int).Value = tn; //conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException sqlException) { response.ErrorList.Add("Exception: " + sqlException.Message); } } conn.Close(); } return(response); }