Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9166587
implement profiles APIs + tests
nadimakk Feb 18, 2023
6867305
start of images implementation
nadimakk Feb 18, 2023
106d166
Implement ImageController & BlobImageStore
alijaafar21 Feb 19, 2023
7a90a8a
Implement ImageControllerTests & Perform Minor Changes
alijaafar21 Feb 20, 2023
a68c064
Create ImageDto & Modify ImageController and BlobImageStore accordingly
alijaafar21 Feb 21, 2023
f456588
add checks for validity of profile pic, add delete image when profile…
nadimakk Feb 21, 2023
2a85615
Change ImageDto to Image
alijaafar21 Feb 22, 2023
d82da04
Modify CosmosProfileStoreTests Constructor to handle dependencies inj…
alijaafar21 Feb 22, 2023
569d4b3
use response from DownloadToAsync to avoid calling Blob storage
nadimakk Feb 22, 2023
62ebf48
add tests for ImageExists from BlobStorage
nadimakk Feb 22, 2023
dfe4f8e
Create ProfileService with Tests
alijaafar21 Feb 26, 2023
b37371f
Edit relevant classes and tests to incorporate ProfileService
alijaafar21 Feb 26, 2023
2d9b7b4
Create custom exceptions
alijaafar21 Mar 1, 2023
7cf6206
Create prbuild.yml
alijaafar21 Mar 8, 2023
17405d3
Create azure_deploy.yml
alijaafar21 Mar 8, 2023
4454fe3
Update prbuild.yml
nadimakk Mar 8, 2023
60e144f
Merge pull request #6 from nadimakk/Lab3
alijaafar21 Mar 8, 2023
2945732
Edit workflow azure_deploy.yml
alijaafar21 Mar 9, 2023
58c53ca
Edit workflow prbuild.yml
nadimakk Mar 9, 2023
c4b52e9
Update workflow azure_deploy.yml
nadimakk Mar 9, 2023
335e335
Remove connection strings from appsettings
nadimakk Mar 9, 2023
a7decb1
Update prbuild.yml
nadimakk Mar 9, 2023
270dea7
rename Blob connection string name
nadimakk Mar 9, 2023
6623f7c
fix BlobStorage name in Program.cs
nadimakk Mar 9, 2023
5bd108e
Merge pull request #8 from nadimakk/Lab3
nadimakk Mar 9, 2023
dd5f28c
structure and begin storage layer
nadimakk Mar 27, 2023
c0b3947
Modify database entities & update ComosConversationStore
alijaafar21 Mar 28, 2023
d6152f4
complete conversation store and tests
nadimakk Mar 28, 2023
233bf11
Implement CosmosMessageStore
alijaafar21 Mar 29, 2023
5c1623c
begin conversation service
nadimakk Mar 29, 2023
f4a76d3
complete conversation service
nadimakk Mar 30, 2023
1ca4e88
complete message service
nadimakk Mar 30, 2023
e019ded
Perform code refactor & implement ConversationsController
alijaafar21 Mar 30, 2023
b4df943
Refactor & start ImageService
alijaafar21 Mar 30, 2023
a11b1ba
begin ConversationServiceTests
nadimakk Mar 30, 2023
1b092e9
Refactor & Implement ImageService
alijaafar21 Mar 30, 2023
00a8405
complete UserConversationServiceTests
nadimakk Mar 30, 2023
adb0b35
Merge branch 'Phase2' of https://github.com/nadimakk/ChatService into…
nadimakk Mar 30, 2023
31dab5f
refactoring of CosmosProfileStoreTest
nadimakk Mar 30, 2023
782b799
ConversationsControllerTests
alijaafar21 Mar 30, 2023
340398b
Merge branch 'Phase2' of https://github.com/nadimakk/ChatService into…
alijaafar21 Mar 30, 2023
8fbb5a5
Tiny bug fix
alijaafar21 Mar 30, 2023
f8fc10d
Implement ImageServiceTests and refactor
alijaafar21 Mar 31, 2023
26ab01f
Code Refactor
nadimakk Mar 31, 2023
88630dd
Add ChatService.sln.DotSettings.user to .gitignore
nadimakk Mar 31, 2023
5f6a69f
Add logs
nadimakk Mar 31, 2023
d5117a9
change log level
nadimakk Apr 1, 2023
f1c9a63
Bug fixes
alijaafar21 Apr 1, 2023
1f5971f
bug fixes and test refactoring
nadimakk Apr 1, 2023
4e95493
bug fix
nadimakk Apr 1, 2023
79f0560
Merge branch 'Phase2' into Submission
nadimakk Apr 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/azure_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build, Test, and Deploy to Azure

on:
workflow_dispatch:
push:
branches:
- main

env:
AZURE_WEBAPP_NAME: chat-service-ali-nadim
AZURE_WEBAPP_PACKAGE_PATH: './publish'

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:

- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

- name: Restore dependencies
run: dotnet restore ./ChatService.sln

- name: Build
run: dotnet build ./ChatService.sln --configuration Release --no-restore

- name: Run unit tests
run: dotnet test ChatService.Web.Tests/bin/Release/net6.0/ChatService.Web.Tests.dll

- name: Run integration tests
run: dotnet test ChatService.Web.IntegrationTests/bin/Release/net6.0/ChatService.Web.IntegrationTests.dll
env:
Cosmos:ConnectionString: ${{ secrets.COSMOS_CONNECTIONSTRING }}
BlobStorage:ConnectionString: ${{ secrets.BLOBSTORAGE_CONNECTIONSTRING }}

- name: Publish
run: dotnet publish --configuration Release --output '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}' --no-restore ChatService.Web

- name: Deploy
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_CHATSERVICE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
35 changes: 35 additions & 0 deletions .github/workflows/prbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR Build

on:
pull_request:
branches: [ "main" ]

jobs:
build-and-test:

runs-on: ubuntu-latest

steps:

- name: Checkout code
uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Run unit tests
run: dotnet test ChatService.Web.Tests/bin/Release/net6.0/ChatService.Web.Tests.dll

- name: Run integration tests
run: dotnet test ChatService.Web.IntegrationTests/bin/Release/net6.0/ChatService.Web.IntegrationTests.dll
env:
Cosmos:ConnectionString: ${{ secrets.COSMOS_CONNECTIONSTRING }}
BlobStorage:ConnectionString: ${{ secrets.BLOBSTORAGE_CONNECTIONSTRING }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
ChatService.sln.DotSettings.user
13 changes: 13 additions & 0 deletions .idea/.idea.ChatService/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.ChatService/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.ChatService/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions ChatService.Web.IntegrationTests/BlobImageStoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Text;
using Azure;
using ChatService.Web.Dtos;
using ChatService.Web.Storage;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;

namespace ChatService.Web.IntegrationTests;

public class BlobImageStoreTests : IClassFixture<WebApplicationFactory<Program>>, IAsyncLifetime

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class can be renamed to ImageStoreIntegrationTests because it doesn't depend on Blob storage at all, it only depends on the interface.

{
private readonly IImageStore _imageStore;
private readonly Image _image = new Image("image/jpg",
new MemoryStream(Encoding.UTF8.GetBytes("This is a mock image file content")));
private string _imageId;

public Task InitializeAsync()
{
return Task.CompletedTask;
}

public async Task DisposeAsync()
{
await _imageStore.DeleteImage(_imageId);
}

public BlobImageStoreTests(WebApplicationFactory<Program> factory)
{
_imageStore = factory.Services.GetRequiredService<IImageStore>();
}

[Fact]
public async Task UploadImage_Success()
{
string imageId = await _imageStore.UploadImage(_image);
var downloadedImage = await _imageStore.DownloadImage(imageId);

Assert.Equal(_image.ContentType, downloadedImage.ContentType);
Assert.True(_image.Content.ToArray().SequenceEqual(downloadedImage.Content.ToArray()));

_imageId = imageId;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this as soon as possible (at line 35 above) to make sure that the image is deleted even if the assert fails.

_imageId = await _imageStore.UploadImage(_image);

}

[Fact]
public async Task UploadImage_Failure()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the test can be more specific here, something like UploadImage_WrongContentType

{
var notImage = new Image("text/plain",
new MemoryStream(Encoding.UTF8.GetBytes("This is a mock file simulating an invalid image type")));

await Assert.ThrowsAsync<ArgumentException>(async () => await _imageStore.UploadImage(notImage));
}

[Fact]
public async Task DownloadImage_Success()
{
var imageId = await _imageStore.UploadImage(_image);
var downloadedImage = await _imageStore.DownloadImage(imageId);

Assert.Equal(_image.ContentType, downloadedImage.ContentType);
Assert.True(_image.Content.ToArray().SequenceEqual(downloadedImage.Content.ToArray()));
}
Comment on lines +53 to +61

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already tested above, no need to do this twice. You can just rename the test above UploadDownloadImage_Success


[Fact]
public async Task DownloadImage_NotFound()
{
var downloadedImage = await _imageStore.DownloadImage("dummy_id");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank line

Assert.Null(downloadedImage);
}

[Fact]
public async Task DeleteImage_Success()
{
var imageId = await _imageStore.UploadImage(_image);
Assert.True(await _imageStore.DeleteImage(imageId));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not enough, you want to Download the image and make sure it's not there anymore

}

[Fact]
public async Task DeleteImage_Failure()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteNonExistingImage

{
Assert.False(await _imageStore.DeleteImage("dummy_id"));
}

[Fact]
public async Task ImageExists_Exists()
{
string imageId = await _imageStore.UploadImage(_image);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, using _imageId directly instead of temp variable


Assert.True(await _imageStore.ImageExists(imageId));

_imageId = imageId;
}

[Fact]
public async Task ImageExists_DoesntExist()
{
Assert.False(await _imageStore.ImageExists("dummy_id"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ChatService.Web\ChatService.Web.csproj" />
</ItemGroup>

</Project>
Loading