Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dim@6043 unittests toevoegen #718

Merged
merged 17 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Kiss.Bff.Test/CategorienControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Links.Controllers;
using Kiss.Bff.Beheer.Links.Data.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace Kiss.Bff.Test
{
Expand Down
83 changes: 83 additions & 0 deletions Kiss.Bff.Test/GetFaqTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Faq;
using Kiss.Bff.ZaakGerichtWerken.Contactmomenten;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Kiss.Bff.Test
{
[TestClass]
public class GetFaqTests
{
private BeheerDbContext _dbContext;

[TestInitialize]
public void Initialize()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();

var options = new DbContextOptionsBuilder<BeheerDbContext>()
.UseInMemoryDatabase(databaseName: "TestDatabase")
.UseInternalServiceProvider(serviceProvider)
.Options;

_dbContext = new BeheerDbContext(options);
}

[TestCleanup]
public void Cleanup()
{
_dbContext.Database.EnsureDeleted();
_dbContext.Dispose();
}

[TestMethod]
public void Get_ReturnsTopQuestions()
PascalIcatt marked this conversation as resolved.
Show resolved Hide resolved
{
// Arrange
var controller = new GetFaq(_dbContext);

var testData = new List<ContactmomentDetails>
{
new ContactmomentDetails
{
Id = "1",
Vraag = "Question 1",
Einddatum = DateTime.UtcNow
},
new ContactmomentDetails
{
Id = "2",
Vraag = "Question 2",
Einddatum = DateTime.UtcNow
},
new ContactmomentDetails
{
Id = "3",
Vraag = "Question 1",
Einddatum = DateTime.UtcNow
},
};

_dbContext.ContactMomentDetails.AddRange(testData);
_dbContext.SaveChanges();

// Act
var result = controller.Get() as OkObjectResult;

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var resultList = result.Value as IEnumerable<string>;
Assert.IsNotNull(resultList);

// Ensure that the result contains the top questions
var expectedQuestions = new List<string> { "Question 1", "Question 2" };
CollectionAssert.AreEqual(expectedQuestions, resultList.ToList());
}
}
}
12 changes: 1 addition & 11 deletions Kiss.Bff.Test/GetFeaturedCountControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.NieuwsEnWerkinstructies.Controllers;
using Kiss.Bff.NieuwsEnWerkinstructies.Data.Entities;
using Kiss.Bff.NieuwsEnWerkinstructies.Migrations;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Kiss.Bff.Test
{
Expand Down
7 changes: 1 addition & 6 deletions Kiss.Bff.Test/LinksControllerUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.Beheer.Links.Controllers;
using Kiss.Bff.Beheer.Links.Data.Entities;
using Microsoft.AspNetCore.Mvc;
Expand Down
10 changes: 1 addition & 9 deletions Kiss.Bff.Test/MarkeerGelezenControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using IdentityModel;
using System.Security.Claims;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.NieuwsEnWerkinstructies.Controllers;
using Kiss.Bff.NieuwsEnWerkinstructies.Data.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Kiss.Bff.Test
{
Expand Down
116 changes: 116 additions & 0 deletions Kiss.Bff.Test/ReadContactmomentenDetailsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.ZaakGerichtWerken.Contactmomenten;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Kiss.Bff.Test
{
[TestClass]
public class ReadContactmomentenDetailsTests
{
private BeheerDbContext _dbContext;

[TestInitialize]
public void Initialize()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();

var options = new DbContextOptionsBuilder<BeheerDbContext>()
.UseInMemoryDatabase(databaseName: "TestDatabase")
.UseInternalServiceProvider(serviceProvider)
.Options;

_dbContext = new BeheerDbContext(options);
SeedTestData();
}

[TestCleanup]
public void Cleanup()
{
_dbContext.Database.EnsureDeleted();
_dbContext.Dispose();
}

private void SeedTestData()
{
var contactmoment1 = new ContactmomentDetails
{
Id = "1",
Startdatum = DateTime.Now,
Einddatum = DateTime.Now.AddHours(1),
Gespreksresultaat = "Result 1",
Vraag = "Question 1"
};

var contactmoment2 = new ContactmomentDetails
{
Id = "2",
Startdatum = DateTime.Now,
Einddatum = DateTime.Now.AddHours(1),
Gespreksresultaat = "Result 2",
Vraag = "Question 2"
};

_dbContext.ContactMomentDetails.AddRange(contactmoment1, contactmoment2);
_dbContext.SaveChanges();
}

[TestMethod]
public async Task Get_ValidId_ReturnsOk()
{
// Arrange
var controller = new ReadContactmomentenDetails(_dbContext);
var validId = "1";

// Act
var result = await controller.Get(validId, CancellationToken.None) as OkObjectResult;

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var contactmoment = result.Value as ContactmomentDetails;
Assert.IsNotNull(contactmoment);
Assert.AreEqual(validId, contactmoment.Id);
}

[TestMethod]
public async Task Get_InvalidId_ReturnsNotFound()
{
// Arrange
var controller = new ReadContactmomentenDetails(_dbContext);
var invalidId = "nonexistent";

// Act
var result = await controller.Get(invalidId, CancellationToken.None) as NotFoundResult;

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(404, result.StatusCode);
}

[TestMethod]
public void Get_All_ReturnsOkWithContactmomenten()
{
// Arrange
var controller = new ReadContactmomentenDetails(_dbContext);

// Act
var result = controller.Get() as OkObjectResult;

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var contactmomenten = result.Value as IEnumerable<ContactmomentDetails>;
Assert.IsNotNull(contactmomenten);

var contactmomentList = contactmomenten.ToList();
Assert.IsNotNull(contactmomentList);
Assert.AreEqual(2, contactmomentList.Count());
}
}
}
93 changes: 93 additions & 0 deletions Kiss.Bff.Test/ReadContactverzoekenVragensetsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.ZaakGerichtWerken.Contactverzoeken;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Kiss.Bff.Test
{
[TestClass]
public class ReadContactverzoekenVragenSetsTests
{
private BeheerDbContext _dbContext;

[TestInitialize]
public void Initialize()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();

var options = new DbContextOptionsBuilder<BeheerDbContext>()
.UseInMemoryDatabase(databaseName: "TestDatabase")
.UseInternalServiceProvider(serviceProvider)
.Options;

_dbContext = new BeheerDbContext(options);
}

[TestCleanup]
public void Cleanup()
{
_dbContext.Database.EnsureDeleted();
_dbContext.Dispose();
}

[TestMethod]
public async Task Get_ContactVerzoekVragenSetsExist_ReturnsOkWithList()
{
// Arrange
var controller = new ReadContactverzoekenVragenSets(_dbContext);

var vragenSets = new List<ContactVerzoekVragenSet>
{
new ContactVerzoekVragenSet
{
Id = 1,
Naam = "VragenSet 1",
JsonVragen = "{ \"Question1\": \"Answer1\" }",
AfdelingId = "Dept1"
},
new ContactVerzoekVragenSet
{
Id = 2,
Naam = "VragenSet 2",
JsonVragen = "{ \"Question2\": \"Answer2\" }",
AfdelingId = "Dept2"
}
};

await _dbContext.ContactVerzoekVragenSets.AddRangeAsync(vragenSets);
await _dbContext.SaveChangesAsync();

// Act
var result = await controller.Get(CancellationToken.None) as OkObjectResult;

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var resultList = result.Value as List<ContactVerzoekVragenSet>;
Assert.IsNotNull(resultList);
Assert.AreEqual(2, resultList.Count);
}

[TestMethod]
public async Task Get_NoContactVerzoekVragenSets_ReturnsOkWithEmptyList()
{
// Arrange
var controller = new ReadContactverzoekenVragenSets(_dbContext);

// Act
var result = await controller.Get(CancellationToken.None) as OkObjectResult;

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(200, result.StatusCode);

var resultList = result.Value as List<ContactVerzoekVragenSet>;
Assert.IsNotNull(resultList);
Assert.AreEqual(0, resultList.Count);
}
}
}
7 changes: 1 addition & 6 deletions Kiss.Bff.Test/SearchBerichtenControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Security.Claims;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.NieuwsEnWerkinstructies.Controllers;
using Kiss.Bff.NieuwsEnWerkinstructies.Data.Entities;
Expand Down
8 changes: 1 addition & 7 deletions Kiss.Bff.Test/SkillsUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.Mvc;
using Kiss.Bff.Beheer.Data;
using Kiss.Bff.NieuwsEnWerkinstructies.Controllers;
using Kiss.Bff.NieuwsEnWerkinstructies.Data.Entities;
using Kiss.Bff.Test;

namespace Kiss.Bff.Test
{
Expand Down
Loading