public async Task DeletePredefinedWatchList() { WatchListDTO TestWatchListPredefinedDelete = await CreateTestWatchList(); string url = ApiPaths.WATCH_LIST_PREDEFINED_PATH + "/" + TestWatchListPredefinedDelete.Id; var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.DELETE); Assert.True(response.Status == HttpStatusCode.NoContent); WatchListEntity entity = await this.WatchListRepository.TryGetAsync("PublicWatchList", TestWatchListPredefinedDelete.Id) as WatchListEntity; Assert.Null(entity); }
public async Task DeleteCustomWatchList() { WatchListDTO TestWatchListCustomDelete = await CreateTestWatchList(TestAccountId); string url = ApiPaths.WATCH_LIST_CUSTOM_PATH + "/" + TestWatchListCustomDelete.Id; Dictionary <string, string> queryParams = new Dictionary <string, string> { { "userId", this.TestAccountId } }; var response = await this.Consumer.ExecuteRequest(url, queryParams, null, Method.DELETE); Assert.True(response.Status == HttpStatusCode.NoContent); WatchListEntity entity = await this.WatchListRepository.TryGetAsync(this.TestAccountId, TestWatchListCustomDelete.Id) as WatchListEntity; Assert.Null(entity); }
public async Task <WatchListDTO> CreateTestWatchList(string clientId = null) { string url = ApiPaths.WATCH_LIST_BASE_PATH; Dictionary <string, string> queryParams = new Dictionary <string, string>(); bool readOnlyValue = true; if (clientId == null) { url += "/predefined"; } else { url += "/custom"; queryParams.Add("userId", clientId); readOnlyValue = false; } WatchListEntity tempalteEntity = EnumerableUtils.PickRandom(AllWatchListsFromDB); WatchListDTO createDTO = new WatchListDTO() { Id = tempalteEntity.Id, Name = tempalteEntity.Name, ReadOnly = tempalteEntity.ReadOnly, Order = tempalteEntity.Order, AssetIds = tempalteEntity.AssetIDsList }; createDTO.Id += Helpers.Random.Next(1000, 9999).ToString() + GlobalConstants.AutoTest; createDTO.Name += Helpers.Random.Next(1000, 9999).ToString() + GlobalConstants.AutoTest; createDTO.ReadOnly = readOnlyValue; string createParam = JsonUtils.SerializeObject(createDTO); var response = await Consumer.ExecuteRequest(url, queryParams, createParam, Method.POST); if (response.Status != HttpStatusCode.Created) { return(null); } AddOneTimeCleanupAction(async() => await DeleteTestWatchList(createDTO.Id, clientId)); return(createDTO); }
public async Task UpdateCustomWatchList() { string url = ApiPaths.WATCH_LIST_CUSTOM_PATH; WatchListDTO TestWatchListCustomUpdate = await CreateTestWatchList(TestAccountId); Dictionary <string, string> queryParams = new Dictionary <string, string> { { "userId", this.TestAccountId } }; WatchListDTO updateWatchList = new WatchListDTO() { Id = TestWatchListCustomUpdate.Id, Name = TestWatchListCustomUpdate.Name + Helpers.Random.Next(1000, 9999).ToString() + GlobalConstants.AutoTest, Order = Helpers.Random.Next(1, 100), ReadOnly = TestWatchListCustomUpdate.ReadOnly, AssetIds = TestWatchListCustomUpdate.AssetIds }; updateWatchList.AssetIds.Add("AutoTest"); string updateParam = JsonUtils.SerializeObject(updateWatchList); var response = await this.Consumer.ExecuteRequest(url, queryParams, updateParam, Method.PUT); Assert.True(response.Status == HttpStatusCode.NoContent); WatchListEntity entity = await this.WatchListRepository.TryGetAsync(this.TestAccountId, updateWatchList.Id) as WatchListEntity; Assert.NotNull(entity); entity.ShouldBeEquivalentTo(updateWatchList, o => o .ExcludingMissingMembers() .Excluding(e => e.AssetIds) .Excluding(e => e.ReadOnly)); entity.AssetIDsList.Should().HaveSameCount(updateWatchList.AssetIds); foreach (string assetId in entity.AssetIDsList) { updateWatchList.AssetIds.Should().Contain(assetId); } }
public async Task CreatePredefinedWatchList() { WatchListDTO createdDTO = await this.CreateTestWatchList(); Assert.NotNull(createdDTO); WatchListEntity entity = await this.WatchListRepository.TryGetAsync("PublicWatchList", createdDTO.Id) as WatchListEntity; Assert.NotNull(entity); entity.ShouldBeEquivalentTo(createdDTO, o => o .ExcludingMissingMembers() .Excluding(e => e.AssetIds) .Excluding(e => e.ReadOnly)); entity.AssetIDsList.Should().HaveSameCount(createdDTO.AssetIds); foreach (string assetId in entity.AssetIDsList) { createdDTO.AssetIds.Should().Contain(assetId); } }
/// <summary> /// Converts a WatchListEntity to WatchListModel. /// </summary> /// <param name="watchListEntity">WatchListEntity to be converted to WatchListModel.</param> /// <returns>WatchListModel corresponding to WatchListEntity.</returns> public static WatchListModel ConvertWatchListEntityToModel(WatchListEntity watchListEntity) { return(new WatchListModel { AlertRequired = watchListEntity.AlertRequired, AltNameOne = watchListEntity.AltNameOne, AltNameThree = watchListEntity.AltNameThree, AltNameTwo = watchListEntity.AltNameTwo, BseSymbol = watchListEntity.BseSymbol, CreatedOn = (watchListEntity.CreatedOn != null) ? DataFormatter.FormatDateToString(DataFormatter.GetDateTimeInLocalFormat(watchListEntity.CreatedOn)) : null, IsActive = watchListEntity.IsActive, ModifiedOn = (watchListEntity.ModifiedOn != null) ? DataFormatter.FormatDateToString(DataFormatter.GetDateTimeInLocalFormat(watchListEntity.ModifiedOn)) : null, Name = watchListEntity.Name, NseSymbol = watchListEntity.NseSymbol, TempName = watchListEntity.TempName, WatchListID = watchListEntity.WatchListID }); }
/// <summary> /// Business method to add/update WatchListEntity based on Id. /// </summary> /// <param name="watchListEntity">WatchListEntity to be saved or updated.</param> /// <returns>Id of WatchListEntity inserted/updated.</returns> public int SaveWatchListItem(WatchListEntity watchListEntity) { IWatchListDataHandler watchListData = new WatchListDataHandler(); return(watchListData.SaveWatchListItem(watchListEntity)); }
/// <summary> /// Data handling method to add/update WatchListEntity based on Id. /// </summary> /// <param name="watchListEntity">WatchListEntity to be saved or updated.</param> /// <returns>Id of WatchListEntity inserted/updated.</returns> public int SaveWatchListItem(WatchListEntity watchListEntity) { int watchListIdSaved; try { using (DbCommand cmd = Database.GetStoredProcCommand(DataAccess.StoredProcedure.Dbo.WATCH_LIST_ITEM_SAVE)) { cmd.Connection = Database.CreateConnection(); cmd.Connection.Open(); Database.AddInParameter(cmd, DataAccess.Params.BSE_SYMBOL, DbType.String, SqlUtil.ParameterValue(watchListEntity.BseSymbol)); Database.AddInParameter(cmd, DataAccess.Params.NSE_SYMBOL, DbType.String, SqlUtil.ParameterValue(watchListEntity.NseSymbol)); Database.AddInParameter(cmd, DataAccess.Params.NAME, DbType.String, SqlUtil.ParameterValue(watchListEntity.Name)); Database.AddInParameter(cmd, DataAccess.Params.ALT_NAME_ONE, DbType.String, SqlUtil.ParameterValue(watchListEntity.AltNameOne)); Database.AddInParameter(cmd, DataAccess.Params.ALT_NAME_TWO, DbType.String, SqlUtil.ParameterValue(watchListEntity.AltNameTwo)); Database.AddInParameter(cmd, DataAccess.Params.ALT_NAME_THREE, DbType.String, SqlUtil.ParameterValue(watchListEntity.AltNameThree)); Database.AddInParameter(cmd, DataAccess.Params.TEMP_NAME, DbType.String, SqlUtil.ParameterValue(watchListEntity.TempName)); Database.AddInParameter(cmd, DataAccess.Params.IS_ACTIVE, DbType.Boolean, SqlUtil.ParameterValue(watchListEntity.IsActive)); Database.AddInParameter(cmd, DataAccess.Params.ALERT_REQUIRED, DbType.Boolean, SqlUtil.ParameterValue(watchListEntity.AlertRequired)); Database.AddInParameter(cmd, DataAccess.Params.MODIFIED_ON, DbType.DateTime, SqlUtil.ParameterValue(watchListEntity.ModifiedOn)); Database.AddInParameter(cmd, DataAccess.Params.CREATED_ON, DbType.DateTime, SqlUtil.ParameterValue(watchListEntity.CreatedOn)); Database.AddParameter(cmd, DataAccess.Params.WATCH_LIST_ID, DbType.Int32, ParameterDirection.InputOutput, null, DataRowVersion.Default, watchListEntity.WatchListID); var dbRes = cmd.ExecuteNonQuery(); watchListIdSaved = SqlUtil.SetValue(cmd.Parameters["@" + DataAccess.Params.WATCH_LIST_ID], 0); // Set the value to 0 if DB operation failed. watchListIdSaved = (dbRes > 0) ? watchListIdSaved : 0; } } catch (Exception exception) { watchListIdSaved = 0; } return(watchListIdSaved); }
/// <summary> /// Data handling method to search for WatchList entities based on search criteria. /// </summary> /// <param name="searchCriteria">The search criteria object containing all required criteria info.</param> /// <param name="watchListId">Id of particular watchlist entity that has to be fetched. Pass 0 if not applicable.</param> /// <returns>List of WatchListEntity.</returns> public IList <WatchListEntity> SearchWatchList(GridSearchCriteriaEntity searchCriteria, int watchListId) { var watchList = new List <WatchListEntity>(); try { using (DbCommand cmd = Database.GetStoredProcCommand(DataAccess.StoredProcedure.Dbo.WATCH_LIST_SEARCH)) { cmd.Connection = Database.CreateConnection(); cmd.Connection.Open(); Database.AddInParameter(cmd, DataAccess.Params.WATCH_LIST_ID, DbType.Int32, SqlUtil.ParameterValue(watchListId)); Database.AddInParameter(cmd, DataAccess.Params.START_ROW_INDEX, DbType.Int32, SqlUtil.ParameterValue(searchCriteria.StartRowIndex)); Database.AddInParameter(cmd, DataAccess.Params.MAXIMUM_ROWS, DbType.Int32, SqlUtil.ParameterValue(searchCriteria.MaximumRows)); Database.AddInParameter(cmd, DataAccess.Params.SORT_COLUMN, DbType.String, SqlUtil.ParameterValue(searchCriteria.SortColumn)); Database.AddInParameter(cmd, DataAccess.Params.SORT_ASCENDING, DbType.Boolean, SqlUtil.ParameterValue(searchCriteria.SortAscending)); Database.AddInParameter(cmd, DataAccess.Params.SEARCH_CRITERIA, DbType.Xml, SqlUtil.ParameterValue(searchCriteria.SearchCriteria)); Database.AddInParameter(cmd, DataAccess.Params.TEXT_SEARCH_KEY, DbType.String, SqlUtil.ParameterValue(searchCriteria.TextSearchKey)); Database.AddInParameter(cmd, DataAccess.Params.SEARCH_AGAINST, DbType.Boolean, SqlUtil.ParameterValue(searchCriteria.SearchAgainst)); Database.AddInParameter(cmd, DataAccess.Params.SEARCH_WITH_OR, DbType.Boolean, SqlUtil.ParameterValue(searchCriteria.SearchWithOr)); Database.AddParameter(cmd, DataAccess.Params.RECORD_COUNT, DbType.Int32, ParameterDirection.InputOutput, null, DataRowVersion.Default, searchCriteria.RecordCount); using (IDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { var watchListItem = new WatchListEntity(); watchListItem.Load(SqlUtil.SetValue(dr[DataAccess.Params.WATCH_LIST_ID], 0), SqlUtil.SetValue(dr[DataAccess.Params.BSE_SYMBOL], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.NSE_SYMBOL], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.NAME], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.ALT_NAME_ONE], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.ALT_NAME_TWO], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.ALT_NAME_THREE], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.TEMP_NAME], string.Empty), SqlUtil.SetValue(dr[DataAccess.Params.IS_ACTIVE], true), SqlUtil.SetValue(dr[DataAccess.Params.ALERT_REQUIRED], true), SqlUtil.SetValue(dr[DataAccess.Params.CREATED_ON], DateTime.MinValue), SqlUtil.SetValue(dr[DataAccess.Params.MODIFIED_ON], DateTime.MinValue)); watchList.Add(watchListItem); } } searchCriteria.RecordCount = SqlUtil.SetValue(cmd.Parameters["@" + DataAccess.Params.RECORD_COUNT], 0); } } catch (Exception exception) { watchList = null; } return(watchList); }