public void Insert() { short routes = 0; BAudit bAudit = new BAudit(); EAudit eAudit = null; BUser bUser = new BUser(); EUser eUser = new EUser(); EUser insertedUser = null; TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); eUser.CodeUser = Aleatory.GetString(8); eUser.Name = Aleatory.GetString(8); eUser.Password = Aleatory.GetString(8); eUser.Email = Aleatory.GetString(15); eUser.State = Aleatory.GetShort(); eUser.Audit.UserRegister = Aleatory.GetString(8); if (bUser.Select(eUser) != null) { bUser.Delete(eUser); } if (bUser.Select(eUser) == null) { routes++; } bUser.Insert(eUser); insertedUser = bUser.Select(eUser); if (insertedUser != null) { routes++; } string hash = bUser.CalculateHash(eUser); if (insertedUser.Password == hash) { routes++; } eAudit = bAudit.Select(eUser.Audit). Where(x => x.UserRegister == eUser.Audit.UserRegister && x.Code == eUser.Audit.Code && x.TypeEvent == "Insert").FirstOrDefault(); if (eAudit != null) { routes++; } ts.Dispose(); Assert.AreEqual(routes, 4); }
public void Delete() { bool result = false; BUserCompany bUserCompany = new BUserCompany(); EUserCompany eUserCompany = new EUserCompany(); EUserCompany insertedUserCompany = new EUserCompany(); EUserCompany deletedUserCompany = new EUserCompany(); BCorporation bCorporation = new BCorporation(); ECorporation eCorporation = new ECorporation(); BCompany bCompany = new BCompany(); ECompany eCompany = new ECompany(); BUser bUser = new BUser(); EUser eUser = new EUser(); TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); eCorporation.CodeCorporation = Aleatory.GetString(2); eCorporation.Name = Aleatory.GetString(15); eCorporation.State = Aleatory.GetShort(); eCorporation.Audit.UserRegister = Aleatory.GetString(8); bCorporation.Insert(eCorporation); eCompany.CodeCompany = Aleatory.GetString(2); eCompany.CodeCorporation = eCorporation.CodeCorporation; eCompany.Ruc = Aleatory.GetString(11); eCompany.LongName = Aleatory.GetString(15); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = Aleatory.GetString(8); bCompany.Insert(eCompany); eUser.CodeUser = Aleatory.GetString(8); eUser.Name = Aleatory.GetString(8); eUser.Password = Aleatory.GetString(8); eUser.State = Aleatory.GetShort(); eUser.Audit.UserRegister = Aleatory.GetString(8); bUser.Insert(eUser); eUserCompany.CodeUser = eUser.CodeUser; eUserCompany.CodeCompany = eCompany.CodeCompany; bUserCompany.Insert(eUserCompany); insertedUserCompany = bUserCompany.Select(eUserCompany); if (insertedUserCompany != null) { bUserCompany.Delete(eUserCompany); } deletedUserCompany = bUserCompany.Select(eUserCompany); if (deletedUserCompany == null) { result = true; } Assert.IsTrue(result); }
public void Update() { short routes = 0; BAudit bAudit = new BAudit(); EAudit eAudit = null; BCompany bCompany = new BCompany(); ECompany eCompany = new ECompany(); ECompany updatedCompany = new ECompany(); BCorporation bCorporation = new BCorporation(); ECorporation eCorporation = new ECorporation(); TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); eCorporation.CodeCorporation = Aleatory.GetString(2); eCorporation.Name = Aleatory.GetString(8); eCorporation.State = Aleatory.GetShort(); eCorporation.Audit.UserRegister = Aleatory.GetString(8); bCorporation.Insert(eCorporation); eCompany.CodeCompany = Aleatory.GetString(2); eCompany.Ruc = Aleatory.GetString(11); eCompany.CodeCorporation = eCorporation.CodeCorporation; eCompany.LongName = Aleatory.GetString(8); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = Aleatory.GetString(8); bCompany.Insert(eCompany); eCompany.LongName = Aleatory.GetString(8); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = Aleatory.GetString(8); bCompany.Update(eCompany); updatedCompany = bCompany.Select(eCompany); if (updatedCompany != null && updatedCompany.CodeCompany == eCompany.CodeCompany && updatedCompany.CodeCorporation == eCompany.CodeCorporation && updatedCompany.LongName != eCompany.LongName && updatedCompany.State == eCompany.State) { routes++; } eAudit = bAudit.Select(eCompany.Audit). Where(x => x.UserRegister == eCompany.Audit.UserRegister && x.Code == eCompany.Audit.Code && x.TypeEvent == "Update").FirstOrDefault(); if (eAudit != null) { routes++; } ts.Dispose(); }
public void Delete() { short routes = 0; BAudit bAudit = new BAudit(); EAudit eAudit = null; BCompany bCompany = new BCompany(); ECompany eCompany = new ECompany(); BCorporation bCorporation = new BCorporation(); ECorporation eCorporation = new ECorporation(); TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); eCorporation.CodeCorporation = Aleatory.GetString(2); eCorporation.Name = Aleatory.GetString(8); eCorporation.State = 1; eCorporation.Audit.UserRegister = Aleatory.GetString(8); bCorporation.Insert(eCorporation); eCompany.CodeCompany = Aleatory.GetString(2); eCompany.Ruc = Aleatory.GetString(11); eCompany.CodeCorporation = eCorporation.CodeCorporation; eCompany.LongName = Aleatory.GetString(8); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = Aleatory.GetString(8); bCompany.Insert(eCompany); if (bCompany.Select(eCompany) != null) { routes++; } bCompany.Delete(eCompany); if (bCompany.Select(eCompany) == null) { routes++; } eAudit = bAudit.Select(eCompany.Audit). Where(x => x.UserRegister == eCompany.Audit.UserRegister && x.TypeEvent == "Delete" && x.Code == eCompany.Audit.Code).FirstOrDefault(); if (eAudit != null) { routes++; } ts.Dispose(); Assert.AreEqual(routes, 3); }
public void GetShort() { bool result = false; List <short> list = new List <short>(); List <short> dist = new List <short>(); short value = 0; for (int i = 1; i <= 10; i++) { value = Aleatory.GetShort(); list.Add(value); } dist = list.Distinct().ToList(); if (list.Count == dist.Count) { result = true; } Assert.IsTrue(result); }
public void Insert() { bool result = false; string codeSequence = Aleatory.GetString(8); int correlativo = Aleatory.GetShort(); BSequence bSequence = new BSequence(); ESequence eSequence = new ESequence(codeSequence, correlativo); ESequence insertedSequence = null; TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); bSequence.Insert(eSequence); insertedSequence = bSequence.Select(eSequence); if (insertedSequence != null && insertedSequence.CodeSequence == eSequence.CodeSequence && insertedSequence.Correlative == eSequence.Correlative) { result = true; } ts.Dispose(); Assert.AreEqual(result, true); }
public void DeleteByUser() { bool result = false; List <ECompany> listECompanies = new List <ECompany>(); BUserCompany bUserCompany = new BUserCompany(); EUserCompany eUserCompany = new EUserCompany(); EUserCompany insertedOneUserCompany = new EUserCompany(); EUserCompany insertedTwoUserCompany = new EUserCompany(); BCorporation bCorporation = new BCorporation(); ECorporation eCorporation = new ECorporation(); BCompany bCompany = new BCompany(); ECompany eCompany = new ECompany(); BUser bUser = new BUser(); EUser eUser = new EUser(); TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); eCorporation.CodeCorporation = Aleatory.GetString(2); eCorporation.Name = Aleatory.GetString(15); eCorporation.State = Aleatory.GetShort(); eCorporation.Audit.UserRegister = Aleatory.GetString(8); bCorporation.Insert(eCorporation); eCompany.CodeCompany = Aleatory.GetString(2); eCompany.CodeCorporation = eCorporation.CodeCorporation; eCompany.Ruc = Aleatory.GetString(11); eCompany.LongName = Aleatory.GetString(15); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = Aleatory.GetString(8); bCompany.Insert(eCompany); eUser.CodeUser = Aleatory.GetString(8); eUser.Name = Aleatory.GetString(8); eUser.Password = Aleatory.GetString(8); eUser.State = Aleatory.GetShort(); eUser.Audit.UserRegister = Aleatory.GetString(8); bUser.Insert(eUser); eUserCompany.CodeUser = eUser.CodeUser; eUserCompany.CodeCompany = eCompany.CodeCompany; bUserCompany.Insert(eUserCompany); insertedOneUserCompany = bUserCompany.Select(eUserCompany); eCompany.CodeCompany = Aleatory.GetString(2); eCompany.CodeCorporation = eCorporation.CodeCorporation; eCompany.LongName = Aleatory.GetString(15); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = Aleatory.GetString(8); bCompany.Insert(eCompany); eUserCompany.CodeUser = eUser.CodeUser; eUserCompany.CodeCompany = eCompany.CodeCompany; bUserCompany.Insert(eUserCompany); insertedTwoUserCompany = bUserCompany.Select(eUserCompany); listECompanies = bUserCompany.SelectByUser(eUser); if (listECompanies.Count == 2 && listECompanies.Exists(x => x.CodeCompany == insertedOneUserCompany.CodeCompany) && listECompanies.Exists(x => x.CodeCompany == insertedTwoUserCompany.CodeCompany)) { bUserCompany.DeleteByUser(eUser); } listECompanies = bUserCompany.SelectByUser(eUser); if (listECompanies.Count == 0) { result = true; } Assert.IsTrue(result); }
public void Update() { ECorporation eCorporation = new ECorporation(); BCorporation bCorporation = new BCorporation(); BAudit bAudit = new BAudit(); short routes = 0; eCorporation.CodeCorporation = Aleatory.GetString(2); eCorporation.Name = Aleatory.GetString(8); eCorporation.State = Aleatory.GetShort(); eCorporation.Audit.UserRegister = Aleatory.GetString(8); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew)) { bCorporation.Insert(eCorporation); ECorporation originalCorporation = bCorporation.Select(eCorporation); if (originalCorporation != null && originalCorporation.Name == eCorporation.Name && originalCorporation.State == eCorporation.State) { routes++; } EAudit lastAudit = bAudit.Select(eCorporation.Audit).Where(x => x.UserRegister == eCorporation.Audit.UserRegister && x.TypeEvent == "Insert").FirstOrDefault(); if (lastAudit != null) { routes++; } eCorporation.Name = string.Format("{0} {1}", eCorporation.Name, "update"); eCorporation.State = Aleatory.GetShort(); eCorporation.Audit.UserRegister = Aleatory.GetString(8); bCorporation.Update(eCorporation); ECorporation updatedCorporation = bCorporation.Select(eCorporation); if (updatedCorporation != null && updatedCorporation.Name == eCorporation.Name && updatedCorporation.State == eCorporation.State && updatedCorporation.Name != originalCorporation.Name && updatedCorporation.State != originalCorporation.State) { routes++; } lastAudit = bAudit.Select(updatedCorporation.Audit). Where(x => x.UserRegister == eCorporation.Audit.UserRegister && x.Code == eCorporation.Audit.Code && x.TypeEvent == "Update").FirstOrDefault(); if (lastAudit != null) { routes++; } } Assert.AreEqual(routes, 4); }
public void Delete() { short routes = 0; BAudit bAudit = new BAudit(); EAudit eAudit = null; BCorporation bCorporation = new BCorporation(); ECorporation eCorporation = new ECorporation(); ECorporation insertedCorporation = new ECorporation(); BCompany bCompany = new BCompany(); ECompany eCompany = new ECompany(); ECompany insertedCompany = new ECompany(); TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew); eCorporation.CodeCorporation = Aleatory.GetString(2); eCorporation.Name = Aleatory.GetString(8); eCorporation.State = Aleatory.GetShort(); eCorporation.Audit.UserRegister = Aleatory.GetString(8); bCorporation.Insert(eCorporation); insertedCorporation = bCorporation.Select(eCorporation); if (insertedCorporation != null) { routes++; } insertedCorporation.Audit.UserRegister = eCorporation.Audit.UserRegister; bCorporation.Delete(insertedCorporation); if (bCorporation.Select(insertedCorporation) == null) { routes++; } eAudit = bAudit.Select(eCorporation.Audit). Where(x => x.UserRegister == eCorporation.Audit.UserRegister && x.Code == eCorporation.Audit.Code && x.TypeEvent == "Delete").FirstOrDefault(); if (eAudit != null) { routes++; } bCorporation.Insert(eCorporation); eCompany.CodeCorporation = eCorporation.CodeCorporation; eCompany.Ruc = Aleatory.GetString(11); eCompany.CodeCompany = Aleatory.GetString(2); eCompany.LongName = Aleatory.GetString(8); eCompany.State = Aleatory.GetShort(); eCompany.Audit.UserRegister = eCorporation.Audit.UserRegister; bCompany.Insert(eCompany); insertedCompany = bCompany.Select(eCompany); if (insertedCompany != null) { try { eCorporation.Audit.UserRegister = Aleatory.GetString(9); bCorporation.Delete(eCorporation); } catch { } if (bCorporation.Message.Contains("La Corporación") && bCorporation.Message.Contains("tiene referencias en el Sistema, no se puede eliminar el registro.")) { routes++; } eAudit = bAudit.Select(eCorporation.Audit). Where(x => x.UserRegister == eCorporation.Audit.UserRegister && x.Code == eCorporation.Audit.Code && x.TypeEvent == "Delete").FirstOrDefault(); if (eAudit == null) { routes++; } } ts.Dispose(); Assert.AreEqual(routes, 5); }