Skip to content

Commit

Permalink
Get information about project (#70)
Browse files Browse the repository at this point in the history
* Get information about project

* Fix inline docs for service class

* Update BaseFixture.cs

* Fix test for user filter

* Use gitversion as msbuild task

* Update appveyor.yml

* Update UserFilter.cs
  • Loading branch information
nvborisenko authored Jan 4, 2022
1 parent e01b483 commit 29cf9da
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 38 deletions.
17 changes: 8 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
image: Visual Studio 2019

environment:
IGNORE_NORMALISATION_GIT_HEAD_MOVE: 1

install:
- gitversion /l console /output buildserver
- dotnet tool install -g codecov.tool

configuration:
- Release

dotnet_csproj:
patch: true
version: '$(GitVersion_SemVer)'

build_script:
- dotnet pack

after_build:
- appveyor PushArtifact src\ReportPortal.Client\bin\%configuration%\ReportPortal.Client.%GitVersion_SemVer%.nupkg

test_script:
- dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=OpenCover /p:CoverletOutput=./Coverage.xml

after_test:
- codecov -f test\ReportPortal.Client.IntegrationTests\Coverage.*.xml
- codecov -f test\ReportPortal.Client.IntegrationTests\Coverage.*.xml

artifacts:
- path: '**\*.nupkg'
- path: '**\*.html'
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,31 @@ public class CreateUserFilterRequest
public IEnumerable<Condition> Conditions { get; set; }

/// <summary>
/// list of parameters of selection
/// List of parameters of selection.
/// </summary>
[DataMember(Name = "orders")]
public IEnumerable<FilterOrder> Orders { get; set; }

/// <summary>
/// is filter shared
/// Indicates if filter is shared.
/// </summary>
[DataMember(Name = "share")]
public bool IsShared { get; set; }

/// <summary>
/// filter type
/// Filter type.
/// </summary>
[DataMember(Name = "type")]
public string TypeStr { get; set; }

/// <summary>
/// user filter type enum
/// Owner of the filter.
/// </summary>
[DataMember(Name = "owner")]
public string Owner { get; set; }

/// <summary>
/// User filter type enum.
/// </summary>
public UserFilterType UserFilterType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
using ReportPortal.Client.Abstractions.Responses;
using ReportPortal.Client.Abstractions.Responses.Project;
using System.Threading.Tasks;

namespace ReportPortal.Client.Abstractions.Resources
{
public interface IProjectResource
{
/// <summary>
/// Returns information about current accosiated project.
/// </summary>
/// <returns>Project info.</returns>
Task<ProjectResponse> GetAsync();

/// <summary>
/// Returns information about project filtered by name.
/// </summary>
/// <returns>Project info.</returns>
Task<ProjectResponse> GetAsync(string projectName);

/// <summary>
/// Updates the project preference for user.
/// </summary>
Expand All @@ -13,6 +26,6 @@ public interface IProjectResource
/// <summary>
/// Gets all user preferences.
/// </summary>
Task<PreferenceResponse> GetAllPreferences(string projectName, string userName);
Task<PreferenceResponse> GetAllPreferencesAsync(string projectName, string userName);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ReportPortal.Client.Abstractions.Responses
namespace ReportPortal.Client.Abstractions.Responses.Project
{
[DataContract]
public class PreferenceResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Runtime.Serialization;

namespace ReportPortal.Client.Abstractions.Responses.Project
{
/// <summary>
/// Information about project.
/// </summary>
[DataContract]
public class ProjectConfiguration
{
[DataMember(Name = "subTypes")]
public ProjectDefectSubTypesContainer DefectSubTypes { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Runtime.Serialization;

namespace ReportPortal.Client.Abstractions.Responses.Project
{
[DataContract]
public class ProjectDefectSubType
{
[DataMember(Name = "id")]
public long Id { get; set; }

[DataMember(Name = "color")]
public string Color { get; set; }

[DataMember(Name = "locator")]
public string Locator { get; set; }

[DataMember(Name = "longName")]
public string LongName { get; set; }

[DataMember(Name = "shortName")]
public string ShortName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ReportPortal.Client.Abstractions.Responses.Project
{
[DataContract]
public class ProjectDefectSubTypesContainer
{
[DataMember(Name = "PRODUCT_BUG")]
public IList<ProjectDefectSubType> ProductBugTypes { get; set; }

[DataMember(Name = "AUTOMATION_BUG")]
public IList<ProjectDefectSubType> AutomationBugTypes { get; set; }

[DataMember(Name = "SYSTEM_ISSUE")]
public IList<ProjectDefectSubType> SystemIssueTypes { get; set; }

[DataMember(Name = "TO_INVESTIGATE")]
public IList<ProjectDefectSubType> ToInvestigateTypes { get; set; }

[DataMember(Name = "NO_DEFECT")]
public IList<ProjectDefectSubType> NoDefectTypes { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Runtime.Serialization;

namespace ReportPortal.Client.Abstractions.Responses.Project
{
/// <summary>
/// Information about project.
/// </summary>
[DataContract]
public class ProjectResponse
{
[DataMember(Name = "projectId")]
public string Id { get; set; }

[DataMember(Name = "projectName")]
public string Name { get; set; }

[DataMember(Name = "configuration")]
public ProjectConfiguration Configuration { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/ReportPortal.Client/ReportPortal.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@

<None Include="..\..\Logo.png" Pack="true" PackagePath="\" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
13 changes: 12 additions & 1 deletion src/ReportPortal.Client/Resources/ServiceProjectResource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ReportPortal.Client.Abstractions.Resources;
using ReportPortal.Client.Abstractions.Responses;
using ReportPortal.Client.Abstractions.Responses.Project;
using System.Net.Http;
using System.Threading.Tasks;

Expand All @@ -12,14 +13,24 @@ public ServiceProjectResource(HttpClient httpClient, string project) : base(http

}

public Task<ProjectResponse> GetAsync()
{
return GetAsJsonAsync<ProjectResponse>($"project/{this.ProjectName}");
}

public Task<ProjectResponse> GetAsync(string projectName)
{
return GetAsJsonAsync<ProjectResponse>($"project/{projectName}");
}

public Task<MessageResponse> UpdatePreferencesAsync(string projectName, string userName, long filterId)
{
return PutAsJsonAsync<MessageResponse, object>(
$"project/{projectName}/preference/{userName}/{filterId}",
string.Empty);
}

public Task<PreferenceResponse> GetAllPreferences(string projectName, string userName)
public Task<PreferenceResponse> GetAllPreferencesAsync(string projectName, string userName)
{
return GetAsJsonAsync<PreferenceResponse>($"project/{projectName}/preference/{userName}");
}
Expand Down
17 changes: 9 additions & 8 deletions src/ReportPortal.Client/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ReportPortal.Client
{
/// <inheritdoc/>
/// <inheritdoc cref="IClientService"/>
public partial class Service : IClientService, IDisposable
{
private readonly HttpClient _httpClient;
Expand Down Expand Up @@ -38,28 +38,29 @@ public Service(Uri uri, string projectName, string token, IHttpClientFactory htt
}

/// <summary>
/// Get or set project name to interact with.
/// Gets current project name to interact with.
/// </summary>
public string ProjectName { get; }

/// <inheritdoc/>
/// <inheritdoc cref="ILaunchResource"/>
public ILaunchResource Launch { get; }

/// <inheritdoc/>
/// <inheritdoc cref="ITestItemResource"/>
public ITestItemResource TestItem { get; }

/// <inheritdoc/>
/// <inheritdoc cref="ILogItemResource"/>
public ILogItemResource LogItem { get; }

/// <inheritdoc/>
/// <inheritdoc cref="IUserResource"/>
public IUserResource User { get; }

/// <inheritdoc/>
/// <inheritdoc cref="IUserFilterResource"/>
public IUserFilterResource UserFilter { get; }

/// <inheritdoc/>
/// <inheritdoc cref="IProjectResource"/>
public IProjectResource Project { get; }

/// <inheritdoc />
public void Dispose()
{
_httpClient.Dispose();
Expand Down
11 changes: 5 additions & 6 deletions test/ReportPortal.Client.IntegrationTests/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ namespace ReportPortal.Client.IntegrationTests
{
public class BaseFixture
{
//protected static readonly string Username = "ci_check_net_client";
//protected readonly Service Service = new Service(new Uri("https://rp.epam.com/api/v1"), "ci-agents-checks", "ba7eb7c8-7b33-42f6-8cf0-e9cd26e717f4");

protected static readonly string Username = "default";
protected readonly Service Service = new Service(new Uri("https://demo.reportportal.io/api/v1"), "default_personal", "6475bbef-a343-4f6a-add2-3dfc5e4af7bc");
protected static readonly string ProjectName = "default_personal";
protected readonly Service Service = new Service(new Uri("https://demo.reportportal.io/api/v1"), ProjectName, "3372f701-dbe2-419e-8404-1aa4c3096830");

//protected static readonly string Username = "ci_check_net_client";
//protected readonly Service Service = new Service(new Uri("https://alpha.reportportal.io/api/v1"), "default_personal", "cd9c39d6-c9a2-45b0-8e48-c4f0151114d0");
//protected static readonly string Username = "default";
//protected static readonly string ProjectName = "default_personal";
//protected readonly Service Service = new Service(new Uri("http://localhost:8080/api/v1"), ProjectName, "694b1c68-a3dd-4fd5-a752-8cd233cb2733");
}
}
47 changes: 44 additions & 3 deletions test/ReportPortal.Client.IntegrationTests/Project/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ReportPortal.Client.Abstractions.Models;
using ReportPortal.Client.Abstractions.Requests;
using ReportPortal.Client.Abstractions.Responses;
using ReportPortal.Client.Abstractions.Responses.Project;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -12,6 +13,45 @@ namespace ReportPortal.Client.IntegrationTests.Project
{
public class ProjectFixture : BaseFixture
{
[Fact]
public async Task GetProjectInfo()
{
var projectInfo = await Service.Project.GetAsync();

projectInfo.Name.Should().Be(ProjectName);
projectInfo.Id.Should().NotBeNull();

projectInfo.Configuration.Should().NotBeNull();
projectInfo.Configuration.DefectSubTypes.Should().NotBeNull();

VerifyDefectTypesModel(projectInfo.Configuration.DefectSubTypes.ProductBugTypes);
VerifyDefectTypesModel(projectInfo.Configuration.DefectSubTypes.AutomationBugTypes);
VerifyDefectTypesModel(projectInfo.Configuration.DefectSubTypes.SystemIssueTypes);
VerifyDefectTypesModel(projectInfo.Configuration.DefectSubTypes.ToInvestigateTypes);
VerifyDefectTypesModel(projectInfo.Configuration.DefectSubTypes.NoDefectTypes);
}

private void VerifyDefectTypesModel(IList<ProjectDefectSubType> defectTypes)
{
defectTypes.Should().NotBeEmpty();
foreach (var defectType in defectTypes)
{
defectType.Id.Should().BeGreaterThan(0);
defectType.Color.Should().NotBeNullOrEmpty();
defectType.Locator.Should().NotBeNullOrEmpty();
defectType.LongName.Should().NotBeNullOrEmpty();
defectType.ShortName.Should().NotBeNullOrEmpty();
}
}

[Fact]
public async Task GetProjectInfoByName()
{
var projectInfo = await Service.Project.GetAsync(ProjectName);

projectInfo.Name.Should().Be(ProjectName);
}

[Fact]
public async Task UpdatePreferences()
{
Expand All @@ -32,18 +72,19 @@ public async Task UpdatePreferences()
{
Name = Guid.NewGuid().ToString(),
Description = "testDscr_1",
IsShared = true,
IsShared = false,
UserFilterType = UserFilterType.Launch,
Conditions = new List<Condition> { condition },
Orders = new List<FilterOrder> { order }
Orders = new List<FilterOrder> { order },
Owner = "default"
};

var userFilterCreatedReponse = await Service.UserFilter.CreateAsync(createUserFilterRequest);

var message = await Service.Project.UpdatePreferencesAsync(Service.ProjectName, Username, userFilterCreatedReponse.Id);
message.Info.Should().Contain("successfully added");

var allPreferences = await Service.Project.GetAllPreferences(Service.ProjectName, Username);
var allPreferences = await Service.Project.GetAllPreferencesAsync(Service.ProjectName, Username);
allPreferences.Filters.Should().ContainSingle(p => p.Id == userFilterCreatedReponse.Id);

var delMessage = await Service.UserFilter.DeleteAsync(userFilterCreatedReponse.Id);
Expand Down
Loading

0 comments on commit 29cf9da

Please sign in to comment.