public async Task <IActionResult> Create([FromBody] WatchListCreateModel model) { if (!await IsValidAsync(model.AssetPairIds) || string.IsNullOrEmpty(model.Name)) { return(BadRequest()); } var watchlists = await GetAllWatchlists(); if (watchlists.Any(item => item.Name == model.Name)) { return(BadRequest()); } var watchList = new WatchList { Id = Guid.NewGuid().ToString(), Name = model.Name, Order = model.Order, AssetIds = model.AssetPairIds.ToList() }; var result = await _assetsHelper.AddCustomWatchListAsync(_requestContext.ClientId, watchList); return(Ok(result.ToApiModel())); }
public void PostWatchlistsTest() { var assetId = "wrong asset id"; Step("Make GET /assets request. Take id of first asset in response", () => { var assets = apiV2.Assets.GetAssets(); Assert.That(assets.StatusCode, Is.EqualTo(HttpStatusCode.OK)); assetId = assets.GetResponseObject().Assets[0].Id; }); Step("Make POST /api/watchlists and validate response", () => { var model = new WatchListCreateModel { AssetPairIds = new List <string> { assetId }, Name = "Autotest", Order = 0 }; var response = apiV2.Watchlists.PostWatchLists(model, token); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); }); }
public async Task <IActionResult> Create([FromBody] WatchListCreateModel model) { if (!await IsValidAsync(model.AssetIds)) { return(BadRequest("Wrong assets in 'AssetIds' list")); } if (string.IsNullOrEmpty(model.Name)) { return(BadRequest("Name can't be empty")); } var watchlists = await GetAllWatchlists(); if (watchlists.Any(item => item.Name == model.Name)) { return(BadRequest($"Watch-list with name '{model.Name}' already exists")); } var watchList = new WatchList { Id = Guid.NewGuid().ToString(), Name = model.Name, Order = model.Order, AssetIds = model.AssetIds.ToList() }; var result = await _assetsService.WatchListAddCustomAsync(watchList, _requestContext.ClientId); return(Ok(result)); }
public void PostWatchlistsEmptyObjectTest() { Step("Make POST/api/watchlists with invalid token and validate response", () => { var model = new WatchListCreateModel { }; var response = apiV2.Watchlists.PostWatchLists(model, token); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); }); }
public void PostWatchlistsInvalidTokenTest() { Step("Make POST /api/watchlists with invalid token and validate response", () => { var model = new WatchListCreateModel { AssetPairIds = new List <string> { "BTCUSD" }, Name = "Autotest", Order = 1 }; var response = apiV2.Watchlists.PostWatchLists(model, Guid.NewGuid().ToString()); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized)); }); }
public IResponse <WatchListModel> PostWatchLists(WatchListCreateModel model, string token) => Request.Post("/watchlists").WithBearerToken(token).AddJsonBody(model).Build().Execute <WatchListModel>();