Skip to content

Commit 0379436

Browse files
committed
Add failure test for CreateResource in AdminResourceRepositoryTests
1 parent 37a2fe5 commit 0379436

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminResourceRepositoryTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.DependencyInjection;
1010

1111
using NSubstitute;
12+
using NSubstitute.ExceptionExtensions;
1213

1314
namespace AzureOpenAIProxy.ApiApp.Tests.Repositories;
1415

@@ -90,4 +91,24 @@ await tableClient.Received(1).AddEntityAsync(Arg.Is<AdminResourceDetails>(x =>
9091
));
9192
result.Should().BeEquivalentTo(resourceDetails);
9293
}
94+
95+
[Fact]
96+
public async Task Given_Failure_In_Add_Entity_When_CreateResource_Invoked_Then_It_Should_Throw_Exception()
97+
{
98+
// Arrange
99+
var settings = Substitute.For<StorageAccountSettings>();
100+
var tableServiceClient = Substitute.For<TableServiceClient>();
101+
var tableClient = Substitute.For<TableClient>();
102+
tableServiceClient.GetTableClient(Arg.Any<string>()).Returns(tableClient);
103+
104+
var repository = new AdminResourceRepository(tableServiceClient, settings);
105+
106+
tableClient.AddEntityAsync(Arg.Any<AdminResourceDetails>()).ThrowsAsync(new InvalidOperationException());
107+
108+
// Act
109+
Func<Task> func = () => repository.CreateResource(new AdminResourceDetails());
110+
111+
// Assert
112+
await func.Should().ThrowAsync<InvalidOperationException>();
113+
}
93114
}

0 commit comments

Comments
 (0)