|
|
|
@ -1,6 +1,16 @@
|
|
|
|
|
using cat_cafe.Controllers;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Castle.Core.Logging;
|
|
|
|
|
using cat_cafe.Controllers;
|
|
|
|
|
using cat_cafe.Dto;
|
|
|
|
|
using cat_cafe.Entities;
|
|
|
|
|
using cat_cafe.Mappers;
|
|
|
|
|
using cat_cafe.Repositories;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using NuGet.Protocol.Core.Types;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -9,13 +19,60 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace cat_cafe.Controllers.Tests
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[TestClass()]
|
|
|
|
|
public class CatsControllerTest
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<CatsController> logger = new NullLogger<CatsController>();
|
|
|
|
|
|
|
|
|
|
private readonly MapperConfiguration mapperConf = new(mapper => mapper.AddProfile(typeof(CatMapper)));
|
|
|
|
|
|
|
|
|
|
private readonly IMapper mapper;
|
|
|
|
|
|
|
|
|
|
private readonly DbContextOptions<CatContext> options = new DbContextOptionsBuilder<CatContext>()
|
|
|
|
|
.UseInMemoryDatabase(databaseName: "CatCafeTests")
|
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
private readonly CatContext context;
|
|
|
|
|
|
|
|
|
|
private readonly CatsController controller;
|
|
|
|
|
|
|
|
|
|
public CatsControllerTest()
|
|
|
|
|
{
|
|
|
|
|
mapper = mapperConf.CreateMapper();
|
|
|
|
|
context = new CatContext(options);
|
|
|
|
|
controller = new CatsController(context, mapper, logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void StartUp()
|
|
|
|
|
{
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
context.Cats.AddRange(
|
|
|
|
|
new Cat
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Name = "Alice",
|
|
|
|
|
Age = 5
|
|
|
|
|
},
|
|
|
|
|
new Cat
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
Name = "Bob",
|
|
|
|
|
Age = 3
|
|
|
|
|
});
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
// TODO tear down and drop all before each test method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod()]
|
|
|
|
|
public void GetCatsTest()
|
|
|
|
|
public async Task GetCatsTest()
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail();
|
|
|
|
|
ActionResult<IEnumerable<CatDto>> actual = await controller.GetCats();
|
|
|
|
|
Assert.Equals(200, actual.Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod()]
|
|
|
|
@ -47,5 +104,6 @@ namespace cat_cafe.Controllers.Tests
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|