public void GetCompanies_InvalidRegulatorCode(string name) { RunInitSql(name, "ConnectionStringFilings"); GetCompanies request = PrepareRequest <GetCompanies>(name); GetCompaniesResponse response = Post <GetCompanies, GetCompaniesResponse>("GetCompanies", request); RunFinalizeSql(name, "ConnectionStringFilings"); Assert.AreEqual(response.Success, true, "GetCompanies call failed"); Assert.AreEqual(response.Payload.Companies.Count, 0, "Non-empty list of companies returned for invalid regulator code"); }
public void GetCompanies_Success(string name) { RunInitSql(name, "ConnectionStringFilings"); GetCompanies request = PrepareRequest <GetCompanies>(name); GetCompaniesResponse response = Post <GetCompanies, GetCompaniesResponse>("GetCompanies", request); RunFinalizeSql(name, "ConnectionStringFilings"); Assert.AreEqual(response.Success, true, "GetCompanies call failed"); Assert.Greater(response.Payload.Companies.Count, 0, "Empty companies list returned"); }
public void GetCompanies_InvalidSession(string name) { RunInitSql(name, "ConnectionStringFilings"); GetCompanies request = PrepareRequest <GetCompanies>(name); request.SessionToken = Guid.NewGuid().ToString(); GetCompaniesResponse response = Post <GetCompanies, GetCompaniesResponse>("GetCompanies", request); RunFinalizeSql(name, "ConnectionStringFilings"); Assert.AreEqual(response.Success, false, "GetCompanies succeeded with invalid session"); Assert.AreEqual(response.Payload.Companies.Count, 0, "Regulator list is not empty"); Assert.IsNotEmpty(response.Errors, "Errors are empty in the response"); Assert.AreEqual(response.Errors[0].Code, EErrorCodes.InvalidSession, "Incorrect error code returned"); }
public Task Handle(GetCompaniesRequest message, IMessageHandlerContext context) { log.Info("Received GetCompaniesRequest"); List <Company> companies; using (var unitOfWork = new CarUnitOfWork(new CarApiContext(_dbContextOptionsBuilder.Options))) { companies = unitOfWork.Companies.GetAll().ToList(); } var response = new GetCompaniesResponse { DataId = Guid.NewGuid(), Companies = companies }; var reply = context.Reply(response); return(reply); }
public object Any(GetCompanies request) { DateTime dtStart = DateTime.UtcNow; _logger.Log(EErrorType.Info, " ****** Call start: GetCompanies"); GetCompaniesResponse response = new GetCompaniesResponse(); TransferHeader(request, response); EErrorCodes valSession = ValidateSession(request.SessionToken); if (valSession == EErrorCodes.Success) { try { GetRegulatorCompaniesParams getCmpParams = new GetRegulatorCompaniesParams(); getCmpParams.RegulatorCode = request.RegulatorCode; var companies = _dal.GetCompaniesByRegulator(getCmpParams); if (companies != null && companies.Companies != null) { foreach (var c in companies.Companies) { response.Payload.Companies.Add(new DTO.CompanyInfo() { Name = c.Name, Code = c.Code, LastUpdate = c.LastUpdated != DateTime.MinValue ? (DateTime?)c.LastUpdated : null }); } } else { response.Errors.Add(new Error() { Code = EErrorCodes.EmptyCollection, Type = EErrorType.Warning, Message = string.Format("No companies found for regulator {0}", request.RegulatorCode) }); } response.Payload.RegulatorCode = request.RegulatorCode; response.Success = true; } catch (Exception ex) { _logger.Log(ex); response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.GeneralError, Type = EErrorType.Error, Message = string.Format("Unpexcted error: {0}", ex.Message) }); } } else { response.Success = false; response.Errors.Add(new Error() { Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = string.Format("Invalid session") }); } DateTime dtEnd = DateTime.UtcNow; _logger.Log(EErrorType.Info, string.Format(" ****** Call end: GetCompanies\t{0}", dtEnd - dtStart)); return(response); }