-
Notifications
You must be signed in to change notification settings - Fork 1
Submission for March Pull Request #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: MarchPR
Are you sure you want to change the base?
Changes from all commits
9166587
6867305
106d166
7a90a8a
a68c064
f456588
2a85615
d82da04
569d4b3
62ebf48
dfe4f8e
b37371f
2d9b7b4
7cf6206
17405d3
4454fe3
60e144f
2945732
58c53ca
c4b52e9
335e335
a7decb1
270dea7
6623f7c
5bd108e
dd5f28c
c0b3947
d6152f4
233bf11
5c1623c
f4a76d3
1ca4e88
e019ded
b4df943
a11b1ba
1b092e9
00a8405
adb0b35
31dab5f
782b799
340398b
8fbb5a5
f8fc10d
26ab01f
88630dd
5f6a69f
d5117a9
f1c9a63
1f5971f
4e95493
79f0560
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 }} |
| 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 }} |
| 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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 | ||
| { | ||
| 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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| [Fact] | ||
| public async Task UploadImage_Failure() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of the test can be more specific here, something like |
||
| { | ||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| Assert.False(await _imageStore.DeleteImage("dummy_id")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ImageExists_Exists() | ||
| { | ||
| string imageId = await _imageStore.UploadImage(_image); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
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.