小编jya*_*nks的帖子

Dagger没有为/ test class生成组件

我在这里关注指南:https://github.com/ecgreb/dagger-2-testing-demo

我的app/src/main中有以下设置(省略了注入和@Provides代码):

public class FlingyApplication extends Application {
    @Singleton
    @Component(modules = { FlingyModule.class })
    public interface FlingyComponent
}

@Module
public class FlingyModule
Run Code Online (Sandbox Code Playgroud)

在app/src/test中:

public class TestFlingyApplication extends Application {
    @Singleton
    @Component(modules = { TestFlingyModule.class })
    public interface TestFlingyComponent extends FlingyComponent
}

@Module
public class TestFlingyModule
Run Code Online (Sandbox Code Playgroud)

到目前为止,它几乎与示例github相同.当dagger为src/main中的Component构建器生成代码时,它们会正确生成.但是,Dagger不会在src/test中为Component构建器生成代码.

我的主要build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0-alpha3'

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.5.1'
}
Run Code Online (Sandbox Code Playgroud)

我的app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'


android {
    # There is obviously more in here, but this is the custom part:
    packagingOptions …
Run Code Online (Sandbox Code Playgroud)

android dagger-2

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

单元测试未出现

我在Windows 8 Release Preview上使用Visual Studio Express 2012,我似乎无法让我的单元测试出现在测试资源管理器中.

我有一个名为TestApp.Entity的类,以及TestApp.EntityTest ...

这是我的代码:

namespace TestApp.Entity.Test
{
    using System;
    using System.Net.Http;
    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
    using TestApp.Domain;

    [TestClass]
    public class EntityTests
    {
        [TestMethod]
        public async void TestObject1Deserialize()
        {
            Uri agencyUri = new Uri("*removed*");
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.GetAsync(agencyUri);

            string responseBodyAsText = await response.Content.ReadAsStringAsync();
            List<Agency> agencyList = Deserializers.AgencyDeserialize(responseBodyAsText);

            CollectionAssert.Contains(agencyList, new Agency() { Tag = "*removed*", Title = "*removed*", ShortTitle = "", RegionTitle = "*removed*" });
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

我认为这就是我需要做的全部,但它们仍未出现在测试资源管理器中.任何意见将是有益的.

unit-testing visual-studio-2012 windows-store-apps

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

使用其他程序集中的字体资源

目前,我有一个包含主题/模板和字体(作为资源)的类库项目.然后我在我的主WPF应用程序项目中引用名为Shared.UI的项目.

我使用以下方法引用它:

<ResourceDictionary Source="pack://application:,,,/Shared.UI;component/Skin.xaml" />
Run Code Online (Sandbox Code Playgroud)

在MergedDictionary标记内.

我遇到的问题是主WPF应用程序无法使用项目中的字体作为资源构建.

在我的Shared.UI/Skins.xaml文件中,我有:

<!-- LABEL -->
<Style TargetType="{x:Type Label}">
    <Setter Property="FontFamily" Value="./resources/#Helvetica Neue" />
    <Setter Property="Foreground" Value="{DynamicResource PrimaryBlue}" />
    <Setter Property="FontSize" Value="12" />
</Style>
Run Code Online (Sandbox Code Playgroud)

我假设这在我的主WPF应用程序中不起作用,因为它自己./resources查找#Helvetica Neue并且找不到它(因为它在Shared.UI中).我试图/Shared.UI;component/resources/#Helvetica Neue在资源文件中明确引用,但这对我不起作用.

wpf resources fonts label resourcedictionary

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

在播种数据时查找 id

基本上,我想要做的是用一堆初始数据为我的网络应用程序设置我的数据库。例如,有一个产品列表,所有产品都具有一个 product_type。

seeds.rb有以下代码:

ProductType.delete_all
ProductType.create(:name => 'Furniture')

Product.delete_all
Product.create(:name => 'Chair', :type_id => ProductType.first.id, :packaging => '2 for $20', :price_per => 0.1, :default_packaging_number => 2)
Run Code Online (Sandbox Code Playgroud)

现在,我的问题ProductType.first.id是 只是一个占位符。我真正想做的是放一些类似的东西:

:type_id => ProductType.where(:name => "Furniture").id
Run Code Online (Sandbox Code Playgroud)

问题是,当我这样做时,我得到了一个巨大的数字 (70247318042560),这显然不是 id。控制台也返回警告

warning Object#id will be deprecated; use Object#object_id
Run Code Online (Sandbox Code Playgroud)

当我.object_id在 where 语句的末尾使用时,它仍然返回相同的大且不正确的数字。

如何ProductType从数据库中提取家具的 id ?我需要修改权限或其他东西才能访问它吗?

ruby-on-rails

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

Rails使用多个字段更新单个属性

我正在尝试创建一个名为countcash的表单,允许用户输入实际的季度,硬币,镍币,便士,二十,数十,五,一的数量,然后输入现金箱中任何其他项目的货币价值,然后当他们点击提交时,我想总计这些值并设置我当前班次记录的cashstart字段.

真正的问题是,我不确定我的表单应该是什么样子以及在这种情况下应该如何设置控制器/模型.

我有一个shift_id保存在一个session[:shift_id]变量中,其中id的转移是我想用计算的cashstart修改的转移.

<%= form_for %>如果我想正确地遵循MVC,那么标签需要看起来是什么?如何设置控制器/模型以使用计算值更新数据库?我该怎么设置路线?我在堆栈溢出或其他rails论坛上找不到这样的东西(尽管你认为通过多个文本字段修改单个属性会非常简单)

作为参考,这是我以前使用的形式(无济于事)

应用/视图/ countcash.html.erb

<%= form_for @shift do |f| %>   

<table>
  <tr>  
    <th>Coins</th>
    <th></th>
  </tr>

  <tr>
    <td>Quarters: </td>
    <td><%= f.text_field :quarters %><br /></td>
  </tr>

  <tr>
    <td>Dimes: </td>
    <td><%= f.text_field :dimes %><br /></td>
  </tr>

  <tr>
    <td>Nickels: </td>
    <td><%= f.text_field :nickels %><br /></td>
  </tr>

  <tr>
    <td>Pennies: </td>
    <td><%= f.text_field :pennies %><br /></td>
  </tr>

  <tr>
    <th>Bills</th>
    <th></th>
  </tr>

  <tr>
    <td>Twenties: </td>
    <td><%= f.text_field :twenties %><br /></td>
  </tr>

  <tr>
    <td>Tens: </td>
    <td><%= f.text_field :tens …
Run Code Online (Sandbox Code Playgroud)

forms ruby-on-rails

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