-
Notifications
You must be signed in to change notification settings - Fork 0
/
SupportRequestControllerTests.cs
64 lines (55 loc) · 2.05 KB
/
SupportRequestControllerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.AspNetCore.Mvc;
using SupportApp.Controllers;
using SupportApp.Models;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace SupportApp.Tests
{
public class SupportRequestControllerTests
{
[Fact]
public void Index_ReturnsViewResult_WithListOfRequests()
{
// Arrange
var controller = new SupportRequestController();
// Act
var result = controller.Index() as ViewResult;
// Assert
Assert.NotNull(result);
var viewData = result?.ViewData; // Access ViewData after casting to ViewResult
var model = Assert.IsAssignableFrom<List<SupportRequest>>(viewData?.Model);
Assert.NotNull(model);
}
[Fact]
public void AddRequest_AddsNewRequest_AndRedirectsToIndex()
{
// Arrange
var controller = new SupportRequestController();
string customerName = "John Doe";
string description = "Need help with product";
// Act
var result = controller.AddRequest(customerName, description);
// Assert
var redirectToActionResult = Assert.IsType<RedirectToActionResult>(result);
Assert.Equal("Index", redirectToActionResult.ActionName);
}
[Fact]
public void ResolveRequest_ResolvesRequest_AndRedirectsToIndex()
{
// Arrange
var controller = new SupportRequestController();
controller.AddRequest("John Doe", "Need help with product");
int requestId = 1;
// Act
var result = controller.ResolveRequest(requestId) as RedirectToActionResult;
// Assert
Assert.NotNull(result);
Assert.Equal("Index", result.ActionName);
var viewResult = controller.Index() as ViewResult;
var request = viewResult?.ViewData.Model as List<SupportRequest>;
Assert.NotNull(request);
Assert.True(request.First().IsResolved);
}
}
}