1291 lines
45 KiB
C#
1291 lines
45 KiB
C#
using MediatR;
|
|
using cuqmbr.TravelGuide.Application.Common.Models;
|
|
using cuqmbr.TravelGuide.Application.Common.Exceptions;
|
|
using cuqmbr.TravelGuide.Application.Countries.Commands.AddCountry;
|
|
using cuqmbr.TravelGuide.Application.Regions.Commands.AddRegion;
|
|
using cuqmbr.TravelGuide.Application.Regions.Commands.UpdateRegion;
|
|
using cuqmbr.TravelGuide.Application.Regions.Commands.DeleteRegion;
|
|
using cuqmbr.TravelGuide.Application.Regions.Queries.GetRegion;
|
|
using cuqmbr.TravelGuide.Application.Regions.Queries.GetRegionsPage;
|
|
|
|
|
|
namespace cuqmbr.TravelGuide.Application.IntegrationTests;
|
|
|
|
public class RegionsTests : TestBase
|
|
{
|
|
[Fact]
|
|
public async Task AddRegion_WithAdminRole_RegionCreated()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
string countryName = "Country Name";
|
|
|
|
var createCountryResult = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = countryName
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
string regionName = "Regin Name";
|
|
|
|
var createRegionResult = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = regionName,
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
var getRegionResult = await mediator.Send(
|
|
new GetRegionQuery()
|
|
{
|
|
Uuid = createRegionResult.Uuid,
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
Assert.NotNull(getRegionResult);
|
|
Assert.NotNull(getRegionResult.Name);
|
|
Assert.Equal(regionName, getRegionResult.Name);
|
|
Assert.Equal(createCountryResult.Uuid, getRegionResult.CountryUuid);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task
|
|
AddDuplicateRegion_WithAdminRole_ThrowsDuplicateEntityException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
string countryName = "Country Name";
|
|
|
|
var createCountryResult = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = countryName
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
string regionName = "Regin Name";
|
|
|
|
var createRegionResult = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = regionName,
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
await Assert.ThrowsAsync<DuplicateEntityException>(() =>
|
|
mediator.Send(new AddRegionCommand()
|
|
{
|
|
Name = regionName,
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task
|
|
AddSameRegionsToDifferentCountries_WithAdminRole_RegionsCreated()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
string countryName1 = "Country Name 1";
|
|
|
|
var createCountryResult1 = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = countryName1
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
string countryName2 = "Country Name2 ";
|
|
|
|
var createCountryResult2 = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = countryName2
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
string regionName = "Regin Name";
|
|
|
|
var createRegionResult1 = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = regionName,
|
|
CountryUuid = createCountryResult1.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
var createRegionResult2 = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = regionName,
|
|
CountryUuid = createCountryResult2.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
var getRegionResult1 = await mediator.Send(
|
|
new GetRegionQuery()
|
|
{
|
|
Uuid = createRegionResult1.Uuid,
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
Assert.NotNull(getRegionResult1);
|
|
Assert.NotNull(getRegionResult1.Name);
|
|
Assert.Equal(regionName, getRegionResult1.Name);
|
|
Assert.Equal(createCountryResult1.Uuid, getRegionResult1.CountryUuid);
|
|
|
|
var getRegionResult2 = await mediator.Send(
|
|
new GetRegionQuery()
|
|
{
|
|
Uuid = createRegionResult2.Uuid,
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
Assert.NotNull(getRegionResult2);
|
|
Assert.NotNull(getRegionResult2.Name);
|
|
Assert.Equal(regionName, getRegionResult2.Name);
|
|
Assert.Equal(createCountryResult2.Uuid, getRegionResult2.CountryUuid);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task
|
|
AddRegion_WithNonExistentCountryUuid_WithAdminRole_ThrowsNotFoundException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
mediator.Send(new AddRegionCommand()
|
|
{
|
|
Name = "Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("01234567890123456789012345678901234567890123456789012345678901234")]
|
|
public async Task
|
|
AddRegion_WithInvalidName_WithAdminRole_ThrowsValidationException
|
|
(string name)
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() =>
|
|
mediator.Send(new AddRegionCommand()
|
|
{
|
|
Name = name
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("not an uuid")]
|
|
public async Task
|
|
AddRegion_WithInvalidCountryUuid_WithAdminRole_ThrowsValidationException
|
|
(string uuid)
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() =>
|
|
mediator.Send(new AddRegionCommand()
|
|
{
|
|
Name = "Name",
|
|
CountryUuid =
|
|
Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AddRegion_WithUserRole_ThrowsForbiddenException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
mediator.Send(new AddRegionCommand()
|
|
{
|
|
Name = "Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
// TODO: Add more tests with user role (copy tests with admin role)
|
|
|
|
[Fact]
|
|
public async Task AddRegion_UnAuthnticatedUser_ThrowsForbiddenException()
|
|
{
|
|
SetUnAuthenticatedUser();
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
mediator.Send(new AddRegionCommand()
|
|
{
|
|
Name = "Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
// TODO: Add more tests with unauthenticated user
|
|
// (copy tests with admin role)
|
|
|
|
[Fact]
|
|
public async Task UpdateRegion_WithAdminRole_RegionUpdated()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
string countryName = "Country Name";
|
|
|
|
var createCountryResult = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = countryName
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
string regionName = "Region Name";
|
|
|
|
var createRegionResult = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = regionName,
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
string newName = "Different Name";
|
|
|
|
var editRegionResult = await mediator.Send(
|
|
new UpdateRegionCommand()
|
|
{
|
|
Uuid = createRegionResult.Uuid,
|
|
Name = newName,
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
var getRegionResult = await mediator.Send(
|
|
new GetRegionQuery()
|
|
{
|
|
Uuid = createRegionResult.Uuid,
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
Assert.NotNull(getRegionResult);
|
|
Assert.NotNull(getRegionResult.Name);
|
|
Assert.Equal(newName, getRegionResult.Name);
|
|
Assert.Equal(createCountryResult.Uuid, getRegionResult.CountryUuid);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("01234567890123456789012345678901234567890123456789012345678901234")]
|
|
public async Task
|
|
UpdateRegion_WithInvalidName_WithAdminRole_ThrowsValidationException
|
|
(string name)
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Name = name,
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("not an uuid")]
|
|
public async Task
|
|
UpdateRegion_WithInvalidCountryUuid_WithAdminRole_ThrowsValidationException
|
|
(string uuid)
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid(),
|
|
Name = "Name",
|
|
CountryUuid =
|
|
Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("not an uuid")]
|
|
public async Task
|
|
UpdateRegion_WithInvalidUuid_WithAdminRole_ThrowsValidationException
|
|
(string uuid)
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Uuid = Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty,
|
|
Name = "Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task
|
|
UpdateRegion_WithNonExistentUuid_WithAdminRole_ThrowsNotFoundException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
var createCountryResult = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = "Name"
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid(),
|
|
Name = "Different Name",
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task
|
|
UpdateRegion_WithNonExistentCountryUuid_WithAdminRole_ThrowsNotFoundException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
var createCountryResult = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = "Name"
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
var createRegionResult = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = "Name",
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Uuid = createCountryResult.Uuid,
|
|
Name = "Different Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateRegion_WithUserRole_ThrowsForbiddenException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid(),
|
|
Name = "Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
// TODO: Add more tests with user role (copy tests with admin role)
|
|
|
|
[Fact]
|
|
public async Task UpdateRegion_UnAuthnticatedUser_ThrowsForbiddenException()
|
|
{
|
|
SetUnAuthenticatedUser();
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
mediator.Send(new UpdateRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid(),
|
|
Name = "Name",
|
|
CountryUuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
// TODO: Add more tests with unauthenticated user
|
|
// (copy tests with admin role)
|
|
|
|
[Fact]
|
|
public async Task DeleteRegion_WithAdminRole_RegionDeleted()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
var createCountryResult = await mediator.Send(
|
|
new AddCountryCommand()
|
|
{
|
|
Name = "Name"
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
var createRegionResult = await mediator.Send(
|
|
new AddRegionCommand()
|
|
{
|
|
Name = "Name",
|
|
CountryUuid = createCountryResult.Uuid
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
await mediator.Send(
|
|
new DeleteRegionCommand()
|
|
{
|
|
Uuid = createRegionResult.Uuid,
|
|
}, TestContext.Current.CancellationToken);
|
|
|
|
await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
mediator.Send(new GetRegionQuery()
|
|
{
|
|
Uuid = createRegionResult.Uuid,
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("not an uuid")]
|
|
public async Task
|
|
DeleteRegion_WithInvalidUuid_WithAdminRole_ThrowsValidationException
|
|
(string uuid)
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() =>
|
|
mediator.Send(new DeleteRegionCommand()
|
|
{
|
|
Uuid = Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task
|
|
DeleteRegion_WithNonExistentUuid_WithAdminRole_ThrowsNotFoundException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
mediator.Send(new DeleteRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DeleteRegion_WithUserRole_ThrowsForbiddenException()
|
|
{
|
|
SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
mediator.Send(new DeleteRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
// TODO: Add more tests with user role (copy tests with admin role)
|
|
|
|
[Fact]
|
|
public async Task DeleteRegion_UnAuthnticatedUser_ThrowsForbiddenException()
|
|
{
|
|
SetUnAuthenticatedUser();
|
|
|
|
var mediator = GetService<IMediator>();
|
|
|
|
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
mediator.Send(new DeleteRegionCommand()
|
|
{
|
|
Uuid = Guid.NewGuid()
|
|
}, TestContext.Current.CancellationToken));
|
|
}
|
|
|
|
// TODO: Add more tests with unauthenticated user
|
|
// (copy tests with admin role)
|
|
|
|
// TODO: Add test for GetRegion and GetRegionPage
|
|
|
|
// [Theory]
|
|
// // Empty
|
|
// [InlineData("")]
|
|
// // Length > 64 (65)
|
|
// [InlineData("01234567890123456789012345678901234567890123456789012345678901234")]
|
|
// public async Task
|
|
// AddRegion_WithInvalidName_WithAdminRole_ThrowsValidationException
|
|
// (string name)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(new AddRegionCommand()
|
|
// {
|
|
// Name = name
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task AddRegion_WithUserRole_ThrowsForbiddenException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new AddRegionCommand()
|
|
// {
|
|
// Name = "Name"
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// AddRegion_WithUnAuthenticatedUser_ThrowsUnAuthorizedException()
|
|
// {
|
|
// SetUnAuthenticatedUser();
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new AddRegionCommand()
|
|
// {
|
|
// Name = "Name"
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task UpdateRegion_WithAdminRole_RegionUpdated()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// var createRegionResult = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = "Name"
|
|
// });
|
|
//
|
|
// string newName = "Different Name";
|
|
//
|
|
// var editRegionResult = await mediator.Send(
|
|
// new UpdateRegionCommand()
|
|
// {
|
|
// Guid = createRegionResult.Uuid,
|
|
// Name = newName
|
|
// });
|
|
//
|
|
// var getRegionResult = await mediator.Send(
|
|
// new GetRegionQuery()
|
|
// {
|
|
// Guid = createRegionResult.Uuid,
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionResult);
|
|
// Assert.Equal(newName, getRegionResult.Name);
|
|
// Assert.Equal(createRegionResult.Uuid, getRegionResult.Uuid);
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// UpdateDuplicateRegion_WithAdminRole_DuplicateEntityExceptionThrown()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// var createRegionResult1 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = "Name 1"
|
|
// });
|
|
//
|
|
// var createRegionResult2 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = "Name 2"
|
|
// });
|
|
//
|
|
// await Assert.ThrowsAsync<DuplicateEntityException>(() =>
|
|
// mediator.Send(new UpdateRegionCommand()
|
|
// {
|
|
// Guid = createRegionResult2.Uuid,
|
|
// Name = createRegionResult1.Name
|
|
// }));
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// // Empty
|
|
// [InlineData("")]
|
|
// // Length > 64 (65)
|
|
// [InlineData("01234567890123456789012345678901234567890123456789012345678901234")]
|
|
// public async Task
|
|
// UpdateRegion_WithInvalidName_WithAdminRole_ThrowsValidationException
|
|
// (string name)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// var createRegionResult = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = "Name 1"
|
|
// });
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(new UpdateRegionCommand()
|
|
// {
|
|
// Guid = createRegionResult.Uuid,
|
|
// Name = name
|
|
// }));
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// [InlineData("")]
|
|
// [InlineData("not an uuid")]
|
|
// public async Task
|
|
// UpdateRegion_WithInvalidUuid_WithAdminRole_ThrowsValidationException
|
|
// (string uuid)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(new UpdateRegionCommand()
|
|
// {
|
|
// Guid = Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty,
|
|
// Name = "Name"
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// UpdateRegion_WithNonExistentUuid_WithAdminRole_ThrowsNotFoundException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
// mediator.Send(new UpdateRegionCommand()
|
|
// {
|
|
// Guid = Guid.NewGuid(),
|
|
// Name = "Name"
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task UpdateRegion_WithUserRole_ThrowsForbiddenException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new UpdateRegionCommand()
|
|
// {
|
|
// Guid = Guid.NewGuid(),
|
|
// Name = "Name"
|
|
// }));
|
|
// }
|
|
//
|
|
// // TODO: Add more tests with user role (copy tests with admin role)
|
|
//
|
|
// [Fact]
|
|
// public async Task UpdateRegion_UnAuthnticatedUser_ThrowsForbiddenException()
|
|
// {
|
|
// SetUnAuthenticatedUser();
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new UpdateRegionCommand()
|
|
// {
|
|
// Guid = Guid.NewGuid(),
|
|
// Name = "Name"
|
|
// }));
|
|
// }
|
|
//
|
|
// // TODO: Add more tests with unauthenticated user
|
|
// // (copy tests with admin role)
|
|
//
|
|
// [Fact]
|
|
// public async Task DeleteRegion_WithAdminRole_RegionDeleted()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// var createRegionResult = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = "Name"
|
|
// });
|
|
//
|
|
// await mediator.Send(
|
|
// new DeleteRegionCommand()
|
|
// {
|
|
// Guid = createRegionResult.Uuid,
|
|
// });
|
|
//
|
|
// await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionQuery()
|
|
// {
|
|
// Guid = createRegionResult.Uuid,
|
|
// }));
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// [InlineData("")]
|
|
// [InlineData("not an uuid")]
|
|
// public async Task
|
|
// DeleteRegion_WithInvalidUuid_WithAdminRole_ThrowsValidationException
|
|
// (string uuid)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(new DeleteRegionCommand()
|
|
// {
|
|
// Guid = Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// DeleteRegion_WithNonExistentUuid_WithAdminRole_ThrowsNotFoundException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
// mediator.Send(new DeleteRegionCommand()
|
|
// {
|
|
// Guid = Guid.NewGuid()
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task DeleteRegion_WithUserRole_ThrowsForbiddenException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new DeleteRegionCommand()
|
|
// {
|
|
// Guid = Guid.NewGuid()
|
|
// }));
|
|
// }
|
|
//
|
|
// // TODO: Add more tests with user role (copy tests with admin role)
|
|
//
|
|
// [Fact]
|
|
// public async Task DeleteRegion_UnAuthnticatedUser_ThrowsForbiddenException()
|
|
// {
|
|
// SetUnAuthenticatedUser();
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new DeleteRegionCommand()
|
|
// {
|
|
// Guid = Guid.NewGuid()
|
|
// }));
|
|
// }
|
|
//
|
|
// // TODO: Add more tests with unauthenticated user
|
|
// // (copy tests with admin role)
|
|
//
|
|
// [Fact]
|
|
// public async Task GetRegion_WithAdminRole_RegionReturned()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// string name = "Name";
|
|
//
|
|
// var createRegionResult = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name
|
|
// });
|
|
//
|
|
// var getRegionResult = await mediator.Send(
|
|
// new GetRegionQuery()
|
|
// {
|
|
// Guid = createRegionResult.Uuid,
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionResult);
|
|
// Assert.NotNull(getRegionResult.Name);
|
|
// Assert.Equal(name, getRegionResult.Name);
|
|
// Assert.NotNull(getRegionResult.Uuid);
|
|
// Assert.Equal(createRegionResult.Uuid, getRegionResult.Uuid);
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// [InlineData("")]
|
|
// [InlineData("not an uuid")]
|
|
// public async Task
|
|
// GetRegion_WithInvalidUuid_WithAdminRole_ThrowsValidationException
|
|
// (string uuid)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionQuery()
|
|
// {
|
|
// Guid = Guid.TryParse(uuid, out var guid) ? guid : Guid.Empty
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// GetRegion_WithNonExistentUuid_WithAdminRole_ThrowsNotFoundException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<NotFoundException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionQuery()
|
|
// {
|
|
// Guid = Guid.NewGuid()
|
|
// }));
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task GetRegion_WithUserRole_ThrowsForbiddenException()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.User });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionQuery()
|
|
// {
|
|
// Guid = Guid.NewGuid()
|
|
// }));
|
|
// }
|
|
//
|
|
// // TODO: Add more tests with user role (copy tests with admin role)
|
|
//
|
|
// [Fact]
|
|
// public async Task GetRegion_UnAuthnticatedUser_ThrowsForbiddenException()
|
|
// {
|
|
// SetUnAuthenticatedUser();
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ForbiddenException>(() =>
|
|
// mediator.Send(new GetRegionQuery()
|
|
// {
|
|
// Guid = Guid.NewGuid()
|
|
// }));
|
|
// }
|
|
//
|
|
// // TODO: Add more tests with unauthenticated user
|
|
// // (copy tests with admin role)
|
|
//
|
|
// [Fact]
|
|
// public async Task GetRegionsPage_WithAdminRole_RegionsPageReturned()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// string name1 = "Name 1";
|
|
// string name2 = "Name 2";
|
|
//
|
|
// var createRegionResult1 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name1
|
|
// });
|
|
//
|
|
// var createRegionResult2 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name2
|
|
// });
|
|
//
|
|
// var getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 1,
|
|
// PageSize = 1
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(1, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(2, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(true, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(false, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(1, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Uuid, getRegionsResult.Items.First().Uuid);
|
|
//
|
|
// getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 2,
|
|
// PageSize = 1
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(2, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(2, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(false, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(true, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(1, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Uuid, getRegionsResult.Items.First().Uuid);
|
|
//
|
|
// getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 1,
|
|
// PageSize = 10
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(1, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(1, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(false, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(false, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(2, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Uuid, getRegionsResult.Items.First().Uuid);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Name, getRegionsResult.Items.Last().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Uuid, getRegionsResult.Items.Last().Uuid);
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// GetRegionsPage_WithSearch_WithAdminRole_SearchedRegionsPageReturned()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// string name1 = "Name 1";
|
|
// string name2 = "Some 3 String";
|
|
// string name3 = "3 Name Some";
|
|
//
|
|
// var createRegionResult1 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name1
|
|
// });
|
|
//
|
|
// var createRegionResult2 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name2
|
|
// });
|
|
//
|
|
// var createRegionResult3 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name3
|
|
// });
|
|
//
|
|
// var getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 1,
|
|
// PageSize = 10,
|
|
// Search = "name"
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(1, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(1, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(false, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(false, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(2, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Uuid, getRegionsResult.Items.First().Uuid);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult3.Name, getRegionsResult.Items.Last().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult3.Uuid, getRegionsResult.Items.Last().Uuid);
|
|
//
|
|
// getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 1,
|
|
// PageSize = 10,
|
|
// Search = "3"
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(1, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(1, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(false, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(false, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(2, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Uuid, getRegionsResult.Items.First().Uuid);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult3.Name, getRegionsResult.Items.Last().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult3.Uuid, getRegionsResult.Items.Last().Uuid);
|
|
// }
|
|
//
|
|
// [Fact]
|
|
// public async Task
|
|
// GetRegionsPage_WithSort_WithAdminRole_SortedRegionsPageReturned()
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// string name1 = "Name 1";
|
|
// string name2 = "Some 2";
|
|
//
|
|
// var createRegionResult1 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name1
|
|
// });
|
|
//
|
|
// var createRegionResult2 = await mediator.Send(
|
|
// new AddRegionCommand()
|
|
// {
|
|
// Name = name2
|
|
// });
|
|
//
|
|
// var getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 1,
|
|
// PageSize = 10,
|
|
// Sort = "-name"
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(1, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(1, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(false, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(false, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(2, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Uuid, getRegionsResult.Items.First().Uuid);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Name, getRegionsResult.Items.Last().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Uuid, getRegionsResult.Items.Last().Uuid);
|
|
//
|
|
// getRegionsResult = await mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = 1,
|
|
// PageSize = 10,
|
|
// Sort = "+name"
|
|
// });
|
|
//
|
|
// Assert.NotNull(getRegionsResult);
|
|
// Assert.NotNull(getRegionsResult.PageNumber);
|
|
// Assert.Equal(1, getRegionsResult.PageNumber);
|
|
// Assert.NotNull(getRegionsResult.TotalCount);
|
|
// Assert.Equal(2, getRegionsResult.TotalCount);
|
|
// Assert.NotNull(getRegionsResult.TotalPages);
|
|
// Assert.Equal(1, getRegionsResult.TotalPages);
|
|
// Assert.NotNull(getRegionsResult.HasNextPage);
|
|
// Assert.Equal(false, getRegionsResult.HasNextPage);
|
|
// Assert.NotNull(getRegionsResult.HasPreviousPage);
|
|
// Assert.Equal(false, getRegionsResult.HasPreviousPage);
|
|
// Assert.NotNull(getRegionsResult.Items);
|
|
// Assert.Equal(2, getRegionsResult.Items.Count());
|
|
// Assert.NotNull(getRegionsResult.Items.First().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Name, getRegionsResult.Items.First().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.First().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult1.Uuid, getRegionsResult.Items.First().Uuid);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Name);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Name, getRegionsResult.Items.Last().Name);
|
|
// Assert.NotNull(getRegionsResult.Items.Last().Uuid);
|
|
// Assert.Equal(
|
|
// createRegionResult2.Uuid, getRegionsResult.Items.Last().Uuid);
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// // Length > 64 (65)
|
|
// [InlineData("01234567890123456789012345678901234567890123456789012345678901234")]
|
|
// public async Task
|
|
// GetRegionsPage_WithInvalidSearch_WithAdminRole_ThrowsValidationException
|
|
// (string search)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// Search = search
|
|
// }));
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// [InlineData(int.MinValue)]
|
|
// [InlineData(0)]
|
|
// public async Task
|
|
// GetRegionsPage_WithInvalidPageNumber_WithAdminRole_ThrowsValidationException
|
|
// (int pageNumber)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageNumber = pageNumber
|
|
// }));
|
|
// }
|
|
//
|
|
// [Theory]
|
|
// [InlineData(int.MinValue)]
|
|
// [InlineData(0)]
|
|
// [InlineData(51)]
|
|
// [InlineData(int.MaxValue)]
|
|
// public async Task
|
|
// GetRegionsPage_WithInvalidPageSize_WithAdminRole_ThrowsValidationException
|
|
// (int pageSize)
|
|
// {
|
|
// SetAuthenticatedUserRoles(new[] { IdentityRole.Administrator });
|
|
//
|
|
// var mediator = GetService<IMediator>();
|
|
//
|
|
// await Assert.ThrowsAsync<ValidationException>(() =>
|
|
// mediator.Send(
|
|
// new GetRegionsPageQuery()
|
|
// {
|
|
// PageSize = pageSize
|
|
// }));
|
|
// }
|
|
}
|