小编ser*_*gpa的帖子

单元测试中的进度指示

我有一个很长的单元测试,我想要一些反馈和进度指示。我已经尝试使用 Debug.Writelline()、相应的 Console 和 Trace 方法,但是我无法从我的测试中获得输出。

任何人都可以帮忙吗?我正在使用 Visual Studio 2012、xUnit 和 Resharper。网上有很多关于这个的文章,但没有一篇能解决问题。

谢谢,米

c# resharper unit-testing xunit visual-studio

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

AngularJS:使用timeout属性取消$ http请求

我已经看过很多关于这个主题的帖子,以及很多网络文章,但我仍然对我的问题感到难过.我发现这篇文章非常有用,但我的timeoutRequest()函数永远不会被调用.

我使用的是具有$ http的超时属性的promise,但是基础HTTP请求没有被取消.我认为承诺本身正在解决,但请求未被取消.

我的控制器行为如下所示:

$scope.enquiriesSelected = function() {
    $scope.cancelHttpRequests();
    $location.path("/enquiries");
};

$scope.cancelHttpRequests = function () {
    console.log(canceller.promise.$$state);
    canceller.resolve("User cancelled");
    console.log(canceller.promise.$$state);
};
Run Code Online (Sandbox Code Playgroud)

我的HTTP请求承诺如下所示:

var canceller = $q.defer();

$scope.searchResultsPromise = $http({
        url: "/api/customers/customersearch",
        method: "POST",
        data: criteria,
        timeout: canceller.promise 
    })
    .success(function(data) {
        $scope.customerSearchResults = data;
    });
Run Code Online (Sandbox Code Playgroud)

我已经尝试了各种方法来实现这一点,包括将取消器放在$ scope中.

我一直在查看AngularJS源代码,我发现这些行:

if (timeout > 0) {
    var timeoutId = $browserDefer(timeoutRequest, timeout);
} else if (isPromiseLike(timeout)) {
    timeout.then(timeoutRequest);
}

function timeoutRequest() {
    jsonpDone && jsonpDone();
    xhr && xhr.abort();
}
Run Code Online (Sandbox Code Playgroud)

但是,当我的承诺得到解决时,执行路径不会到达这些行.永远不会调用xhr.abort(),这是AngularJS源代码中唯一中止HTTP请求的地方.

在尝试取消请求时使用F12(Chrome)中的控制台进行检查会发现promise的$$状态从0变为1,因此我可以肯定该承诺正在解决.但是,在网络流量中,HTTP请求未被取消.在HTTP请求完成之前,我无法导航到另一个页面.

有人可以帮忙吗?

中号

javascript angularjs

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

RxJS主题和Angular2组件

我接受了Web开发正在发生变化的事实,我需要掌握RxJS.我目前正在使用Angular 2.0.0-beta.15开发一个Web应用程序.

我正在关注最优秀的ng-book 2(这种广告是否允许?哦,好吧).它涵盖了RxJS中的一些重要概念,并提供了进一步阅读的链接.我已经阅读并理解了源代码和附带的解释,但是我对于某些关于Subjects的细节以及Angular 2组件如何使用这些主题流有点暗淡.

我这样增加了书中的代码:

export class SubmitResourceComponent {
    private _newResourceTags: Subject<Tag> = new Subject<Tag>();
    private _resourceTags: Observable<Tag[]>;
    private _tagUpdates: Subject<any> = new Subject<any>();
    private _create: Subject<Tag> = new Subject<Tag>();
    private _remove: Subject<Tag> = new Subject<Tag>();

    constructor() {
        this._resourceTags = this._tagUpdates
            .scan((tags: Tag[], operation: ITagsOperation) => operation(tags), initialTags);

        this._create
            .map((tag: Tag): ITagsOperation => (tags: Tag[]) => _.uniq(tags.concat(tag)))
            .subscribe(this._tagUpdates);

        this._remove
            .map((tag: Tag): ITagsOperation => (tags: Tag[]) => _.without(tags, tag))
            .subscribe(this._tagUpdates);

        this._newResourceTags.subscribe(this._create);
    }

    get resourceTags(): Observable<Tag[]> { …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular

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

Angular 2和Visual Studio 2015与ReSharper 2016.1

我正在使用Visual Studio Code在Mac OS X下开发webpack Angular 2.0.0-rc.1应用程序,但我正在尝试将编辑迁移到Parallels下的Visual Studio 2015.我想保持实际的构建过程在OS X中运行.我这样做是因为我在使用几个月后发现Visual Studio Code非常有限.

ReSharper 2016.1抱怨我的很多TypeScript.例如,它不喜欢@Component@RouteConfig抱怨它无法解析符号.我有几个选项 - 我可以禁用ReSharper(否),我可以禁用检查(否),...等等.

我该怎么办?我已经将ReSharper配置为使用TypeScript 1.8,但我不确定我还能做些什么.

由于某种原因,它无法找到导入中定义的Router类或ROUTER_DIRECTIVES对象:

import { RouteConfig, Router, ROUTER_DIRECTIVES } from '@angular/router-deprecated';
Run Code Online (Sandbox Code Playgroud)

它们未在此导入中暗示,但稍后在代码中暗示.有很多这样的错误,有一些错误要枚举.

任何使用Angular 2与Visual Studio 2015和ReSharper 2016.1的人都有成功吗?

resharper typescript webpack visual-studio-2015 angular

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

导出的常量未定义(Angular、TypeScript)

我有一个文件声明了一些常量,如下所示:

// color-constants.ts: no imports in this file
export const aoiToImageMaterial = new Cesium.ColorMaterialProperty(
    new Cesium.Color(0.4, 0.6, 0.8, 0.1)
);

export const aoiToImageOutline = new Cesium.Color(0.4, 0.6, 0.8, 1);
Run Code Online (Sandbox Code Playgroud)

但是,当我将它们导入我的 Angular 组件文件时,它们返回undefined

import { Component, Input } from '@angular/core';

import { Aoi } from '../../../models/aoi.model';
import * as colorConstants from '../../color-constants';

@Component({
  selector: 'cs-aoi',
  templateUrl: './aoi.component.html',
  styleUrls: ['./aoi.component.scss']
})
export class AoiComponent {
  @Input('aoi') aoi: Aoi;

  materialProperty;
  outlineColor;

  constructor() {
    this.materialProperty = colorConstants.aoiToImageMaterial; // undefined
    this.outlineColor = colorConstants.aoiToImageOutline; …
Run Code Online (Sandbox Code Playgroud)

typescript angular cesiumjs

5
推荐指数
0
解决办法
1065
查看次数

ts-loader(webpack)上挂着的“ npm run”

我正在Mac OS X 10.11.3上使用webpack构建一个包含静态HTML和其他资产的Web应用程序。该应用程序与另一台服务器上的API通讯。

我在使用webpack构建应用程序时遇到问题。构建过程似乎挂在ts-loader执行过程中或周围。我正在运行这样的构建:

npm run go --loglevel verbose
Run Code Online (Sandbox Code Playgroud)

从我的package.json中执行以下命令:

./node_modules/.bin/webpack-dev-server --display-reasons --display-chunks --watch
Run Code Online (Sandbox Code Playgroud)

终端窗口中的输出以结尾

ts-loader: Using typescript@1.7.5 and /Users/mn/Documents/source/J/appstore/store-front/app/ts/tsconfig.json
Run Code Online (Sandbox Code Playgroud)

我尝试删除node_modules文件夹并重新安装它们;我尝试卸载webpack并重新安装;我已经尝试将webpack.config.js还原为我知道可以使用的版本;但它只是挂在这里!

我的webpack.config.js看起来像这样:

var webpack = require('webpack'),
    ReloadPlugin = require('webpack-reload-plugin'),
    path = require('path'),
    ChunkManifestPlugin = require('chunk-manifest-webpack-plugin'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    WebpackNotifierPlugin = require('webpack-notifier'),
    ExtractTextPlugin = require("extract-text-webpack-plugin");

/**
 * optimist has been depracted. Find an alternative? minimist?  
 */
var argv = require('optimist')
    .alias('r', 'release').default('r', false)
    .argv;

/**
 * Useful variables
 */
var cwd = process.cwd();
var DEBUG = !argv.release;
var isDevServer = …
Run Code Online (Sandbox Code Playgroud)

node.js typescript webpack visual-studio-code ts-loader

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

@ ngrx/effects:测试一个效果返回empty()

我正在使用@ ngrx/effects 4.1.1.我有一个效果,返回一个像这样的空observable:

@Effect() showDialog$: Observable<Action> = this
.actions$
.ofType( ActionTypes.DIALOG_SHOW )
.map( ( action: DialogAction ) => action.payload )
.switchMap( payload => {
    this.dialogsService.showDialog( payload.className );
    return empty();
} );
Run Code Online (Sandbox Code Playgroud)

我正在尝试按照这些指南编写一个单元测试,测试该效果会产生一个空的可观察量.我有这个:

describe( 'DialogEffects', () => {
    let effects: DialogEffects;
    let actions: Observable<any>;
    const mockDialogService = {
        showDialog: sinon.stub()
    };

    beforeEach( () => {
        TestBed.configureTestingModule( {
            providers: [
                DialogEffects, provideMockActions( () => actions ),
                {
                    provide: DialogsService,
                    useValue: mockDialogService
                }
            ]
        } );

        effects = TestBed.get( DialogEffects ); …
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine ngrx-effects angular

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

SwiftUI 的 List 如何更新选择绑定?

我真的很难理解这是如何List(selection:)导致选择绑定更新的。

我正在https://developer.apple.com/documentation/swiftui/building_a_great_mac_app_with_swiftui上取消选择 Apple 示例代码

该项目是Session2/Part2-End/GardenApp.xcodeproj

左侧有一个侧边栏,右侧有主要细节视图。看起来ContentView像这样:

struct ContentView: View {
    @EnvironmentObject var store: Store
    @SceneStorage("selection") private var selectedGardenID: Garden.ID?
    @AppStorage("defaultGarden") private var defaultGardenID: Garden.ID?

    var body: some View {
        NavigationView {
            Sidebar(selection: selection)
            GardenDetail(garden: selectedGarden)
        }
    }

    private var selection: Binding<Garden.ID?> {
        Binding(get: { selectedGardenID ?? defaultGardenID }, set: { selectedGardenID = $0 })
    }

    private var selectedGarden: Binding<Garden> {
        $store[selection.wrappedValue]
    }
}
Run Code Online (Sandbox Code Playgroud)

和侧边栏是这样的:

struct Sidebar: View {
    @EnvironmentObject var store: Store
    @SceneStorage("expansionState") var …
Run Code Online (Sandbox Code Playgroud)

swift swiftui

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

基类中的属性未出现在视图模型中

我有一个看起来像这样的基类:

public class EformBase
{
    public decimal Latitude { get; set; }
    public decimal Longitude {get;set;}
    // lots of other properties here
}
Run Code Online (Sandbox Code Playgroud)

和一个看起来像这样的派生类:

public class GraffitiViewModel : EformBase
{
    public RadioButtonList<YesNoType> GraffitiOffensive { get; set; }
    public RadioButtonList<YesNoType> GraffitiTag { get; set; }
    // other properties here
}
Run Code Online (Sandbox Code Playgroud)

我在MVC中使用此类作为视图模型.不幸的是,当回发视图模型时,基类中的属性不会出现在视图模型中.像这样:

[HttpPost]
public ActionResult Index(GraffitiViewModel vm)
{
   // add to database code
}
Run Code Online (Sandbox Code Playgroud)

当回发到此操作时,vm不包括基类中指定的经度和纬度.我错过了什么?我是否必须为基类做一些特殊的事情?

c# asp.net-mvc asp.net-mvc-5

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

当我可以在 S3 管理控制台中看到该文件时,为什么 AWS S3 返回 404?

我的标题几乎概括了我的问题。我已使用 Web 界面上传文件,可以启动index.html,但资产文件夹中的 PDF 返回 404。

服务器响应:

404 Not Found

Code: NoSuchKey
Message: The specified key does not exist.
Key: assets/PDF/piano0817.pdf
RequestId: 02770C292FC4DBFA
HostId: zSn07EPw7JngHLCdcveteFDJNKATslKDCSKkJSAhsFsbW+gfeVQwvFMu3WMcY513iwt32F/OG1c=```
Run Code Online (Sandbox Code Playgroud)

我已经等待了规定的时间,但 S3 仍然无法提供我的 PDF。我究竟做错了什么?

amazon-s3 amazon-web-services

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