Anda di halaman 1dari 26

JURUSAN TEKNIK INFORMATIKA

FAKULTAS TEKNOLOGI INFORMASI


INSTITUT TEKNOLOGI SEPULUH NOPEMBER
SURABAYA

Test Case – White Box


Matakuliah Verifikasi dan Validasi Perangkat
Lunak
Oleh :
Agung Diananto P.P 5107100044
A. Dibyanugraha 5107100075

Dokumen ini adalah test case white box (unit testing) untuk perangkat lunak Comic’s Nerd Admin
Daftar Isi
Daftar Isi_________________________________________________________________________1
Penjelasan Singkat_________________________________________________________________2
Sequence Diagram_________________________________________________________________2
Use Case Manage Komik__________________________________________________________________2
Use Case Tambah Komik_________________________________________________________________________2
Use Case Ubah Komik___________________________________________________________________________3
Use Case Hapus Komik__________________________________________________________________________3

Use Case Manage Anggota________________________________________________________________4


Use Case Tambah Anggota_______________________________________________________________________4
Use Case Ubah Anggota_________________________________________________________________________5
Use Case Hapus Anggota________________________________________________________________________6

Source Code Program_______________________________________________________________6


Entity_________________________________________________________________________________6
Anggota.cs____________________________________________________________________________________6
Karyawan.cs__________________________________________________________________________________7
Komik.cs_____________________________________________________________________________________8

Controls_______________________________________________________________________________9
ConnectDbAccess.cs____________________________________________________________________________9
ControlCheck.cs______________________________________________________________________________11
UserAuthentification.cs________________________________________________________________________13

Presentation__________________________________________________________________________14
FormAnggota.cs______________________________________________________________________________14
FormKomik.cs________________________________________________________________________________16
FormLogin.cs_________________________________________________________________________________18
FormMainApp.cs______________________________________________________________________________19

Test Case________________________________________________________________________20
Entity________________________________________________________________________________20
Class Komik__________________________________________________________________________________20
Class Anggota________________________________________________________________________________21
Class Karyawan_______________________________________________________________________________21

Controls______________________________________________________________________________21
Class UserAuthentification______________________________________________________________________21

Code unit testing_________________________________________________________________22


Entity________________________________________________________________________________22
Class Komik__________________________________________________________________________________22
Class Anggota________________________________________________________________________________23
Class Karyawan_______________________________________________________________________________23

Controls______________________________________________________________________________24
Class UserAuthentification______________________________________________________________________24

1
Screenshot______________________________________________________________________25

Penjelasan Singkat
Dokumen ini berisi test case dari unit testing untuk perangkat lunak Comic’s Nerd Admin, suatu program
backend untuk petugas tempat persewaan komik. Adapun method-method yang akan diuji hanyalah
method dalam class yang memiliki return value dan tidak termasuk dalam Boundary (kelas Form).

Sequence Diagram
Use Case Manage Komik
Manage Komik tidak memiliki Main Flow yang spesifik karena hanya menjadi Use Case acuan dari Use Case
yang berhubungan dengan pengubahan data Komik.

Use Case Tambah Komik

Main Flow
sd Tambah Komik

Karyawan FormLogin ControlCheck UserAuthentification Karyawan MainFormApp FormKomik Komik

btnLogin_Click()

checkMaskedTextboxesEmptiness() :bool

:bool

authenticateUser() :bool

getMd5Hash() :string

getMd5Password() :string

:string

verifyMd5Hash() :bool
:bool

hide()
show()

komikToolStripMenuItem_Click()

show()

rbTambahKomik_CheckedChanged()

btnKomik_Click()

checkTextboxesEmptiness() :bool

:bool

tambahKomik() :bool

:bool

(from Use Case Model) (from Class Model) (from Class Model) (from Class Model) (from Cl ass Model) (from Class Model)

2
Use Case Ubah Komik

Main Flow
sd Ubah Komik

Karyawan FormLogin ControlCheck UserAuthenti fication Karyawan MainFormApp FormKomi k Komik

btnLogin_Click()

checkMaskedTextboxesEmptiness() :bool

:bool

authenticateUser() :bool

getMd5Hash() :string

getMd5Password() :string

:string

verifyMd5Hash() :bool
:bool

hide()
show()

komikToolStripMenuItem_Click()

show()

rbUbahKomik_CheckedChanged()

dataGridVi ew1_CellContentCli ck()

btnKomik_Cl ick()

checkT extboxesEmptiness() :bool

:bool

ubahKomik() :bool

:bool

(from Use Case Model) (from Cl ass Model) (from Class Model) (from Class Model) (from Cl ass Model) (from Class Model)

Use Case Hapus Komik

Main Flow
sd Hapus Komik

Karyawan FormLogin ControlCheck UserAuthentification Karyawan MainFormApp FormKomik Komik

btnLogin_Click()

checkMaskedTextboxesEmptiness() :bool

:bool

authenticateUser() :bool

getMd5Hash() :string

getMd5Password() :string

:string

verifyMd5Hash() :bool
:bool

hide()
show()

komikToolStripMenuItem_Click()

show()

rbHapusKomik_CheckedChanged()

dataGridVi ew1_CellContentClick()

btnKomik_Click()

hapusKomik() :bool

:bool

(from Use Case Model) (from Class Model) (from Class Model) (from Class Model) (from Cl ass Model) (from Class Model)

3
Use Case Manage Anggota
Manage Anggota tidak memiliki Main Flow yang spesifik karena hanya menjadi Use Case acuan dari Use Case
yang berhubungan dengan pengubahan data Anggota.

Use Case Tambah Anggota

Main Flow
sd Tambah Anggota

Karyawan FormLogin ControlCheck UserAuthentification Karyawan MainFormApp FormAnggota Anggota

btnLogi n_Click()

checkMaskedTextboxesEmptiness() :bool

:bool

authenticateUser() :bool

getMd5Hash() :string

getMd5Password() :string

:string

verifyMd5Hash() :bool
:bool

hide()

show()

membersTool Stri pMenuItem_Click()


CheckMdiClientDuplicates(WndCls) :
bool

show()

rbTambahAnggota_CheckedChanged()

btnSimpanAnggota_Click()

checkTextboxesEmpti ness(panelTb) :
bool

:bool

tambahAnggota() :bool

:bool

(from Use Case Model) (from Class Model) (from Class Model) (from Class Model) (from Class Model) (from Class Model)

4
Use Case Ubah Anggota

Main Flow
sd Ubah Anggota

Karyawan FormLogin ControlCheck UserAuthentification Karyawan MainFormApp FormAnggota Anggota

btnLogin_Click()

checkMaskedTextboxesEmptiness() :bool

:bool

authenticateUser()

getMd5Hash() :string
getMd5Hash() :string

:string

verifyMd5Hash()
:bool
:bool

hide()
show()

membersToolStripMenuItem_Click()

show()

rbUbahAnggota_CheckedChanged()

dataGridView1_CellContentClick()

btnSimpanAnggota_Click()

checkTextboxesEmptiness()
:bool

:bool

ubahAnggota() :bool

:bool

(from Use Case Model) (from Class Model) (from Class Model) (from Class Model) (from Class Model) (from Class Model)

5
Use Case Hapus Anggota

Main Flow
sd Hapus Anggota

Karyawan FormLogin ControlCheck UserAuthentification Karyawan MainFormApp FormAnggota Anggota

btnLogin_Click()

checkMaskedTextboxesEmptiness() :bool

:bool

authenticateUser() :bool

getMd5Hash() :string

getMd5Password() :string

:string

verifyMd5Hash()
:bool
:bool

hide()

show()

membersToolStripMenuItem_Click()

show()

rbUbahAnggota_CheckedChanged()

dataGridView1_CellContentClick()

btnSimpanAnggota_Click()
hapusAnggota() :bool

:bool

(from Use Case Model) (from Class Model) (from Class Model) (from Class Model) (from Class Model) (from Class Model)

Source Code Program


Entity
Anggota.cs
Class Anggota
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SewaKomikGui_net35.Controls;

namespace SewaKomikGui_net35.Entity.Implementation
{
/**
* anggota adalah entity dan utility class sehingga tidak butuh diinstance
**/
static class Anggota
{
static ConnectDbAccess myConnection = new ConnectDbAccess();

#region Anggota methods


public static bool tambahAnggota(string inNAMA_ANGGOTA, string inALAMAT_ANGGOTA, string
inNO_TELP_ANGGOTA, string inNO_TANDA_PENGENAL_ANGGOTA)
{
Guid g;
g = Guid.NewGuid();

string sqlInsertAnggotaBaru = "insert into ANGGOTA (ID_ANGGOTA, NAMA_ANGGOTA, ALAMAT_ANGGOTA,


NO_TELP_ANGGOTA, NO_TANDA_PENGENAL_ANGGOTA) values (\"" + g.ToString() + "\", \"" + inNAMA_ANGGOTA + "\", \""
+ inALAMAT_ANGGOTA + "\", \"" + inNO_TELP_ANGGOTA + "\", \"" + inNO_TANDA_PENGENAL_ANGGOTA + "\")";

if (myConnection.dbExecuteNonQueryCommand(sqlInsertAnggotaBaru))

6
{
return true;
}
else
{
return false;
}
}

public static bool cariAnggota(string inNAMA_ANGGOTA)


{
return false;
}

public static bool ubahAnggota(string oldNAMA_ANGGOTA, string inNAMA_ANGGOTA, string inALAMAT_ANGGOTA,


string inNO_TELP_ANGGOTA, string inNO_TANDA_PENGENAL_ANGGOTA)
{
string sqlUpdateAnggota = "UPDATE ANGGOTA SET ANGGOTA.NAMA_ANGGOTA = \"" + inNAMA_ANGGOTA +
"\",ANGGOTA.ALAMAT_ANGGOTA = \"" + inALAMAT_ANGGOTA + "\", ANGGOTA.NO_TELP_ANGGOTA = \"" + inNO_TELP_ANGGOTA +
"\", ANGGOTA.NO_TANDA_PENGENAL_ANGGOTA = \"" + inNO_TANDA_PENGENAL_ANGGOTA + "\" where ANGGOTA.NAMA_ANGGOTA
= \"" + oldNAMA_ANGGOTA + "\"";

if (myConnection.dbExecuteNonQueryCommand(sqlUpdateAnggota))
{
return true;
}
else
{
return false;
}
}

public static bool hapusAnggota(string inNAMA_ANGGOTA)


{
string sqlHapusAnggota = "delete from ANGGOTA where NAMA_ANGGOTA = \"" + inNAMA_ANGGOTA + "\"";

if (myConnection.dbExecuteNonQueryCommand(sqlHapusAnggota))
{
return true;
}
else
{
return false;
}
}

#endregion

}
}

Karyawan.cs
Class Karyawan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SewaKomikGui_net35.Controls;
using System.Windows.Forms;

namespace SewaKomikGui_net35.Entity.Implementation
{
/**
* karyawan adalah entity dan utility class sehingga tidak butuh diinstance
**/
static class Karyawan
{
#region Karyawan Methods
public static string getMd5Password(string inputNamaKaryawan)
{
string md5password;
string[] data = new string[10];

7
string sqlGetPass = "SELECT password FROM karyawan WHERE nama_karyawan = " + "\"" +
inputNamaKaryawan + "\"";

ConnectDbAccess myConnection = new ConnectDbAccess();

// ambil password dari database


data = myConnection.getDataIterated(sqlGetPass);

if (data != null)
{
md5password = data[0];
}
else // jika tidak ada password
{
return null;
}

// tutup database
myConnection = null;

return md5password;
}
#endregion
}
}

Komik.cs
Class Komik
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SewaKomikGui_net35.Controls;

namespace SewaKomikGui_net35.Entity.Implementation
{
/**
* komik adalah entity dan utility class sehingga tidak butuh diinstance
**/
static class Komik
{
static ConnectDbAccess myConnection = new ConnectDbAccess();

#region Comic Methods


public static bool tambahKomik(string inJUDUL_KOMIK, string inSERI, string inPENERBIT, string
inTGL_PEMBELIAN, string inHARGA, string inSTATUS)
{
Guid g;
g = Guid.NewGuid();

string sqlInsertKomikBaru = "insert into KOMIK (ID_KOMIK, JUDUL_KOMIK, SERI, PENERBIT,


TGL_PEMBELIAN, HARGA, STATUS) values (\"" + g.ToString() + "\", \"" + inJUDUL_KOMIK + "\", \"" + inSERI + "\",
\"" + inPENERBIT + "\", \"" + inTGL_PEMBELIAN + "\", \"" + inHARGA + "\", " + "1)";

if (myConnection.dbExecuteNonQueryCommand(sqlInsertKomikBaru))
{
return true;
}
else
{
return false;
}
}

public static bool updateKomik(string oldJUDUL_KOMIK, string inJUDUL_KOMIK, string inSERI, string
inPENERBIT, string inTGL_PEMBELIAN, string inHARGA, bool inSTATUS)
{
byte status;
if (inSTATUS == true)
{
status = 1;
}

8
string sqlUpdateKomik = "UPDATE KOMIK SET KOMIK.JUDUL_KOMIK = \"" + inJUDUL_KOMIK + "\",
KOMIK.SERI = \"" + inSERI + "\", KOMIK.PENERBIT = \"" + inPENERBIT + "\", KOMIK.TGL_PEMBELIAN = \"" +
inTGL_PEMBELIAN + "\", KOMIK.HARGA = \"" + inHARGA + "\" where KOMIK.JUDUL_KOMIK = \"" + oldJUDUL_KOMIK +
"\"";

if (myConnection.dbExecuteNonQueryCommand(sqlUpdateKomik))
{
return true;
}
else
{
return false;
}
}

public static bool deleteKomik(string inJUDUL_KOMIK)


{
string sqlDeleteKomik = "delete from KOMIK where JUDUL_KOMIK = \"" + inJUDUL_KOMIK + "\"";

if (myConnection.dbExecuteNonQueryCommand(sqlDeleteKomik))
{
return true;
}
else
{
return false;
}
}
#endregion
}
}

Controls
ConnectDbAccess.cs
Class ConnectDbAccess
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.OleDb;
using System.Data;
using System.Windows.Forms;

namespace SewaKomikGui_net35.Controls
{
class ConnectDbAccess
{
OleDbConnection thisConnection = new OleDbConnection();
OleDbCommand thisCommand;

private string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data


Source=C:\sewakomik.accdb;Persist Security Info=False;";

public ConnectDbAccess()
{
this.thisConnection.ConnectionString = connectionString;
}

public ConnectDbAccess(string inputConnectionString)


{
this.thisConnection.ConnectionString = inputConnectionString;
}

// buka koneksi ke database


private bool openConnectionToDb()
{
try
{
thisConnection.Open();

return true;
9
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}

// tutup koneksi database


private bool closeConnectionFromDb()
{
thisConnection.Close();
return true;
}

public bool isAnyData(string inputSqlCommand)


{
string[] data = this.getOleDbDataReaderIterated(dbExecuteReaderCommand(inputSqlCommand));

if (data != null)
{
return true;
}
else
{
return false;
}
}

public string[] getDataIterated(string inputSqlCommand)


{
string[] data = this.getOleDbDataReaderIterated(dbExecuteReaderCommand(inputSqlCommand));

if (data != null)
{
return data;
}
else
{
return null;
}
}

private string[] getOleDbDataReaderIterated(OleDbDataReader inputOleDbDataReader)


{
// seharusnya jangan pake array
string[] returnData = new string[10];
int numberOfRow = 0;

if (inputOleDbDataReader.HasRows)
{
while (inputOleDbDataReader.Read())
{
returnData[numberOfRow] = inputOleDbDataReader[numberOfRow].ToString();
numberOfRow++;
}
this.closeConnectionFromDb();

return returnData;
}
else
{
return null;
}
}

public DataSet getMyDataSet(string sqlCommand)


{
this.openConnectionToDb();
thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = sqlCommand;
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = thisCommand;
DataSet filter = new DataSet();
this.closeConnectionFromDb();
adapter.Fill(filter);

10
return filter;
}

public DataTable getMyDataTable(string sqlCommand)


{
this.openConnectionToDb();
thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = sqlCommand;
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = thisCommand;
DataTable filter = new DataTable();
this.closeConnectionFromDb();
adapter.Fill(filter);
return filter;
}

private OleDbDataReader dbExecuteReaderCommand(string sqlCommand)


{
// buka database
this.openConnectionToDb();

thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = sqlCommand;
OleDbDataReader thisReader = thisCommand.ExecuteReader();

// tutup database
// this.closeConnectionFromDb();

return thisReader;
}

public bool dbExecuteNonQueryCommand(string sqlCommand)


{
try
{
this.openConnectionToDb();
thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = sqlCommand;
if (thisCommand.ExecuteNonQuery() != 0)
{
this.closeConnectionFromDb();
return true;
}
else
{
this.closeConnectionFromDb();
return false;
}
}
catch (Exception ex)
{
this.closeConnectionFromDb();
MessageBox.Show(ex.Message.ToString(), "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return false;
}
}
}
}

ControlCheck.cs
Class ControlCheck
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SewaKomikGui_net35.Controls
{
/**
* ControlEmptinessCheck adalah utility class sehingga tidak butuh diinstance
**/
static class ControlCheck
{

11
#region ControlCheck methods
public static void clearAllTextBoxes(Panel input)
{
foreach (Control c in input.Controls)
{
if (c is TextBox)
{
((TextBox)c).Clear();
}
}
}

public static void enabledAllTextBoxes(Panel input, bool enable)


{
foreach (Control c in input.Controls)
{
if (c is TextBox)
{
((TextBox)c).Enabled = enable;
}
}
}

public static void enabledAllCheckBoxes(GroupBox input, bool enable)


{
foreach (Control c in input.Controls)
{
if (c is CheckBox)
{
((CheckBox)c).Enabled = enable;
}
}
}

public static bool checkMaskedTextboxesEmptiness(Panel inputPanel)


{
bool tbEmpty = false;

foreach (Control c in inputPanel.Controls)


{
if (c is MaskedTextBox)
{
if (string.IsNullOrEmpty(((MaskedTextBox)c).Text))
{
tbEmpty = true;
}
}
}

if (tbEmpty)
{
MessageBox.Show("Harap isi semua keterangan!", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return false;
}
else
{
return true;
}
}

public static bool checkTextboxesEmptiness(Panel inputPanel)


{
bool tbEmpty = false;

foreach (Control c in inputPanel.Controls)


{
if (c is TextBox)
{
if (string.IsNullOrEmpty(((TextBox)c).Text))
{
tbEmpty = true;
}
}
}

12
if (tbEmpty)
{
MessageBox.Show("Harap isi semua keterangan!", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return false;
}
else
{
return true;
}
}
#endregion
}
}

UserAuthentification.cs
Class UserAuthentification
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SewaKomikGui_net35.Controls;

namespace SewaKomikGui_net35.Entity.Implementation
{
/**
* komik adalah entity dan utility class sehingga tidak butuh diinstance
**/
static class Komik
{
static ConnectDbAccess myConnection = new ConnectDbAccess();

#region Comic Methods


public static bool tambahKomik(string inJUDUL_KOMIK, string inSERI, string inPENERBIT, string
inTGL_PEMBELIAN, string inHARGA, string inSTATUS)
{
Guid g;
g = Guid.NewGuid();

string sqlInsertKomikBaru = "insert into KOMIK (ID_KOMIK, JUDUL_KOMIK, SERI, PENERBIT,


TGL_PEMBELIAN, HARGA, STATUS) values (\"" + g.ToString() + "\", \"" + inJUDUL_KOMIK + "\", \"" + inSERI + "\",
\"" + inPENERBIT + "\", \"" + inTGL_PEMBELIAN + "\", \"" + inHARGA + "\", " + "1)";

if (myConnection.dbExecuteNonQueryCommand(sqlInsertKomikBaru))
{
return true;
}
else
{
return false;
}
}

public static bool updateKomik(string oldJUDUL_KOMIK, string inJUDUL_KOMIK, string inSERI, string
inPENERBIT, string inTGL_PEMBELIAN, string inHARGA, bool inSTATUS)
{
byte status;
if (inSTATUS == true)
{
status = 1;
}

string sqlUpdateKomik = "UPDATE KOMIK SET KOMIK.JUDUL_KOMIK = \"" + inJUDUL_KOMIK + "\",


KOMIK.SERI = \"" + inSERI + "\", KOMIK.PENERBIT = \"" + inPENERBIT + "\", KOMIK.TGL_PEMBELIAN = \"" +
inTGL_PEMBELIAN + "\", KOMIK.HARGA = \"" + inHARGA + "\" where KOMIK.JUDUL_KOMIK = \"" + oldJUDUL_KOMIK +
"\"";

if (myConnection.dbExecuteNonQueryCommand(sqlUpdateKomik))
{
return true;
}
else
{
return false;

13
}
}

public static bool deleteKomik(string inJUDUL_KOMIK)


{
string sqlDeleteKomik = "delete from KOMIK where JUDUL_KOMIK = \"" + inJUDUL_KOMIK + "\"";

if (myConnection.dbExecuteNonQueryCommand(sqlDeleteKomik))
{
return true;
}
else
{
return false;
}
}
#endregion
}
}

Presentation
FormAnggota.cs
Class FormAnggota
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SewaKomikGui_net35.Controls;
using SewaKomikGui_net35.Entity.Implementation;
using System.Collections;

namespace SewaKomikGui_net35.Presentation
{
public partial class FormAnggota : Form
{
public FormAnggota()
{
InitializeComponent();
this.aNGGOTATableAdapter.ClearBeforeFill = true;
}

private void FormTambahAnggota_Load(object sender, EventArgs e)


{
this.aNGGOTATableAdapter.Fill(this.sewakomikDataSet.ANGGOTA);
}

private void rbTambahAnggota_CheckedChanged(object sender, EventArgs e)


{
if (rbTambahAnggota.Checked == true)
{
ControlCheck.clearAllTextBoxes(panelTb);
ControlCheck.enabledAllCheckBoxes(groupBox1, false);
ControlCheck.enabledAllTextBoxes(panelTb, true);
btnSimpanAnggota.Enabled = true;
btnSimpanAnggota.Text = "Tambah";
}
}

private void rbCariAnggota_CheckedChanged(object sender, EventArgs e)


{
if (rbCariAnggota.Checked == true)
{
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}

private void rbUbahAnggota_CheckedChanged(object sender, EventArgs e)


{
if (rbUbahAnggota.Checked == true)
14
{
ControlCheck.clearAllTextBoxes(panelTb);
ControlCheck.enabledAllCheckBoxes(groupBox1, true);
ControlCheck.enabledAllTextBoxes(panelTb, true);
btnSimpanAnggota.Enabled = true;
btnSimpanAnggota.Text = "Simpan";
}
}

private void rbHapusAnggota_CheckedChanged(object sender, EventArgs e)


{
if (rbHapusAnggota.Checked == true)
{
ControlCheck.clearAllTextBoxes(panelTb);
ControlCheck.enabledAllCheckBoxes(groupBox1, false);
ControlCheck.enabledAllTextBoxes(panelTb, false);
btnSimpanAnggota.Enabled = true;
btnSimpanAnggota.Text = "Hapus";
}
}

private void btnSimpanAnggota_Click(object sender, EventArgs e)


{
bool hasil;

switch (btnSimpanAnggota.Text)
{
case "Tambah":
{
bool suksesTambahAnggota;

if (ControlCheck.checkTextboxesEmptiness(panelTb))
{
suksesTambahAnggota = Anggota.tambahAnggota(tbNamaAnggota.Text,
tbAlamatAnggota.Text, tbNoTeleponAnggota.Text, tbNoTandaPengenalAnggota.Text);
}
else
{
MessageBox.Show("Harap isi semua keterangan!", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
this.aNGGOTATableAdapter.Fill(this.sewakomikDataSet.ANGGOTA);
break;

case "Cari":
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
;
break;

case "Temukan":
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
break;

case "Simpan":
{
bool suksesUpdateKomik;

if (ControlCheck.checkTextboxesEmptiness(panelTb))
{
suksesUpdateKomik =
Anggota.ubahAnggota((this.sewakomikDataSet.ANGGOTA.Rows[dataGridView1.CurrentRow.Index].ItemArray.GetValue(1))
.ToString(), tbNamaAnggota.Text, tbAlamatAnggota.Text, tbNoTeleponAnggota.Text,
tbNoTandaPengenalAnggota.Text);
}
else
{
MessageBox.Show("Harap isi semua keterangan!", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
this.aNGGOTATableAdapter.Fill(this.sewakomikDataSet.ANGGOTA);
;
break;

15
case "Hapus":
{
bool suksesHapusKomik;

if (String.IsNullOrEmpty(tbNamaAnggota.Text) == false)
{
suksesHapusKomik = Anggota.hapusAnggota(tbNamaAnggota.Text);
}
else
{

}
}
this.aNGGOTATableAdapter.Fill(this.sewakomikDataSet.ANGGOTA);
;
break;
}
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)


{
int row = dataGridView1.CurrentRow.Index;

ArrayList arrayList = new ArrayList();

for(int i = 0; i < 5; i++)


{
arrayList.Insert(i, (this.sewakomikDataSet.ANGGOTA.Rows[row].ItemArray.GetValue(i)));
}

tbNamaAnggota.Text = arrayList[1].ToString();
tbAlamatAnggota.Text = arrayList[2].ToString();
tbNoTeleponAnggota.Text = arrayList[3].ToString();
tbNoTandaPengenalAnggota.Text = arrayList[4].ToString();
}
}
}

FormKomik.cs
Class FormKomik
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SewaKomikGui_net35.Controls;
using SewaKomikGui_net35.Entity.Implementation;
using System.Collections;

namespace SewaKomikGui_net35.Presentation
{
public partial class FormKomik : Form
{
public FormKomik()
{
InitializeComponent();
this.kOMIKTableAdapter.ClearBeforeFill = true;
}

private void FormKomik_Load(object sender, EventArgs e)


{
this.kOMIKTableAdapter.Fill(this.sewakomikDataSet.KOMIK);
}

private void rbTambahKomik_CheckedChanged(object sender, EventArgs e)


{
if (rbTambahKomik.Checked == true)
{
ControlCheck.clearAllTextBoxes(panelTb);
ControlCheck.enabledAllCheckBoxes(groupBox1, false);
ControlCheck.enabledAllTextBoxes(panelTb, true);
btnSimpanKomik.Enabled = true;
16
btnSimpanKomik.Text = "Tambah";
}
}

private void btnKomik_Click(object sender, EventArgs e)


{
switch (btnSimpanKomik.Text)
{
case "Tambah":
{
bool suksesTambahKomik;

if (ControlCheck.checkTextboxesEmptiness(panelTb))
{
suksesTambahKomik = Komik.tambahKomik(tbJudulKomik.Text, tbSeriKomik.Text,
tbPenerbitKomik.Text, dtpTglBeliKomik.Text, tbHargaKomik.Text, "1");
}
else
{
MessageBox.Show("Harap isi semua keterangan!", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
this.kOMIKTableAdapter.Fill(this.sewakomikDataSet.KOMIK);
break;
case "Cari" :
{
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
;
break;
case "Temukan":
{
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
;
break;
case "Simpan" :
{
bool suksesUpdateKomik;

if (ControlCheck.checkTextboxesEmptiness(panelTb))
{
suksesUpdateKomik =
Komik.updateKomik((this.sewakomikDataSet.KOMIK.Rows[dataGridView1.CurrentRow.Index].ItemArray.GetValue(1).ToSt
ring()), tbJudulKomik.Text, tbSeriKomik.Text, tbPenerbitKomik.Text, dtpTglBeliKomik.Text, tbHargaKomik.Text,
cbAda.Checked);
}
else
{
MessageBox.Show("Harap isi semua keterangan!", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
this.kOMIKTableAdapter.Fill(this.sewakomikDataSet.KOMIK);
;
break;
case "Hapus" :
{
bool suksesHapusKomik;

if (String.IsNullOrEmpty(tbJudulKomik.Text) == false)
{
suksesHapusKomik = Komik.deleteKomik(tbJudulKomik.Text);
}
else
{

}
}
this.kOMIKTableAdapter.Fill(this.sewakomikDataSet.KOMIK);
;
break;
}

17
}

private void rbCariKomik_CheckedChanged(object sender, EventArgs e)


{
if (rbCariKomik.Checked == true)
{
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}

private void rbUbahKomik_CheckedChanged(object sender, EventArgs e)


{
if (rbUbahKomik.Checked == true)
{
ControlCheck.clearAllTextBoxes(panelTb);
ControlCheck.enabledAllCheckBoxes(groupBox1, true);
ControlCheck.enabledAllTextBoxes(panelTb, true);
btnSimpanKomik.Enabled = true;
btnSimpanKomik.Text = "Simpan";
}
}

private void rbHapus_CheckedChanged(object sender, EventArgs e)


{
if (rbHapusKomik.Checked == true)
{
ControlCheck.clearAllTextBoxes(panelTb);
ControlCheck.enabledAllCheckBoxes(groupBox1, false);
ControlCheck.enabledAllTextBoxes(panelTb, false);
btnSimpanKomik.Enabled = true;
btnSimpanKomik.Text = "Hapus";
}
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)


{
int row = dataGridView1.CurrentRow.Index;

ArrayList arrayList = new ArrayList();

for (int i = 0; i < 7; i++)


{
arrayList.Insert(i, (this.sewakomikDataSet.KOMIK.Rows[row].ItemArray.GetValue(i)));
}

tbJudulKomik.Text = arrayList[1].ToString();
tbSeriKomik.Text = arrayList[2].ToString();
tbPenerbitKomik.Text = arrayList[3].ToString();
dtpTglBeliKomik.Text = arrayList[4].ToString();
tbHargaKomik.Text = arrayList[5].ToString();
if (arrayList[6].ToString().Equals("0"))
{
cbAda.Checked = false;
}
else
{
cbAda.Checked = true;
}
}
}
}

FormLogin.cs
Class FormLogin
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using SewaKomikGui_net35.Controls;

18
namespace SewaKomikGui_net35.Presentation
{
public partial class FormLogin : Form
{
public FormLogin()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)


{
// periksa apakah TextBox kosong
if (ControlCheck.checkMaskedTextboxesEmptiness(panelTbLogin))
{
// periksa apakah user-password telah benar
if (UserAuthentification.authenticateUser(mtbNamaKaryawan.Text, mtbPasswordKaryawan.Text))
{
// jika cocok, buka form program
FormMainApp myFormMainApp = new FormMainApp();
myFormMainApp.Show();
this.Hide();
}
else
{
// pesan kesalahan saat user-password salah
MessageBox.Show("User atau password tidak sesuai", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}

private void btnExitApp_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

FormMainApp.cs
Class FormMainApp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SewaKomikGui_net35.Presentation
{
public partial class FormMainApp : Form
{
public FormMainApp()
{
InitializeComponent();
}

// periksa apakah ada anak MDI sudah ada


internal bool CheckMdiClientDuplicates(string WndCls)
{
Form[] mdichld = this.MdiChildren;
if (this.MdiChildren.Length == 0)
{
return true;
}
foreach (Form selfm in mdichld)
{
string str = selfm.Name;
str = str.IndexOf(WndCls).ToString();
if (str != "-1")
{
return true;
}
}
return false;
19
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void komikToolStripMenuItem_Click(object sender, EventArgs e)


{
if (CheckMdiClientDuplicates("SewaKomikGui_net35.FormKomik") == true)
{
FormKomik formKomik = new FormKomik();
formKomik.MdiParent = this;
formKomik.Show();
}
else
{
MessageBox.Show("Jendela Anggota masih terbuka", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

private void daftarSewaToolStripMenuItem_Click(object sender, EventArgs e)


{
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

private void pemasukanToolStripMenuItem_Click(object sender, EventArgs e)


{
MessageBox.Show("Maaf belum diimplementasikan", "Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

private void membersToolStripMenuItem_Click(object sender, EventArgs e)


{
if (CheckMdiClientDuplicates("SewaKomikGui_net35.FormAnggota") == true)
{
FormAnggota formAnggota = new FormAnggota();
formAnggota.MdiParent = this;
formAnggota.Show();
}
else
{
MessageBox.Show("Jendela Tambah Komik masih terbuka", "Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}

Test Case
Entity
Class Komik
Data Test
No. Method Expected Value Return Value Result
Parameter Data
inJUDUL_KOMIK Plants vs. Zombies
inSERI 1
inPENERBIT PopCap Games
1 tambahKomik TRUE TRUE Passed
inTGL_PEMBELIAN 28/09/2009
inHARGA 29999
inSTATUS 1
2 deleteKomik inJUDUL_KOMIK Plants vs. Zombies TRUE TRUE Passed
3 updateKomik oldJUDUL_KOMIK Bejeweled FALSE FALSE Passed

20
inJUDUL_KOMIK Plants vs. Zombies
inSERI 1
inPENERBIT PopCap Games
inTGL_PEMBELIAN 28/09/2009
inHARGA 29999
inSTATUS 1

Class Anggota
Data Test Expected Return
No. Method Result
Parameter Data Value Value

inNAMA_ANGGOTA Agung Diananto


inALAMAT_ANGGOTA Surabaya
tambahAnggot
1 TRUE TRUE Passed
a inNO_TELP_ANGGOTA 0315423432
748573825723689876
inNO_TANDA_PENGENAL_ANGGOTA
3
2 hapusAnggota inJUDUL_KOMIK Plants vs. Zombies FALSE FALSE Passed
oldNAMA_ANGGOTA  
inNAMA_ANGGOTA Agung Diananto

3 ubahAnggota inALAMAT_ANGGOTA Surabaya TRUE TRUE Passed


inNO_TELP_ANGGOTA 0315423432
748573825723689876
inNO_TANDA_PENGENAL_ANGGOTA
3

Class Karyawan
No Data Test
Method Expected Value Return Value Result
. Parameter Data

1 getMd5Password input dibya a482921766272cebfcdad751e6244f5b a482921766272cebfcdad751e6244f5b Passed

Controls
Class UserAuthentification
No Data Test
Method Expected Value Return Value Result
. Parameter Data
e954037b61a5686029b458e5c e954037b61a5686029b458
1 getMd5Hash input dibya Passed
6a92446 e5c6a92446
input aries
verifyMd5Ha
2 a482921766272cebfcdad751e TRUE TRUE Passed
sh hash
6244f5b
inputString dibya
authenticate
3 inputPassw TRUE TRUE Passed
User aries
ord

Code unit testing


Entity
Class Komik
Test Class Komik
21
using SewaKomikGui_net35.Entity.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using SewaKomikGui_net35.Controls;

namespace SewaKomikTest
{
[TestClass()]
public class KomikTest
{
private TestContext testContextInstance;

public TestContext TestContext


{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}

[TestMethod()]
public void deleteKomikTest()
{
string inJUDUL_KOMIK = "Plants vs. Zombies";
bool expected = false;
bool actual;
actual = Komik.deleteKomik(inJUDUL_KOMIK);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void tambahKomikTest()
{
string inJUDUL_KOMIK = "Plants vs. Zombies";
string inSERI = "1";
string inPENERBIT = "PopCap Games";
string inTGL_PEMBELIAN = "28/9/2009";
string inHARGA = "29999";
string inSTATUS = "1";
bool expected = true;
bool actual;
actual = Komik.tambahKomik(inJUDUL_KOMIK, inSERI, inPENERBIT, inTGL_PEMBELIAN, inHARGA, inSTATUS);
Assert.AreEqual(expected, actual);
}

public void updateKomikTest()


{
string oldJUDUL_KOMIK = "Bejeweled";
string inJUDUL_KOMIK = "Plants vs. Zombies";
string inSERI = "1";
string inPENERBIT = "PopCap Games";
string inTGL_PEMBELIAN = "28/9/2009";
string inHARGA = "29999";
bool inSTATUS = true;
bool expected = false;
bool actual;
actual = Komik.updateKomik(oldJUDUL_KOMIK, inJUDUL_KOMIK, inSERI, inPENERBIT, inTGL_PEMBELIAN,
inHARGA, inSTATUS);
Assert.AreEqual(expected, actual);
}
}
}

Class Anggota
Test Class Anggota
using SewaKomikGui_net35.Entity.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Windows.Forms;

22
namespace SewaKomikTest
{
[TestClass()]
public class AnggotaTest
{
private TestContext testContextInstance;

public TestContext TestContext


{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}

[TestMethod()]
public void hapusAnggotaTest()
{
string inNAMA_ANGGOTA = "Agung Diananto";
bool expected = false;
bool actual;
actual = Anggota.hapusAnggota(inNAMA_ANGGOTA);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void tambahAnggotaTest()
{
string inNAMA_ANGGOTA = "Agung Diananto";
string inALAMAT_ANGGOTA = "Surabaya";
string inNO_TELP_ANGGOTA = "0315423432";
string inNO_TANDA_PENGENAL_ANGGOTA = "7485738257236898763";
bool expected = false;
bool actual;
actual = Anggota.tambahAnggota(inNAMA_ANGGOTA, inALAMAT_ANGGOTA, inNO_TELP_ANGGOTA,
inNO_TANDA_PENGENAL_ANGGOTA);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void ubahAnggotaTest()
{
string oldNAMA_ANGGOTA = "Agung Diananto";
string inNAMA_ANGGOTA = "A. Dibyanugraha";
string inALAMAT_ANGGOTA = "Surabaya";
string inNO_TELP_ANGGOTA = "0315423432";
string inNO_TANDA_PENGENAL_ANGGOTA = "7485738257236898763";
bool expected = false;
bool actual;
actual = Anggota.ubahAnggota(oldNAMA_ANGGOTA, inNAMA_ANGGOTA, inALAMAT_ANGGOTA, inNO_TELP_ANGGOTA,
inNO_TANDA_PENGENAL_ANGGOTA);
Assert.AreEqual(expected, actual);
}
}
}

Class Karyawan
Test Class Karyawan
using SewaKomikGui_net35.Entity.Implementation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace SewaKomikTest
{
[TestClass()]
public class KaryawanTest
{
private TestContext testContextInstance;

public TestContext TestContext


{

23
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}

public void getMd5PasswordTest()


{
string inputNamaKaryawan = "dibya";
string expected = "a482921766272cebfcdad751e6244f5b";
string actual;
actual = Karyawan.getMd5Password(inputNamaKaryawan);
Assert.AreEqual(expected, actual);
}
}
}

Controls
Class UserAuthentification
Test Class UserAuthentification
using SewaKomikGui_net35.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace SewaKomikTest
{
[TestClass()]
public class UserAuthentificationTest
{
private TestContext testContextInstance;
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}

[TestMethod()]
public void authenticateUserTest()
{
string inputString = "dibya";
string inputPassword = "aries";
bool expected = true;
bool actual;
actual = UserAuthentification.authenticateUser(inputString, inputPassword);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
[DeploymentItem("SewaKomikGui_net35.exe")]
public void getMd5HashTest()
{
string input = "dibya";
string expected = "e954037b61a5686029b458e5c6a92446";
string actual;
actual = UserAuthentification_Accessor.getMd5Hash(input);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
[DeploymentItem("SewaKomikGui_net35.exe")]
public void verifyMd5HashTest()
{
string input = "aries";

24
string hash = "a482921766272cebfcdad751e6244f5b";
bool expected = true;
bool actual;
actual = UserAuthentification_Accessor.verifyMd5Hash(input, hash);
Assert.AreEqual(expected, actual);
}
}
}

Screenshot

25

Anda mungkin juga menyukai