小编Iva*_*tan的帖子

如何根据XUnit测试隔离EF InMemory数据库

我正在尝试使用InMemory EF7数据库进行我的xunit存储库测试.

但我的问题是,当我尝试Dispose创建的上下文时,内存db仍然存在.这意味着一个测试涉及其他.

我已阅读这篇文章单元测试实体框架7与内存中的数据存储和我试图安装在我的TestClass的构造背景.但这种方法不起作用.当我单独运行测试时一切正常,但我的第一个测试方法是在DB中添加一些东西,第二个测试方法从之前的测试方法开始使用脏DB.我尝试添加IDispose到测试类,但方法DatabaseContext和DB在内存中持久存在.我错了什么我错了什么?

我的代码看起来像:

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Fabric.Tests.Repositories
{
    /// <summary>
    /// Test for TaskRepository 
    /// </summary>
    public class TaskRepositoryTests:IDisposable
    {

        private readonly DatabaseContext contextMemory;

        /// <summary>
        /// Constructor
        /// </summary>
        public TaskRepositoryTests()
        {
            var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
            optionsBuilder.UseInMemoryDatabase();
            contextMemory = new DatabaseContext(optionsBuilder.Options);

        }

        /// <summary>
        /// Dispose DB 
        /// </summary>
        public void Dispose()
        {
            //this has no effect 
            if (contextMemory != null)
            { …
Run Code Online (Sandbox Code Playgroud)

.net c# in-memory-database entity-framework-core .net-core

27
推荐指数
2
解决办法
7207
查看次数

通过给定的@decorators 获取所有类/构造函数

大家好,我想知道是否有可能获得所有给定装饰器 javascript/typescript 的类。

例如我有课

@mydecorator
class SomeClass1{
}
Run Code Online (Sandbox Code Playgroud)

还有一些在模块中

@mydecorator
class SomeClass2{
}
Run Code Online (Sandbox Code Playgroud)

然后在运行时的其他模块中,我想获得所有具有装饰器 @mydecorator 的类或构造函数......恐怕这是不可能的:(

export function getaAllClassesByDecorator(decorator:string){
... return constructor or something that  i am able to call static method 
}
Run Code Online (Sandbox Code Playgroud)

javascript typescript

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

JavaScript从实数和整数中计算哈希码

嗨,我需要函数来计算从数字(实数双精度)和整数的唯一整数.

尝试解释我正在开发javascript中的GIS应用程序,我正在使用复杂的矢量对象,如polygon(点对象数组,环中有两个坐标)和点数组.我需要快速算法来识别元素已被更改它必须非常快,因为我的矢量对象是千点的集合.在C#中,我使用按位运算XOR从坐标计算哈希码.

但是javascript将按位运算中的所有操作数转换为整数,但我需要在c#way(binnary)中按位置应用之前将双精度转换为整数.在反射器中,我看到c#计算哈希码这样的双倍,我需要这个函数在javascript中尽可能快.

public override unsafe int GetHashCode() //from System.Double
{
    double num = this;
    if (num == 0.0)
    {
        return 0;
    }
    long num2 = *((long*) &num);
    return (((int) num2) ^ ((int) (num2 >> 32)));
}
Run Code Online (Sandbox Code Playgroud)

例:

var rotation = function (n) {
    n = (n >> 1) | ((n & 0x001) << 31);
    return n;
}

var x: number = 1;
var y: number = 5;

var hash = x ^ rotation(y); // result is -2147483645

var x1: …
Run Code Online (Sandbox Code Playgroud)

javascript html5 typescript

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

Material UI v1.0.0如何覆盖Stepper类以设置图标大小

我现在正在迁移到新版本的Material UI。我不得不说,我有点困惑如何重写类。

我需要使用带有替代标签的Stepper,它对我有用,我能够覆盖根类以设置透明背景。

但是我需要将步骤图标大小设置为42px,但我不成功。

我的代码看起来:

    const styles = {
        root: {
            backgroundColor: "rgba(255, 0, 0, 0)",
        }
    };

    const MyStepper = (props) => {
        return (
            <Stepper
                activeStep={props.activeStep}
                alternativeLabel
                classes={{
                    root: props.classes.root,               
                }}
            >
                {props.children}
            </Stepper>        
        );
    }

    const StyledStepper = withStyles(styles)(MyStepper);

    export default class CheckoutStepper extends React.PureComponent<ICheckoutStepperProps, {}> {

    public render() {

        return <div >
            <StyledStepper
                activeStep={this.props.step}
                >
                <Step>
                    <StepLabel>
                        {stepTable[0].label}
                    </StepLabel>
                </Step>
                <Step>
                    <StepLabel>
                        {stepTable[1].label}
                    </StepLabel>
                </Step>
                <Step >
                    <StepLabel>{stepTable[2].label}</StepLabel>
                </Step>
                <Step>
                    <StepLabel>{stepTable[3].label}</StepLabel>
                </Step>
            </StyledStepper>
        </div>; …
Run Code Online (Sandbox Code Playgroud)

css typescript reactjs material-ui

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