Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
d1534ab
Started working on the Chat Application
kassabronald Feb 18, 2023
a291d95
Update README.md
kassabronald Feb 18, 2023
52ffc24
Added the DTOS file
kassabronald Feb 18, 2023
1eb9994
Merge branch 'main' of https://github.com/kassabronald/ChatApplication
kassabronald Feb 18, 2023
ede792f
DTOS
kassabronald Feb 18, 2023
8ce3a02
Rider changes
jadmoukaddam Feb 18, 2023
7ccdd3c
Merge branch 'main' of https://github.com/kassabronald/ChatApplication
jadmoukaddam Feb 18, 2023
7d3303f
Created profile and imagescontroller
jadmoukaddam Feb 18, 2023
bc3e57b
Finished working on the ProfileController
kassabronald Feb 18, 2023
3927a9d
Uploadimagerequest created and imagescontroller updated
jadmoukaddam Feb 18, 2023
0e0835f
Worked on the ProfileControllerTests
kassabronald Feb 18, 2023
efd4c5e
Safe commit
jadmoukaddam Feb 18, 2023
bd6f80a
Merge branch 'main' of https://github.com/kassabronald/ChatApplication
jadmoukaddam Feb 18, 2023
ec20780
Updated ImagesControllers to use stream in HTTPPost
jadmoukaddam Feb 18, 2023
4852508
V1 for images controller and imagestore
jadmoukaddam Feb 18, 2023
b8623e4
Worked on the Profile Controller Tests
kassabronald Feb 18, 2023
5b013f7
Profile Updates
kassabronald Feb 18, 2023
ce946ba
Worked on Image Controller Tests
kassabronald Feb 18, 2023
6c8eeb1
Created imagescontrollertest for get (not working)
jadmoukaddam Feb 18, 2023
6cf9128
Safe_commit_3
jadmoukaddam Feb 19, 2023
0f16572
Worked on the ImageController and its associated tests
kassabronald Feb 19, 2023
675eee4
Made inmemoryprofilestore and imagestore with their tests
jadmoukaddam Feb 19, 2023
c7be88e
merged inmemory tests and integration tests
jadmoukaddam Feb 19, 2023
9f9c7ef
Finalized the ImageController Tests
kassabronald Feb 19, 2023
f22f482
Updates
kassabronald Feb 19, 2023
6f21869
Jad commit stable version of tests
jadmoukaddam Feb 19, 2023
b186dfa
May be unstable
jadmoukaddam Feb 19, 2023
13903ac
Worked on the Cosmos DB tests
kassabronald Feb 20, 2023
18ba8d8
Modified some of the tests
kassabronald Feb 20, 2023
67e7e0c
Added the BlobImageStore.cs file
kassabronald Feb 20, 2023
07e946a
Removed an unecessary file
kassabronald Feb 20, 2023
284113b
Added the delete functionality to IProfileStore
kassabronald Feb 21, 2023
e2273cc
Worked on the BlobImageStore
kassabronald Feb 21, 2023
8516e20
Added the delete functionality to the IImageStore interface and its c…
kassabronald Feb 21, 2023
c4872a3
Started working on the Service Layer
kassabronald Feb 26, 2023
96aaa2e
Worked on the service layer and associated tests
kassabronald Feb 26, 2023
3c922f8
Changed the return statements of some of the ProfileService functions…
kassabronald Feb 28, 2023
8e93101
Added some exceptions handling
kassabronald Feb 28, 2023
8dabbab
Added a test
kassabronald Feb 28, 2023
56fc25d
Finalized all the tests
kassabronald Mar 1, 2023
eb5ab69
Create .gitignore
kassabronald Mar 2, 2023
1415a7c
Delete ChatApplication/.idea directory
kassabronald Mar 2, 2023
878dce9
Delete ChatApplication/ChatApplication.Web.IntegrationTests/bin/Debug…
kassabronald Mar 2, 2023
248e5af
Delete ChatApplication/ChatApplication.Web.IntegrationTests/obj direc…
kassabronald Mar 2, 2023
113d013
Delete ChatApplication/ChatApplication.Web.Tests/bin/Debug/net7.0 dir…
kassabronald Mar 2, 2023
b541b90
Delete ChatApplication/ChatApplication.Web.Tests/obj directory
kassabronald Mar 2, 2023
4bdc175
Delete ChatApplication/ChatApplication.Web/obj directory
kassabronald Mar 2, 2023
c8ee83f
Delete ChatApplication/ChatApplication.Web/bin/Debug/net7.0 directory
kassabronald Mar 2, 2023
a2f9cd2
Create prbuild.yml
kassabronald Mar 2, 2023
e46e4ab
Delete ChatApplication.sln.DotSettings.user
kassabronald Mar 9, 2023
cb7f536
Delete ChatApplication.sln.DotSettings.user.Corrupted.2023-02-19T19-5…
kassabronald Mar 9, 2023
a52969d
Delete ChatApplication.sln.DotSettings.user.Corrupted.2023-02-19T19-5…
kassabronald Mar 9, 2023
6ae8066
Delete ChatApplication.sln.DotSettings.user.Corrupted.2023-02-20T21-0…
kassabronald Mar 9, 2023
ebed348
Delete ChatApplication.sln.DotSettings.user.Corrupted.2023-02-20T21-0…
kassabronald Mar 9, 2023
aab13b2
Created ImageUtil.cs and used it instead of FileContentResult in both…
kassabronald Mar 9, 2023
a1a7514
Implemented the vertical slice that involves the Post Message reques…
kassabronald Mar 10, 2023
23a2128
updated all exceptions, added documentation, created inMemoryMessageS…
jadmoukaddam Mar 11, 2023
8b7cdf7
Modified the userConversation.cs
kassabronald Mar 11, 2023
b7553a9
Merge branch 'Jad' of https://github.com/kassabronald/ChatApplication…
kassabronald Mar 11, 2023
a24e5ca
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Mar 11, 2023
efe8aef
Worked on ConversationController Tests
kassabronald Mar 11, 2023
72c9b5e
created startconversationrequest/response
jadmoukaddam Mar 11, 2023
670b886
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Mar 11, 2023
9fda4a0
Modified some files
kassabronald Mar 11, 2023
804c04d
Fixed conversationservice
jadmoukaddam Mar 11, 2023
54a8ccc
Merged with fixing for controller and for conversationservice
jadmoukaddam Mar 11, 2023
db614e3
Fixed some issues related to message.cs
kassabronald Mar 12, 2023
bd30602
Worked on the StartConversation API
kassabronald Mar 13, 2023
950d27e
Worked on the Create Conversation Tests
kassabronald Mar 14, 2023
ec6d918
Changed Messagestoretests
jadmoukaddam Mar 14, 2023
cd69ebb
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Mar 14, 2023
9f3f558
Reverted some changes
kassabronald Mar 14, 2023
0b7f2c5
Finished the integration tests for the CosmosConversationStore and mo…
kassabronald Mar 14, 2023
c180016
Reorganized the Services and Storage directories by adding sub-direct…
kassabronald Mar 14, 2023
6b5ac72
modified conversationservicetests
jadmoukaddam Mar 16, 2023
ba1172f
not working
jadmoukaddam Mar 18, 2023
4d7acfa
fixed merge
jadmoukaddam Mar 18, 2023
97d09f6
Started implementing the GetConversationMessages API
kassabronald Mar 25, 2023
285827e
Added telemtry
jadmoukaddam Mar 28, 2023
f83334a
added TODOs
jadmoukaddam Mar 30, 2023
756b703
modified profilenotfoundexception calls to return the username, and m…
jadmoukaddam Mar 30, 2023
b3cc5fc
Specified the TODO's in preparation for PR1
kassabronald Mar 31, 2023
0bcbd7a
Started refactoring the code; modified Conversation DTO by adding a u…
kassabronald Mar 31, 2023
ed8d16f
fixed conversationservicetests
jadmoukaddam Mar 31, 2023
d4d829c
configured getting all messages with token and timestamp ~UNTESTED
jadmoukaddam Mar 31, 2023
c22ca40
added DTOs, but not working
jadmoukaddam Mar 31, 2023
80146f5
getconversationmessages is working, but server still not returning URI
jadmoukaddam Mar 31, 2023
33b2c3a
Fixed all the tests, and started implementing the GetAllConversations…
kassabronald Mar 31, 2023
6b01ae3
fixed continuation token and used linq querying
jadmoukaddam Apr 1, 2023
fb60565
added tests
jadmoukaddam Apr 1, 2023
82cfd4a
Finished the main implementation of all required API's with the assoc…
kassabronald Apr 1, 2023
e730ef3
Update prbuild.yml
kassabronald Apr 2, 2023
2845093
made a modification to conversationscontroller
jadmoukaddam Apr 2, 2023
f8d2ea7
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Apr 2, 2023
53d2297
Created deploy.yml
kassabronald Apr 2, 2023
154f6da
Finalized all tests and removed connection strings
kassabronald Apr 2, 2023
1aa5782
Updated prbuild.yml
kassabronald Apr 2, 2023
25fd5ce
Create prdeploy.yml
kassabronald Apr 2, 2023
2cbd6cb
Update prbuild.yml
kassabronald Apr 2, 2023
31cb106
Update prdeploy.yml
kassabronald Apr 2, 2023
4a3e938
Update prdeploy.yml
kassabronald Apr 2, 2023
5b40f49
Update prdeploy.yml
kassabronald Apr 2, 2023
3c4b908
Update prdeploy.yml
kassabronald Apr 2, 2023
0e3fa75
Update prdeploy.yml
kassabronald Apr 2, 2023
f22612b
Update prdeploy.yml
kassabronald Apr 2, 2023
7002e6f
Update prdeploy.yml
kassabronald Apr 2, 2023
9e9e750
Update prbuild.yml
kassabronald Apr 2, 2023
8820936
Update prdeploy.yml
kassabronald Apr 2, 2023
80d6013
Update prbuild.yml
kassabronald Apr 2, 2023
02b4f63
Cleaned all the code, and fixed a couple of issues regarding the Conv…
kassabronald Apr 2, 2023
b562520
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
kassabronald Apr 2, 2023
02976b1
Update prbuild.yml
kassabronald Apr 2, 2023
a5fb2bd
Update prbuild.yml
kassabronald Apr 2, 2023
bd16675
Update prbuild.yml
kassabronald Apr 2, 2023
9d64bd0
Update prbuild.yml
kassabronald Apr 2, 2023
4d0e2b3
Update prbuild.yml
kassabronald Apr 2, 2023
fc09ec3
Renamed the DTO's directories
kassabronald Apr 2, 2023
077dc28
Fixed a bug in GetAllConversations
kassabronald Apr 2, 2023
3fe7209
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Apr 2, 2023
e60650e
Implemented most of the changes required from the pull request
kassabronald Apr 7, 2023
8517d9b
commit before PR1
jadmoukaddam Apr 7, 2023
0ae8d04
5 conversation controller tests failing
jadmoukaddam Apr 7, 2023
b9b8064
fixed conversatioinscontrollertests
jadmoukaddam Apr 7, 2023
1f10022
Fixed some issues related to the Conversation Service layer and the s…
kassabronald Apr 11, 2023
697c9bb
added try catch for conversationService conflicts
jadmoukaddam Apr 11, 2023
c832983
Fixed some conversationServiceTests by removing throwing assertions
jadmoukaddam Apr 11, 2023
d2838aa
Added a mock functionality in one of the tests
kassabronald Apr 11, 2023
ea87aa8
Committing nothing
jadmoukaddam Apr 11, 2023
48e0257
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Apr 11, 2023
244b80c
Throwing error only on duplicate message
jadmoukaddam Apr 11, 2023
c61231b
Fixed a bug that caused some integration tests to fail
kassabronald Apr 12, 2023
6dd8e59
Merge pull request #4 from kassabronald/Ronald
kassabronald Apr 12, 2023
87b0daf
Fixed some tests
kassabronald Apr 13, 2023
ac4322c
Removed unit and Integration tests from prdeploy
kassabronald Apr 13, 2023
0566280
Merge branch 'main' of https://github.com/kassabronald/ChatApplicatio…
kassabronald Apr 13, 2023
85a53e9
Adapted the image controller to accept any type of media
kassabronald Apr 13, 2023
97f2b31
Fixed a bug in the Profile Controller Tests
kassabronald Apr 13, 2023
e072b23
Merge pull request #5 from kassabronald/Ronald
kassabronald Apr 13, 2023
d376c8c
refactored
kassabronald Apr 13, 2023
f733d97
Passes 4/8 conversation functional tests
jadmoukaddam Apr 14, 2023
8ea729e
3 out of 7 functional tests passing
jadmoukaddam Apr 15, 2023
22d9a2f
Implemented conversation controller in a new way
kassabronald Apr 15, 2023
b462d4a
Fixed the code so that all functional tests pass
kassabronald Apr 15, 2023
949872b
Merge pull request #6 from kassabronald/Ronald
kassabronald Apr 15, 2023
58ba15e
Fixed an implementation mistake
kassabronald Apr 17, 2023
9a40fba
Merge pull request #7 from kassabronald/Ronald
kassabronald Apr 17, 2023
e8eff60
Readded connection strings
kassabronald Apr 17, 2023
0986489
Merge pull request #8 from kassabronald/Ronald
kassabronald Apr 17, 2023
8437e22
Fixed the code so that it satisfies the functional tests requirements
kassabronald Apr 18, 2023
da9683c
Fixed the code so that it satisfies the functional tests requirements
kassabronald Apr 18, 2023
1fb1a5b
Merge pull request #9 from kassabronald/Ronald
kassabronald Apr 18, 2023
cf1c9f3
Added the skeleton needed to start implementing Message Broker
kassabronald Apr 19, 2023
726fde6
added service bus settings
jadmoukaddam Apr 19, 2023
b3c91a9
Started working on the Message Broker
kassabronald Apr 19, 2023
8fb35f4
finished service bus start conversation publisher
jadmoukaddam Apr 19, 2023
d195d5d
Merge branch 'Ronald' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Apr 19, 2023
af61a78
Merge branch 'jad' of https://github.com/kassabronald/ChatApplication…
kassabronald Apr 19, 2023
cb3755d
added inheritance
jadmoukaddam Apr 19, 2023
b2d2bab
Merge branch 'jad' of https://github.com/kassabronald/ChatApplication…
kassabronald Apr 19, 2023
82a329e
added bus publisher for start conversation
jadmoukaddam Apr 19, 2023
247ec09
Merge branch 'jad' of https://github.com/kassabronald/ChatApplication…
kassabronald Apr 19, 2023
cc085b4
Worked on the AddMessage Service bus
kassabronald Apr 19, 2023
a341468
First Sprint for message broker done
kassabronald Apr 19, 2023
6396f66
Finished the Message Broker Implementation
kassabronald Apr 21, 2023
15e46a2
Worked on the conversation controller tests
kassabronald Apr 22, 2023
31da301
added some conv service tests
jadmoukaddam Apr 22, 2023
e34d833
Merge branch 'jad' of https://github.com/kassabronald/ChatApplication…
kassabronald Apr 22, 2023
ce930b1
fixed conversation service coverage
jadmoukaddam Apr 22, 2023
6b93c74
Merge branch 'jad' of https://github.com/kassabronald/ChatApplication…
kassabronald Apr 22, 2023
b6f9ce9
Reformatted some tests
kassabronald Apr 22, 2023
1bc77f7
Update prbuild.yml
kassabronald Apr 24, 2023
f60b4d5
Update prdeploy.yml
kassabronald Apr 24, 2023
170be48
Update prbuild.yml
kassabronald Apr 24, 2023
9989c33
Test
kassabronald Apr 24, 2023
9e04b43
Update prbuild.yml
kassabronald Apr 24, 2023
79e6a9b
Update prbuild.yml
kassabronald Apr 24, 2023
701aea8
Testing pr build with connection string
kassabronald Apr 24, 2023
c6ff3fc
Merge branch 'Service-Bus' of https://github.com/kassabronald/ChatApp…
kassabronald Apr 24, 2023
5964fa4
Update prbuild.yml
kassabronald Apr 24, 2023
434b2a5
Rearranged the cs
kassabronald Apr 24, 2023
2ec5034
Merge branch 'Service-Bus' of https://github.com/kassabronald/ChatApp…
kassabronald Apr 24, 2023
dd71e9f
Added the needed files for SQL
kassabronald Apr 25, 2023
f50704a
added config files and models for SQL
jadmoukaddam Apr 25, 2023
e99c786
Implemented the SQLProfileStore
kassabronald Apr 25, 2023
7e2a9eb
Started implementing the SQLConversationStore
kassabronald Apr 25, 2023
8ee07dd
safe commit
jadmoukaddam Apr 26, 2023
48e5449
added Add message
jadmoukaddam Apr 26, 2023
e13f3aa
Worked on ConversationStore
kassabronald Apr 26, 2023
09605d4
Finished the implementation of SQL
kassabronald Apr 28, 2023
dab63a0
made tests for conversation and messages
jadmoukaddam Apr 29, 2023
57411e4
fixed profilestore test sql
jadmoukaddam Apr 29, 2023
6c30dea
Beautified some tests
kassabronald Apr 29, 2023
b6c20ed
Merge branch 'SQL_SB' of https://github.com/kassabronald/ChatApplicat…
kassabronald Apr 29, 2023
2d77ec4
Fixed some tests
kassabronald Apr 29, 2023
d9dcfd3
safe commit
jadmoukaddam Apr 29, 2023
223c4ba
fixed few things
jadmoukaddam Apr 29, 2023
68292fe
Jad See this
kassabronald Apr 29, 2023
fbfb8f1
Fixes
kassabronald Apr 29, 2023
5eae32d
changed the order
jadmoukaddam Apr 29, 2023
3603ee9
Fixed all the SQL Tests
kassabronald Apr 29, 2023
cfe450b
Update prbuild.yml
kassabronald Apr 29, 2023
09601a6
Update prdeploy.yml
kassabronald Apr 29, 2023
cd2747f
Fixes
kassabronald Apr 29, 2023
a08c98e
Merge branch 'SQL_SB' of https://github.com/kassabronald/ChatApplicat…
kassabronald Apr 29, 2023
dbdcaec
Fixed
kassabronald Apr 29, 2023
f86cc7c
Update prbuild.yml
kassabronald Apr 29, 2023
2b6f6ae
Update prdeploy.yml
kassabronald Apr 29, 2023
e1b0ac5
fixed some styling
jadmoukaddam Apr 29, 2023
1b845fa
Style fixes
kassabronald Apr 29, 2023
11989fd
Merge branch 'SQL_SB' of https://github.com/kassabronald/ChatApplicat…
kassabronald Apr 29, 2023
e077db4
arranged options
jadmoukaddam Apr 29, 2023
8294b72
Merge branch 'SQL_SB' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam Apr 29, 2023
4e92098
fixed some logging issues
jadmoukaddam May 3, 2023
fe7c157
Added middleware
kassabronald May 5, 2023
f080fa6
Worked on the unit tests of the storage layer
kassabronald May 6, 2023
190b035
added annotations
jadmoukaddam May 7, 2023
0c5ca59
Cleaned the tests
kassabronald May 7, 2023
127f808
Merge branch 'SQL_SB' of https://github.com/kassabronald/ChatApplicat…
kassabronald May 7, 2023
f4d7023
Cleaned the tests
kassabronald May 7, 2023
81210bb
Cleaned the code again
kassabronald May 7, 2023
cadf6cb
Reverted back to before the bug
kassabronald May 7, 2023
8495f2d
Fixes in the tests
kassabronald May 7, 2023
482be7d
depends on cascading
jadmoukaddam May 7, 2023
a09d08a
Merge branch 'SQL_SB' of https://github.com/kassabronald/ChatApplicat…
jadmoukaddam May 7, 2023
d8dfc4a
Readded the cosmos injections
kassabronald May 7, 2023
ac8c46f
Merge pull request #11 from kassabronald/SQL_SB
kassabronald May 7, 2023
3a61402
Update README.md
kassabronald May 29, 2023
9c5013a
Update README.md
kassabronald May 29, 2023
7e0c000
Update README.md
kassabronald May 29, 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
40 changes: 40 additions & 0 deletions .github/workflows/prbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
workflow_dispatch:
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

env:
BlobStorage:ConnectionString: "${{ secrets.BLOBSTORAGE_CONNECTIONSTRING}}"
Cosmos:ConnectionString: "${{ secrets.COSMOS_CONNECTIONSTRING}}"
ServiceBus:ConnectionString: "${{ secrets.SERVICEBUS_CONNECTIONSTRING}}"
SQL:ConnectionString: "${{ secrets.SQL_CONNECTIONSTRING}}"

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

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

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

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

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

- name: Run integration tests
run: dotnet test ./ChatApplication/ChatApplication.Web.IntegrationTests/bin/Release/net7.0/ChatApplication.Web.IntegrationTests.dll
41 changes: 41 additions & 0 deletions .github/workflows/prdeploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build, Test and Deploy to Azure

on:
workflow_dispatch:
push:
branches:
- main

env:
AZURE_WEBAPP_NAME: chatservice-jad-ronald
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: '7.0.x'

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

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

- name: Publish
run: dotnet publish --configuration Release --output '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}' --no-restore ./ChatApplication/ChatApplication.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 }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# User-specific stuff
.idea
*.user

### DotnetCore ###
# .NET Core build folders
bin/
obj/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
1,016 changes: 1,016 additions & 0 deletions ChatApplication/.vs/ChatApplication/config/applicationhost.config

Large diffs are not rendered by default.

Binary file not shown.
Binary file added ChatApplication/.vs/ChatApplication/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System.Runtime.InteropServices;
using ChatApplication.Exceptions;
using ChatApplication.Storage;
using ChatApplication.Utils;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;

namespace ChatApplication.Web.IntegrationTests;

public class BlobImageStoreTests : IClassFixture<WebApplicationFactory<Program>>, IAsyncLifetime
{
private readonly IImageStore _store;
private readonly string blobName = Guid.NewGuid().ToString();
private readonly MemoryStream _data = new(new byte[] { 1, 2, 3 });
private readonly string _contentType = "image/png";

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

public async Task DisposeAsync()
{
await _store.DeleteImage(blobName);
}

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

[Fact]

public async Task AddImage_Success()
{
await _store.AddImage(blobName, _data, _contentType);
var actual = await _store.GetImage(blobName);
var actualData = new MemoryStream(actual!.ImageData);
Assert.Equal(_data.ToArray(), actualData.ToArray());
Assert.Equal(_contentType, actual.ContentType);
}

[Theory]
[InlineData(null, new byte[0], "image/jpeg")]
[InlineData("", new byte[0], "image/jpeg")]
[InlineData(" ", new byte[0], "image/jpeg")]
[InlineData("foobar", new byte[0], "image/jpeg")]
[InlineData("foobar", new byte[0], "image/pdf")]
[InlineData("foobar", new byte[0], "")]
[InlineData("foobar", new byte[0], " ")]
[InlineData("foobar", new byte[0], null)]

public async Task AddImage_InvalidArgs(string blobName, byte[] data, string contentType)
{
var stream = new MemoryStream(data);
await Assert.ThrowsAsync<ArgumentException>(() => _store.AddImage(blobName, stream, contentType));
}

[Fact]

public async Task GetImage_NotFound()
{
await Assert.ThrowsAsync<ImageNotFoundException>(
async () => await _store.GetImage("foobar"));
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public async Task GetImage_InvalidArgs(string id)
{
await Assert.ThrowsAsync<ArgumentException>(async () =>
{
await _store.GetImage(id);
});
}

[Fact]

public async Task DeleteImage_Success()
{

await _store.AddImage(blobName, _data, _contentType);
await _store.DeleteImage(blobName);
await Assert.ThrowsAsync<ImageNotFoundException>(async () =>
{
await _store.GetImage(blobName);
});
}

[Fact]

public async Task DeleteImage_EmptyImage()
{
await Assert.ThrowsAsync<ArgumentException>(async () =>
{
await _store.DeleteImage("");
});
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

<ItemGroup>
<PackageReference Include="Cake.ESLint" Version="2.1.0" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0-eap1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="ReSharper.Annotations" Version="7.1.3" />
<PackageReference Include="StyleCop" Version="6.2.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<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="..\ChatApplication.Web\ChatApplication.Web.csproj" />
</ItemGroup>

</Project>
Loading