Exemplo n.º 1
0
        public void RemoveAccountAlerts_InvalidSessionToken(string name)
        {
            RunInitSql(name, "ConnectionStringAlerts");

            // getting alerts to obtain IDs
            GetAccountAlerts getAlertsReq = new GetAccountAlerts()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                SessionToken = ConfigurationManager.AppSettings["SessionToken"],
                RequestID    = Guid.NewGuid().ToString()
            };

            GetAccountAlertsResponse getAlertsResp = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", getAlertsReq);

            // setting proper IDs
            RemoveAccountAlerts request = PrepareRequest <RemoveAccountAlerts>(name);

            request.SubscriptionIds.AddRange(getAlertsResp.Payload.Alerts.Select(x => x.ID));

            RemoveAccountAlertsResponse response = Post <RemoveAccountAlerts, RemoveAccountAlertsResponse>("RemoveAccountAlerts", request);

            RunFinalizeSql(name, "ConnectionStringAlerts");

            Assert.AreEqual(response.Success, false, "RemoveAccountAlerts succeeded unexpectedly");
            Assert.IsNotNull(response.Errors.FirstOrDefault(e => e.Type == Interfaces.EErrorType.Error), "Errors are empty");
            Assert.AreEqual(response.Errors[0].Code, Interfaces.EErrorCodes.InvalidSession, "Wrong error code returned");
        }
Exemplo n.º 2
0
        public void RemoveAccountAlerts_Success(string name)
        {
            RunInitSql(name, "ConnectionStringAlerts");

            // getting alerts to obtain IDs
            GetAccountAlerts getAlertsReq = new GetAccountAlerts()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                SessionToken = ConfigurationManager.AppSettings["SessionToken"],
                RequestID    = Guid.NewGuid().ToString()
            };

            GetAccountAlertsResponse getAlertsResp = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", getAlertsReq);

            // setting proper IDs
            RemoveAccountAlerts request = PrepareRequest <RemoveAccountAlerts>(name);

            request.SubscriptionIds.AddRange(getAlertsResp.Payload.Alerts.Select(x => x.ID));

            RemoveAccountAlertsResponse response = Post <RemoveAccountAlerts, RemoveAccountAlertsResponse>("RemoveAccountAlerts", request);

            RunFinalizeSql(name, "ConnectionStringAlerts");

            Assert.AreEqual(response.Success, true, "RemoveAccountAlerts failed unexpectedly");
        }
Exemplo n.º 3
0
        public void UpdateAccountAlerts_InvalidSessionToken(string name)
        {
            RunInitSql(name, "ConnectionStringAlerts");

            // getting alerts to obtain IDs
            GetAccountAlerts getAlertsReq = new GetAccountAlerts()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                SessionToken = ConfigurationManager.AppSettings["SessionToken"],
                RequestID    = Guid.NewGuid().ToString()
            };

            GetAccountAlertsResponse getAlertsResp = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", getAlertsReq);

            // setting proper IDs
            UpdateAccountAlerts request = PrepareRequest <UpdateAccountAlerts>(name);

            foreach (var a in request.Alerts)
            {
                var alert = getAlertsResp.Payload.Alerts.FirstOrDefault(x => a.Name.Contains(x.Name));
                if (alert != null)
                {
                    a.ID = alert.ID;
                }
            }

            UpdateAccountAlertsResponse response = Post <UpdateAccountAlerts, UpdateAccountAlertsResponse>("UpdateAccountAlerts", request);

            RunFinalizeSql(name, "ConnectionStringAlerts");

            Assert.AreEqual(response.Success, false, "UpdateAccountAlerts succeeded unexpectedly");
            Assert.IsNotNull(response.Errors.FirstOrDefault(e => e.Type == Interfaces.EErrorType.Error), "Errors are empty");
            Assert.AreEqual(response.Errors[0].Code, Interfaces.EErrorCodes.InvalidSession, "Wrong error code returned");
        }
Exemplo n.º 4
0
        public void UpdateAccountAlerts_NewAccountKey(string name)
        {
            RunInitSql(name, "ConnectionStringAlerts");

            // getting alerts to obtain IDs
            GetAccountAlerts getAlertsReq = new GetAccountAlerts()
            {
                AccountKey   = ConfigurationManager.AppSettings["AccountKey"],
                SessionToken = ConfigurationManager.AppSettings["SessionToken"],
                RequestID    = Guid.NewGuid().ToString()
            };

            GetAccountAlertsResponse getAlertsResp = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", getAlertsReq);

            // setting proper IDs
            UpdateAccountAlerts request = PrepareRequest <UpdateAccountAlerts>(name);

            foreach (var a in request.Alerts)
            {
                var alert = getAlertsResp.Payload.Alerts.FirstOrDefault(x => a.Name.Contains(x.Name));
                if (alert != null)
                {
                    a.ID = alert.ID;
                }
            }

            UpdateAccountAlertsResponse response = Post <UpdateAccountAlerts, UpdateAccountAlertsResponse>("UpdateAccountAlerts", request);

            RunFinalizeSql(name, "ConnectionStringAlerts");

            Assert.AreEqual(response.Success, true, "UpdateAccountAlerts failed unexpectedly");
        }
Exemplo n.º 5
0
        public void GetAccountAlerts_InvalidKey(string name)
        {
            RunInitSql(name, "ConnectionStringAlerts");

            GetAccountAlerts request = PrepareRequest <GetAccountAlerts>(name);

            GetAccountAlertsResponse response = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", request);

            RunFinalizeSql(name, "ConnectionStringAlerts");

            Assert.AreEqual(response.Success, true, "GetAccountAlerts call failed unexpectedly");
            Assert.IsEmpty(response.Payload.Alerts, "Alerts are not empty");
        }
Exemplo n.º 6
0
        public void GetAccountAlerts_Success(string name)
        {
            RunInitSql(name, "ConnectionStringAlerts");

            GetAccountAlerts request = PrepareRequest <GetAccountAlerts>(name);

            GetAccountAlertsResponse response = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", request);

            RunFinalizeSql(name, "ConnectionStringAlerts");

            Assert.AreEqual(response.Success, true, "GetAccountAlerts call failed");
            Assert.IsNotEmpty(response.Payload.Alerts, "Alerts is empty");
            Assert.AreEqual(response.Payload.Alerts.Count, 2, "Invalid alerts count");
        }
Exemplo n.º 7
0
        public GetAccountAlertsResponse PostGetAccountAlerts(GetAccountAlerts request)
        {
            GetAccountAlertsResponse response = Post <GetAccountAlerts, GetAccountAlertsResponse>("GetAccountAlerts", request);

            return(response);
        }
        public object Any(GetAccountAlerts request)
        {
            GetAccountAlertsResponse response = new GetAccountAlertsResponse();

            TransferHeader(request, response);

            try
            {
                if (IsValidSessionToken(request))
                {
                    IAlertsDalGetAccountSubscriptionsParams getSubsParams = _dal.CreateGetAccountSubscrParams();
                    getSubsParams.AccountKey = request.AccountKey;

                    var getSubsResult = _dal.GetAccountSubscriptions(getSubsParams);
                    if (getSubsResult.Success)
                    {
                        response.Payload.AccountKey = request.AccountKey;
                        foreach (var s in getSubsResult.Subscriptions)
                        {
                            AlertSubscription alertSub = new AlertSubscription()
                            {
                                AlertTypeId        = s.TypeId,
                                ID                 = s.Id,
                                Name               = s.Name,
                                NotificationTypeId = (long)s.NotificationTypeId,
                                Subscribed         = (DateTime)s.SubscribedDttm,
                                StatusId           = s.StatusId
                            };
                            foreach (var p in s.SubscriptionData)
                            {
                                alertSub.Properties.Add(new AlertSubscriptionProperty()
                                {
                                    Name  = p.Key,
                                    Value = p.Value
                                });
                            }

                            response.Payload.Alerts.Add(alertSub);
                        }

                        response.Success = true;
                    }
                    else
                    {
                        response.Success = false;
                        response.Errors.AddRange(getSubsResult.Errors);
                    }
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session token"
                    });
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Errors.Add(new Interfaces.Error()
                {
                    Code    = Interfaces.EErrorCodes.GeneralError,
                    Type    = Interfaces.EErrorType.Error,
                    Message = ex.Message
                });
            }

            return(response);
        }