Example #1
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");
        }
Example #2
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");
        }
Example #3
0
        public UpdateAccountAlertsResponse PostUpdateAccountAlerts(UpdateAccountAlerts request)
        {
            UpdateAccountAlertsResponse response = Post <UpdateAccountAlerts, UpdateAccountAlertsResponse>("UpdateAccountAlerts", request);

            return(response);
        }
        public object Any(UpdateAccountAlerts request)
        {
            UpdateAccountAlertsResponse response = new UpdateAccountAlertsResponse();

            TransferHeader(request, response);

            try
            {
                if (IsValidSessionToken(request))
                {
                    IAlertsDalUpdateAccountSubscrParams updSubParams = _dal.CreateUpdateAccountSubscrParams();

                    foreach (var a in request.Alerts)
                    {
                        updSubParams.SubscriptonDetails = new Subscription()
                        {
                            Id                 = a.ID,
                            AccountKey         = request.AccountKey,
                            Name               = a.Name,
                            NotificationTypeId = a.NotificationTypeId,
                            SubscribedDttm     = DateTime.UtcNow,
                            TypeId             = a.AlertTypeId
                        };
                        foreach (var p in a.Properties)
                        {
                            updSubParams.SubscriptonDetails.SubscriptionData.Add(p.Name, p.Value);
                        }

                        var updSubResult = _dal.UpdateAlertSubscription(updSubParams);
                        if (updSubResult.Success)
                        {
                            response.Errors.Add(new Error()
                            {
                                Type    = EErrorType.Info,
                                Code    = EErrorCodes.Success,
                                Message = string.Format("Alert subscription  {0}, {1} updated", a.ID, a.Name)
                            });
                        }
                        else
                        {
                            response.Errors.Add(new Error()
                            {
                                Type    = EErrorType.Warning,
                                Code    = EErrorCodes.AlertsSourceFail,
                                Message = string.Format("Failed to update alert subscription {0}, {1}", a.ID, a.Name)
                            });
                        }
                    }

                    response.Success = response.Errors.Find(e => e.Type == EErrorType.Error) == null;
                }
                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);
        }