Minor changes
This commit is contained in:
@@ -9,6 +9,7 @@ using Events.MVC.Models;
|
||||
using Events.MVC.Models.People;
|
||||
using Events.Tests.UnitTests.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sieve.Models;
|
||||
|
||||
@@ -59,8 +60,8 @@ public class PeopleControllerShould
|
||||
|
||||
var partial = Assert.IsType<PartialViewResult>(result);
|
||||
Assert.Equal("_PeopleList", partial.ViewName);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(partial.Model);
|
||||
Assert.Contains(model.People.Data, p => p.FullName == "Ana Kovac" && p.CountryName == "Croatia");
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(partial.Model);
|
||||
Assert.Contains(model.Data, p => p.FullName == "Ana Kovac" && p.CountryName == "Croatia");
|
||||
Assert.Contains("was added successfully", controller.Response.Headers[Events.MVC.Constants.HtmxHeaders.Trigger].ToString());
|
||||
}
|
||||
|
||||
@@ -100,8 +101,8 @@ public class PeopleControllerShould
|
||||
|
||||
var partial = Assert.IsType<PartialViewResult>(result);
|
||||
Assert.Equal("_PeopleList", partial.ViewName);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(partial.Model);
|
||||
var person = Assert.Single(model.People.Data);
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(partial.Model);
|
||||
var person = Assert.Single(model.Data);
|
||||
Assert.Equal("Ana Kovac", person.FullName);
|
||||
Assert.Equal("Croatia", person.CountryName);
|
||||
}
|
||||
@@ -178,8 +179,8 @@ public class PeopleControllerShould
|
||||
});
|
||||
|
||||
var view = Assert.IsType<ViewResult>(result);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(view.Model);
|
||||
var people = Assert.Single(model.People.Data);
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(view.Model);
|
||||
var people = Assert.Single(model.Data);
|
||||
Assert.Equal(1, people.Id);
|
||||
Assert.Equal("Ђорђе Петровић", people.FullName);
|
||||
}
|
||||
@@ -203,11 +204,12 @@ public class PeopleControllerShould
|
||||
});
|
||||
|
||||
var view = Assert.IsType<ViewResult>(result);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(view.Model);
|
||||
var person = Assert.Single(model.People.Data);
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(view.Model);
|
||||
var person = Assert.Single(model.Data);
|
||||
Assert.Equal("Ana Novak", person.FullName);
|
||||
Assert.Equal("SI", model.CountryFilter);
|
||||
Assert.Contains(model.CountryOptions, option => option.Value == "SI" && option.Selected);
|
||||
Assert.Equal("SI", Assert.IsType<string>(view.ViewData[Events.MVC.Constants.ViewDataKeys.PeopleCountryFilter]));
|
||||
var countryOptions = Assert.IsAssignableFrom<IEnumerable<SelectListItem>>(view.ViewData[Events.MVC.Constants.ViewDataKeys.PeopleCountryOptions]);
|
||||
Assert.Contains(countryOptions, option => option.Value == "SI" && option.Selected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SportsControllerShould
|
||||
new Sport { Id = 3, Name = "Cycling" });
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
var optionsMock = new Mock<IOptions<PagingSettings>>();
|
||||
var optionsMock = new Mock<IOptionsSnapshot<PagingSettings>>();
|
||||
optionsMock
|
||||
.SetupGet(options => options.Value)
|
||||
.Returns(new PagingSettings { PageSize = 2 });
|
||||
|
||||
@@ -24,9 +24,9 @@ internal static class ControllerTestContext
|
||||
return new EventsContext(options);
|
||||
}
|
||||
|
||||
public static IOptions<PagingSettings> CreatePagingOptions(int pageSize = 10)
|
||||
public static IOptionsSnapshot<PagingSettings> CreatePagingOptions(int pageSize = 10)
|
||||
{
|
||||
return Options.Create(new PagingSettings { PageSize = pageSize });
|
||||
return new TestOptionsSnapshot<PagingSettings>(new PagingSettings { PageSize = pageSize });
|
||||
}
|
||||
|
||||
public static SieveModel EmptySieveModel()
|
||||
@@ -95,4 +95,12 @@ internal static class ControllerTestContext
|
||||
Name = name
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class TestOptionsSnapshot<TOptions>(TOptions value) : IOptionsSnapshot<TOptions>
|
||||
where TOptions : class
|
||||
{
|
||||
public TOptions Value => value;
|
||||
|
||||
public TOptions Get(string? name) => value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ public class ProviderSpecificQueryShould
|
||||
ctx.People.Add(ControllerTestContext.CreatePerson());
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
var people = await ctx.People
|
||||
.Where(person => person.FirstName != null && Microsoft.EntityFrameworkCore.EF.Functions.ILike(person.FirstName, "%iv%"))
|
||||
.ToListAsync();
|
||||
var people = await ctx.People
|
||||
.Where(person => person.FirstName != null && Microsoft.EntityFrameworkCore.EF.Functions.ILike(person.FirstName, "%iv%"))
|
||||
.ToListAsync();
|
||||
|
||||
Assert.Single(people);
|
||||
Assert.Equal("Ivan", people[0].FirstName);
|
||||
}
|
||||
Assert.Single(people);
|
||||
Assert.Equal("Ivan", people[0].FirstName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ThrowInvalidOperationExceptionWhenUsingILikeWithInMemoryProvider()
|
||||
|
||||
Reference in New Issue
Block a user