61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Moq;
|
|
using ResourcesManager.Controllers;
|
|
using ResourcesManager.Interfaces;
|
|
using ResourcesManager.Models;
|
|
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;
|
|
Mock<IStatisticRepository> mockStatRepo;
|
|
StatisticsController statController;
|
|
|
|
[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 };
|
|
statController = new StatisticsController(mockStatRepo.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);
|
|
}
|
|
|
|
[TestCleanup]
|
|
public void CleanUpTestData()
|
|
{
|
|
expectedStat = null;
|
|
mockStatRepo = null;
|
|
}
|
|
}
|
|
} |