thesis/ResoursesManager/ResourcesManagerTests/Controllers/StatisticsControllerTests.cs
2019-04-28 21:17:02 +02:00

73 lines
2.8 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using ResourcesManager.Controllers;
using ResourcesManager.Interfaces;
using ResourcesManager.Models;
using ResourcesManagerTests.RepositoryTests;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace ResourcesManager.Controllers.Tests
{
[TestClass()]
public class StatisticsControllerTests
{
List<StatisticModel> expectedStat;
public Mock<IStatisticRepository> mockStatRepo;
StatisticsController statController;
ResourcesControllerTests resourcesContTest;
UserRepositoryTests userRepoTest;
public StatisticsControllerTests()
{
InitializeStatisticTestData();
}
[TestInitialize]
public void InitializeStatisticTestData()
{
expectedStat = new List<StatisticModel> {
new StatisticModel(){ Id= 1, ResourceId = 1, ReservationId = 1, StatisticType = StatisticType.Login, DateTime = DateTime.Now, UserId = Guid.NewGuid().ToString()},
new StatisticModel(){ Id= 2, ResourceId = 2, ReservationId = 2, StatisticType = StatisticType.Reserv, DateTime = DateTime.Now, UserId = Guid.NewGuid().ToString()},
new StatisticModel(){ Id= 3, ResourceId = 3, ReservationId = 3, StatisticType = StatisticType.ResourceCreate, DateTime = DateTime.Now, UserId = Guid.NewGuid().ToString()},
};
mockStatRepo = new Mock<IStatisticRepository>() { CallBase = true };
resourcesContTest = new ResourcesControllerTests();
userRepoTest = new UserRepositoryTests();
statController = new StatisticsController(mockStatRepo.Object, resourcesContTest.mockResourceRepo.Object, userRepoTest.mockUserRepo.Object);
mockStatRepo.Setup(m => m.GetStatistics()).Returns(expectedStat);
mockStatRepo.Setup(m => m.GetStatisticByID(It.IsAny<int>())).Returns((int id) =>
{
return expectedStat.FirstOrDefault(x => x.Id == id);
});
mockStatRepo.Setup(m => m.InsertStatistic(It.IsAny<StatisticModel>())).Returns((StatisticModel stat) =>
{
expectedStat.Add(stat);
return true;
});
}
[TestMethod()]
public void Statistic_Get_Index_Test()
{
var result = statController.Index(StatisticType.Login, 1);
Assert.IsNotNull((result as ViewResult).Model);
}
//todo: még
[TestCleanup]
public void Statistic_CleanUpTestData()
{
expectedStat = null;
resourcesContTest.Resources_CleanUpTestData();
userRepoTest.User_CleanUpTestData();
}
}
}