Ejemplo n.º 1
0
        private static async Task <int?> GetIncidentId(this ServerApiClient client, int applicationId,
                                                       string incidentMessage, string reportMessage = null)
        {
            int?returnValue = null;

            await Repeat(async() =>
            {
                var query = new FindIncidents
                {
                    ApplicationIds = new[] { applicationId },
                    FreeText       = incidentMessage,
                    SortType       = IncidentOrder.Newest
                };
                var result = await client.QueryAsync(query);
                if (result.Items.Count <= 0)
                {
                    return(false);
                }

                if (reportMessage == null)
                {
                    returnValue = result.Items[0].Id;
                    return(true);
                }

                var item = result.Items.FirstOrDefault(x => x.Name.Contains(reportMessage));
                if (item != null)
                {
                    var query2  = new GetReportList(item.Id);
                    var result2 = await client.QueryAsync(query2);
                    var report  = result2.Items.FirstOrDefault(x => x.Message.Contains(reportMessage));
                    if (report != null)
                    {
                        returnValue = item.Id;
                        return(true);
                    }
                }

                foreach (var resultItem in result.Items)
                {
                    var query2  = new GetReportList(resultItem.Id);
                    var result2 = await client.QueryAsync(query2);
                    var report  = result2.Items.FirstOrDefault(x => x.Message.Contains(reportMessage));
                    if (report != null)
                    {
                        returnValue = resultItem.Id;
                        return(true);
                    }
                }

                return(false);
            });

            return(returnValue);
        }
Ejemplo n.º 2
0
        public async Task Reset()
        {
            var query  = new GetWhitelistEntries();
            var result = await _apiClient.QueryAsync(query);

            foreach (var item in result.Entries)
            {
                var cmd = new RemoveEntry
                {
                    Id = item.Id
                };
                await _apiClient.SendAsync(cmd);
            }
        }
Ejemplo n.º 3
0
        public static async Task <GetReportResult> FindReport(this ServerApiClient client, int incidentId,
                                                              string partOfErrorMessage, Func <GetReportResult, bool> filter = null)
        {
            var reportListItem = await client.GetReportListItem(incidentId, partOfErrorMessage);

            if (reportListItem == null)
            {
                throw new InvalidOperationException("Failed to find our uploaded report");
            }

            GetReportResult result = null;

            await Repeat(async() =>
            {
                var query3 = new GetReport(reportListItem.Id);
                result     = await client.QueryAsync(query3);
                if (result == null)
                {
                    return(false);
                }

                if (filter != null && filter(result))
                {
                    return(true);
                }

                return(result.ContextCollections.Any());
            });

            if (result != null)
            {
                Console.WriteLine($"Got report {result.CreatedAtUtc:yyyyMMdd hh:mm:ss.fff}");
            }
            return(result);
        }
Ejemplo n.º 4
0
        public async Task Assign(int userId)
        {
            await _apiClient.SendAsync(new AssignIncident(DTO.Id, userId, userId));

            async Task <bool> Func()
            {
                var query  = new GetIncident(DTO.Id);
                var result = await _apiClient.QueryAsync(query);

                if (result.AssignedToId != userId)
                {
                    return(false);
                }

                DTO = result;
                return(true);
            }

            if (!await ActionExtensions.Retry(Func))
            {
                throw new TestFailedException($"Incident {DTO.Id} was not assigned to {userId}.");
            }
        }
Ejemplo n.º 5
0
        public static async Task <int> EnsureApplication(this ServerApiClient client, string name)
        {
            var query  = new GetApplicationList();
            var result = await client.QueryAsync(query);

            var app = result.FirstOrDefault(x => x.Name == name);

            if (app != null)
            {
                return(app.Id);
            }

            var cmd = new CreateApplication(name, TypeOfApplication.DesktopApplication)
            {
                ApplicationKey = Guid.NewGuid().ToString("N"),
                UserId         = 1
            };
            await client.SendAsync(cmd);

            var query2      = new GetApplicationIdByKey(cmd.ApplicationKey);
            var retriesLeft = 3;

            while (retriesLeft-- > 0)
            {
                var app2 = await client.QueryAsync(query2);

                if (app2 != null)
                {
                    return(app2.Id);
                }

                await Task.Delay(500);
            }

            throw new TestFailedException("Could not create application.");
        }
Ejemplo n.º 6
0
        public async Task Should_be_able_to_retrieve_feedback()
        {
            var incident = await _applicationClient.CreateIncident(new[]
            {
                new ContextCollectionDTO("UserSuppliedInformation",
                                         new Dictionary <string, string>
                {
                    { "Description", "Hello world" }
                })
            });

            await GetInformation(incident);

            var query  = new GetFeedbackForApplicationPage(_applicationClient.ApplicationId);
            var result = await _apiClient.QueryAsync(query);

            result.Items[0].Message.Should().Be("Hello world");
        }
Ejemplo n.º 7
0
        //[Fact]
        public async Task Test()
        {
            var client = new ServerApiClient();

            client.Open(new Uri("http://localhost/coderr/"), "", "");
            FindAccountByUserNameResult result = null;

            try
            {
                result = await client.QueryAsync(new FindAccountByUserName("admin"));
            }
            catch (WebException)
            {
            }


            result.Should().NotBeNull();
        }
Ejemplo n.º 8
0
        public static async Task <int> Reset(this ServerApiClient client, int applicationId, string environmentName)
        {
            var envs   = new GetEnvironments();
            var result = await client.QueryAsync(envs);

            var id = result.Items.FirstOrDefault(x => x.Name == environmentName)?.Id;

            // haven't reported for that environment yet
            if (id == null)
            {
                return(id ?? 0);
            }

            var cmd = new ResetEnvironment(applicationId, id.Value);
            await client.SendAsync(cmd);

            return(id ?? 0);
        }
Ejemplo n.º 9
0
        public async Task Clearing_environment_should_remove_all_incidents_in_it()
        {
            await _applicationClient.CreateIncident(x => { x.EnvironmentName = "Mock"; });

            var id = await _apiClient.Reset(_applicationClient.ApplicationId, "Mock");

            // required for some reason. TODO: Investigate ;)
            await Task.Delay(500);

            var actual = await _apiClient.QueryAsync(new FindIncidents()
            {
                ApplicationIds = new[] { _applicationClient.ApplicationId },
                EnvironmentIds = new[] { id }
            }
                                                     );

            actual.Items.Should().BeEmpty();
        }
Ejemplo n.º 10
0
        public static async Task <GetIncidentResult> GetIncident(this ServerApiClient client, int applicationId,
                                                                 string incidentMessage, string reportMessage = null)
        {
            var id = await client.GetIncidentId(applicationId, incidentMessage, reportMessage);

            if (id == null)
            {
                throw new InvalidOperationException("Failed to find our uploaded report");
            }


            var query  = new GetIncident(id.Value);
            var result = await client.QueryAsync(query);

            if (result != null)
            {
                Console.WriteLine($"Got incident {result.CreatedAtUtc:yyyyMMdd hh:mm:ss.fff}");
            }

            return(result);
        }
Ejemplo n.º 11
0
        public static async Task <GetReportListResultItem> GetReportListItem(this ServerApiClient client, int incidentId,
                                                                             string partOfErrorMessage)
        {
            var attempt = 0;

            while (attempt++ < 6)
            {
                var query2  = new GetReportList(incidentId);
                var result2 = await client.QueryAsync(query2);

                var report = result2.Items.FirstOrDefault(x => x.Message.Contains(partOfErrorMessage));
                if (report != null)
                {
                    return(report);
                }


                await Task.Delay(attempt * 150);
            }

            return(null);
        }
Ejemplo n.º 12
0
        private static async Task <TResult> TryQuery <TQuery, TResult>(this ServerApiClient client, TQuery query)
            where TQuery : Query <TResult>
        {
            var attempt = 0;

            while (attempt++ < 6)
            {
                var result = await client.QueryAsync(query);

                if (result != null)
                {
                    var collection = (IList)result.GetType().GetProperty("Items")?.GetValue(result);
                    if (collection != null)
                    {
                        if (collection.Count > 0)
                        {
                            return(result);
                        }
                    }

                    var prop = result.GetType().GetProperties()
                               .FirstOrDefault(x => x.PropertyType.GetProperty("Count") != null);
                    if (prop != null)
                    {
                        var collection2 = prop.GetValue(result);
                        var value       = (int)collection2.GetType().GetProperty("Count").GetValue(collection2);
                        if (value > 0)
                        {
                            return(result);
                        }
                    }
                }

                await Task.Delay(attempt * 150);
            }

            return(default);