Skip to content

Commit

Permalink
Ready for deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Nov 13, 2023
1 parent 8799427 commit dfa1afa
Show file tree
Hide file tree
Showing 63 changed files with 1,208 additions and 852 deletions.
10 changes: 0 additions & 10 deletions az-appservice-dotnet.MSTest/UnitTest1.cs

This file was deleted.

1 change: 0 additions & 1 deletion az-appservice-dotnet.MSTest/Usings.cs

This file was deleted.

24 changes: 0 additions & 24 deletions az-appservice-dotnet.MSTest/az-appservice-dotnet.MSTest.csproj

This file was deleted.

1 change: 0 additions & 1 deletion az-appservice-dotnet.nUnit/Usings.cs

This file was deleted.

25 changes: 0 additions & 25 deletions az-appservice-dotnet.nUnit/az-appservice-dotnet.nUnit.csproj

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions az-appservice-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "az-appservice-dotnet", "az-
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "az-appservice-dotnet.xUnit", "az-appservice-dotnet.xUnit\az-appservice-dotnet.xUnit.csproj", "{EC930BCF-7CE0-4E27-82BB-F7C1754EEF73}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "az-appservice-dotnet.nUnit", "az-appservice-dotnet.nUnit\az-appservice-dotnet.nUnit.csproj", "{6CF3129B-1C2F-4DAE-B81C-1861ACC2C5BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "az-appservice-dotnet.MSTest", "az-appservice-dotnet.MSTest\az-appservice-dotnet.MSTest.csproj", "{3CCB2931-9411-4579-9C2C-536DA2A991D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,14 +21,6 @@ Global
{EC930BCF-7CE0-4E27-82BB-F7C1754EEF73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC930BCF-7CE0-4E27-82BB-F7C1754EEF73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC930BCF-7CE0-4E27-82BB-F7C1754EEF73}.Release|Any CPU.Build.0 = Release|Any CPU
{6CF3129B-1C2F-4DAE-B81C-1861ACC2C5BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CF3129B-1C2F-4DAE-B81C-1861ACC2C5BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CF3129B-1C2F-4DAE-B81C-1861ACC2C5BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CF3129B-1C2F-4DAE-B81C-1861ACC2C5BB}.Release|Any CPU.Build.0 = Release|Any CPU
{3CCB2931-9411-4579-9C2C-536DA2A991D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CCB2931-9411-4579-9C2C-536DA2A991D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CCB2931-9411-4579-9C2C-536DA2A991D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CCB2931-9411-4579-9C2C-536DA2A991D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 0 additions & 4 deletions az-appservice-dotnet.xUnit/az-appservice-dotnet.xUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<ProjectReference Include="..\az-appservice-dotnet\az-appservice-dotnet.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="routes\v1\" />
</ItemGroup>

<ItemGroup>
<Content Update="App.config">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Azure.Storage.Blobs;
using Microsoft.Extensions.Configuration;

namespace az_appservice_dotnet.xUnit.providers.v1.Azure.AzureBlobProvider;

public class ContainerFixture : IDisposable
{
public readonly BlobContainerClient ContainerClient;
public readonly List<string> DisposableBag = new();

public ContainerFixture()
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false)
.Build();

string? connectionString = config.GetSection("BlobStorage")["ConnectionString"];
if (connectionString == null)
throw new Exception("Configuration is missing the PrimaryKey setting (BlobStorage:ConnectionString)");
var containerName = "processed-files-test";
var blobServiceClient = new BlobServiceClient(connectionString);
ContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
}

public void Dispose()
{
foreach (var blob in DisposableBag)
{
ContainerClient.DeleteBlob(blob);
}
}

public az_appservice_dotnet.providers.Azure.v1.AzureBlobProvider GetProvider()
{
return new az_appservice_dotnet.providers.Azure.v1.AzureBlobProvider(ContainerClient);
}
}

[CollectionDefinition("AzureBlobService collection")]
public class ContainerCollection : ICollectionFixture<ContainerFixture>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using az_appservice_dotnet.services;
using az_appservice_dotnet.services.v1;
using az_appservice_dotnet.services.v1.UploadedFiles;

namespace az_appservice_dotnet.xUnit.providers.v1.Azure.AzureBlobProvider;

public class FileProviderFixture : IDisposable
{
private readonly IFileProviderService _fileProviderService = new FakeFileProviderService();

private readonly List<string> _files = new();

public IFileProviderService.FileObject GetFileObject(string name, uint size)
{
var fileObejct = _fileProviderService.GetFileObject(name, size);
_files.Add(fileObejct.Path);
return fileObejct;
}

public void Dispose()
{
foreach (var file in _files)
{
if (File.Exists(file))
File.Delete(file);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using az_appservice_dotnet.services;
using az_appservice_dotnet.services.v1.UploadedFiles;

namespace az_appservice_dotnet.xUnit.providers.v1.Azure.AzureBlobProvider;

[Collection("AzureBlobService collection")]

public class StoreBlobAsyncTest: IClassFixture<FileProviderFixture>
{
readonly ContainerFixture _containerFixture;
readonly FileProviderFixture _fileProviderFixture;

public StoreBlobAsyncTest(ContainerFixture containerFixture, FileProviderFixture fileProviderFixture)
{
_containerFixture = containerFixture;
_fileProviderFixture = fileProviderFixture;
}

[Fact]
public async Task Should_ReturnUri()
{
// Arrange
var provider = _containerFixture.GetProvider();
var fileObject = _fileProviderFixture.GetFileObject("test.bin",1);
// Act
var actual = await provider.StoreBlobAsync(fileObject.Name, fileObject.Path);
_containerFixture.DisposableBag.Add(fileObject.Name);
// Assert
var readResponse = await _containerFixture.ContainerClient.GetBlobClient(fileObject.Name).ExistsAsync();
Assert.True(readResponse.Value);

Assert.IsType<Uri>(actual);
var expectedUri = _containerFixture.ContainerClient.Uri.ToString() + '/' + fileObject.Name;
Assert.Equal(expectedUri, actual.ToString());
}

// Test for exception
[Fact]
public async Task Should_ThrowException()
{
// Arrange
var provider = _containerFixture.GetProvider();
var fileObject = new IFileProviderService.FileObject("test.bin","/nonexistent");
// Act
var exception = await Record.ExceptionAsync(() => provider.StoreBlobAsync(fileObject.Name, fileObject.Path));
// Assert
Assert.NotNull(exception);
Assert.IsType<AggregateException>(exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace az_appservice_dotnet.xUnit.providers.v1.Azure.AzureSbPublishProcessingStateProvider;

public class Base: IDisposable
{
protected readonly ServiceBusSenderFixture _fixture;
protected readonly az_appservice_dotnet.providers.Azure.v1.AzureSbPublishProcessingStateProvider _provider;

public Base(ServiceBusSenderFixture fixture)
{
_fixture = fixture;
_provider = _fixture.GetProvider();
}

public void Dispose()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using az_appservice_dotnet.services.v1.State;

namespace az_appservice_dotnet.xUnit.providers.v1.Azure.AzureSbPublishProcessingStateProvider;

[Collection("ServiceBusSender collection")]
public class PublishStateAsyncTest : Base
{
public PublishStateAsyncTest(ServiceBusSenderFixture fixture) : base(fixture)
{
}

[Fact]
public async Task Should_PublishState()
{
// Arrange
var (messages, errors,_) = _fixture.RunProcessor();
var state = new IProcessingStateService.State(
"some-id-to-be-published",
1,
IProcessingStateService.Status.Created,
null,
null,
"file1.txt",
null);
// Act
var result = await _provider.PublishStateAsync(state);
// TODO: Find a better way to wait for the message to be processed; semaphore?
Thread.Sleep(1000);
// Assert
Assert.Equal(state, result);
Assert.Empty(errors);
Assert.Single(messages);
var message = messages.First().Message.Body.ToString();
Assert.Equal(state.Id, message);
}
}
Loading

0 comments on commit dfa1afa

Please sign in to comment.