🧪 Added a failing test for movieController
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
parent
8c1ef192b1
commit
e7d8ff1e34
2 changed files with 39 additions and 0 deletions
|
@ -0,0 +1,37 @@
|
|||
using Xunit;
|
||||
using Moq;
|
||||
using backend;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public class MovieControllerTests
|
||||
{
|
||||
private readonly Mock<ILogger<MovieController>> _mockLogger;
|
||||
private readonly Mock<MovieDbContext> _mockDbContext;
|
||||
|
||||
public MovieControllerTests()
|
||||
{
|
||||
_mockLogger = new Mock<ILogger<MovieController>>();
|
||||
var options = new DbContextOptionsBuilder<MovieDbContext>()
|
||||
.UseInMemoryDatabase(databaseName: "MovieDatabase")
|
||||
.Options;
|
||||
_mockDbContext = new Mock<MovieDbContext>(options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMovies_ValidQueryParams_ReturnsOk()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new MovieController(_mockLogger.Object, _mockDbContext.Object);
|
||||
|
||||
// Act
|
||||
var result = controller.Get("Star Wars", "movie", "2021", "titleasc", 1, 5);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<OkObjectResult>(result.Result);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,12 +9,14 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.12" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.11">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Moq" Version="4.20.69" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
|
|
Reference in a new issue