Commit 6b86086a authored by adnansetiawan's avatar adnansetiawan
Browse files

add unit testing for Student Controller

parent 32e0d832
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SIX.Core\SIX.Core.csproj" />
<ProjectReference Include="..\SIX.Web\SIX.Web.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" />
<Reference Include="Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" />
</ItemGroup>
</Project>
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SIX.ApplicationLayer.Student;
using SIX.Web.Controllers;
namespace SIX.Web.Test
{
[TestClass]
public class StudentControllerTest
{
[TestMethod]
public void Index_Student_Number_Grather_Than_Zero()
{
// Arrange
var mockService = new Mock<IStudentService>();
mockService.Setup(svc => svc.GetAll())
.Returns(new List<Core.Student.Student>
{
new Core.Student.Student { NIM = "001", Name = "A" },
new Core.Student.Student { NIM = "002", Name = "B" },
new Core.Student.Student { NIM = "003", Name = "C" },
new Core.Student.Student { NIM = "004", Name = "D" }
});
var controller = new StudentController(mockService.Object);
// Act
var result = controller.Index() as ViewResult;
// Assert
Assert.AreEqual(typeof(SIX.Web.Models.StudentPageViewModel), result.Model);
Assert.AreNotEqual(0, (result.Model as SIX.Web.Models.StudentPageViewModel).Students.Count);
}
}
}
......@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIX.Infrastructure", "SIX.I
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIX.Web", "SIX.Web\SIX.Web.csproj", "{7DB6F399-DA1C-463E-ABEA-AC6F0897B428}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIX.Web.Test", "SIX.Web.Test\SIX.Web.Test.csproj", "{AEF7D299-9B77-4D86-9731-0B979B28DF1C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -31,5 +33,9 @@ Global
{7DB6F399-DA1C-463E-ABEA-AC6F0897B428}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DB6F399-DA1C-463E-ABEA-AC6F0897B428}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DB6F399-DA1C-463E-ABEA-AC6F0897B428}.Release|Any CPU.Build.0 = Release|Any CPU
{AEF7D299-9B77-4D86-9731-0B979B28DF1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEF7D299-9B77-4D86-9731-0B979B28DF1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEF7D299-9B77-4D86-9731-0B979B28DF1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEF7D299-9B77-4D86-9731-0B979B28DF1C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment