unit uDataModuleContactos_Test;
{

  Delphi DUnit Test Case
  ----------------------
  This unit contains a skeleton test case class generated by the Test Case Wizard.
  Modify the generated code to correctly setup and call the methods from the unit 
  being tested.

}

interface

uses
  TestFramework, uBizContactos, uROBinMessage, uROServiceComponent, 
  uDAClientDataModule, uROClient, uDataModuleContactos, uDACDSDataTable, 
  uBizDatosBancarios, uDADataTable, Contnrs, Classes, SysUtils, DB, uDAScriptingProvider, 
  uROWinInetHttpChannel, uDABINAdapter, uRORemoteService, DBClient,
  uBizCategoriasContacto;
type
  // Test methods for class TdmContactos
  
  TestTdmContactos = class(TTestCase)
  strict private
    FdmContactos: TDataModuleContactos;
  private
    procedure Test_GetItems;
  public
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure Test_GetItems_Clientes;
    procedure Test_GetItems_Proveedor;    
    function Test_GetDatosBancarios : IBizDatosBancarios;
    function Test_GetCategorias : IBizCategoriasContacto;
//    function Test_GetItems (IDCategoria : Integer): IBizContacto;
  end;

implementation

uses
  Dialogs, uDataTableUtils;
  
procedure TestTdmContactos.SetUp;
begin
  FdmContactos := TDataModuleContactos.Create(NIL);
end;

procedure TestTdmContactos.TearDown;
begin
  FdmContactos.Free;
  FdmContactos := nil;
end;

function TestTdmContactos.Test_GetCategorias: IBizCategoriasContacto;
begin

end;

function TestTdmContactos.Test_GetDatosBancarios: IBizDatosBancarios;
begin

end;

procedure TestTdmContactos.Test_GetItems;
begin
  //
end;

procedure TestTdmContactos.Test_GetItems_Clientes;
var
  AContacto : IBizContacto;
  ACliente: IBizCliente;
  I: Integer;
begin
  AContacto := FdmContactos._GetItems(CATEGORIA_CLIENTE);
  CheckIs(AContacto.DataTable.BusinessEventsObj, TBizCliente);
  ACliente := (AContacto as IBizCliente);

  try
    with ACliente do
    begin
      DataTable.Active := True;
      Insert;

      Check(ID < 0, Format('ID no válido ID=%d', [ID]));
      CheckEquals('Cliente', Categoria);

      NIF_CIF := '1234567890-X';
      NOMBRE := 'David Arranz Puerta';
      CALLE := 'Dehesa de Vicálvaro, 47 2ºC';
      POBLACION := 'Madrid';
      PROVINCIA := 'Madrid';
      CODIGO_POSTAL := '28053';
      TELEFONO_1 := '123456789';
      TELEFONO_2 := '9876543231';
      MOVIL_1 := '101918171615141312';
      MOVIL_2 := '010203040506070809';
      FAX := '1111111111';
      EMAIL_1 := 'porqueyolovalgo@osea.com';
      EMAIL_2 := 'fromlost@totheriver.com';
      PAGINA_WEB := 'http://www.trapicheos.com';

      Post;
    end;

    Check(Assigned(ACliente.DatosBancarios), 'Datos bancarios no creado');
    with ACliente.DatosBancarios do
    begin
      Insert;
      for i := 0 to 5 do
      begin
        Insert;
        Check(ID < 0, Format('ID no válido ID=%d', [ID]));
        TITULAR := ACliente.NOMBRE;
        ENTIDAD := '1931';
        SUCURSAL := '3034';
        DC := '15';
        CUENTA := '000000' + IntToStr(i);
        Post;
      end;
    end;
    ACliente.DataTable.ApplyUpdates;
    ShowMessage(SysUtils.Format('ID = %d', [ACliente.ID]));
  finally
    ACliente := NIL;
    AContacto := NIL;
  end;
end;

procedure TestTdmContactos.Test_GetItems_Proveedor;
begin

end;

initialization
  // Register any test cases with the test runner
  RegisterTest(TestTdmContactos.Suite);
end.

