-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
tests/Aspire.Hosting.Redis.Tests/RedisPublicApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Hosting.ApplicationModel; | ||
using Xunit; | ||
|
||
namespace Aspire.Hosting.Redis.Tests; | ||
|
||
public class RedisPublicApiTests | ||
{ | ||
#region RedisBuilderExtensions | ||
|
||
[Fact] | ||
public void AddRedisContainerShouldThrowsWhenBuilderIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = null!; | ||
const string name = "Redis"; | ||
|
||
var action = () => builder.AddRedis(name); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void AddRedisContainerShouldThrowsWhenNameIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = new DistributedApplicationBuilder([]); | ||
string name = null!; | ||
|
||
var action = () => builder.AddRedis(name); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void WithRedisCommanderShouldThrowsWhenBuilderIsNull() | ||
{ | ||
IResourceBuilder<RedisResource> builder = null!; | ||
|
||
var action = () => builder.WithRedisCommander(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void WithHostPortShouldThrowsWhenBuilderIsNull() | ||
{ | ||
IResourceBuilder<RedisCommanderResource> builder = null!; | ||
const int port = 777; | ||
|
||
var action = () => builder.WithHostPort(port); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void WithDataVolumeShouldThrowsWhenBuilderIsNull() | ||
{ | ||
IResourceBuilder<RedisResource> builder = null!; | ||
|
||
var action = () => builder.WithDataVolume(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void WithDataBindMountShouldThrowsWhenBuilderIsNull() | ||
{ | ||
IResourceBuilder<RedisResource> builder = null!; | ||
const string source = "/data"; | ||
|
||
var action = () => builder.WithDataBindMount(source); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void WithDataBindMountShouldThrowsWhenNameIsNull() | ||
{ | ||
var distributedApplicationBuilder = new DistributedApplicationBuilder([]); | ||
const string name = "Redis"; | ||
var resource = new RedisResource(name); | ||
var builder = distributedApplicationBuilder.AddResource(resource); | ||
string source = null!; | ||
|
||
var action = () => builder.WithDataBindMount(source); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(source), exception.ParamName); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void WithPersistenceShouldThrowsWhenBuilderIsNull() | ||
{ | ||
IResourceBuilder<RedisResource> builder = null!; | ||
|
||
var action = () => builder.WithPersistence(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
}); | ||
} | ||
|
||
#endregion | ||
|
||
#region RedisCommanderConfigWriterHook | ||
|
||
[Fact] | ||
public async Task AfterEndpointsAllocatedAsyncShouldThrowsWhenDistributedApplicationModelIsNull() | ||
{ | ||
DistributedApplicationModel appModel = null!; | ||
var cancellationToken = CancellationToken.None; | ||
|
||
var instance = (RedisCommanderConfigWriterHook)Activator.CreateInstance(typeof(RedisCommanderConfigWriterHook), true)!; | ||
|
||
async Task Action() => await instance.AfterEndpointsAllocatedAsync(appModel, cancellationToken); | ||
|
||
var exception = await Assert.ThrowsAsync<ArgumentNullException>(Action); | ||
Assert.Equal(nameof(appModel), exception.ParamName); | ||
} | ||
|
||
#endregion | ||
|
||
#region RedisCommanderResource | ||
|
||
[Fact] | ||
public void CtorRedisCommanderResourceShouldThrowsWhenNameIsNull() | ||
{ | ||
string name = null!; | ||
|
||
var action = () => new RedisCommanderResource(name); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
}); | ||
} | ||
|
||
#endregion | ||
|
||
#region RedisResource | ||
|
||
[Fact] | ||
public void CtorRedisResourceShouldThrowsWhenNameIsNull() | ||
{ | ||
string name = null!; | ||
|
||
var action = () => new RedisResource(name); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
}); | ||
} | ||
|
||
#endregion | ||
} |