小编Kil*_*ine的帖子

内联形式的Bootstrap全角文本输入

我正在努力创建一个适合我的容器区域的整个宽度的文本框.

<div class="row">
    <div class="col-md-12">
        <form class="form-inline" role="form">           
                <input type="text" class="form-control input-lg" id="search-church" placeholder="Your location (City, State, ZIP)">
                <button type="submit" class="btn btn-lg">Search</button>            
        </form>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

当我执行上述操作时,正如我所料,这两个表单元素是内联的,但最多只占用几列.徘徊col-md-12在萤火虫的div上显示它占据了预期的全宽.它只是文本输入似乎没有填补.我甚至尝试添加一个内嵌宽度值,但它没有改变任何东西.我知道这应该很简单,现在感觉真的很蠢.

这是一个小提琴:http://jsfiddle.net/52VtD/4119/embedded/result/

编辑:

选择的答案在各方面都是彻底的,并提供了很好的帮助.这就是我最终使用的东西.但是我认为我的初始问题实际上是Visual Studio 2013中默认MVC5模板的问题.它包含在Site.css中:

input,
select,
textarea {
    max-width: 280px;
}
Run Code Online (Sandbox Code Playgroud)

显然这阻止了文本输入的适当扩展......对未来的ASP.NET模板用户的公平警告......

html css twitter-bootstrap-3

134
推荐指数
3
解决办法
21万
查看次数

NUnit 3.0和Assert.Throws

我正在使用NUnit 3.0编写一些单元测试,并且与v2.x不同,ExpectedException()它已从库中删除.

根据这个答案,我绝对可以看到试图捕捉特定位置的逻辑,在测试中人们期望他们的系统抛出异常(而不是仅仅说"测试中的任何地方").

但是,我倾向于非常清楚我的Arrange,Act和Assert步骤,这使它成为一个挑战.

我曾经做过类似的事情:

[Test, ExpectedException(typeof(FormatException))]
public void Should_not_convert_from_prinergy_date_time_sample1()
{
    //Arrange
    string testDate = "20121123120122";

    //Act
    testDate.FromPrinergyDateTime();

    //Assert
    Assert.Fail("FromPrinergyDateTime should throw an exception parsing invalid input.");
}
Run Code Online (Sandbox Code Playgroud)

现在我需要做一些事情:

[Test]
public void Should_not_convert_from_prinergy_date_time_sample2()
{
    //Arrange
    string testDate = "20121123120122";

    //Act/Assert
    Assert.Throws<FormatException>(() => testDate.FromPrinergyDateTime());
}
Run Code Online (Sandbox Code Playgroud)

这并不可怕,但在我看来,这种行为和断言是混乱的.(显然,对于这个简单的测试,它并不难理解,但在更大的测试中可能更具挑战性).

我有一位同事建议我Assert.Throws完全摆脱,只做以下事情:

[Test]
public void Should_not_convert_from_prinergy_date_time_sample3()
{
    //Arrange
    int exceptions = 0;
    string testDate = "20121123120122";

    //Act
    try
    {
        testDate.FromPrinergyDateTime();
    }
    catch (FormatException) { exceptions++;}

    //Assert
    Assert.AreEqual(1, exceptions);
}
Run Code Online (Sandbox Code Playgroud)

在这里,我坚持严格的AAA格式,但代价是更加臃肿. …

c# nunit unit-testing

64
推荐指数
3
解决办法
3万
查看次数

每个类实例的唯一日志文件

我目前正在运行一个创建多个类实例的Windows服务.

在服务类的顶部和我的解决方案中的每个其他类,我有这样的事情:

private static readonly ILog _log = LogManager.GetLogger(typeof(SomeClassTypeHere));
Run Code Online (Sandbox Code Playgroud)

在我的App.config中,我为单个文件配置了Log4Net:

<log4net debug="true">
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="Logs\SomeLogFileName.xml" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <countDirection value="1" />
      <maxSizeRollBackups value="30" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
        <locationInfo value="true" />
      </layout>
    </appender>

    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
    </root>
  </log4net>
Run Code Online (Sandbox Code Playgroud)

这在大多数方面都很有效,并且所有内容都记录到单个文件中.但是,我真的想为我的服务创建的特定类的每个实例创建一个单独的日志文件.
这是一个我们经常需要监视以获得支持的类,我们可以同时运行少量实例.
我们不知道哪些实例将在给定时间运行,因此它使得在配置中创建静态文件有点痛苦.

我尝试取消readonly修饰符并在类构造函数中设置以下内容:

_log = LogManager.GetLogger("DataCollectionClass_" + deviceName + "_" + DateTime.Now.ToString("MMddyyyy"), typeof(SomeClassTypeHere));
Run Code Online (Sandbox Code Playgroud)

但这需要我在配置中手动定义一个appender,这将是繁琐且难以跟上的.

有关在L4N这样做的任何想法?我在这里看过链接,但不知道是否需要那么多的框架.

c# service logging log4net

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

Visual Studio代码 - 删除包含条件的行

这可能不是VS Code特定的问题,但它是我选择的工具.

我有一个日志文件,其中包含许多行,包含以下内容:

Company.Environment.Security.RightsBased.Policies.RightsUserAuthorizationPolicy

这些是调试级别的日志记录,混乱了我正在尝试处理的文件.我想删除包含该内容的行.

我查看了Regex但是,不像删除一个空白行,你在搜索条件中有完整的内容(使查找/替换变得简单),这里我需要在两个之间的某些标准上从换行符到换行符匹配,我认为...

您对这样的标准如何运作有何看法?

regex visual-studio-code

12
推荐指数
3
解决办法
9191
查看次数

数据绑定WPF中的Enum属性

以下是我所拥有的课程的简化示例:

public class ExampleClassDto 
{
     public int DriverTypeId
}
Run Code Online (Sandbox Code Playgroud)

我还有一个Enum,它将DriverType的Ids映射到有意义的名称:

public enum DriverType
{
    None,
    Driver1,
    Driver2,
    Driver3
}
Run Code Online (Sandbox Code Playgroud)

但是我希望将它在XAML中绑定到一个组合框.不幸的是,由于类型不匹配,它不喜欢这个.所以在我的ViewModel中,我必须创建第二个属性来映射这两个

public class ExampleViewModel
{
    private ExampleClassDto _selectedExampleClass;
    public ExampleClassDto SelectedExampleClass
    {
        get { return _selectedExampleClass; }
        set
        {
            _selectedExampleClass = value;
            SelectedDriverType = (DriverType)_selectedExampleClass.DriverTypeId;
            OnPropertyChanged("SelectedDeviceType");
        }
    }

public DriverType SelectedDriverType
{
    get
        {
            if (_selectedDeviceType != null) 
            { 
                return (DriverType)_selectedDeviceType.DriverTypeId;
            }
            return DriverType.None;
        }
        set
        {
            _selectedDeviceType.DriverTypeId = (int) value;
            OnPropertyChanged("SelectedDriverType");
        }
}
}
Run Code Online (Sandbox Code Playgroud)

然后我绑定到新属性.

<ComboBox ItemsSource="{Binding Source={StaticResource DriverTypeEnum}}" SelectedValue="{Binding …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf xaml

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

单元测试自定义ConfigurationElement和ConfigurationElementCollection

我创建了一个自定义ConfigurationElement,ConfigurationSection以便在启动时更容易设置一系列应用程序参数.但是,我真的很想对这个逻辑进行单元测试.

ServiceConnection

public class ServiceConnection : ConfigurationElement
{
    [ConfigurationProperty("locationNumber", IsRequired = true)] 
    public string LocationNumber
    {
        get { return (string) base["locationNumber"]; }
        set { base["locationNumber"] = value; }
    }

    [ConfigurationProperty("hostName", IsRequired = true)]
    public string HostName
    {
        get { return (string) base["hostName"]; }
        set { base["hostName"] = value; }
    }

    [ConfigurationProperty("port", IsRequired = true)]
    public int Port
    {
        get { return (int) base["port"]; }
        set { base["port"] = value; }
    }

    [ConfigurationProperty("environment", IsRequired = true)]
    public …
Run Code Online (Sandbox Code Playgroud)

c# nunit unit-testing rhino-mocks configuration-files

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

返回 EFcore 中新增的记录

我正在使用 EFCore 制作原型,并努力寻找一种好方法来返回我刚刚添加到实体集合中的对象。

例如:

public Songleader AddSongleader(int congregationId, Songleader songleader)
{
    var congregation = _dbContext.Congregations.Include(c => c.Songleaders).FirstOrDefault(c => c.Id == congregationId);
    congregation.Songleaders.Add(songleader);                        
    _dbContext.SaveChanges();

    //TODO: return the recently-added record...
    return null;
}
Run Code Online (Sandbox Code Playgroud)

ACongregation有一个集合Songleaders。但是,一旦保存上下文,我就不确定返回新实例的好方法。Songleader的Id是在插入数据库时​​生成的,因此我不能只返回传递给方法的对象......

是否有一个好的策略或者 EF 中的某些内容可以在这种情况下提供帮助?

c# entity-framework .net-core

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

.NET Core 2.0 用户秘密和单元测试

我目前正在研究使用Microsoft 应用程序机密管理的 .net 核心解决方案(多个项目)。我可以在我的运行时项目(例如控制台应用程序)中拉回机密,但是当谈到在单独的项目(例如 Model.Test 项目)中利用用户机密进行集成测试时,正确的方法是什么?

我能想到几个选择:

  1. 给每个项目相同的UserSecretsId:这对于可能利用运行时项目使用的相同秘密的测试项目来说似乎是有意义的。

  2. 让每个项目都独一无二UserSecretsId:这将需要在开发机器上手动保持机密同步

似乎即使在 .net core 1.0 和 2.0 之间,用户机密也发生了一些变化,而且我对这个系统一般不太熟悉。谢谢!

security unit-testing .net-core

7
推荐指数
2
解决办法
1782
查看次数

ModelState无效时触发InvalidModelStateResponseFactory

我正在使用 asp.net core 3.0 编写一个 API,并为所有控制器配置了以下行为的应用程序:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers()
        .ConfigureApiBehaviorOptions(setupAction =>
        {
            setupAction.InvalidModelStateResponseFactory = context =>
            {
                var problemDetails = new ValidationProblemDetails(context.ModelState)
                {
                    Type = "https://courselibrary.com/modelvalidationproblem",
                    Title = "One or more model validation errors occurred.",
                    Status = StatusCodes.Status422UnprocessableEntity,
                    Detail = "See the errors property for details",
                    Instance = context.HttpContext.Request.Path
                };

                problemDetails.Extensions.Add("traceId", context.HttpContext.TraceIdentifier);

                return new UnprocessableEntityObjectResult(problemDetails)
                {
                    ContentTypes = { "application/problem+json" }
                };
            };
        });
    ...
}
Run Code Online (Sandbox Code Playgroud)

[Required]这对于我的输入(例如:)类属性上的数据注释非常有效。如果任何注释失败,它会返回 422 Unprocessable Entity 响应,如下所示:

{
    "type": "https://courselibrary.com/modelvalidationproblem",
    "title": "One …
Run Code Online (Sandbox Code Playgroud)

c# rest fluentvalidation asp.net-core

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

Serilog未写入文件(.net core 2.2)

我正在编写使用Serilog的Web服务。我在使文件写出来时遇到问题(但控制台日志记录有效)。我注意到,基于以及页面的说明,.net core 2.0发行时,设置发生了变化。

但是,现在,我看不到任何日志记录(也许过去默认的M $记录器实际上就是我所看到的)。

以下是如何program.cs设置:

public class Program
    {
        public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .AddUserSecrets<Startup>()
            .Build();

        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .ReadFrom.Configuration(Configuration.GetSection("Serilog"))
                .CreateLogger();

            try
            {
                Log.Information("Starting webhost...");
                BuildWebHost(args).Run();
                return 0;
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
                return 1;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }

        public static …
Run Code Online (Sandbox Code Playgroud)

c# logging serilog .net-core

6
推荐指数
2
解决办法
4355
查看次数