小编Pau*_*aul的帖子

Moq.Mock <T> - 如何设置一个表达式的方法

我正在模拟我的存储库接口,我不知道如何设置一个接受表达式并返回一个对象的方法?我正在使用Moq和NUnit

接口:

public interface IReadOnlyRepository : IDisposable
{
    IQueryable<T> All<T>() where T : class;
    T Single<T>(Expression<Func<T, bool>> expression) where T : class;
}
Run Code Online (Sandbox Code Playgroud)

使用IQueryable进行测试已经设置,但不知道如何设置T Single:

private Moq.Mock<IReadOnlyRepository> _mockRepos;
private AdminController _controller;
[SetUp]
public void SetUp()
{
    var allPages = new List<Page>();
    for (var i = 0; i < 10; i++)
    {
        allPages.Add(new Page { Id = i, Title = "Page Title " + i, Slug = "Page-Title-" + i, Content = "Page " + i + " on page content." …
Run Code Online (Sandbox Code Playgroud)

c# nunit unit-testing moq

29
推荐指数
2
解决办法
2万
查看次数

使用C#与实体框架CTP 4的域建模问题

我正在尝试建立一个包含照片集的相册.每个专辑都有一组照片和一张拇指照片.这就是我所拥有的,但EF似乎并不喜欢它:

public class Album : IEntity {
        private DateTime _dateCreated;

        public Album() {
            _dateCreated = SystemTime.Now();
            Photos = new List<Photo>();
        }
        public long Id { get; set; }
        public string Name { get; set; }
        public string Location { get; set; }
        public DateTime DateCreated
        {
            get { return _dateCreated; }
            set { _dateCreated = value; }
        }
        public virtual Site Site { get; set; }
        public virtual Photo Thumbnail { get; set; }
        public virtual ICollection<Photo> Photos { get; …
Run Code Online (Sandbox Code Playgroud)

domain-driven-design entity-framework-4 ef-code-first

6
推荐指数
1
解决办法
657
查看次数

构建实体框架CPT5的EntityTypeConfiguration列表的思考

我不想手动将每个映射类添加到ModelBuilder()中,因此尝试使用我有限的反射知识来注册它们.这就是我所拥有的,这是我得到的错误:

码:

private static ModelBuilder CreateBuilder() {
            var contextBuilder = new ModelBuilder();
            IEnumerable<Type> configurationTypes = typeof(DatabaseFactory)
                .Assembly
                .GetTypes()
                .Where(type => type.IsPublic && type.IsClass && !type.IsAbstract && !type.IsGenericType && typeof(EntityTypeConfiguration).IsAssignableFrom(type) && (type.GetConstructor(Type.EmptyTypes) != null));

            foreach (var configuration in configurationTypes.Select(type => (EntityTypeConfiguration)Activator.CreateInstance(type)))
            {
                contextBuilder.Configurations.Add(configuration);
            }

            return contextBuilder;
        }
Run Code Online (Sandbox Code Playgroud)

错误: 错误2无法从用法推断出方法'System.Data.Entity.ModelConfiguration.Configuration.ConfigurationRegistrar.Add(System.Data.Entity.ModelConfiguration.EntityTypeConfiguration)'的类型参数.尝试显式指定类型参数.C:\ root\development\playground\PostHopeProject\PostHope.Infrastructure.DataAccess\DatabaseFactory.cs 67 17 PostHope.Infrastructure.DataAccess

c# reflection entity-framework-4

6
推荐指数
1
解决办法
4293
查看次数

C#UTC到用户本地时间

我有一个用户可以发帖的网站.用户可以来自全球各地,所以当他们发布时,我将发布的日期存储为DateTime.UtcNow.我正在使用JQuery时间插件显示发布的数据类似于堆栈溢出(1分钟前等...)但我不知道如何转换为我已存储在系统中的日期到用户当地时间?这是我正在使用的:

public static MvcHtmlString ConvertToLocalTime(this HtmlHelper htmlHelper, DateTime date)
    {
        DateTime convertedDate = DateTime.SpecifyKind(DateTime.Parse(date.ToString()),DateTimeKind.Utc);
        return MvcHtmlString.Create(convertedDate.ToLocalTime().ToString());
    }
Run Code Online (Sandbox Code Playgroud)

这看到将时间转换为服务器本地时间,但我需要它为用户本地时间.我究竟做错了什么?我正在使用.NET MVC 2和.NET 4.0

c# asp.net .net-4.0 asp.net-mvc-2

5
推荐指数
1
解决办法
1万
查看次数

jquery ui autocomplete with delegate

我根据文档设置了JQuery UI自动完成功能,它适用于任何带有class ="tag-item"的输入,该输入被呈现给页面.但是,用户可以通过JS将输入添加到dom中,因此我需要一种方法使用委托将自动完成绑定到新动态创建的输入.我不确定如何设置,任何想法将不胜感激.

谢谢

jquery delegates jquery-ui

4
推荐指数
2
解决办法
3642
查看次数

显示填充Stackoverflow和Facebook的时间 - C#

我正在构建一个ASP.NET MVC 2应用程序,允许用户在某些部分发布数据.我想以Stackoverflow和Facebook所做的相同格式显示"发布于".

即在我发布此问题的网站上,它将显示"问3秒前",然后"询问3分钟前",几天后它将显示日期.

我的应用程序是C#,如果有人能指出我正确的方向,以最好的方式完成这将是伟大的!

.net c# asp.net asp.net-mvc asp.net-mvc-2

4
推荐指数
1
解决办法
366
查看次数

在构造函数中使用HttpContextBase时出现Structuremap错误

我正在.NET 4.0上构建一个ASP.NET MVC 2.0应用程序,并使用Structuremap 2.6.1 for IoC.我最近添加了一个ICookie和Cookie类,Cookie类将HttpContextBase作为构造函数参数(见下文),现在当我运行我的应用程序时,我收到此错误:没有为PluginFamily System.Web.HttpContextBase定义默认实例.

我之前在另一个具有相同堆栈的MVC应用程序中使用过此方法,但没有收到此错误.我错过了什么吗?如果我确实需要在我的structuremap配置文件中为HttoContextBase添加一些映射代码,我会使用什么?

帮助会很棒!!!

Cookie.cs

public class Cookie : ICookie
{
    private readonly HttpContextBase _httpContext;
    private static bool defaultHttpOnly = true;
    private static float defaultExpireDurationInDays = 1;
    private readonly ICryptographer _cryptographer;
    public Cookie(HttpContextBase httpContext, ICryptographer cryptographer)
    {
        Check.Argument.IsNotNull(httpContext, "httpContext");
        Check.Argument.IsNotNull(cryptographer, "cryptographer");
        _cryptographer = cryptographer;
        _httpContext = httpContext;
    }
    public static bool DefaultHttpOnly
    {
        [DebuggerStepThrough]
        get { return defaultHttpOnly; }

        [DebuggerStepThrough]
        set { defaultHttpOnly = value; }
    }

    public static float DefaultExpireDurationInDays
    {
        [DebuggerStepThrough]
        get …
Run Code Online (Sandbox Code Playgroud)

structuremap asp.net .net-4.0 asp.net-mvc-2

1
推荐指数
1
解决办法
2700
查看次数

为什么MVC认为同一页面上的多个不同地址是SEO友好的?

它引起了我的注意,http://www.example.com/Home/About被认为是完全不同的http://www.example.com/homE/abouT,但它们是相同的页面,并且都有标题响应200.

这些URL应该全部为大写或大写,并且任何变体都应返回301并重定向到所有小写或大写的URL.

这可能适用于"AboutUs"页面,但如果你说的是一个拥有大量产品的大型商店,这可能会杀死你将来或将来可能获得的任何排名.

希望MVC/ASP.NET可以使用某种选项在路由引擎中设置严格的URL.

model-view-controller seo

-5
推荐指数
1
解决办法
237
查看次数